-
Notifications
You must be signed in to change notification settings - Fork 0
CMake with Qt
Hong, Jian-Ching edited this page Oct 31, 2016
·
2 revisions
CMakeLists.txt - Last Version
cmake_minimum_required (VERSION 2.8.12)
project (MyProject)
find_package(Qt5 COMPONENTS Core Widgets REQUIRED)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
add_library (${PROJECT_NAME}Lib
mainwindow.h mainwindow.cpp mainwindow.ui
resources/resources.qrc
)
target_link_libraries (${PROJECT_NAME}Lib Qt5::Widgets)
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries (${PROJECT_NAME} ${PROJECT_NAME}Lib)
Execute project use libary qrc, need use Q_INIT_RESOURCE
main.cpp
QApplication a(argc, argv);
Q_INIT_RESOURCE(resources);
MainWindow w;
w.show();
return a.exec();
Don't forget CMAKE_PREFIX_PATH
SET CMAKE_PREFIX_PATH=C:/Qt/5.7/msvc2015
...
Ref:
Implementing Qt project through CMake
CMake: Finding Qt 5 the “Right Way”
Qt Documentation - CMake Manual
CMake 3.7 Documentation - cmake-qt
Default installation prefix QT5 / QT5 Widgets Ubuntu
What package do I need to build a Qt 5 & CMake application?
Add the installation prefix of “Qt5Widgets” to CMAKE_PREFIX_PATH
##add automoc file and autorcc file to group
# add automoc file and autorcc file to group
source_group("zzzautofile" REGULAR_EXPRESSION "(.*_automoc\\.cpp|qrc_.*)")
Ref:
Hide _automoc targets in CMake
Todo: