目录结构
├── cmakeLists.txt
└── main.cpp
源文件
main.c
#include <stdio.h>
#include <QMainWindow>
int main(int argc, char *argv[])
{
printf("qt5 cmake:hello\r\n");
return 0;
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(test_qt5)
set(CMAKE_CXX_STANDARD 14)
find_package(Qt5 COMPONENTS Core Widgets REQUIRED)
add_executable(test_qt5 main.cpp)
target_link_libraries(test_qt5 PRIVATE Qt5::Core Qt5::Widgets)
)
第四行使用find_package寻找QT5的库。
编译
$ mkdir build
$ cd build/
$ cmake ..
$ make VERBOSE=1 (打印详细的编译信息,可以看到连接的QT5的so,则配置成功)
./test_qt5
qt5 cmake:hello