@@ -206,6 +206,27 @@ function(compile_asm)
206
206
set (${COMPILE_ASM_OUTPUT_OBJECTS} ${ASSEMBLED_OBJECTS} PARENT_SCOPE)
207
207
endfunction ()
208
208
209
+ # add_component(componentName [targetName] [EXCLUDE_FROM_ALL])
210
+ function (add_component componentName)
211
+ if (${ARGC} GREATER 2 OR ${ARGC} EQUAL 2)
212
+ set (componentTargetName "${ARGV1} " )
213
+ else ()
214
+ set (componentTargetName "${componentName} " )
215
+ endif ()
216
+ if (${ARGC} EQUAL 3 AND "${ARG2} " STREQUAL "EXCLUDE_FROM_ALL" )
217
+ set (exclude_from_all_flag "EXCLUDE_FROM_ALL" )
218
+ endif ()
219
+ get_property (definedComponents GLOBAL PROPERTY CLR_CMAKE_COMPONENTS)
220
+ list (FIND definedComponents "${componentName} " componentIndex)
221
+ if (${componentIndex} EQUAL -1)
222
+ list (APPEND definedComponents "${componentName} " )
223
+ add_custom_target ("${componentTargetName} "
224
+ COMMAND "${CMAKE_COMMAND} " "-DCMAKE_INSTALL_COMPONENT=${componentName} " "-DBUILD_TYPE=$<CONFIG>" -P "${CMAKE_BINARY_DIR} /cmake_install.cmake"
225
+ ${exclude_from_all_flag} )
226
+ set_property (GLOBAL PROPERTY CLR_CMAKE_COMPONENTS ${definedComponents} )
227
+ endif ()
228
+ endfunction ()
229
+
209
230
function (generate_exports_file)
210
231
set (INPUT_LIST ${ARGN} )
211
232
list (GET INPUT_LIST -1 outputFilename)
@@ -248,12 +269,29 @@ function(generate_exports_file_prefix inputFilename outputFilename prefix)
248
269
PROPERTIES GENERATED TRUE )
249
270
endfunction ()
250
271
272
+ function (get_symbol_file_name targetName outputSymbolFilename)
273
+ if (CLR_CMAKE_HOST_UNIX)
274
+ if (CLR_CMAKE_TARGET_OSX OR CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS)
275
+ set (strip_destination_file $<TARGET_FILE:${targetName} >.dwarf)
276
+ else ()
277
+ set (strip_destination_file $<TARGET_FILE:${targetName} >.dbg)
278
+ endif ()
279
+
280
+ set (${outputSymbolFilename} ${strip_destination_file} PARENT_SCOPE)
281
+ else (CLR_CMAKE_HOST_UNIX)
282
+ # We can't use the $<TARGET_PDB_FILE> generator expression here since
283
+ # the generator expression isn't supported on resource DLLs.
284
+ set (${outputSymbolFilename} $<TARGET_FILE_DIR:${targetName} >/$<TARGET_FILE_PREFIX:${targetName} >$<TARGET_FILE_BASE_NAME:${targetName} >.pdb PARENT_SCOPE)
285
+ endif (CLR_CMAKE_HOST_UNIX)
286
+ endfunction ()
287
+
251
288
function (strip_symbols targetName outputFilename)
289
+ get_symbol_file_name(${targetName} strip_destination_file)
290
+ set (${outputFilename} ${strip_destination_file} PARENT_SCOPE)
252
291
if (CLR_CMAKE_HOST_UNIX)
253
292
set (strip_source_file $<TARGET_FILE:${targetName} >)
254
293
255
294
if (CLR_CMAKE_TARGET_OSX OR CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS)
256
- set (strip_destination_file ${strip_source_file} .dwarf)
257
295
258
296
# Ensure that dsymutil and strip are present
259
297
find_program (DSYMUTIL dsymutil)
@@ -282,7 +320,6 @@ function(strip_symbols targetName outputFilename)
282
320
COMMENT "Stripping symbols from ${strip_source_file} into file ${strip_destination_file} "
283
321
)
284
322
else (CLR_CMAKE_TARGET_OSX OR CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS)
285
- set (strip_destination_file ${strip_source_file} .dbg)
286
323
287
324
add_custom_command (
288
325
TARGET ${targetName}
@@ -294,26 +331,13 @@ function(strip_symbols targetName outputFilename)
294
331
COMMENT "Stripping symbols from ${strip_source_file} into file ${strip_destination_file} "
295
332
)
296
333
endif (CLR_CMAKE_TARGET_OSX OR CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS)
297
-
298
- set (${outputFilename} ${strip_destination_file} PARENT_SCOPE)
299
- else (CLR_CMAKE_HOST_UNIX)
300
- get_property (is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
301
- if (is_multi_config)
302
- # We can't use the $<TARGET_PDB_FILE> generator expression here since
303
- # the generator expression isn't supported on resource DLLs.
304
- set (${outputFilename} ${CMAKE_CURRENT_BINARY_DIR} /$<CONFIG>/${targetName} .pdb PARENT_SCOPE)
305
- else ()
306
- # We can't use the $<TARGET_PDB_FILE> generator expression here since
307
- # the generator expression isn't supported on resource DLLs.
308
- set (${outputFilename} ${CMAKE_CURRENT_BINARY_DIR} /${targetName} .pdb PARENT_SCOPE)
309
- endif ()
310
334
endif (CLR_CMAKE_HOST_UNIX)
311
335
endfunction ()
312
336
313
337
function (install_with_stripped_symbols targetName kind destination )
314
338
if (NOT CLR_CMAKE_KEEP_NATIVE_SYMBOLS)
315
339
strip_symbols(${targetName} symbol_file)
316
- install_symbols (${symbol_file} ${destination} )
340
+ install_symbol_file (${symbol_file} ${destination} ${ARGN } )
317
341
endif ()
318
342
319
343
if ((CLR_CMAKE_TARGET_OSX OR CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) AND ("${kind} " STREQUAL "TARGETS" ))
@@ -328,59 +352,75 @@ function(install_with_stripped_symbols targetName kind destination)
328
352
else ()
329
353
message (FATAL_ERROR "The `kind` argument has to be either TARGETS or PROGRAMS, ${kind} was provided instead" )
330
354
endif ()
331
- install (${kind} ${install_source} DESTINATION ${destination} )
355
+ install (${kind} ${install_source} DESTINATION ${destination} ${ARGN} )
332
356
endfunction ()
333
357
334
- function (install_symbols symbol_file destination_path)
358
+ function (install_symbol_file symbol_file destination_path)
335
359
if (CLR_CMAKE_TARGET_WIN32)
336
- install (FILES ${symbol_file} DESTINATION ${destination_path} /PDB)
360
+ install (FILES ${symbol_file} DESTINATION ${destination_path} /PDB ${ARGN} )
337
361
else ()
338
- install (FILES ${symbol_file} DESTINATION ${destination_path} )
362
+ install (FILES ${symbol_file} DESTINATION ${destination_path} ${ARGN } )
339
363
endif ()
340
364
endfunction ()
341
365
342
- # install_clr(TARGETS TARGETS targetName [targetName2 ...] [ADDITIONAL_DESTINATIONS destination])
366
+ # install_clr(TARGETS targetName [targetName2 ...] [DESTINATIONS destination [destination2 ...]] [COMPONENT componentName ])
343
367
function (install_clr)
344
- set (multiValueArgs TARGETS ADDITIONAL_DESTINATIONS)
345
- cmake_parse_arguments (INSTALL_CLR "" "" "${multiValueArgs} " ${ARGV} )
368
+ set (multiValueArgs TARGETS DESTINATIONS)
369
+ set (singleValueArgs COMPONENT )
370
+ set (options "" )
371
+ cmake_parse_arguments (INSTALL_CLR "${options} " "${singleValueArgs} " "${multiValueArgs} " ${ARGV} )
346
372
347
373
if ("${INSTALL_CLR_TARGETS} " STREQUAL "" )
348
374
message (FATAL_ERROR "At least one target must be passed to install_clr(TARGETS )" )
349
375
endif ()
350
376
351
- set (destinations "." )
377
+ if ("${INSTALL_CLR_DESTINATIONS} " STREQUAL "" )
378
+ message (FATAL_ERROR "At least one destination must be passed to install_clr." )
379
+ endif ()
380
+
381
+ set (destinations "" )
382
+
383
+ if (NOT "${INSTALL_CLR_DESTINATIONS} " STREQUAL "" )
384
+ list (APPEND destinations ${INSTALL_CLR_DESTINATIONS} )
385
+ endif ()
352
386
353
- if (NOT "${INSTALL_CLR_ADDITIONAL_DESTINATIONS } " STREQUAL "" )
354
- list ( APPEND destinations ${INSTALL_CLR_ADDITIONAL_DESTINATIONS } )
387
+ if ("${INSTALL_CLR_COMPONENT } " STREQUAL "" )
388
+ set (INSTALL_CLR_COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME } )
355
389
endif ()
356
390
357
391
foreach (targetName ${INSTALL_CLR_TARGETS} )
358
- list (FIND CLR_CROSS_COMPONENTS_LIST ${targetName} INDEX)
359
- if (NOT DEFINED CLR_CROSS_COMPONENTS_LIST OR NOT ${INDEX} EQUAL -1)
360
- if (NOT CLR_CMAKE_KEEP_NATIVE_SYMBOLS)
361
- strip_symbols(${targetName} symbol_file)
362
- endif ()
392
+ if (NOT "${INSTALL_CLR_COMPONENT} " STREQUAL "${targetName} " )
393
+ get_property (definedComponents GLOBAL PROPERTY CLR_CMAKE_COMPONENTS)
394
+ list (FIND definedComponents "${INSTALL_CLR_COMPONENT} " componentIdx)
395
+ if (${componentIdx} EQUAL -1)
396
+ message (FATAL_ERROR "The ${INSTALL_CLR_COMPONENT} component is not defined. Add a call to `add_component(${INSTALL_CLR_COMPONENT} )` to define the component in the build." )
397
+ endif ()
398
+ add_dependencies (${INSTALL_CLR_COMPONENT} ${targetName} )
399
+ endif ()
400
+ get_target_property (targetType ${targetName} TYPE )
401
+ if (NOT CLR_CMAKE_KEEP_NATIVE_SYMBOLS AND NOT "${targetType} " STREQUAL "STATIC" )
402
+ get_symbol_file_name(${targetName} symbol_file)
403
+ endif ()
363
404
364
- foreach (destination ${destinations} )
365
- # We don't need to install the export libraries for our DLLs
366
- # since they won't be directly linked against.
367
- install (PROGRAMS $<TARGET_FILE:${targetName} > DESTINATION ${destination} )
368
- if (NOT CLR_CMAKE_KEEP_NATIVE_SYMBOLS )
369
- install_symbols (${symbol_file} ${destination} )
370
- endif ()
405
+ foreach (destination ${destinations} )
406
+ # We don't need to install the export libraries for our DLLs
407
+ # since they won't be directly linked against.
408
+ install (PROGRAMS $<TARGET_FILE:${targetName} > DESTINATION ${destination} COMPONENT ${INSTALL_CLR_COMPONENT } )
409
+ if (NOT " ${symbolFile} " STREQUAL "" )
410
+ install_symbol_file (${symbol_file} ${destination} COMPONENT ${INSTALL_CLR_COMPONENT } )
411
+ endif ()
371
412
372
- if (CLR_CMAKE_PGO_INSTRUMENT)
373
- if (WIN32 )
374
- get_property (is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
375
- if (is_multi_config)
376
- install (FILES ${CMAKE_CURRENT_BINARY_DIR} /$<CONFIG>/${targetName} .pgd DESTINATION ${destination} /PGD OPTIONAL )
377
- else ()
378
- install (FILES ${CMAKE_CURRENT_BINARY_DIR} /${targetName} .pgd DESTINATION ${destination} /PGD OPTIONAL )
379
- endif ()
380
- endif ()
413
+ if (CLR_CMAKE_PGO_INSTRUMENT)
414
+ if (WIN32 )
415
+ get_property (is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
416
+ if (is_multi_config)
417
+ install (FILES ${CMAKE_CURRENT_BINARY_DIR} /$<CONFIG>/${targetName} .pgd DESTINATION ${destination} /PGD OPTIONAL COMPONENT ${INSTALL_CLR_COMPONENT} )
418
+ else ()
419
+ install (FILES ${CMAKE_CURRENT_BINARY_DIR} /${targetName} .pgd DESTINATION ${destination} /PGD OPTIONAL COMPONENT ${INSTALL_CLR_COMPONENT} )
381
420
endif ()
382
- endforeach ()
383
- endif ()
421
+ endif ()
422
+ endif ()
423
+ endforeach ()
384
424
endforeach ()
385
425
endfunction ()
386
426
@@ -427,45 +467,29 @@ if (CMAKE_VERSION VERSION_LESS "3.16")
427
467
endfunction ()
428
468
endif ()
429
469
430
- function (_add_executable )
470
+ function (add_executable_clr )
431
471
if (NOT WIN32 )
432
472
add_executable (${ARGV} ${VERSION_FILE_PATH} )
433
473
disable_pax_mprotect(${ARGV} )
434
474
else ()
435
475
add_executable (${ARGV} )
436
476
endif (NOT WIN32 )
437
- list (FIND CLR_CROSS_COMPONENTS_LIST ${ARGV0} INDEX)
438
- if (DEFINED CLR_CROSS_COMPONENTS_LIST AND ${INDEX} EQUAL -1)
439
- set_target_properties (${ARGV0} PROPERTIES EXCLUDE_FROM_ALL 1)
477
+ if (NOT CLR_CMAKE_KEEP_NATIVE_SYMBOLS)
478
+ strip_symbols(${ARGV0} symbolFile)
440
479
endif ()
441
480
endfunction ()
442
481
443
- function (_add_library )
482
+ function (add_library_clr )
444
483
if (NOT WIN32 AND "${ARGV1} " STREQUAL "SHARED" )
445
484
add_library (${ARGV} ${VERSION_FILE_PATH} )
446
485
else ()
447
486
add_library (${ARGV} )
448
487
endif (NOT WIN32 AND "${ARGV1} " STREQUAL "SHARED" )
449
- list (FIND CLR_CROSS_COMPONENTS_LIST ${ARGV0} INDEX)
450
- if (DEFINED CLR_CROSS_COMPONENTS_LIST AND ${INDEX} EQUAL -1)
451
- set_target_properties (${ARGV0} PROPERTIES EXCLUDE_FROM_ALL 1)
452
- endif ()
453
- endfunction ()
454
-
455
- function (_install)
456
- if (NOT DEFINED CLR_CROSS_COMPONENTS_BUILD)
457
- install (${ARGV} )
488
+ if ("${ARGV1} " STREQUAL "SHARED" AND NOT CLR_CMAKE_KEEP_NATIVE_SYMBOLS)
489
+ strip_symbols(${ARGV0} symbolFile)
458
490
endif ()
459
491
endfunction ()
460
492
461
- function (add_library_clr)
462
- _add_library(${ARGV} )
463
- endfunction ()
464
-
465
- function (add_executable_clr)
466
- _add_executable(${ARGV} )
467
- endfunction ()
468
-
469
493
# add_linker_flag(Flag [Config1 Config2 ...])
470
494
function (add_linker_flag Flag)
471
495
if (ARGN STREQUAL "" )
0 commit comments