使用CMake搭建简单的Qt程序

目录结构

代码

CMakeLists.txt:

bash 复制代码
cmake_minimum_required(VERSION 3.15)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

# set the project name
project(xxx)

# 设置Qt的路径
# 例如 E:/Qt/Qt/aaa/msvc2019_64
# aaa 为Qt的版本号
set(QT_PATH "C:/Qt/5.15.2/msvc2019_64")
set(CMAKE_PREFIX_PATH ${QT_PATH}/lib/cmake)

# 添加模块
find_package(Qt5 COMPONENTS Widgets Core Sql REQUIRED )
# include_directories(${QT_PATH}/include)
include_directories(${PROJECT_SOURCE_DIR}/inc)

file(GLOB_RECURSE user_headers inc/*.h)
file(GLOB_RECURSE user_cpps src/*.cpp)
set(user 
${user_headers}
${user_cpps})

add_executable(${PROJECT_NAME} WIN32
${user}
)

# link_libraries(${QT_PATH}/lib)

target_include_directories(${PROJECT_NAME}
PUBLIC
${PROJECT_SOURCE_DIR}/inc)

# 添加模块
target_link_libraries(${PROJECT_NAME} 
 Qt5::Widgets
 Qt5::Core
 Qt5::Sql)
相关推荐
xcyxiner1 天前
DicomViewer (后台线程处理文件)4
qt
xcyxiner1 天前
DicomViewer (添加模型类)3
qt
xcyxiner2 天前
DicomViewer (目录调整) 2
qt
xcyxiner2 天前
dcmtk vtk vtk-dicom(gdcm) 编译(debug) v2
qt
clint4563 天前
C++进阶(1)——前景提要
c++
夜悊3 天前
C++代码示例:进制数简单生成工具
c++
郝学胜_神的一滴3 天前
CMake 021: IF 条件判据详诠
c++·cmake
_wyt0014 天前
洛谷 B3930 [GESP202312 五级] 烹饪问题 题解
c++·gesp
玖玥拾4 天前
C/C++ 数据结构(七)栈、容器适配器
c语言·数据结构·c++··容器适配器
桥田智能4 天前
桥田智能 QT-650S:面向白车身焊装的 800kg 重载快换解决方案
开发语言·qt·系统架构