-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
119 lines (81 loc) · 2.92 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
cmake_minimum_required (VERSION 3.0)
cmake_policy(VERSION 3.0) # 处理该项目的最低策略版本
# 如果支持,请为 MSVC 编译器启用热重载。
if (POLICY CMP0141)
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>,$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>>")
endif()
project (app)
set(NAME app)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_PREFIX_PATH "C:/Qt/6.5.1/msvc2019_64")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
link_directories(${CMAKE_SOURCE_DIR}/lib)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONMENTS Widgets)
message("Qt version ::: " ${QT_VERSION_MAJOR})
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS
Widgets
Gui
Core
OpenGL
OpenGLWidgets)
# 查找 OpenGL 库
find_package(OpenGL REQUIRED)
# 添加资源文件
qt6_add_resources(RESOURCES src/resources.qrc)
file(GLOB SOURCE
"src/ui/*.h"
"src/ui/*.cpp"
"src/ui/*.ui"
"src/ui/widgets/*.h"
"src/ui/widgets/*.cpp"
"src/ui/widgets/*.ui"
"src/ui/items/*.h"
"src/ui/items/*.cpp"
"public/process/*.h"
"public/process/*.cpp"
"src/*.cpp"
)
# message(STATUS "============ source :: ${SOURCE}")
add_executable (${NAME} ${SOURCE} ${RESOURCES})
macro(makeLink src dest target)
add_custom_command(TARGET ${target} POST_BUILD COMMAND ${CMAKE_COMMAND} -E create_symlink ${src} ${dest} DEPENDS ${dest} COMMENT "mklink ${src} -> ${dest}")
endmacro()
target_link_libraries(app PRIVATE Qt${QT_VERSION_MAJOR}::Widgets
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::OpenGL
Qt${QT_VERSION_MAJOR}::OpenGLWidgets
)
if(MSVC)
target_compile_options(${NAME} PRIVATE /std:c++17 /MP)
target_link_options(${NAME} PUBLIC /ignore:4099)
endif(MSVC)
if(WIN32)
set_target_properties(${NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin")
set_target_properties(${NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/bin/Debug")
endif(WIN32)
# copy dlls
file(GLOB DLLS "dlls/*.dll")
add_custom_command(TARGET ${NAME} PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${DLLS} $<TARGET_FILE_DIR:${NAME}>)
include_directories(${CMAKE_SOURCE_DIR}/includes)
include_directories(app PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src
)
# 链接 OpenGL 库
if(OPENGL_FOUND)
message(STATUS "++++++++ :: sss"${OPENGL_INCLUDE_DIRS})
include_directories(${OPENGL_INCLUDE_DIR})
target_link_libraries(app PRIVATE ${OPENGL_LIBRARIES})
else()
message(STATUS "++++++ :: have not find opengl")
endif()
if (CMAKE_VERSION VERSION_GREATER 3.12)
set_property(TARGET app PROPERTY CXX_STANDARD 17)
endif()
# TODO: 如有需要,请添加测试并安装目标。