写在前面
在macOS里面构建qt项目的方法[^1], 下面是cmakelists
文件.
cmake文件
cmake_minimum_required(VERSION 3.21)
project(QtApp)
set(CMAKE_CXX_STANDARD 17)
#激活自动生成moc文件(通过qmake编译)选项
set(CMAKE_AUTOMOC ON)
#激活自动处理rcc文件(即资源文件,通过qmake编译)选项
set(CMAKE_AUTORCC ON)
#激活自动处理ui文件(通过qmake编译)选项
set(CMAKE_AUTOUIC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# 设置cmake模块的查询目录,注意这里的路径
set(CMAKE_PREFIX_PATH /opt/homebrew/Cellar/qt@5/5.15.2_2/lib/cmake)
# 查找QT的模块
find_package(Qt5 COMPONENTS
Core
Widgets
Quick
REQUIRED)
find_package(Qt5Widgets REQUIRED)
include_directories(.)
add_executable(QtApp
QtApp.pro
main.cpp
MainWindow.cpp
MainWindow.h
res.qrc
ui_MainWindow.h)
target_link_libraries(QtApp Qt5::Widgets)
参考
[^1]:[Get started with CMake | Build with CMake 5.15.9 (qt.io)](https://doc.qt.io/qt-5/cmake-get-started.html); |