目录结构
代码
CMakeLists.txt:
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)