forked from bloomberg/ntf-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepository.cmake
9024 lines (7251 loc) · 303 KB
/
repository.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
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
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright 2020-2023 Bloomberg Finance L.P.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
include_guard(GLOBAL)
include(CMakePackageConfigHelpers)
# Return the current log level name.
function (ntf_log_level_name)
cmake_parse_arguments(
NTF_LOG_LEVEL_NAME "" "OUTPUT" "" ${ARGN})
if (NOT DEFINED NTF_LOG_LEVEL_NAME)
if ("${CMAKE_MESSAGE_LOG_LEVEL}" STREQUAL "")
set(NTF_LOG_LEVEL_NAME "STATUS" CACHE INTERNAL "")
else()
set(NTF_LOG_LEVEL_NAME
"${CMAKE_MESSAGE_LOG_LEVEL}" CACHE INTERNAL "")
endif()
endif()
if (DEFINED NTF_LOG_LEVEL_NAME_OUTPUT)
set(${NTF_LOG_LEVEL_NAME_OUTPUT} ${NTF_LOG_LEVEL_NAME} PARENT_SCOPE)
endif()
endfunction()
# Return the current log level number.
function (ntf_log_level_number)
cmake_parse_arguments(
NTF_LOG_LEVEL_NUMBER "" "OUTPUT" "" ${ARGN})
if (NOT DEFINED NTF_LOG_LEVEL_NUMBER)
ntf_log_level_name(OUTPUT log_level_name)
set(log_level_number ${NTF_LOG_LEVEL_NUMBER_OFF})
if("${log_level_name}" STREQUAL "ERROR")
set(log_level_number ${NTF_LOG_LEVEL_NUMBER_ERROR})
elseif("${log_level_name}" STREQUAL "WARNING")
set(log_level_number ${NTF_LOG_LEVEL_NUMBER_WARNING})
elseif("${log_level_name}" STREQUAL "NOTICE")
set(log_level_number ${NTF_LOG_LEVEL_NUMBER_NOTICE})
elseif("${log_level_name}" STREQUAL "STATUS")
set(log_level_number ${NTF_LOG_LEVEL_NUMBER_STATUS})
elseif("${log_level_name}" STREQUAL "VERBOSE")
set(log_level_number ${NTF_LOG_LEVEL_NUMBER_VERBOSE})
elseif("${log_level_name}" STREQUAL "DEBUG")
set(log_level_number ${NTF_LOG_LEVEL_NUMBER_DEBUG})
elseif("${log_level_name}" STREQUAL "TRACE")
set(log_level_number ${NTF_LOG_LEVEL_NUMBER_TRACE})
else()
message(FATAL_ERROR "Invalid log level: ${log_level_name}")
endif()
set(NTF_LOG_LEVEL_NUMBER "${log_level_number}" CACHE INTERNAL "")
endif()
if (DEFINED NTF_LOG_LEVEL_NUMBER_OUTPUT)
set(${NTF_LOG_LEVEL_NUMBER_OUTPUT} ${NTF_LOG_LEVEL_NUMBER} PARENT_SCOPE)
endif()
endfunction()
# Return true if the given log level is enabled.
#
# NUMBER - The log level number.
# OUTPUT - The variable name set in the parent scope.
function (ntf_log_level_enabled)
cmake_parse_arguments(
NTF_LOG_LEVEL_ENABLED "" "NUMBER;OUTPUT" "" ${ARGN})
ntf_assert_defined(${NTF_LOG_LEVEL_ENABLED_NUMBER})
ntf_assert_defined(${NTF_LOG_LEVEL_ENABLED_OUTPUT})
ntf_log_level_number(OUTPUT threshold)
if (${NTF_LOG_LEVEL_ENABLED_NUMBER} LESS_EQUAL ${threshold})
set(${NTF_LOG_LEVEL_ENABLED_OUTPUT} TRUE PARENT_SCOPE)
else()
set(${NTF_LOG_LEVEL_ENABLED_OUTPUT} FALSE PARENT_SCOPE)
endif()
endfunction()
# ERROR, WARNING, NOTICE, STATUS (default), VERBOSE, DEBUG, or TRACE.
function (ntf_log_init)
set(NTF_LOG_LEVEL_NUMBER_OFF 0 CACHE INTERNAL "")
set(NTF_LOG_LEVEL_NUMBER_ERROR 1 CACHE INTERNAL "")
set(NTF_LOG_LEVEL_NUMBER_WARNING 2 CACHE INTERNAL "")
set(NTF_LOG_LEVEL_NUMBER_NOTICE 3 CACHE INTERNAL "")
set(NTF_LOG_LEVEL_NUMBER_STATUS 3 CACHE INTERNAL "")
set(NTF_LOG_LEVEL_NUMBER_VERBOSE 4 CACHE INTERNAL "")
set(NTF_LOG_LEVEL_NUMBER_DEBUG 4 CACHE INTERNAL "")
set(NTF_LOG_LEVEL_NUMBER_TRACE 5 CACHE INTERNAL "")
ntf_log_level_enabled(
NUMBER ${NTF_LOG_LEVEL_NUMBER_ERROR}
OUTPUT ntf_log_error_enabled)
if (${ntf_log_error_enabled})
set(NTF_LOG_ERROR TRUE CACHE INTERNAL "")
else()
unset(NTF_LOG_ERROR CACHE)
endif()
ntf_log_level_enabled(
NUMBER ${NTF_LOG_LEVEL_NUMBER_WARNING}
OUTPUT ntf_log_warning_enabled)
if (${ntf_log_warning_enabled})
set(NTF_LOG_WARNING TRUE CACHE INTERNAL "")
else()
unset(NTF_LOG_WARNING CACHE)
endif()
ntf_log_level_enabled(
NUMBER ${NTF_LOG_LEVEL_NUMBER_NOTICE}
OUTPUT ntf_log_notice_enabled)
if (${ntf_log_notice_enabled})
set(NTF_LOG_NOTICE TRUE CACHE INTERNAL "")
else()
unset(NTF_LOG_NOTICE CACHE)
endif()
ntf_log_level_enabled(
NUMBER ${NTF_LOG_LEVEL_NUMBER_STATUS}
OUTPUT ntf_log_status_enabled)
if (${ntf_log_status_enabled})
set(NTF_LOG_STATUS TRUE CACHE INTERNAL "")
else()
unset(NTF_LOG_STATUS CACHE)
endif()
ntf_log_level_enabled(
NUMBER ${NTF_LOG_LEVEL_NUMBER_VERBOSE}
OUTPUT ntf_log_verbose_enabled)
if (${ntf_log_verbose_enabled})
set(NTF_LOG_VERBOSE TRUE CACHE INTERNAL "")
else()
unset(NTF_LOG_VERBOSE CACHE)
endif()
ntf_log_level_enabled(
NUMBER ${NTF_LOG_LEVEL_NUMBER_DEBUG}
OUTPUT ntf_log_debug_enabled)
if (${ntf_log_debug_enabled})
set(NTF_LOG_DEBUG TRUE CACHE INTERNAL "")
else()
unset(NTF_LOG_DEBUG CACHE)
endif()
ntf_log_level_enabled(
NUMBER ${NTF_LOG_LEVEL_NUMBER_TRACE}
OUTPUT ntf_log_trace_enabled)
if (${ntf_log_trace_enabled})
set(NTF_LOG_TRACE TRUE CACHE INTERNAL "")
else()
unset(NTF_LOG_TRACE CACHE)
endif()
endfunction()
# Log a message at the "info" severity level.
macro (ntf_log_info)
cmake_parse_arguments(
NTF_LOG_INFO "" "CONTEXT" "CONTENT" ${ARGN})
if (${NTF_LOG_STATUS})
if ("${NTF_LOG_INFO_CONTENT}" STREQUAL "")
set(NTF_LOG_INFO_CONTENT ${ARGN})
endif()
string(
REPLACE
";" " "
ntf_log_info_content
"${NTF_LOG_INFO_CONTENT}")
string(
REGEX REPLACE
"[ \t\r\n]+"
" "
ntf_log_info_content
"${ntf_log_info_content}")
list(APPEND CMAKE_MESSAGE_CONTEXT "${NTF_LOG_INFO_CONTEXT}")
message(
STATUS
"[ INFO ][ ${CMAKE_CURRENT_FUNCTION} ]"
"[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ]: "
"${ntf_log_info_content}")
list(POP_BACK CMAKE_MESSAGE_CONTEXT)
endif()
endmacro()
# Log a message at the "debug" severity level.
macro (ntf_log_debug)
cmake_parse_arguments(
NTF_LOG_DEBUG "" "CONTEXT" "CONTENT" ${ARGN})
if (${NTF_LOG_DEBUG})
if ("${NTF_LOG_DEBUG_CONTENT}" STREQUAL "")
set(NTF_LOG_DEBUG_CONTENT ${ARGN})
endif()
string(
REPLACE
";" " "
ntf_log_debug_content
"${NTF_LOG_DEBUG_CONTENT}")
string(
REGEX REPLACE
"[ \t\r\n]+"
" "
ntf_log_debug_content
"${ntf_log_debug_content}")
list(APPEND CMAKE_MESSAGE_CONTEXT "${NTF_LOG_DEBUG_CONTEXT}")
message(
DEBUG
"[ INFO ][ ${CMAKE_CURRENT_FUNCTION} ]"
"[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ]: "
"${ntf_log_info_content}")
list(POP_BACK CMAKE_MESSAGE_CONTEXT)
endif()
endmacro()
# Log a message at the "trace" severity level.
macro (ntf_log_trace)
cmake_parse_arguments(
NTF_LOG_TRACE "" "CONTEXT" "CONTENT" ${ARGN})
if (${NTF_LOG_TRACE})
if ("${NTF_LOG_TRACE_CONTENT}" STREQUAL "")
set(NTF_LOG_TRACE_CONTENT ${ARGN})
endif()
string(
REPLACE
";" " "
ntf_log_trace_content
"${NTF_LOG_TRACE_CONTENT}")
string(
REGEX REPLACE
"[ \t\r\n]+"
" "
ntf_log_trace_content
"${ntf_log_trace_content}")
list(APPEND CMAKE_MESSAGE_CONTEXT "${NTF_LOG_TRACE_CONTEXT}")
message(
TRACE
"[ INFO ][ ${CMAKE_CURRENT_FUNCTION} ]"
"[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ]: "
"${ntf_log_info_content}")
list(POP_BACK CMAKE_MESSAGE_CONTEXT)
endif()
endmacro()
# Log a message and abort with a stack trace.
function (ntf_die message)
message(FATAL_ERROR ${message})
endfunction()
# Abort if a variable value is not defined.
function (ntf_assert_defined)
list(POP_FRONT ARGN value)
if ("${value}" STREQUAL "")
ntf_die("The value is not defined")
endif()
endfunction()
# Abort if a target is not defined.
function (ntf_assert_target_defined target)
if(NOT TARGET ${target})
ntf_die("There is no target named '${target}'")
endif()
endfunction()
# Return the case-appropriate name of a target.
#
# TARGET - The target.
# OUTPUT - The variable name set in the parent scope.
function (ntf_nomenclature_target)
cmake_parse_arguments(
ARG "" "TARGET;OUTPUT" "" ${ARGN})
ntf_assert_defined(${ARG_TARGET})
ntf_assert_defined(${ARG_OUTPUT})
# string(TOLOWER ${ARG_TARGET} target_lowercase)
# set(${ARG_OUTPUT} ${target_lowercase} PARENT_SCOPE)
set(${ARG_OUTPUT} ${ARG_TARGET} PARENT_SCOPE)
endfunction()
# Return the case-appropriate name of a variable.
#
# VARIABLE - The variable.
# OUTPUT - The variable name set in the parent scope.
function (ntf_nomenclature_variable)
cmake_parse_arguments(
ARG "" "VARIABLE;OUTPUT" "" ${ARGN})
ntf_assert_defined(${ARG_VARIABLE})
ntf_assert_defined(${ARG_OUTPUT})
string(TOUPPER ${ARG_VARIABLE} variable_uppercase)
set(${ARG_OUTPUT} NTF_${variable_uppercase} PARENT_SCOPE)
endfunction()
# Set a variable scoped to a target.
#
# TARGET - The target.
# VARIABLE - The variable name.
# VALUE - The variable value.
function (ntf_target_variable_set)
cmake_parse_arguments(
ARG "" "TARGET;VARIABLE" "VALUE" ${ARGN})
ntf_assert_defined(${ARG_TARGET})
ntf_assert_defined(${ARG_VARIABLE})
# ntf_assert_defined(${ARG_VALUE})
ntf_nomenclature_target(TARGET ${ARG_TARGET} OUTPUT target)
ntf_nomenclature_variable(VARIABLE ${ARG_VARIABLE} OUTPUT variable)
ntf_assert_target_defined(${target})
if (NOT "${ARG_VALUE}" STREQUAL "")
set_property(TARGET ${target} PROPERTY ${variable} ${ARG_VALUE})
else()
set_property(TARGET ${target} PROPERTY ${variable} "")
endif()
endfunction()
# Append to a variable scoped to a target.
#
# TARGET - The target.
# VARIABLE - The variable name.
# VALUE - The variable value.
function (ntf_target_variable_append)
cmake_parse_arguments(
ARG "" "TARGET;VARIABLE" "VALUE" ${ARGN})
ntf_assert_defined(${ARG_TARGET})
ntf_assert_defined(${ARG_VARIABLE})
# ntf_assert_defined(${ARG_VALUE})
ntf_nomenclature_target(TARGET ${ARG_TARGET} OUTPUT target)
ntf_nomenclature_variable(VARIABLE ${ARG_VARIABLE} OUTPUT variable)
ntf_assert_target_defined(${target})
if (NOT "${ARG_VALUE}" STREQUAL "")
get_property(result TARGET ${target} PROPERTY ${variable})
list(APPEND result ${ARG_VALUE})
set_property(TARGET ${target} PROPERTY ${variable} ${result})
endif()
endfunction()
# Get a variable scoped to a target.
#
# TARGET - The target.
# VARIABLE - The variable name.
# OUTPUT - The variable name set in the parent scope.
function (ntf_target_variable_get)
cmake_parse_arguments(
ARG "" "TARGET;VARIABLE;OUTPUT" "" ${ARGN})
ntf_assert_defined(${ARG_TARGET})
ntf_assert_defined(${ARG_VARIABLE})
ntf_assert_defined(${ARG_OUTPUT})
ntf_nomenclature_target(TARGET ${ARG_TARGET} OUTPUT target)
ntf_nomenclature_variable(VARIABLE ${ARG_VARIABLE} OUTPUT variable)
ntf_assert_target_defined(${target})
get_property(result TARGET ${target} PROPERTY ${variable})
set(${ARG_OUTPUT} ${result} PARENT_SCOPE)
endfunction()
# Set the "description" variable scoped to a target.
#
# TARGET - The target.
# VALUE - The variable value.
function (ntf_target_description_set)
cmake_parse_arguments(
ARG "" "TARGET" "VALUE" ${ARGN})
ntf_assert_defined(${ARG_TARGET})
if (NOT "${ARG_VALUE}" STREQUAL "")
ntf_target_variable_set(
TARGET ${ARG_TARGET} VARIABLE "description" VALUE ${ARG_VALUE})
else()
ntf_target_variable_set(
TARGET ${ARG_TARGET} VARIABLE "description" VALUE "")
endif()
endfunction()
# Get the "description" variable scoped to a target.
#
# TARGET - The target.
# OUTPUT - The variable name set in the parent scope.
function (ntf_target_description_get)
cmake_parse_arguments(
ARG "" "TARGET;OUTPUT" "" ${ARGN})
ntf_assert_defined(${ARG_TARGET})
ntf_assert_defined(${ARG_OUTPUT})
ntf_target_variable_get(
TARGET ${ARG_TARGET} VARIABLE "description" OUTPUT result)
set(${ARG_OUTPUT} ${result} PARENT_SCOPE)
endfunction()
# Set the "path" variable scoped to a target.
#
# TARGET - The target.
# VALUE - The variable value.
function (ntf_target_path_set)
cmake_parse_arguments(
ARG "" "TARGET" "VALUE" ${ARGN})
ntf_assert_defined(${ARG_TARGET})
if (NOT "${ARG_VALUE}" STREQUAL "")
ntf_target_variable_set(
TARGET ${ARG_TARGET} VARIABLE "path" VALUE ${ARG_VALUE})
else()
ntf_target_variable_set(
TARGET ${ARG_TARGET} VARIABLE "path" VALUE "")
endif()
endfunction()
# Get the "path" variable scoped to a target.
#
# TARGET - The target.
# OUTPUT - The variable name set in the parent scope.
function (ntf_target_path_get)
cmake_parse_arguments(
ARG "" "TARGET;OUTPUT" "" ${ARGN})
ntf_assert_defined(${ARG_TARGET})
ntf_assert_defined(${ARG_OUTPUT})
ntf_target_variable_get(
TARGET ${ARG_TARGET} VARIABLE "path" OUTPUT result)
set(${ARG_OUTPUT} ${result} PARENT_SCOPE)
endfunction()
# Set the "private" variable scoped to a target.
#
# TARGET - The target.
# VALUE - The variable value.
function (ntf_target_private_set)
cmake_parse_arguments(
ARG "" "TARGET" "VALUE" ${ARGN})
ntf_assert_defined(${ARG_TARGET})
if (NOT "${ARG_VALUE}" STREQUAL "")
ntf_target_variable_set(
TARGET ${ARG_TARGET} VARIABLE "private" VALUE ${ARG_VALUE})
else()
ntf_target_variable_set(
TARGET ${ARG_TARGET} VARIABLE "private" VALUE "")
endif()
endfunction()
# Get the "private" variable scoped to a target.
#
# TARGET - The target.
# OUTPUT - The variable name set in the parent scope.
function (ntf_target_private_get)
cmake_parse_arguments(
ARG "" "TARGET;OUTPUT" "" ${ARGN})
ntf_assert_defined(${ARG_TARGET})
ntf_assert_defined(${ARG_OUTPUT})
ntf_target_variable_get(
TARGET ${ARG_TARGET} VARIABLE "private" OUTPUT result)
set(${ARG_OUTPUT} ${result} PARENT_SCOPE)
endfunction()
# Set the "thirdparty" variable scoped to a target.
#
# TARGET - The target.
# VALUE - The variable value.
function (ntf_target_thirdparty_set)
cmake_parse_arguments(
ARG "" "TARGET" "VALUE" ${ARGN})
ntf_assert_defined(${ARG_TARGET})
if (NOT "${ARG_VALUE}" STREQUAL "")
ntf_target_variable_set(
TARGET ${ARG_TARGET} VARIABLE "thirdparty" VALUE ${ARG_VALUE})
else()
ntf_target_variable_set(
TARGET ${ARG_TARGET} VARIABLE "thirdparty" VALUE "")
endif()
endfunction()
# Get the "thirdparty" variable scoped to a target.
#
# TARGET - The target.
# OUTPUT - The variable name set in the parent scope.
function (ntf_target_thirdparty_get)
cmake_parse_arguments(
ARG "" "TARGET;OUTPUT" "" ${ARGN})
ntf_assert_defined(${ARG_TARGET})
ntf_assert_defined(${ARG_OUTPUT})
ntf_target_variable_get(
TARGET ${ARG_TARGET} VARIABLE "thirdparty" OUTPUT result)
set(${ARG_OUTPUT} ${result} PARENT_SCOPE)
endfunction()
# Set the "pseudo" variable scoped to a target.
#
# TARGET - The target.
# VALUE - The variable value.
function (ntf_target_pseudo_set)
cmake_parse_arguments(
ARG "" "TARGET" "VALUE" ${ARGN})
ntf_assert_defined(${ARG_TARGET})
if (NOT "${ARG_VALUE}" STREQUAL "")
ntf_target_variable_set(
TARGET ${ARG_TARGET} VARIABLE "pseudo" VALUE ${ARG_VALUE})
else()
ntf_target_variable_set(
TARGET ${ARG_TARGET} VARIABLE "pseudo" VALUE "")
endif()
endfunction()
# Get the "pseudo" variable scoped to a target.
#
# TARGET - The target.
# OUTPUT - The variable name set in the parent scope.
function (ntf_target_pseudo_get)
cmake_parse_arguments(
ARG "" "TARGET;OUTPUT" "" ${ARGN})
ntf_assert_defined(${ARG_TARGET})
ntf_assert_defined(${ARG_OUTPUT})
ntf_target_variable_get(
TARGET ${ARG_TARGET} VARIABLE "pseudo" OUTPUT result)
set(${ARG_OUTPUT} ${result} PARENT_SCOPE)
endfunction()
# Set the "unity" variable scoped to a target.
#
# TARGET - The target.
# VALUE - The variable value.
function (ntf_target_unity_set)
cmake_parse_arguments(
ARG "" "TARGET" "VALUE" ${ARGN})
ntf_assert_defined(${ARG_TARGET})
if (NOT "${ARG_VALUE}" STREQUAL "")
ntf_target_variable_set(
TARGET ${ARG_TARGET} VARIABLE "unity" VALUE ${ARG_VALUE})
else()
ntf_target_variable_set(
TARGET ${ARG_TARGET} VARIABLE "unity" VALUE "")
endif()
endfunction()
# Get the "unity" variable scoped to a target.
#
# TARGET - The target.
# OUTPUT - The variable name set in the parent scope.
function (ntf_target_unity_get)
cmake_parse_arguments(
ARG "" "TARGET;OUTPUT" "" ${ARGN})
ntf_assert_defined(${ARG_TARGET})
ntf_assert_defined(${ARG_OUTPUT})
ntf_target_variable_get(
TARGET ${ARG_TARGET} VARIABLE "unity" OUTPUT result)
set(${ARG_OUTPUT} ${result} PARENT_SCOPE)
endfunction()
# Set the "requires" variable scoped to a target.
#
# TARGET - The target.
# VALUE - The variable value.
function (ntf_target_requires_set)
cmake_parse_arguments(
ARG "" "TARGET" "VALUE" ${ARGN})
ntf_assert_defined(${ARG_TARGET})
if (NOT "${ARG_VALUE}" STREQUAL "")
ntf_target_variable_set(
TARGET ${ARG_TARGET} VARIABLE "requires" VALUE ${ARG_VALUE})
else()
ntf_target_variable_set(
TARGET ${ARG_TARGET} VARIABLE "requires" VALUE "")
endif()
endfunction()
# Append to the "requires" variable scoped to a target.
#
# TARGET - The target.
# VALUE - The variable value.
function (ntf_target_requires_append)
cmake_parse_arguments(
ARG "" "TARGET" "VALUE" ${ARGN})
ntf_assert_defined(${ARG_TARGET})
if (NOT "${ARG_VALUE}" STREQUAL "")
ntf_target_variable_append(
TARGET ${ARG_TARGET} VARIABLE "requires" VALUE ${ARG_VALUE})
endif()
endfunction()
# Get the "requires" variable scoped to a target.
#
# TARGET - The target.
# OUTPUT - The variable name set in the parent scope.
function (ntf_target_requires_get)
cmake_parse_arguments(
ARG "" "TARGET;OUTPUT" "" ${ARGN})
ntf_assert_defined(${ARG_TARGET})
ntf_assert_defined(${ARG_OUTPUT})
ntf_target_variable_get(
TARGET ${ARG_TARGET} VARIABLE "requires" OUTPUT result)
set(${ARG_OUTPUT} ${result} PARENT_SCOPE)
endfunction()
# Set the "aliases" variable scoped to a target. The contents of this variable
# are imported as aliases of the target in the CMake install metadata.
#
# TARGET - The target.
# VALUE - The variable value.
function (ntf_target_aliases_set)
cmake_parse_arguments(
ARG "" "TARGET" "VALUE" ${ARGN})
ntf_assert_defined(${ARG_TARGET})
if (NOT "${ARG_VALUE}" STREQUAL "")
ntf_target_variable_set(
TARGET ${ARG_TARGET} VARIABLE "aliases" VALUE ${ARG_VALUE})
else()
ntf_target_variable_set(
TARGET ${ARG_TARGET} VARIABLE "aliases" VALUE "")
endif()
endfunction()
# Append to the "aliases" variable scoped to a target. The contents of this
# variable are imported as aliases of the target in the CMake install metadata.
#
# TARGET - The target.
# VALUE - The variable value.
function (ntf_target_aliases_append)
cmake_parse_arguments(
ARG "" "TARGET" "VALUE" ${ARGN})
ntf_assert_defined(${ARG_TARGET})
if (NOT "${ARG_VALUE}" STREQUAL "")
ntf_target_variable_append(
TARGET ${ARG_TARGET} VARIABLE "aliases" VALUE ${ARG_VALUE})
endif()
endfunction()
# Get the "aliases" variable scoped to a target. The contents of this variable
# are imported as aliases of the target in the CMake install metadata.
#
# TARGET - The target.
# OUTPUT - The variable name set in the parent scope.
function (ntf_target_aliases_get)
cmake_parse_arguments(
ARG "" "TARGET;OUTPUT" "" ${ARGN})
ntf_assert_defined(${ARG_TARGET})
ntf_assert_defined(${ARG_OUTPUT})
ntf_target_variable_get(
TARGET ${ARG_TARGET} VARIABLE "aliases" OUTPUT result)
set(${ARG_OUTPUT} ${result} PARENT_SCOPE)
endfunction()
# Set the "libs" variable scoped to a target. The contents of this variable
# is assigned to the "Libs.private" variable in pkg-config metadata.
#
# TARGET - The target.
# VALUE - The variable value.
function (ntf_target_libs_set)
cmake_parse_arguments(
ARG "" "TARGET" "VALUE" ${ARGN})
ntf_assert_defined(${ARG_TARGET})
if (NOT "${ARG_VALUE}" STREQUAL "")
ntf_target_variable_set(
TARGET ${ARG_TARGET} VARIABLE "libs" VALUE ${ARG_VALUE})
else()
ntf_target_variable_set(
TARGET ${ARG_TARGET} VARIABLE "libs" VALUE "")
endif()
endfunction()
# Append to the "libs" variable scoped to a target. The contents of this
# variable is assigned to the "Libs.private" variable in pkg-config metadata.
#
# TARGET - The target.
# VALUE - The variable value.
function (ntf_target_libs_append)
cmake_parse_arguments(
ARG "" "TARGET" "VALUE" ${ARGN})
ntf_assert_defined(${ARG_TARGET})
if (NOT "${ARG_VALUE}" STREQUAL "")
ntf_target_variable_append(
TARGET ${ARG_TARGET} VARIABLE "libs" VALUE ${ARG_VALUE})
endif()
endfunction()
# Get the "libs" variable scoped to a target. The contents of this variable is
# assigned to the "Libs.private" variable in pkg-config metadata.
#
# TARGET - The target.
# OUTPUT - The variable name set in the parent scope.
function (ntf_target_libs_get)
cmake_parse_arguments(
ARG "" "TARGET;OUTPUT" "" ${ARGN})
ntf_assert_defined(${ARG_TARGET})
ntf_assert_defined(${ARG_OUTPUT})
ntf_target_variable_get(
TARGET ${ARG_TARGET} VARIABLE "libs" OUTPUT result)
set(${ARG_OUTPUT} ${result} PARENT_SCOPE)
endfunction()
# Add preprocessor defininitions when compiling a target. The definitions
# are always added with private visibility.
#
# TARGET - The target.
# VALUE - The list of preprocessor definitions
function (ntf_target_build_definition)
cmake_parse_arguments(
ARG "" "TARGET" "VALUE" ${ARGN})
ntf_assert_defined(${ARG_TARGET})
ntf_assert_defined(${ARG_VALUE})
ntf_nomenclature_target(TARGET ${ARG_TARGET} OUTPUT target)
get_property(target_type TARGET ${target} PROPERTY "TYPE")
foreach(value ${ARG_VALUE})
if ("${target_type}" STREQUAL "INTERFACE_LIBRARY")
target_compile_definitions(${target} INTERFACE ${value})
else()
target_compile_definitions(${target} PRIVATE ${value})
endif()
endforeach()
endfunction()
# Add options when compiling, and optionally, linking, a target. The options
# are always added with private visibility.
#
# TARGET - The target.
# VALUE - The list of compiler and/or linker options.
# COMPILE - Include the option when compiling.
# COMPILE_ONLY - Include the option only when compiling
# LINK - Include the option when linking.
# LINK_ONLY - Include the option only when linking.
function (ntf_target_build_option)
cmake_parse_arguments(
ARG "COMPILE;COMPILE_ONLY;LINK;LINK_ONLY" "TARGET" "VALUE" ${ARGN})
ntf_assert_defined(${ARG_TARGET})
ntf_assert_defined(${ARG_VALUE})
ntf_nomenclature_target(TARGET ${ARG_TARGET} OUTPUT target)
if (${ARG_COMPILE} AND NOT ${ARG_LINK_ONLY})
set(include_when_compiling TRUE)
else()
set(include_when_compiling FALSE)
endif()
if (${ARG_LINK} AND NOT ${ARG_COMPILE_ONLY})
set(include_when_linking TRUE)
else()
set(include_when_linking FALSE)
endif()
get_property(target_type TARGET ${target} PROPERTY "TYPE")
foreach(value ${ARG_VALUE})
if (${include_when_compiling})
if ("${target_type}" STREQUAL "INTERFACE_LIBRARY")
target_compile_options(${target} INTERFACE ${value})
else()
target_compile_options(${target} PRIVATE ${value})
endif()
endif()
if (${include_when_linking})
if ("${target_type}" STREQUAL "INTERFACE_LIBRARY")
target_link_options(${target} INTERFACE ${value})
else()
target_link_options(${target} PRIVATE ${value})
endif()
endif()
endforeach()
endfunction()
# Add target link libraries.
#
# TARGET - The target.
# VALUE - The list of targets or libraries.
function (ntf_target_build_dependency)
cmake_parse_arguments(
ARG "" "TARGET" "VALUE" ${ARGN})
ntf_assert_defined(${ARG_TARGET})
ntf_assert_defined(${ARG_VALUE})
ntf_nomenclature_target(TARGET ${ARG_TARGET} OUTPUT target)
get_property(target_type TARGET ${target} PROPERTY "TYPE")
foreach(value ${ARG_VALUE})
if ("${target_type}" STREQUAL "INTERFACE_LIBRARY")
target_link_libraries(${target} INTERFACE ${value})
else()
target_link_libraries(${target} PUBLIC ${value})
endif()
endforeach()
endfunction()
# Set the compiler and linker options for a target common to all UFIDs.
function (ntf_target_options_common_prolog target)
ntf_repository_build_ufid_get(OUTPUT ufid)
ntf_ufid_string_has(UFID ${ufid} FLAG "opt" OUTPUT is_opt)
ntf_ufid_string_has(UFID ${ufid} FLAG "dbg" OUTPUT is_dbg)
ntf_ufid_string_has(UFID ${ufid} FLAG "64" OUTPUT is_64_bit)
ntf_ufid_string_has(UFID ${ufid} FLAG "static" OUTPUT is_static)
ntf_repository_toolchain_link_static_get(OUTPUT link_static)
set_property(TARGET ${target} PROPERTY COMPILE_DEFINITIONS "")
set_property(TARGET ${target} PROPERTY COMPILE_OPTIONS "")
ntf_repository_standard_get(OUTPUT cxx_standard)
if ("${cxx_standard}" STREQUAL "98")
ntf_target_build_definition(
TARGET ${target} VALUE BDE_BUILD_TARGET_CPP03)
else()
ntf_target_build_definition(
TARGET ${target} VALUE BDE_BUILD_TARGET_CPP${cxx_standard})
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU|SunPro|XL")
if("${CMAKE_SYSTEM_NAME}" STREQUAL "AIX")
# TODO
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
ntf_target_build_definition(TARGET ${target} VALUE _DARWIN_C_SOURCE _BSD_SOURCE)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
ntf_target_build_definition(TARGET ${target} VALUE _BSD_SOURCE)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
ntf_target_build_definition(TARGET ${target} VALUE _GNU_SOURCE)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "OpenBSD")
ntf_target_build_definition(TARGET ${target} VALUE _BSD_SOURCE)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "SunOS")
ntf_target_build_definition(TARGET ${target} VALUE _GNU_SOURCE)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
# TODO
else()
# TODO
endif()
if (${is_dbg} AND NOT ${is_opt})
ntf_target_build_definition(TARGET ${target} VALUE _DEBUG)
endif()
ntf_target_build_definition(
TARGET
${target}
VALUE
_REENTRANT _THREAD_SAFE _POSIX_PTHREAD_SEMANTICS)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
ntf_target_build_definition(
TARGET
${target}
VALUE
_FILE_OFFSET_BITS=64)
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "XL")
ntf_target_build_definition(
TARGET ${target} VALUE __NOLOCK_ON_INPUT __NOLOCK_ON_OUTPUT)
endif()
if (NOT ${is_dbg} OR ${is_opt})
ntf_target_build_definition(TARGET ${target} VALUE NDEBUG)
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
if (${is_opt} AND ${is_dbg})
ntf_target_build_option(
TARGET ${target} COMPILE LINK VALUE -O2 -g2)
elseif (${is_opt})
ntf_target_build_option(
TARGET ${target} COMPILE LINK VALUE -O2 -g0)
elseif (${is_dbg})
ntf_target_build_option(
TARGET ${target} COMPILE LINK VALUE -O0 -g2)
endif()
if (${is_64_bit})
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
ntf_target_build_option(
TARGET ${target} COMPILE LINK VALUE -m64)
ntf_target_build_option(
TARGET ${target} COMPILE LINK VALUE -march=westmere)
endif()
else()
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
ntf_target_build_option(
TARGET ${target} COMPILE LINK VALUE -m32)
ntf_target_build_option(
TARGET ${target} COMPILE LINK VALUE -march=westmere)
ntf_target_build_option(
TARGET ${target} COMPILE LINK VALUE -mstackrealign)
ntf_target_build_option(
TARGET ${target} COMPILE LINK VALUE -mfpmath=sse)
endif()
endif()
ntf_target_build_option(
TARGET ${target} COMPILE LINK VALUE -pipe)
ntf_target_build_option(
TARGET ${target} COMPILE LINK VALUE -pthread)
if (${is_static} OR ${link_static})
# TODO: static PIE, where supported.
else()
ntf_target_build_option(
TARGET ${target} COMPILE LINK VALUE -fPIC)
endif()
ntf_target_build_option(
TARGET ${target} COMPILE LINK VALUE -fexceptions)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if (DEFINED CMAKE_CXX_COMPILER_VERSION
AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16.0)
ntf_target_build_option(TARGET ${target} COMPILE LINK VALUE
-fcoroutines-ts)
endif()
else()
ntf_target_build_option(TARGET ${target} COMPILE LINK VALUE