-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathCMakeLists.txt
337 lines (286 loc) · 6.71 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
# @file TemplateCMakeLists.txt
# @brief A template CMakeLists.txt which can automatically generate project
# @author WUZHUOBIN
# @version 1.3.0
# @since Sep.19.2017
#
# This template is for generating CMake project easily. Only a few steps.
# 1. Make a good folder name as the parent, because it is going to be your
# CMake Project name.
# 2. Place all header files and implementation files to your parent folder.
# If there is no header files and implementation files, skip this part.
# 3. Create a folder "main" to place your main function. It has to be named
# as "name.cpp". If there is no or a library is being created, skip this
# part.
# 4. Rename "TemplateCMakeLists.txt" to "CMakeLists.txt".
#
# Update Log:
# @date Sep.19.2017
# version 1.0.0
# The first version.
#
# @date Sep.20.2017
# version 1.1.0
# Adding some comments
#
# @date Sep.27.2017
# version 1.2.0
# This is a simple version. Cannot generate shared library, only generate static
# library. No export and install.
#
# @data Oct.09.2017
# version 1.3.0
# Adding qrc in library as well, which provide greater compatibility.
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Copyright (c) WUZHUOBIN #
# All rights reserved. #
# See Copyright.txt #
# This software is distributed WITHOUT ANY WARRANTY; without even #
# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR #
# PURPOSE. See the above copyright notice for more information. #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
cmake_minimum_required(VERSION 3.1)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
get_filename_component(
FOLDER_NAME
${CMAKE_CURRENT_SOURCE_DIR}
NAME
)
project(${FOLDER_NAME})
message(
STATUS
"Building submodule ${PROJECT_NAME}..."
)
# multi-processor build
if(${MSVC})
set(
CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} /MP"
)
set(
CMAKE_C_FLAGS
"${CMAKE_C_FLAGS} /MP"
)
endif()
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # POLICY # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
cmake_policy(SET CMP0043 NEW)
cmake_policy(SET CMP0028 NEW)
# # # # # # # # # # # # # # # # # CHANGE BELOW # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # DEPENDENCY # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Adding dependency library you need
# Please remember to set it to SYSTEM_LIBRARIES as well
# ITK
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
# VTK
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
# QT
find_package(Qt5Core REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5LinguistTools REQUIRED)
# # # # # # # # # # # # # # # # # CHANGE BELOW # # # # # # # # # # # # # # # #
#find_package(Qt5.... REQUIRED)
#find_package(... REQURIED)
find_package(Qt5Concurrent REQUIRED)
# OTHERS
#find_package()
#....
# QT_QRC
#set(
# PROJECT_QRC
# #PATH
#)
# WINDOWS RESOURCES
# set(
# WINDOWS_RESOURCES
# # PATH
# )
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # LIBRARIES # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
set(
CMAKE_ARCHIVE_OUTPUT_DIRECTORY
${CMAKE_BINARY_DIR}/lib
)
set(
CMAKE_LIBRARY_OUTPUT_DIRECTORY
${CMAKE_BINARY_DIR}/lib
)
set(
CMAKE_RUNTIME_OUTPUT_DIRECTORY
${CMAKE_BINARY_DIR}/bin
)
link_directories(
${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}
${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
)
set(
SYSTEM_LIBRARIES
${VTK_LIBRARIES}
${ITK_LIBRARIES}
Qt5::Core
Qt5::Widgets
)
set(
SYSTEM_INCLUDE
${PROJECT_SOURCE_DIR}
${PROJECT_BINARY_DIR}
)
# # # # # # # # # # # # # # # # # CHANGE BELOW # # # # # # # # # # # # # # # #
set(
SYSTEM_LIBRARIES
${SYSTEM_LIBRARIES}
Qt5::Concurrent
# Qt5::LinguistTools
#OTHERS
#...
)
set(
SYSTEM_INCLUDE
${SYSTEM_INCLUDE}
#....
)
# Enable always build static library
set(LIB_TYPE STATIC)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # CODES # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# sources for program mains
file(GLOB MAIN_CPP ${PROJECT_SOURCE_DIR}/main/*.c*)
file(GLOB MAIN_HDR ${PROJECT_SOURCE_DIR}/main/*.h*)
file(GLOB MAIN_UI ${PROJECT_SOURCE_DIR}/main/*.ui)
file(GLOB MAIN_TS ${PROJECT_SOURCE_DIR}/main/*.ts)
# sources for individual projects
file(GLOB PROJECT_SRC *.c*)
file(GLOB PROJECT_INC *.h*)
file(GLOB PROJECT_UI *.ui)
file(GLOB PROJECT_TS *.ts)
# Output mainwindow UI files
qt5_wrap_ui(
MAIN_UI_H
${MAIN_UI}
)
qt5_wrap_cpp(
MAIN_MOC
${MAIN_HDR}
)
qt5_add_resources(
MAIN_QRC_SRC
${MAIN_QRC}
)
qt5_add_translation(
MAIN_QM
${MAIN_TS}
)
# Output UI headers to specified location
qt5_wrap_ui(
PROJECT_UI_H
${PROJECT_UI}
)
qt5_wrap_cpp(
PROJECT_MOC
${PROJECT_INC}
)
qt5_add_resources(
PROJECT_QRC_SRC
${PROJECT_QRC}
)
qt5_add_translation(
PROJECT_QM
${PROJECT_TS}
)
# Building library
if( NOT "${PROJECT_SRC}" STREQUAL "")
add_library(
${PROJECT_NAME}
${LIB_TYPE}
${PROJECT_SRC}
${PROJECT_INC}
${PROJECT_MOC}
${PROJECT_UI}
${PROJECT_UI_H}
${PROJECT_QRC}
${PROJECT_QRC_SRC}
${PROJECT_TS}
${PROJECT_QM}
)
target_link_libraries(
${PROJECT_NAME}
${SYSTEM_LIBRARIES}
)
message(
STATUS
"Linking Libraries\n"
"${SYSTEM_LIBRARIES}"
)
target_include_directories(
${PROJECT_NAME}
PUBLIC
${SYSTEM_INCLUDE}
)
message(
STATUS
"Include directory\n"
"${SYSTEM_INCLUDE}"
)
endif()
if(EXISTS ${PROJECT_SOURCE_DIR}/main/main.cpp OR EXISTS ${PROJECT_SOURCE_DIR}/main/main.cxx)
add_executable(
${PROJECT_NAME}_main
${MAIN_CPP}
${MAIN_HDR}
${MAIN_UI_H}
${MAIN_MOC}
${MAIN_QRC}
${MAIN_QRC_SRC}
${MAIN_TS}
${MAIN_QM}
)
if(NOT "${PROJECT_SRC}" STREQUAL "")
target_link_libraries(
${PROJECT_NAME}_main
${PROJECT_NAME}
)
else()
target_link_libraries(
${PROJECT_NAME}_main
${SYSTEM_LIBRARIES}
)
endif()
endif()
#Grouping in MSVC
source_group(
"Generated Files"
FILES
${MAIN_MOC}
${MAIN_UI_H}
${MAIN_QRC_SRC}
${PROJECT_MOC}
${PROJECT_UI_H}
${PROJECT_QRC_SRC}
)
source_group(
"Forms Files"
FILES
${MAIN_UI}
${PROJECT_UI}
)
source_group(
"Header Files"
FILES
${MAIN_HDR}
${PROJECT_INC}
)
source_group(
"Source Files"
FILES
${PROJECT_SRC}
${MAIN_CPP}
)
MESSAGE(STATUS "Building submodule ${PROJECT_NAME} finished!")