-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnit.cmake
More file actions
852 lines (724 loc) · 39.9 KB
/
Unit.cmake
File metadata and controls
852 lines (724 loc) · 39.9 KB
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
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
# This file contains primary part of CMakeUnitFramework: unit registration and configuration routines.
define_property (TARGET PROPERTY UNIT_TARGET_TYPE
BRIEF_DOCS "Type of the registered unit target."
FULL_DOCS "Supported values: Abstract, Concrete, ConcreteInterface, Interface.")
define_property (TARGET PROPERTY INTERNAL_CONCRETE_SOURCES
BRIEF_DOCS "Property for concrete units that holds list of sources."
FULL_DOCS "Concrete units support preprocessing queues and therefore may change their sources several times "
"during configuration phase. Then, final sources are extracted through generator expression using this "
"property and passed to compiler.")
define_property (TARGET PROPERTY INTERNAL_CONCRETE_SOURCES_INITIAL
BRIEF_DOCS "Property that contains value of INTERNAL_CONCRETE_SOURCES when preprocessing queue was initialized."
FULL_DOCS "Used to provide source file names to preprocess step executors.")
define_property (TARGET PROPERTY INTERNAL_CONCRETE_GATHER_PRODUCTS
BRIEF_DOCS "Property for concrete units that holds list of sources produced by preprocessing gather steps."
FULL_DOCS "Some sources are produced as a result of gather steps and need to be added to sources separately.")
define_property (TARGET PROPERTY INTERNAL_CONCRETE_QUEUE_OUTPUT_INDEX
BRIEF_DOCS "Next step index in preprocessing queue for steps that have output."
FULL_DOCS "Steps that have output need to have their own directories and we use indices for naming them.")
# Defines which case framework uses for generating API macros. Support values:
# - Pascal
# - mixed_snake_case -- screaming case for macros and usual for files.
set (UNIT_FRAMEWORK_API_CASE "Pascal")
# Stub file for highlight-only targets for concrete units.
# In some cases, concrete unit sources are generated by external preprocessor tool. If this happens, most IDEs don't
# know how to highlight real source file that is not preprocessed. To solve this issue, we provide special
# highlight-only object libraries that should never be built, but are used to tell IDE how to highlight real sources.
set (UNIT_FRAMEWORK_HIGHLIGHT_STUB_SOURCE "${CMAKE_CURRENT_LIST_DIR}/highlight_stub.c")
# Anything under directory with that name is considered third party and excluded from Cushion scan only header paths.
# Third party headers are excluded as user cannot guarantee that these headers won't use checks unsupported by Cushion.
set (UNIT_FRAMEWORK_CUSHION_EXCLUDE_THIRD_PARTY_DIRECTORY "third_party")
# Populates values for UNIT_API_MACRO, UNIT_IMPLEMENTATION_MACRO and UNIT_API_FILE with appropriate values.
# UNIT_API_MACRO is a macro that is used to declare exported functions and symbols. UNIT_IMPLEMENTATION_MACRO is a macro
# that is only defined in targets with exported functions and symbols implementations. UNIT_API_FILE is a name of file
# with API macro (only file name, no path).
function (get_unit_api_variables API_UNIT_NAME)
# We expect unit name to follow the same case.
if (UNIT_FRAMEWORK_API_CASE STREQUAL "Pascal")
set (UNIT_API_MACRO "${API_UNIT_NAME}Api" PARENT_SCOPE)
set (UNIT_IMPLEMENTATION_MACRO "${API_UNIT_NAME}Implementation" PARENT_SCOPE)
set (UNIT_API_FILE "${API_UNIT_NAME}Api.h" PARENT_SCOPE)
elseif (UNIT_FRAMEWORK_API_CASE STREQUAL "mixed_snake_case")
string (TOUPPER "${API_UNIT_NAME}" API_UNIT_NAME_UPPER)
set (UNIT_API_MACRO "${API_UNIT_NAME_UPPER}_API" PARENT_SCOPE)
set (UNIT_IMPLEMENTATION_MACRO "${API_UNIT_NAME_UPPER}_IMPLEMENTATION" PARENT_SCOPE)
set (UNIT_API_FILE "${API_UNIT_NAME}_api.h" PARENT_SCOPE)
else ()
message (FATAL_ERROR "Unknown API case value \"${UNIT_FRAMEWORK_API_CASE}\".")
endif ()
endfunction ()
# Starts configuration routine of interface unit: header-only library.
function (register_interface UNIT_NAME)
message (STATUS "Registering interface \"${UNIT_NAME}\"...")
add_library ("${UNIT_NAME}" INTERFACE)
set_target_properties ("${UNIT_NAME}" PROPERTIES UNIT_TARGET_TYPE "Interface")
set (UNIT_NAME "${UNIT_NAME}" PARENT_SCOPE)
endfunction ()
# Adds given directories to interface include list of current interface unit.
function (interface_include)
foreach (INCLUDE_DIR ${ARGV})
message (STATUS " Add include \"${INCLUDE_DIR}\".")
target_include_directories ("${UNIT_NAME}" INTERFACE ${INCLUDE_DIR})
endforeach ()
endfunction ()
# Registers requirements of current interface unit.
# Arguments:
# - ABSTRACT: list of required abstract units.
# - CONCRETE_INTERFACE: list of required interfaces of concrete units.
# - INTERFACE: list of required interface units.
# - THIRD_PARTY: list of required third party targets.
function (interface_require)
cmake_parse_arguments (REQUIRE "" "" "ABSTRACT;CONCRETE_INTERFACE;INTERFACE;THIRD_PARTY" ${ARGV})
if (DEFINED REQUIRE_UNPARSED_ARGUMENTS OR (
NOT DEFINED REQUIRE_ABSTRACT AND
NOT DEFINED REQUIRE_CONCRETE_INTERFACE AND
NOT DEFINED REQUIRE_INTERFACE AND
NOT DEFINED REQUIRE_THIRD_PARTY))
message (FATAL_ERROR "Incorrect function arguments!")
endif ()
if (DEFINED REQUIRE_ABSTRACT)
foreach (DEPENDENCY ${REQUIRE_ABSTRACT})
message (STATUS " Require abstract \"${DEPENDENCY}\".")
reflected_target_link_libraries (TARGET "${UNIT_NAME}" INTERFACE "${DEPENDENCY}")
endforeach ()
endif ()
if (DEFINED REQUIRE_CONCRETE_INTERFACE)
foreach (DEPENDENCY ${REQUIRE_CONCRETE_INTERFACE})
message (STATUS " Require concrete interface \"${DEPENDENCY}\".")
reflected_target_link_libraries (TARGET "${UNIT_NAME}" INTERFACE "${DEPENDENCY}Interface")
endforeach ()
endif ()
if (DEFINED REQUIRE_INTERFACE)
foreach (DEPENDENCY ${REQUIRE_INTERFACE})
message (STATUS " Require interface \"${DEPENDENCY}\".")
reflected_target_link_libraries (TARGET "${UNIT_NAME}" INTERFACE "${DEPENDENCY}")
endforeach ()
endif ()
if (DEFINED REQUIRE_THIRD_PARTY)
foreach (DEPENDENCY ${REQUIRE_THIRD_PARTY})
message (STATUS " Require third party \"${DEPENDENCY}\".")
reflected_target_link_libraries (TARGET "${UNIT_NAME}" INTERFACE "${DEPENDENCY}")
endforeach ()
endif ()
endfunction ()
# Adds interface compile options to current interface unit.
function (interface_compile_options)
message (STATUS " Add compile options \"${ARGV}\".")
target_compile_options ("${UNIT_NAME}" INTERFACE ${ARGV})
endfunction ()
# Adds interface compile definitions to current interface unit.
function (interface_compile_definitions)
message (STATUS " Add compile definitions \"${ARGV}\".")
target_compile_definitions ("${UNIT_NAME}" INTERFACE ${ARGV})
endfunction ()
define_property (TARGET PROPERTY REQUIRED_CONCRETE_UNIT
BRIEF_DOCS "Name of concrete unit for this concrete unit interface."
FULL_DOCS "Concrete units consist of two targets: interface with only headers and implementation objects.")
# Starts configuration routine of concrete unit: headers with one concrete implementation.
function (register_concrete UNIT_NAME)
message (STATUS "Registering concrete \"${UNIT_NAME}\"...")
add_library ("${UNIT_NAME}Interface" INTERFACE)
set_target_properties ("${UNIT_NAME}Interface" PROPERTIES
UNIT_TARGET_TYPE "ConcreteInterface"
REQUIRED_CONCRETE_UNIT "${UNIT_NAME}")
add_library ("${UNIT_NAME}" OBJECT)
set_target_properties ("${UNIT_NAME}" PROPERTIES UNIT_TARGET_TYPE "Concrete")
target_sources ("${UNIT_NAME}" PRIVATE
$<TARGET_PROPERTY:${UNIT_NAME},INTERNAL_CONCRETE_SOURCES>
$<TARGET_PROPERTY:${UNIT_NAME},INTERNAL_CONCRETE_GATHER_PRODUCTS>)
reflected_target_link_libraries (TARGET "${UNIT_NAME}" PUBLIC "${UNIT_NAME}Interface")
add_library ("${UNIT_NAME}Highlight" OBJECT EXCLUDE_FROM_ALL "${UNIT_FRAMEWORK_HIGHLIGHT_STUB_SOURCE}")
set_target_properties ("${UNIT_NAME}Highlight" PROPERTIES UNIT_TARGET_TYPE "Concrete")
target_compile_definitions ("${UNIT_NAME}Highlight" PRIVATE CMAKE_UNIT_FRAMEWORK_HIGHLIGHT)
reflected_target_link_libraries (TARGET "${UNIT_NAME}Highlight" PUBLIC "${UNIT_NAME}Interface")
# Generate API header for shared library support.
set (GENERATED_DIRECTORY "${CMAKE_BINARY_DIR}/Generated/${UNIT_NAME}/")
file (MAKE_DIRECTORY "${GENERATED_DIRECTORY}")
get_unit_api_variables ("${UNIT_NAME}")
generate_api_header (
API_MACRO "${UNIT_API_MACRO}"
EXPORT_MACRO "${UNIT_IMPLEMENTATION_MACRO}"
OUTPUT_FILE "${GENERATED_DIRECTORY}/Include/${UNIT_API_FILE}")
target_compile_definitions ("${UNIT_NAME}" PRIVATE "${UNIT_IMPLEMENTATION_MACRO}")
target_include_directories ("${UNIT_NAME}Interface" INTERFACE "${GENERATED_DIRECTORY}/Include")
set (UNIT_NAME "${UNIT_NAME}" PARENT_SCOPE)
endfunction ()
# For internal use inside this file only.
# Helper for adding source to current concrete unit targets.
function (internal_concrete_add_sources)
get_target_property (QUEUE_STARTED "${UNIT_NAME}" INTERNAL_CONCRETE_SOURCES_INITIAL)
if (QUEUE_STARTED)
message (FATAL_ERROR " Caught attempt to add sources after preprocess queue configuration started.")
endif ()
get_target_property (TARGET_SOURCES "${UNIT_NAME}" INTERNAL_CONCRETE_SOURCES)
if (NOT TARGET_SOURCES)
set (TARGET_SOURCES)
endif ()
foreach (SOURCE ${ARGV})
cmake_path (ABSOLUTE_PATH SOURCE NORMALIZE)
list (APPEND TARGET_SOURCES "${SOURCE}")
endforeach ()
set_target_properties ("${UNIT_NAME}" PROPERTIES INTERNAL_CONCRETE_SOURCES "${TARGET_SOURCES}")
target_sources ("${UNIT_NAME}Highlight" PRIVATE ${ARGV})
endfunction ()
# Adds sources that match given glob recurse patterns to current concrete unit.
function (concrete_sources)
foreach (PATTERN ${ARGV})
message (STATUS " Add sources with recurse pattern \"${PATTERN}\".")
file (GLOB_RECURSE SOURCES "${PATTERN}")
internal_concrete_add_sources (${SOURCES})
endforeach ()
endfunction ()
# Directly adds given sources without globbing and checking for existence.
function (concrete_sources_direct)
message (STATUS " Add sources directly \"${ARGV}\".")
internal_concrete_add_sources (${ARGV})
endfunction ()
# Adds given sources that match given glob recurse patterns to highlight target of current concrete target.
function (concrete_highlight)
foreach (PATTERN ${ARGV})
file (GLOB_RECURSE SOURCES "${PATTERN}")
target_sources ("${UNIT_NAME}Highlight" PRIVATE ${SOURCES})
endforeach ()
endfunction ()
# Directly adds given sources to highlight target without globbing and checking for existence.
function (concrete_highlight_direct)
target_sources ("${UNIT_NAME}Highlight" PRIVATE ${ARGV})
endfunction ()
# Adds include directories to current concrete unit.
# Arguments:
# - PUBLIC: directories that are meant to be publicly linked.
# - PRIVATE: directories that are meant to be privately linked.
function (concrete_include)
cmake_parse_arguments (INCLUDE "" "" "PUBLIC;PRIVATE" ${ARGV})
if (DEFINED INCLUDE_UNPARSED_ARGUMENTS OR (
NOT DEFINED INCLUDE_PUBLIC AND
NOT DEFINED INCLUDE_PRIVATE))
message (FATAL_ERROR "Incorrect function arguments!")
endif ()
if (DEFINED INCLUDE_PUBLIC)
foreach (INCLUDE_DIR ${INCLUDE_PUBLIC})
message (STATUS " Add public scope include \"${INCLUDE_DIR}\".")
target_include_directories ("${UNIT_NAME}Interface" INTERFACE ${INCLUDE_DIR})
endforeach ()
endif ()
if (DEFINED INCLUDE_PRIVATE)
foreach (INCLUDE_DIR ${INCLUDE_PRIVATE})
message (STATUS " Add private scope include \"${INCLUDE_DIR}\".")
target_include_directories ("${UNIT_NAME}" PRIVATE ${INCLUDE_DIR})
target_include_directories ("${UNIT_NAME}Highlight" PRIVATE ${INCLUDE_DIR})
endforeach ()
endif ()
endfunction ()
# Registers requirements of current concrete unit.
# Arguments:
# - SCOPE: scope for these requirements, either PUBLIC or PRIVATE.
# - ABSTRACT: list of required abstract units.
# - CONCRETE_INTERFACE: list of required interfaces of concrete units.
# - INTERFACE: list of required interface units.
# - THIRD_PARTY: list of required third party targets.
function (concrete_require)
cmake_parse_arguments (REQUIRE "" "SCOPE" "INTERFACE;CONCRETE_INTERFACE;ABSTRACT;THIRD_PARTY" ${ARGV})
if (DEFINED REQUIRE_UNPARSED_ARGUMENTS OR
NOT DEFINED REQUIRE_SCOPE OR (
NOT DEFINED REQUIRE_INTERFACE AND
NOT DEFINED REQUIRE_CONCRETE_INTERFACE AND
NOT DEFINED REQUIRE_ABSTRACT AND
NOT DEFINED REQUIRE_THIRD_PARTY))
message (FATAL_ERROR "Incorrect function arguments!")
endif ()
if (REQUIRE_SCOPE STREQUAL "PUBLIC")
if (DEFINED REQUIRE_INTERFACE)
foreach (DEPENDENCY ${REQUIRE_INTERFACE})
message (STATUS " Require public scope interface \"${DEPENDENCY}\".")
reflected_target_link_libraries (TARGET "${UNIT_NAME}Interface" INTERFACE "${DEPENDENCY}")
endforeach ()
endif ()
if (DEFINED REQUIRE_CONCRETE_INTERFACE)
foreach (DEPENDENCY ${REQUIRE_CONCRETE_INTERFACE})
message (STATUS " Require public scope interface of concrete \"${DEPENDENCY}\".")
reflected_target_link_libraries (TARGET "${UNIT_NAME}Interface" INTERFACE "${DEPENDENCY}Interface")
endforeach ()
endif ()
if (DEFINED REQUIRE_ABSTRACT)
foreach (DEPENDENCY ${REQUIRE_ABSTRACT})
message (STATUS " Require public scope abstract \"${DEPENDENCY}\".")
reflected_target_link_libraries (TARGET "${UNIT_NAME}Interface" INTERFACE "${DEPENDENCY}")
endforeach ()
endif ()
if (DEFINED REQUIRE_THIRD_PARTY)
foreach (DEPENDENCY ${REQUIRE_THIRD_PARTY})
message (STATUS " Require public scope third party \"${DEPENDENCY}\".")
reflected_target_link_libraries (TARGET "${UNIT_NAME}Interface" INTERFACE "${DEPENDENCY}")
endforeach ()
endif ()
elseif (REQUIRE_SCOPE STREQUAL "PRIVATE")
if (DEFINED REQUIRE_INTERFACE)
foreach (DEPENDENCY ${REQUIRE_INTERFACE})
message (STATUS " Require private scope interface \"${DEPENDENCY}\".")
reflected_target_link_libraries (TARGET "${UNIT_NAME}" PRIVATE "${DEPENDENCY}")
reflected_target_link_libraries (TARGET "${UNIT_NAME}Highlight" PRIVATE "${DEPENDENCY}")
endforeach ()
endif ()
if (DEFINED REQUIRE_CONCRETE_INTERFACE)
foreach (DEPENDENCY ${REQUIRE_CONCRETE_INTERFACE})
message (STATUS " Require private scope interface of concrete \"${DEPENDENCY}\".")
reflected_target_link_libraries (TARGET "${UNIT_NAME}" PRIVATE "${DEPENDENCY}Interface")
reflected_target_link_libraries (TARGET "${UNIT_NAME}Highlight" PRIVATE "${DEPENDENCY}Interface")
endforeach ()
endif ()
if (DEFINED REQUIRE_ABSTRACT)
foreach (DEPENDENCY ${REQUIRE_ABSTRACT})
message (STATUS " Require private scope abstract \"${DEPENDENCY}\".")
reflected_target_link_libraries (TARGET "${UNIT_NAME}" PRIVATE "${DEPENDENCY}")
reflected_target_link_libraries (TARGET "${UNIT_NAME}Highlight" PRIVATE "${DEPENDENCY}")
endforeach ()
endif ()
if (DEFINED REQUIRE_THIRD_PARTY)
foreach (DEPENDENCY ${REQUIRE_THIRD_PARTY})
message (STATUS " Require private scope third party \"${DEPENDENCY}\".")
reflected_target_link_libraries (TARGET "${UNIT_NAME}" PRIVATE "${DEPENDENCY}")
reflected_target_link_libraries (TARGET "${UNIT_NAME}Highlight" PRIVATE "${DEPENDENCY}")
endforeach ()
endif ()
else ()
message (FATAL_ERROR "Incorrect function arguments!")
endif ()
endfunction ()
# Adds compile options to current concrete unit.
# Arguments:
# - PUBLIC: compile options that are added to public scope.
# - PRIVATE: compile options that are added to private scope.
function (concrete_compile_options)
cmake_parse_arguments (OPTIONS "" "" "PUBLIC;PRIVATE" ${ARGV})
if (DEFINED OPTIONS_UNPARSED_ARGUMENTS OR (
NOT DEFINED OPTIONS_PUBLIC AND
NOT DEFINED OPTIONS_PRIVATE))
message (FATAL_ERROR "Incorrect function arguments!")
endif ()
if (DEFINED OPTIONS_PUBLIC)
message (STATUS " Add public compile options \"${OPTIONS_PUBLIC}\".")
target_compile_options ("${UNIT_NAME}Interface" INTERFACE ${OPTIONS_PUBLIC})
endif ()
if (DEFINED OPTIONS_PRIVATE)
message (STATUS " Add private compile options \"${OPTIONS_PRIVATE}\".")
target_compile_options ("${UNIT_NAME}" PRIVATE ${OPTIONS_PRIVATE})
target_compile_options ("${UNIT_NAME}Highlight" PRIVATE ${OPTIONS_PRIVATE})
endif ()
endfunction ()
# Adds compile definitions to current concrete unit.
# Arguments:
# - PUBLIC: compile definitions that are added to public scope.
# - PRIVATE: compile definitions that are added to private scope.
function (concrete_compile_definitions)
cmake_parse_arguments (DEFINITIONS "" "" "PUBLIC;PRIVATE" ${ARGV})
if (DEFINED DEFINITIONS_UNPARSED_ARGUMENTS OR (
NOT DEFINED DEFINITIONS_PUBLIC AND
NOT DEFINED DEFINITIONS_PRIVATE))
message (FATAL_ERROR "Incorrect function arguments!")
endif ()
if (DEFINED DEFINITIONS_PUBLIC)
message (STATUS " Add public compile definitions \"${DEFINITIONS_PUBLIC}\".")
target_compile_definitions ("${UNIT_NAME}Interface" INTERFACE ${DEFINITIONS_PUBLIC})
endif ()
if (DEFINED DEFINITIONS_PRIVATE)
message (STATUS " Add private compile definitions \"${DEFINITIONS_PRIVATE}\".")
target_compile_definitions ("${UNIT_NAME}" PRIVATE ${DEFINITIONS_PRIVATE})
target_compile_definitions ("${UNIT_NAME}Highlight" PRIVATE ${DEFINITIONS_PRIVATE})
endif ()
endfunction ()
# Informs build system that this concrete unit implements given abstract unit.
# Needed to pass correct compile definitions to concrete unit objects.
function (concrete_implements_abstract ABSTRACT_NAME)
message (STATUS " Implement abstract unit \"${ABSTRACT_NAME}\".")
reflected_target_link_libraries (TARGET "${UNIT_NAME}" PRIVATE "${ABSTRACT_NAME}")
reflected_target_link_libraries (TARGET "${UNIT_NAME}Highlight" PRIVATE "${ABSTRACT_NAME}")
get_unit_api_variables ("${ABSTRACT_NAME}")
target_compile_definitions ("${UNIT_NAME}" PRIVATE "${UNIT_IMPLEMENTATION_MACRO}")
endfunction ()
# For internal use inside this file only.
# Starts preprocessing queue configurations if it is not yet started,
function (internal_concrete_preprocessing_queue_ensure_initialized)
get_target_property (QUEUE_STARTED "${UNIT_NAME}" INTERNAL_CONCRETE_SOURCES_INITIAL)
if (NOT QUEUE_STARTED)
get_target_property (TARGET_SOURCES "${UNIT_NAME}" INTERNAL_CONCRETE_SOURCES)
if (NOT TARGET_SOURCES)
message (FATAL_ERROR " Cannot start preprocessing queue when there is no sources!")
endif ()
set_target_properties ("${UNIT_NAME}" PROPERTIES INTERNAL_CONCRETE_SOURCES_INITIAL "${TARGET_SOURCES}")
endif ()
endfunction ()
# For internal use inside this file only.
# Generates next write step output directory and outputs source and output directories to provided variables.
function (internal_concrete_preprocessing_queue_setup_output_step)
cmake_parse_arguments (ARG "" "OUTPUT_SOURCE_DIR;OUTPUT_TARGET_DIR" "" ${ARGV})
if (DEFINED ARG_UNPARSED_ARGUMENTS OR
NOT DEFINED ARG_OUTPUT_SOURCE_DIR OR
NOT DEFINED ARG_OUTPUT_TARGET_DIR)
message (FATAL_ERROR "Incorrect function arguments!")
endif ()
set (GENERATED_DIRECTORY "${CMAKE_BINARY_DIR}/Generated/${UNIT_NAME}")
get_target_property (INDEX "${UNIT_NAME}" INTERNAL_CONCRETE_QUEUE_OUTPUT_INDEX)
if (INDEX)
math (EXPR PREVIOUS_INDEX "${INDEX} - 1")
set ("${ARG_OUTPUT_SOURCE_DIR}" "${GENERATED_DIRECTORY}/PPQ${PREVIOUS_INDEX}" PARENT_SCOPE)
else ()
set (INDEX 0)
set ("${ARG_OUTPUT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}" PARENT_SCOPE)
get_target_property (INITIAL_SOURCES "${UNIT_NAME}" INTERNAL_CONCRETE_SOURCES_INITIAL)
foreach (INITIAL_SOURCE ${INITIAL_SOURCES})
if (NOT INITIAL_SOURCE MATCHES "^${CMAKE_CURRENT_SOURCE_DIR}")
message (FATAL_ERROR
"Preprocessing input file \"${INITIAL_SOURCE}\" must be "
"under current source dir \"${CMAKE_CURRENT_SOURCE_DIR}\".")
endif ()
endforeach ()
endif ()
file (MAKE_DIRECTORY "${GENERATED_DIRECTORY}/PPQ${INDEX}")
set ("${ARG_OUTPUT_TARGET_DIR}" "${GENERATED_DIRECTORY}/PPQ${INDEX}" PARENT_SCOPE)
math (EXPR NEXT_INDEX "${INDEX} + 1")
set_target_properties ("${UNIT_NAME}" PROPERTIES INTERNAL_CONCRETE_QUEUE_OUTPUT_INDEX "${NEXT_INDEX}")
endfunction ()
# Preprocessing queue write step that runs Cushion preprocessor on sources.
# Only include paths that point under target source directory are used for full include.
# And scan only includes under global source/binary and project source/binary dirs are allowed for scan only includes.
# Additionally, UNIT_FRAMEWORK_CUSHION_EXCLUDE_THIRD_PARTY_DIRECTORY subdirectory of paths above is excluded from
# scan only paths as user cannot guarantee that third party includes are not using defines unknown to Cushion.
function (concrete_preprocessing_queue_step_cushion)
internal_concrete_preprocessing_queue_ensure_initialized ()
internal_concrete_preprocessing_queue_setup_output_step (
OUTPUT_SOURCE_DIR PPQ_SOURCE_DIR
OUTPUT_TARGET_DIR PPQ_TARGET_DIR)
if (NOT TARGET cushion)
message (FATAL_ERROR
"Called concrete_preprocessing_queue_step_cushion, but there is not registered \"cushion\" target.")
endif ()
get_target_property (STEP_SOURCES "${UNIT_NAME}" INTERNAL_CONCRETE_SOURCES)
set (STEP_OUTPUTS)
# Build proper filtered include paths for Cushion.
set (ALL_INCLUDES "$<TARGET_PROPERTY:${UNIT_NAME},INCLUDE_DIRECTORIES>")
set (FULL_INCLUDES "$<LIST:FILTER,${ALL_INCLUDES},INCLUDE,^$<TARGET_PROPERTY:${UNIT_NAME},SOURCE_DIR>.*$>")
set (SCAN_ONLY_ROOTS)
list (APPEND SCAN_ONLY_ROOTS "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}")
set (INCLUDE_ROOTS "${SCAN_ONLY_ROOTS}")
list (TRANSFORM INCLUDE_ROOTS PREPEND "(")
list (TRANSFORM INCLUDE_ROOTS APPEND ")")
list (JOIN INCLUDE_ROOTS "|" SCAN_ONLY_INCLUDE_REGEX)
set (EXCLUDE_MATCH "^.*\/${UNIT_FRAMEWORK_CUSHION_EXCLUDE_THIRD_PARTY_DIRECTORY}\/.*$")
set (SCAN_ONLY_INCLUDES "$<LIST:FILTER,${ALL_INCLUDES},INCLUDE,^(${SCAN_ONLY_INCLUDE_REGEX}).*$>")
set (SCAN_ONLY_INCLUDES "$<LIST:FILTER,${SCAN_ONLY_INCLUDES},EXCLUDE,${EXCLUDE_MATCH}>")
set (DEFINES "$<LIST:FILTER,$<TARGET_PROPERTY:${UNIT_NAME},COMPILE_DEFINITIONS>,EXCLUDE,^__CUSHION_PRESERVE__.*$>")
if (MSVC)
# Some MSVC-specific stuff is too intrusive and therefore we pass _MSC_VER to Cushion to deal with it.
set (DEFINES "${DEFINES};_MSC_VER")
endif ()
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "^.*Clang$")
# Some logic, especially connected to MSVC and Clang CL, might also depend on clang macro.
set (DEFINES "${DEFINES};__clang__")
endif ()
# Add compile definition to erase __CUSHION_PRESERVE__
# if it still exists in scan only headers during real compilation.
concrete_compile_definitions (PRIVATE __CUSHION_PRESERVE__=)
# Run Cushion for every source file.
set (SOURCE_INDEX 0)
foreach (STEP_SOURCE ${STEP_SOURCES})
set (SOURCE_RELATIVE "${STEP_SOURCE}")
cmake_path (RELATIVE_PATH SOURCE_RELATIVE BASE_DIRECTORY "${PPQ_SOURCE_DIR}")
set (STEP_OUTPUT "${PPQ_TARGET_DIR}/${SOURCE_RELATIVE}")
cmake_path (GET STEP_OUTPUT PARENT_PATH STEP_OUTPUT_PARENT)
file (MAKE_DIRECTORY "${STEP_OUTPUT_PARENT}")
add_custom_command (
OUTPUT "${STEP_OUTPUT}"
COMMENT "Preprocessing \"${STEP_SOURCE}\" using Cushion."
DEPENDS "${STEP_SOURCE}" "cushion"
DEPFILE "${STEP_OUTPUT}.deps"
# Compile command.
COMMAND
"cushion"
"--options" "forbid-macro-redefinition"
"--features"
"defer" "wrapper-macro" "statement-accumulator" "snippet" "evaluated-argument" "predefined-macro"
"--input" "${STEP_SOURCE}"
"--output" "${STEP_OUTPUT}"
"--cmake-depfile" "${STEP_OUTPUT}.deps"
"--define" ${DEFINES}
"--include-full" ${FULL_INCLUDES}
"--include-scan" ${SCAN_ONLY_INCLUDES}
COMMAND_EXPAND_LISTS)
math (EXPR SOURCE_INDEX "${SOURCE_INDEX} + 1")
list (APPEND STEP_OUTPUTS "${STEP_OUTPUT}")
endforeach ()
set_target_properties ("${UNIT_NAME}" PROPERTIES INTERNAL_CONCRETE_SOURCES "${STEP_OUTPUTS}")
endfunction ()
# Preprocessing queue write step that runs arbitrary executable with given arguments on filtered sources.
# This step takes sources from previous write step (or initial sources if there is no previous write step) and
# adds custom commands that execute given executable on these sources (separately for every source) in order to provide
# new generation of files. Filter is used to selectively update files, filtered out files will be just copied to the
# new generation.
#
# Arguments:
# - COMMAND: Name of the executable or executable target that is being executed.
# - FILTER: Filter expression in format compatible with CMake MATCHES operation. Optional.
# - ARGUMENTS: List of arguments that are passed to command.
# `$$INPUT` items are replaced with source file name from previous generation.
# `$$INITIAL_INPUT` items are replaced with initial source file name.
# `$$OUTPUT` items are replaced with output file name in new generation.
function (concrete_preprocessing_queue_step_apply)
cmake_parse_arguments (ARG "" "COMMAND;FILTER" "ARGUMENTS" ${ARGV})
if (DEFINED ARG_UNPARSED_ARGUMENTS OR
NOT DEFINED ARG_COMMAND OR
NOT DEFINED ARG_ARGUMENTS)
message (FATAL_ERROR "Incorrect function arguments!")
endif ()
internal_concrete_preprocessing_queue_ensure_initialized ()
internal_concrete_preprocessing_queue_setup_output_step (
OUTPUT_SOURCE_DIR PPQ_SOURCE_DIR
OUTPUT_TARGET_DIR PPQ_TARGET_DIR)
get_target_property (STEP_SOURCES "${UNIT_NAME}" INTERNAL_CONCRETE_SOURCES)
get_target_property (INITIAL_SOURCES "${UNIT_NAME}" INTERNAL_CONCRETE_SOURCES_INITIAL)
set (STEP_OUTPUTS)
foreach (STEP_SOURCE INITIAL_SOURCE IN ZIP_LISTS STEP_SOURCES INITIAL_SOURCES)
set (SOURCE_RELATIVE "${STEP_SOURCE}")
cmake_path (RELATIVE_PATH SOURCE_RELATIVE BASE_DIRECTORY "${PPQ_SOURCE_DIR}")
set (STEP_OUTPUT "${PPQ_TARGET_DIR}/${SOURCE_RELATIVE}")
if (NOT ARG_FILTER OR "${INITIAL_SOURCE}" MATCHES "${ARG_FILTER}")
set (COMMAND_ARGUMENTS)
foreach (ARGUMENT ${ARG_ARGUMENTS})
if ("${ARGUMENT}" STREQUAL "$$INPUT")
list (APPEND COMMAND_ARGUMENTS "${STEP_SOURCE}")
elseif ("${ARGUMENT}" STREQUAL "$$INITIAL_INPUT")
list (APPEND COMMAND_ARGUMENTS "${INITIAL_SOURCE}")
elseif ("${ARGUMENT}" STREQUAL "$$OUTPUT")
list (APPEND COMMAND_ARGUMENTS "${STEP_OUTPUT}")
else ()
list (APPEND COMMAND_ARGUMENTS "${ARGUMENT}")
endif ()
endforeach ()
add_custom_command (
OUTPUT "${STEP_OUTPUT}"
COMMENT "Processing ${STEP_SOURCE} with ${ARG_COMMAND}."
DEPENDS "${STEP_SOURCE}" ${ARG_COMMAND}
COMMAND ${ARG_COMMAND} ${COMMAND_ARGUMENTS}
COMMAND_EXPAND_LISTS
VERBATIM)
list (APPEND STEP_OUTPUTS "${STEP_OUTPUT}")
else ()
if (PPQ_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
# We need to reference source file properly for compilation and debug information.
add_custom_command (
OUTPUT "${STEP_OUTPUT}"
COMMENT "Copying ${STEP_SOURCE}."
DEPENDS "${STEP_SOURCE}"
COMMAND
${CMAKE_COMMAND}
-D INPUT="${STEP_SOURCE}"
-D OUTPUT="${STEP_OUTPUT}"
-P "${UNIT_FRAMEWORK_SCRIPTS}/CopyPrependLine.cmake")
else ()
add_custom_command (
OUTPUT "${STEP_OUTPUT}"
COMMENT "Copying ${STEP_SOURCE}."
DEPENDS "${STEP_SOURCE}"
COMMAND
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${STEP_SOURCE}" "${STEP_OUTPUT}"
VERBATIM)
endif ()
list (APPEND STEP_OUTPUTS "${STEP_OUTPUT}")
endif ()
endforeach ()
set_target_properties ("${UNIT_NAME}" PROPERTIES INTERNAL_CONCRETE_SOURCES "${STEP_OUTPUTS}")
endfunction ()
# Processing queue gather step that runs arbitrary executable on subset of files in order to produce one product file.
# Gather steps are used to extract data from filtered subsets of files from previous write step (or initial sources
# if there is no previous write step) and save it as generated product source file, for example it can be reflection
# for the whole unit. Product does not participate in preprocess generations. Command is executed for all files at
# once and must always have one product file. As gather steps do not modify generation files, they can be executed
# simultaneously with other steps or compilation.
#
# Arguments:
# - COMMAND: Name of the executable or executable target that is being executed.
# - PRODUCT: Relative name of product file. Will be created in generation directory.
# - FILTER: Filter expression in format compatible with CMake MATCHES operation. Optional.
# - ARGUMENTS: List of arguments that are passed to the executable.
# `$$INPUT` items are replaced with list of filtered source files at current generation.
# `$$INPUT_LIST` is the same as `$$INPUT`, but source files as saved to new line separated text list file
# and path to this file is provided.
# `$$PRODUCT` items are replaced with absolute product file name.
# - EXTRA_DEPENDENCIES: Additional dependencies to be added to gather step command.
function (concrete_preprocessing_queue_step_gather)
cmake_parse_arguments (ARG "" "COMMAND;PRODUCT;FILTER" "ARGUMENTS;EXTRA_DEPENDENCIES" ${ARGV})
if (DEFINED ARG_UNPARSED_ARGUMENTS OR
NOT DEFINED ARG_COMMAND OR
NOT DEFINED ARG_PRODUCT OR
NOT DEFINED ARG_ARGUMENTS)
message (FATAL_ERROR "Incorrect function arguments!")
endif ()
internal_concrete_preprocessing_queue_ensure_initialized ()
set (GENERATED_DIRECTORY "${CMAKE_BINARY_DIR}/Generated/${UNIT_NAME}")
get_target_property (INDEX "${UNIT_NAME}" INTERNAL_CONCRETE_QUEUE_OUTPUT_INDEX)
if (INDEX)
math (EXPR PREVIOUS_INDEX "${INDEX} - 1")
set (PPQ_SOURCE_DIR "${GENERATED_DIRECTORY}/PPQ${PREVIOUS_INDEX}")
else ()
set (PPQ_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
endif ()
get_target_property (STEP_SOURCES "${UNIT_NAME}" INTERNAL_CONCRETE_SOURCES)
get_target_property (INITIAL_SOURCES "${UNIT_NAME}" INTERNAL_CONCRETE_SOURCES_INITIAL)
set (PRODUCT_ABSOLUTE "${GENERATED_DIRECTORY}/${ARG_PRODUCT}")
set (COMMAND_ARGUMENTS)
set (FILE_LISTS)
foreach (ARGUMENT ${ARG_ARGUMENTS})
if ("${ARGUMENT}" STREQUAL "$$INPUT")
foreach (STEP_SOURCE INITIAL_SOURCE IN ZIP_LISTS STEP_SOURCES INITIAL_SOURCES)
if (NOT ARG_FILTER OR "${INITIAL_SOURCE}" MATCHES "${ARG_FILTER}")
list (APPEND COMMAND_ARGUMENTS ${STEP_SOURCE})
endif ()
endforeach ()
elseif ("${ARGUMENT}" STREQUAL "$$INPUT_LIST")
set (INPUTS)
foreach (STEP_SOURCE INITIAL_SOURCE IN ZIP_LISTS STEP_SOURCES INITIAL_SOURCES)
if (NOT ARG_FILTER OR "${INITIAL_SOURCE}" MATCHES "${ARG_FILTER}")
list (APPEND INPUTS ${STEP_SOURCE})
endif ()
endforeach ()
list (JOIN INPUTS "\n" INPUT_LIST)
file (WRITE "${PRODUCT_ABSOLUTE}.input.list" "${INPUT_LIST}")
list (APPEND COMMAND_ARGUMENTS "${PRODUCT_ABSOLUTE}.input.list")
list (APPEND FILE_LISTS "${PRODUCT_ABSOLUTE}.input.list")
elseif ("${ARGUMENT}" STREQUAL "$$PRODUCT")
list (APPEND COMMAND_ARGUMENTS "${PRODUCT_ABSOLUTE}")
else ()
list (APPEND COMMAND_ARGUMENTS "${ARGUMENT}")
endif ()
endforeach ()
add_custom_command (
OUTPUT "${PRODUCT_ABSOLUTE}"
COMMENT "Gathering preprocessed data using ${ARG_COMMAND} for target \"${UNIT_NAME}\"."
DEPENDS ${STEP_SOURCES} ${ARG_COMMAND} ${ARG_EXTRA_DEPENDENCIES} ${FILE_LISTS}
COMMAND ${ARG_COMMAND} ${COMMAND_ARGUMENTS}
COMMAND_EXPAND_LISTS
VERBATIM)
get_target_property (PRODUCTS "${UNIT_NAME}" INTERNAL_CONCRETE_GATHER_PRODUCTS)
if (NOT PRODUCTS)
set (PRODUCTS)
endif ()
list (APPEND PRODUCTS "${PRODUCT_ABSOLUTE}")
set_target_properties ("${UNIT_NAME}" PROPERTIES INTERNAL_CONCRETE_GATHER_PRODUCTS "${PRODUCTS}")
endfunction ()
# Exclude source produced from given initial source at given absolute path from further preprocessing queue steps and
# from compilation. Needed for rare cases when we've created temporary source that does not need to be compiled in the
# end as it is only used for some preprocessing routines like processing headers of header-only unit.
function (concrete_preprocessing_queue_exclude_source INITIAL_ABSOLUTE_PATH)
internal_concrete_preprocessing_queue_ensure_initialized ()
get_target_property (STEP_SOURCES "${UNIT_NAME}" INTERNAL_CONCRETE_SOURCES)
get_target_property (INITIAL_SOURCES "${UNIT_NAME}" INTERNAL_CONCRETE_SOURCES_INITIAL)
list (FIND INITIAL_SOURCES "${INITIAL_ABSOLUTE_PATH}" PATH_INDEX)
if (PATH_INDEX EQUAL -1)
message (SEND_ERROR "Unable to exclude \"${INITIAL_ABSOLUTE_PATH}\" from preprocessing queue sources "
"as it is not found among initial sources!")
return ()
endif ()
list (REMOVE_AT STEP_SOURCES ${PATH_INDEX})
list (REMOVE_AT INITIAL_SOURCES ${PATH_INDEX})
set_target_properties ("${UNIT_NAME}" PROPERTIES
INTERNAL_CONCRETE_SOURCES "${STEP_SOURCES}" INTERNAL_CONCRETE_SOURCES_INITIAL "${INITIAL_SOURCES}")
endfunction ()
# Starts configuration routine of abstract unit: headers that might have multiple implementations.
function (register_abstract UNIT_NAME)
message (STATUS "Registering abstract \"${UNIT_NAME}\"...")
add_library ("${UNIT_NAME}" INTERFACE)
set_target_properties ("${UNIT_NAME}" PROPERTIES UNIT_TARGET_TYPE "Abstract")
# Generate API header for shared library support.
set (GENERATED_DIRECTORY "${CMAKE_BINARY_DIR}/Generated/${UNIT_NAME}/")
file (MAKE_DIRECTORY "${GENERATED_DIRECTORY}")
get_unit_api_variables ("${UNIT_NAME}")
generate_api_header (
API_MACRO "${UNIT_API_MACRO}"
EXPORT_MACRO "${UNIT_IMPLEMENTATION_MACRO}"
OUTPUT_FILE "${GENERATED_DIRECTORY}/${UNIT_API_FILE}")
target_include_directories ("${UNIT_NAME}" INTERFACE "${GENERATED_DIRECTORY}")
set (UNIT_NAME "${UNIT_NAME}" PARENT_SCOPE)
endfunction ()
# Adds given directories to interface include list of current abstract unit.
function (abstract_include INCLUDE_DIR)
# Technically, abstract is an advanced interface. Therefore we're using some of the interface functions.
interface_include (${ARGV})
endfunction ()
# Registers requirements of current abstract unit.
# Arguments:
# - ABSTRACT: list of required abstract units.
# - CONCRETE_INTERFACE: list of required interfaces of concrete units.
# - INTERFACE: list of required interface units.
# - THIRD_PARTY: list of required third party targets.
function (abstract_require)
# Technically, abstract is an advanced interface. Therefore we're using some of the interface functions.
interface_require (${ARGV})
endfunction ()
# Adds interface compile options to current abstract unit.
function (abstract_compile_definitions)
interface_compile_definitions (${ARGV})
endfunction ()
define_property (TARGET PROPERTY IMPLEMENTATIONS
BRIEF_DOCS "List of implementations of the abstract unit."
FULL_DOCS "Saving list of implementations makes it easy to add custom logic to build system.")
define_property (TARGET PROPERTY IMPLEMENTATION_REMAP
BRIEF_DOCS "List of concrete units that form implementation of associated abstract unit."
FULL_DOCS "Added to special implementation marker target.")
# Registers new implementation for current abstract unit.
# Arguments:
# - NAME: name of the implementation.
# - PARTS: list of concrete units that form implementation of this abstract unit.
function (abstract_register_implementation)
cmake_parse_arguments (IMPLEMENTATION "" "NAME" "PARTS" ${ARGN})
if (DEFINED IMPLEMENTATION_UNPARSED_ARGUMENTS OR
NOT DEFINED IMPLEMENTATION_NAME OR
NOT DEFINED IMPLEMENTATION_PARTS)
message (FATAL_ERROR "Incorrect function arguments!")
endif ()
message (STATUS " Add implementation \"${IMPLEMENTATION_NAME}\".")
add_library ("${UNIT_NAME}${IMPLEMENTATION_NAME}Marker" INTERFACE)
foreach (PART_NAME ${IMPLEMENTATION_PARTS})
message (STATUS " Add part \"${PART_NAME}\".")
endforeach ()
set_target_properties ("${UNIT_NAME}${IMPLEMENTATION_NAME}Marker" PROPERTIES
UNIT_TARGET_TYPE "AbstractImplementation"
IMPLEMENTATION_REMAP "${IMPLEMENTATION_PARTS}")
get_target_property (IMPLEMENTATIONS "${UNIT_NAME}" IMPLEMENTATIONS)
if (IMPLEMENTATIONS STREQUAL "IMPLEMENTATIONS-NOTFOUND")
set (IMPLEMENTATIONS)
endif ()
list (APPEND IMPLEMENTATIONS "${IMPLEMENTATION_NAME}")
set_target_properties ("${UNIT_NAME}" PROPERTIES IMPLEMENTATIONS "${IMPLEMENTATIONS}")
endfunction ()
# Registers alias to an already registered implementation.
# Arguments:
# - ALIAS: name of the alias implementation.
# - SOURCE: name of the source implementation.
function (abstract_alias_implementation)
cmake_parse_arguments (IMPLEMENTATION "" "ALIAS;SOURCE" "" ${ARGN})
if (DEFINED IMPLEMENTATION_UNPARSED_ARGUMENTS OR
NOT DEFINED IMPLEMENTATION_ALIAS OR
NOT DEFINED IMPLEMENTATION_SOURCE)
message (FATAL_ERROR "Incorrect function arguments!")
endif ()
message (STATUS " Add implementation alias \"${IMPLEMENTATION_ALIAS}\" to \"${IMPLEMENTATION_SOURCE}\".")
add_library ("${UNIT_NAME}${IMPLEMENTATION_ALIAS}Marker" ALIAS "${UNIT_NAME}${IMPLEMENTATION_SOURCE}Marker")
endfunction ()
# Outputs list of all implementations of requested abstract unit. Omits aliases.
# Arguments:
# - ABSTRACT: name of the abstract unit.
# - OUTPUT: name of the output variable.
function (abstract_get_implementations)
cmake_parse_arguments (SEARCH "" "ABSTRACT;OUTPUT" "" ${ARGV})
if (DEFINED SEARCH_UNPARSED_ARGUMENTS OR
NOT DEFINED SEARCH_ABSTRACT OR
NOT DEFINED SEARCH_OUTPUT)
message (FATAL_ERROR "Incorrect function arguments!")
endif ()
get_target_property (IMPLEMENTATIONS "${SEARCH_ABSTRACT}" IMPLEMENTATIONS)
if (IMPLEMENTATIONS STREQUAL "IMPLEMENTATIONS-NOTFOUND")
set ("${SEARCH_OUTPUT}" "" PARENT_SCOPE)
else ()
set ("${SEARCH_OUTPUT}" "${IMPLEMENTATIONS}" PARENT_SCOPE)
endif ()
endfunction ()