This repository has been archived by the owner on Dec 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpile_target.cmake
468 lines (406 loc) · 17.7 KB
/
pile_target.cmake
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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
# ============================================================================
#
# Target Helpers
# ==============
#
# This file contains support CMake script for targets.
#
# Usage
# -----
#
# The file is included by pile_support.cmake, so all the
# user has to do to use it is to:
#
# include(pile_support)
#
# The purpose is to abstract away complex but repetitive statements from
# target specific CMakeLists.txt file.
#
# In the target file start with
#
# pileTarget( "example")
#
# then fill the lists mentioned in `pileTarget` macro, then en with
#
# pileEndTarget( "example" "exe")
#
# to create an executable target.
#
# ============================================================================
# ============================================================================
# Prepares a target for being constructed
#
# The macro defines or changes
# <PILE>_SOURCES: the list of source files
# <PILE>_HEADERS: the list of headers
# <PILE>_UIS: the list of UI files
# <PILE>_RES: the list of resource files
# <PILE>_DLLS: the list of .dll libraries that should be included in package
# <PILE>_LIBRARIES: the list of libraries to link against
# <PILE>_QT_MODS: the list of Qt modules to link against
# <PILE>_TARGET: the actual name of the target
macro (pileTarget
pile_target__name)
set(pile_target__argn ${ARGN})
string (TOUPPER "${pile_target__name}" pile_target__name_u)
string (TOLOWER "${pile_target__name}" pile_target__name_l)
set(pile_target__gui_app OFF)
if (pile_target__argn)
list(GET pile_target__argn 0 pile_target__gui_app)
if("${pile_target__gui_app}" STREQUAL "GUI")
set(pile_target__gui_app ON)
endif()
endif()
# prepare variables
set( ${pile_target__name_u}_INCLUDES )
set( ${pile_target__name_u}_SOURCES )
set( ${pile_target__name_u}_HEADERS )
set( ${pile_target__name_u}_UIS )
set( ${pile_target__name_u}_RES )
set( ${pile_target__name_u}_DLLS )
set( ${pile_target__name_u}_LIBRARIES )
set( ${pile_target__name_u}_QT_MODS )
set( ${pile_target__name_u}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
# name of the target
set( ${pile_target__name_u}_TARGET "${pile_target__name_l}")
unset(THIS_TARGET)
set(THIS_TARGET "${pile_target__name}")
unset(THIS_TARGET_PILES)
if (${pile_target__gui_app})
set( ${pile_target__name_u}_GUI_FLAG "WIN32")
endif()
endmacro ()
# ============================================================================
# Constructs the target based on the provided options
#
# Arguments
# - name: the user name for the target
# - kind: either "exe", "shared" or "static"
# - copy_headers (optional): ON or COPY to copy the headers to output
# directory for headers (uses pileCreateCopyTargetTarget)
#
# The macro defines or changes
# <PILE>_UIS_SRC: the list of source files generated from <PILE>_UIS
# <PILE>_RES_SRC: the list of source files generated from <PILE>_RES
macro (pileEndTarget
pile_end_target__name
pile_end_target__kind)
set(pile_end_target__argn ${ARGN})
unset(pile_end_target__copy_headers)
if (pile_end_target__argn)
list(GET pile_end_target__argn 0 pile_end_target__copy_headers)
if("${pile_end_target__copy_headers}" STREQUAL "COPY")
set(pile_end_target__copy_headers ON)
endif()
endif()
string (TOUPPER "${pile_end_target__name}" pile_end_target__name_u)
string (TOLOWER "${pile_end_target__name}" pile_end_target__name_l)
# expand uis
unset(${pile_end_target__name_u}_UIS_SRC)
if (${pile_end_target__name_u}_UIS)
qt5_wrap_ui (${pile_end_target__name_u}_UIS_SRC
${${pile_end_target__name_u}_UIS})
endif ()
# expand resources
unset(${pile_end_target__name_u}_RES_SRC)
if (${pile_end_target__name_u}_RES)
qt5_add_resources( ${pile_end_target__name_u}_RES_SRC
${${pile_end_target__name_u}_RES})
endif ()
# make sure all paths are absolute
unset(pile_end_target__temp_list )
if (${pile_end_target__name_u}_HEADERS)
foreach(pile_end_target__iter ${${pile_end_target__name_u}_HEADERS})
if (NOT IS_ABSOLUTE "${pile_end_target__iter}")
get_filename_component(
pile_end_target__iter
"${pile_end_target__iter}"
ABSOLUTE)
endif()
list (APPEND pile_end_target__temp_list
"${pile_end_target__iter}")
endforeach()
set (${pile_end_target__name_u}_HEADERS
${pile_end_target__temp_list})
endif()
# install components
if (NOT ${pile_end_target__name_u}_COMP_BIN)
set(${pile_end_target__name_u}_COMP_BIN "applications")
endif()
if (NOT ${pile_end_target__name_u}_COMP_ARCH)
set(${pile_end_target__name_u}_COMP_ARCH "archives")
endif()
if (NOT ${pile_end_target__name_u}_COMP_LIB)
set(${pile_end_target__name_u}_COMP_LIB "applications")
endif()
if (NOT ${pile_end_target__name_u}_COMP_INC)
set(${pile_end_target__name_u}_COMP_INC "headers")
endif()
# remove duplicates from lists
if (${pile_end_target__name_u}_SOURCES)
list(REMOVE_DUPLICATES ${pile_end_target__name_u}_SOURCES)
endif()
if (${pile_end_target__name_u}_HEADERS)
list(REMOVE_DUPLICATES ${pile_end_target__name_u}_HEADERS)
endif()
if (${pile_end_target__name_u}_DLLS)
list(REMOVE_DUPLICATES ${pile_end_target__name_u}_DLLS)
endif()
if (${pile_end_target__name_u}_LIBRARIES)
list(REMOVE_DUPLICATES ${pile_end_target__name_u}_LIBRARIES)
endif()
if (${pile_end_target__name_u}_QT_MODS)
list(REMOVE_DUPLICATES ${pile_end_target__name_u}_QT_MODS)
endif()
if (${pile_end_target__name_u}_INCLUDES)
list(REMOVE_DUPLICATES ${pile_end_target__name_u}_INCLUDES)
include_directories(${${pile_end_target__name_u}_INCLUDES})
endif()
# all sources used to build the target
set( ${pile_end_target__name_u}_ALL_SRCS
${${pile_end_target__name_u}_SOURCES}
${${pile_end_target__name_u}_UIS_SRC}
${${pile_end_target__name_u}_RES_SRC}
${${pile_end_target__name_u}_HEADERS})
# create appropriate target type
if ("${pile_end_target__kind}" STREQUAL "exe")
add_executable("${${pile_end_target__name_u}_TARGET}" ${${pile_end_target__name_u}_GUI_FLAG}
${${pile_end_target__name_u}_ALL_SRCS})
if (WIN32)
if(EXISTS "${EXECUTABLE_OUTPUT_PATH}/${${pile_end_target__name_u}_TARGET}.exe.manifest")
install(
FILES "${EXECUTABLE_OUTPUT_PATH}/${${pile_end_target__name_u}_TARGET}.exe.manifest"
DESTINATION bin
COMPONENT ${${pile_end_target__name_u}_COMP_BIN})
endif()
endif()
pileSignBinary("${${pile_end_target__name_u}_TARGET}")
elseif ("${pile_end_target__kind}" STREQUAL "shared")
add_library("${${pile_end_target__name_u}_TARGET}" SHARED
${${pile_end_target__name_u}_ALL_SRCS})
pileSignBinary("${${pile_end_target__name_u}_TARGET}")
else ()
add_library("${${pile_end_target__name_u}_TARGET}" STATIC
${${pile_end_target__name_u}_ALL_SRCS})
endif()
# link libraries
if (${pile_end_target__name_u}_LIBRARIES)
target_link_libraries( ${${pile_end_target__name_u}_TARGET}
${${pile_end_target__name_u}_LIBRARIES})
endif()
# message(STATUS "${pile_end_target__name_u}_TARGET = ${${pile_end_target__name_u}_TARGET}")
# message(STATUS "${pile_end_target__name_u}_LIBRARIES = ${${pile_end_target__name_u}_LIBRARIES}")
# install dlls
if (${pile_end_target__name_u}_DLLS)
# add modules to list of files to be installed
unset(local_dep_list)
set (local_dep_list
${PILE_PROJECT_DEP_LIBRARIES}
${${pile_end_target__name_u}_DLLS} )
set (PILE_PROJECT_DEP_LIBRARIES ${local_dep_list}
CACHE INTERNAL "The list of dlls to install and package" FORCE)
endif()
# message (STATUS "${pile_end_target__name_u}_DLLS = ${${pile_end_target__name_u}_DLLS}")
# message (STATUS "PILE_PROJECT_DEP_LIBRARIES = ${PILE_PROJECT_DEP_LIBRARIES}")
# link / use Qt modules
if (${pile_end_target__name_u}_QT_MODS)
qt5_use_modules( ${${pile_end_target__name_u}_TARGET}
${${pile_end_target__name_u}_QT_MODS})
# add modules to list of files to be installed
unset(local_dep_list)
set (local_dep_list
${PILE_PROJECT_DEP_LIBRARIES}
${${pile_end_target__name_u}_QT_MODS} )
set (PILE_PROJECT_DEP_LIBRARIES ${local_dep_list}
CACHE INTERNAL "The list of dlls to install and package" FORCE)
# see if there are some plug-ins we also want
unset(local_dep_list)
set (local_dep_list ${PILE_PROJECT_QT_PLUGINS})
foreach(qt_mod ${${pile_end_target__name_u}_QT_MODS})
string(TOLOWER "${qt_mod}" qt_mod_std)
if (qt_mod_std STREQUAL "printsupport")
if (TARGET_SYSTEM_WIN32)
list(APPEND local_dep_list "printsupport/windowsprintersupport")
endif()
endif()
unset(qt_mod_std)
endforeach()
set (PILE_PROJECT_QT_PLUGINS ${local_dep_list}
CACHE INTERNAL "The list of Qt plug-ins to install and package" FORCE)
endif()
# what to install where
if (NOT ${pile_end_target__name_u}_INSTALL_LIB)
set (${pile_end_target__name_u}_INSTALL_LIB lib)
endif()
if (NOT ${pile_end_target__name_u}_INSTALL_ARCH)
set (${pile_end_target__name_u}_INSTALL_ARCH lib)
endif()
if (NOT ${pile_end_target__name_u}_INSTALL_BIN)
set (${pile_end_target__name_u}_INSTALL_BIN bin)
endif()
if (NOT ${pile_end_target__name_u}_INSTALL_INC)
set (${pile_end_target__name_u}_INSTALL_INC include)
endif()
# message(STATUS "bin component of target ${pile_end_target__name_u} is ${${pile_end_target__name_u}_COMP_BIN}")
# message(STATUS "arch component of target ${pile_end_target__name_u} is ${${pile_end_target__name_u}_COMP_ARCH}")
# message(STATUS "lib component of target ${pile_end_target__name_u} is ${${pile_end_target__name_u}_COMP_LIB}")
# message(STATUS "inc component of target ${pile_end_target__name_u} is ${${pile_end_target__name_u}_COMP_INC}")
install(
TARGETS "${${pile_end_target__name_u}_TARGET}"
ARCHIVE
DESTINATION ${${pile_end_target__name_u}_INSTALL_ARCH}
COMPONENT ${${pile_end_target__name_u}_COMP_ARCH}
LIBRARY
DESTINATION ${${pile_end_target__name_u}_INSTALL_LIB}
COMPONENT ${${pile_end_target__name_u}_COMP_LIB}
RUNTIME
DESTINATION ${${pile_end_target__name_u}_INSTALL_BIN}
COMPONENT ${${pile_end_target__name_u}_COMP_BIN})
if (${pile_end_target__name_u}_HEADERS)
install(
FILES ${${pile_end_target__name_u}_HEADERS}
DESTINATION ${${pile_end_target__name_u}_INSTALL_INC}
COMPONENT ${${pile_end_target__name_u}_COMP_INC})
if (pile_end_target__copy_headers)
pileCreateCopyTargetTarget("${pile_end_target__name}")
add_dependencies(
"${${pile_end_target__name_u}_TARGET}"
"copy_${pile_end_target__name_l}_headers")
else()
unset(pile_iter)
foreach(pile_iter ${THIS_TARGET_PILES})
unset(pile_lower)
string(TOLOWER "${pile_iter}" pile_lower)
add_dependencies(
"${${pile_end_target__name_u}_TARGET}"
"copy_${pile_lower}_headers")
endforeach()
if (${pile_end_target__name_u}_OWN_HEADERS)
pileCreateCopyTarget (
"copy_${pile_end_target__name_l}_headers"
"${pile_iter} headers are being copied"
"${INCLUDE_OUTPUT_PATH}"
"${${pile_end_target__name_u}_OWN_HEADERS}")
add_dependencies(
${${pile_end_target__name_u}_TARGET}
"copy_${pile_end_target__name_l}_headers")
endif()
endif()
endif()
endmacro ()
# ============================================================================
# Creates the target that copies headers
#
# Arguments
# - name: the user name for the target
# - destination (optional): where to copy; by default this is INCLUDE_OUTPUT_PATH
#
macro (pileCreateCopyTargetTarget
pile_copy_target_target__name)
unset(pile_copy_target_target__argn)
set (pile_copy_target_target__argn ${ARGN})
unset(pile_copy_target_target__destination)
set(pile_copy_target_target__destination "${INCLUDE_OUTPUT_PATH}")
if (pile_copy_target_target__argn)
list(GET pile_copy_target_target__argn 0 pile_copy_target_target__destination)
endif()
unset(pile_copy_target_target__name_u)
string (TOUPPER "${pile_copy_target_target__name}" pile_copy_target_target__name_u)
unset(pile_copy_target_target__name_l)
string (TOLOWER "${pile_copy_target_target__name}" pile_copy_target_target__name_l)
unset(pile_copy_target_target__target_u)
string (TOUPPER "${THIS_TARGET}" pile_copy_target_target__target_u)
unset(pile_copy_target_target__target_l)
string (TOLOWER "${THIS_TARGET}" pile_copy_target_target__target_l)
pileCreateCopyTarget (
"copy_${pile_copy_target_target__name_l}_headers"
"${pile_copy_target_target__name} headers are being copied"
"${pile_copy_target_target__destination}"
"${${pile_copy_target_target__name_u}_HEADERS}")
#"${${pile_copy_target_target__name_u}_SOURCE_DIR}")
unset(pile_iter)
foreach(pile_iter ${THIS_TARGET_PILES})
unset(pile_upper)
string(TOUPPER "${pile_iter}" pile_upper)
unset(pile_lower)
string(TOLOWER "${pile_iter}" pile_lower)
add_dependencies(
${${pile_copy_target_target__target_u}_TARGET}
"copy_${pile_lower}_headers")
pileCopyHeaders(${pile_iter})
endforeach()
if (${pile_copy_target_target__target_u}_OWN_HEADERS)
pileCreateCopyTarget (
"copy_${pile_copy_target_target__target_l}_headers"
"${pile_iter} headers are being copied"
"${INCLUDE_OUTPUT_PATH}"
"${${pile_copy_target_target__target_u}_OWN_HEADERS}")
add_dependencies(
${${pile_copy_target_target__target_u}_TARGET}
"copy_${pile_copy_target_target__target_l}_headers")
endif()
endmacro ()
# ============================================================================
# Adds specified piles to current target
#
# Arguments
# - all: are the names of the piles
#
# The macro defines or changes
# <PILE>_UIS_SRC: the list of source files generated from <PILE>_UIS
# <PILE>_RES_SRC: the list of source files generated from <PILE>_RES
#
macro (pileTargetSubPiles)
set(THIS_TARGET_PILES ${ARGN})
unset(pile_iter)
foreach(pile_iter ${THIS_TARGET_PILES})
# message(STATUS "pile_iter = ${pile_iter}")
unset(pile_upper)
string(TOUPPER "${pile_iter}" pile_upper)
unset(pile_lower)
string(TOLOWER "${pile_iter}" pile_lower)
unset(pile_target_upper)
string(TOUPPER "${THIS_TARGET}" pile_target_upper)
pileInclude (${pile_iter})
pileCallByName("${pile_lower}Init" PILE_SHARED)
# message(STATUS "${pile_upper}_INCLUDES = ${${pile_upper}_INCLUDES}")
list(APPEND ${pile_target_upper}_INCLUDES ${${pile_upper}_INCLUDES})
# message(STATUS "${pile_upper}_LIBRARIES = ${${pile_upper}_LIBRARIES}")
list(APPEND ${pile_target_upper}_LIBRARIES ${${pile_upper}_LIBRARIES})
# message(STATUS "${pile_upper}_SOURCES = ${${pile_upper}_SOURCES}")
list(APPEND ${pile_target_upper}_SOURCES ${${pile_upper}_SOURCES})
# message(STATUS "${pile_upper}_HEADERS = ${${pile_upper}_HEADERS}")
list(APPEND ${pile_target_upper}_HEADERS ${${pile_upper}_HEADERS})
# message(STATUS "${pile_upper}_UIS = ${${pile_upper}_UIS}")
list(APPEND ${pile_target_upper}_UIS ${${pile_upper}_UIS})
# message(STATUS "${pile_upper}_QT_MODS = ${${pile_upper}_QT_MODS}")
list(APPEND ${pile_target_upper}_QT_MODS ${${pile_upper}_QT_MODS})
# message(STATUS "${pile_upper}_DLLS = ${${pile_upper}_DLLS}")
list(APPEND ${pile_target_upper}_DLLS ${${pile_upper}_DLLS})
if (${pile_target_upper}_QT_MODS)
list(REMOVE_DUPLICATES ${pile_target_upper}_QT_MODS)
endif()
pileCopyHeaders("${pile_iter}")
endforeach()
if (${pile_target_upper}_SOURCES)
list (REMOVE_DUPLICATES ${pile_target_upper}_SOURCES)
# message(STATUS "${pile_target_upper}_SOURCES = ${${pile_target_upper}_SOURCES}")
endif()
if (${pile_target_upper}_HEADERS)
list (REMOVE_DUPLICATES ${pile_target_upper}_HEADERS)
# message(STATUS "${pile_target_upper}_HEADERS = ${${pile_target_upper}_HEADERS}")
endif()
if (${pile_target_upper}_UIS)
list (REMOVE_DUPLICATES ${pile_target_upper}_UIS)
# message(STATUS "${pile_target_upper}_UIS = ${${pile_target_upper}_UIS}")
endif()
if (${pile_target_upper}_LIBRARIES)
list (REMOVE_DUPLICATES ${pile_target_upper}_LIBRARIES)
# message(STATUS "${pile_target_upper}_LIBRARIES = ${${pile_target_upper}_LIBRARIES}")
endif()
if (${pile_target_upper}_DLLS)
list (REMOVE_DUPLICATES ${pile_target_upper}_DLLS)
# message(STATUS "${pile_target_upper}_DLLS = ${${pile_target_upper}_DLLS}")
endif()
endmacro()
# ============================================================================