-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcmi.cmake
1769 lines (1543 loc) · 63.9 KB
/
cmi.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
# BSD 2-Clause License
#
# Copyright (c) 2019-2023, Volker Jacht
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# See https://gitlab.com/nordfox/cmakeit
cmake_minimum_required(VERSION 3.13)
set(CMI_TAG "v0.4.12")
get_property(CMI_LOADER_FILE GLOBAL PROPERTY CMI_LOADER_FILE)
# First include
if(NOT CMI_LOADER_FILE)
# Check for updates
if(DEFINED CMI_DOWNLOAD_TAG AND NOT ("${CMI_DOWNLOAD_TAG}" STREQUAL "${CMI_TAG}"))
message(STATUS "Update ${CMAKE_CURRENT_LIST_FILE} to ${CMI_DOWNLOAD_TAG}")
get_filename_component(CMI_FILENAME_ ${CMAKE_CURRENT_LIST_FILE} NAME)
set(CMI_LOADER_TMP_ "${CMAKE_CURRENT_BINARY_DIR}/${CMI_FILENAME_}")
file(
DOWNLOAD "https://gitlab.com/nordfox/cmakeit/raw/${CMI_DOWNLOAD_TAG}/cmi.cmake"
"${CMI_LOADER_TMP_}.in"
SHOW_PROGRESS
)
#Check filesize of download
set(INPUT_FILE_ "${CMI_LOADER_TMP_}.in")
if(${CMAKE_VERSION} VERSION_LESS "3.14.0")
set(CMI_LOADER_FILESIZE_ "0")
if(EXISTS "${INPUT_FILE_}")
file(READ "${INPUT_FILE_}" FILE_CONTENT_ LIMIT 1 HEX)
string(LENGTH "${FILE_CONTENT_}" CMI_LOADER_FILESIZE_)
math(EXPR CMI_LOADER_FILESIZE_ "${CMI_LOADER_FILESIZE_} / 2")
endif()
unset(FILE_CONTENT_)
else()
file(SIZE "${INPUT_FILE_}" CMI_LOADER_FILESIZE_)
endif()
unset(INPUT_FILE_)
###
if(NOT CMI_LOADER_FILESIZE_ STREQUAL 0)
configure_file("${CMI_LOADER_TMP_}.in" "${CMI_LOADER_TMP_}" @ONLY NEWLINE_STYLE UNIX)
execute_process(
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMI_LOADER_TMP_}" "${CMAKE_CURRENT_LIST_FILE}"
)
file(REMOVE "${CMI_LOADER_TMP_}.in" "${CMI_LOADER_TMP_}")
include("${CMAKE_CURRENT_LIST_FILE}")
unset(CMI_FILENAME_)
unset(CMI_LOADER_TMP_)
return()
else()
message(WARNING "Updating CMI failed! Using existing version.")
endif()
endif()
set_property(GLOBAL PROPERTY CMI_LOADER_FILE "${CMAKE_CURRENT_LIST_FILE}")
set(CMI_FIRST_INCLUDE TRUE)
endif()
# Check if CMI is loaded at local scope
if(CMI_LOADED)
return()
endif()
# Always use the first included CMI file
get_property(CMI_LOADER_FILE GLOBAL PROPERTY CMI_LOADER_FILE)
if(NOT (CMI_LOADER_FILE STREQUAL CMAKE_CURRENT_LIST_FILE))
include("${CMI_LOADER_FILE}")
return()
endif()
unset(CMI_LOADER_FILE)
######################################
# ACTUAL CMI FILE BEGINS
######################################
set(CMI_LOADED TRUE)
set(CMI_VERSION "0.4.12")
if(NOT DEFINED CMI_PRINT_VERSION)
set(CMI_PRINT_VERSION TRUE CACHE INTERNAL "")
message(STATUS "CMI Version: ${CMI_VERSION}")
message(STATUS "CMI Tag: ${CMI_TAG}")
endif()
# Consider root project as populated and included
string(TOUPPER "${CMAKE_PROJECT_NAME}" PROJECT_NAME_UPPER_)
set_property(GLOBAL PROPERTY CMI_${PROJECT_NAME_UPPER_}_INCLUDED "TRUE")
unset(PROJECT_NAME_UPPER_)
set(CMI_EXTERNALS_DIR "${CMAKE_SOURCE_DIR}/_externals" CACHE PATH "")
set(CMI_IDE_PRESETS "_targets" CACHE PATH "")
set(CMI_IDE_EXTERNALS "_externals" CACHE PATH "")
set(CMI_CHECKOUT_SCRIPT "${CMAKE_BINARY_DIR}/checkout.cmake")
option(CMI_AUTO_CHECKOUT "" ON)
mark_as_advanced(CMI_EXTERNALS_DIR)
mark_as_advanced(CMI_IDE_PRESETS)
mark_as_advanced(CMI_IDE_EXTERNALS)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "${CMI_IDE_PRESETS}")
######################################
# HELPER FUNCTIONS
######################################
function(cmi_minimum_required)
cmake_parse_arguments("" "" "VERSION" "" ${ARGN})
if("${CMI_VERSION}" VERSION_LESS "${_VERSION}")
message(FATAL_ERROR "CMI ${_VERSION} or higher is required. You are running version ${CMI_VERSION}")
endif()
endfunction()
function(cmi_file)
cmake_parse_arguments(_FILE "" "" "SIZE;DOWNLOAD" ${ARGN})
list(LENGTH _FILE_SIZE _FILE_SIZE_LENGTH)
list(LENGTH _FILE_DOWNLOAD _FILE_DOWNLOAD_LENGTH)
if (_FILE_SIZE_LENGTH STREQUAL 2)
list(GET _FILE_SIZE 0 INPUT_FILE)
list(GET _FILE_SIZE 1 FILE_SIZE)
if(${CMAKE_VERSION} VERSION_LESS "3.14.0")
set(FILE_SIZE_ "0")
if(EXISTS "${INPUT_FILE}")
file(READ "${INPUT_FILE}" FILE_CONTENT_ HEX)
string(LENGTH "${FILE_CONTENT_}" FILE_SIZE_)
math(EXPR FILE_SIZE_ "${FILE_SIZE_} / 2")
endif()
else()
file(SIZE "${INPUT_FILE}" FILE_SIZE_)
endif()
set(${FILE_SIZE} ${FILE_SIZE_} PARENT_SCOPE)
elseif(_FILE_DOWNLOAD_LENGTH STREQUAL 2)
list(GET _FILE_DOWNLOAD 0 DOWNLOAD_URL)
list(GET _FILE_DOWNLOAD 1 DOWNLOAD_DESTINATION)
set(DOWNLOAD_DESTINATION_TMP "${DOWNLOAD_DESTINATION}.tmp")
if(EXISTS "${DOWNLOAD_DESTINATION_TMP}")
message(STATUS "Removing ${DOWNLOAD_DESTINATION_TMP}")
file(REMOVE_RECURSE "${DOWNLOAD_DESTINATION_TMP}")
endif()
message(STATUS "Downloading ${DOWNLOAD_URL}")
file(DOWNLOAD "${DOWNLOAD_URL}" "${DOWNLOAD_DESTINATION_TMP}" SHOW_PROGRESS)
cmi_file(SIZE "${DOWNLOAD_DESTINATION_TMP}" DOWNLOAD_FILESIZE)
if(DOWNLOAD_FILESIZE STREQUAL 0)
message(WARNING "Can not download ${DOWNLOAD_DESTINATION}")
file(REMOVE "${DOWNLOAD_DESTINATION_TMP}")
else()
file(RENAME "${DOWNLOAD_DESTINATION}.tmp" "${DOWNLOAD_DESTINATION}")
endif()
else()
message(WARNING "CMI_FILE() no matching function for parameters ${ARGN}")
endif()
endfunction()
######################################
# FETCHING
######################################
# PROPERTY, POPULATED => ready to include / up to date
# PROPERTY, INCLUDED => already inclued somewhere
# CACHE, EXTERNAL_TYPE
# CACHE, EXTERNAL_URL
# CACHE, ENABLE
function(cmi_add_subdirectory PROJECT_NAME_)
string(TOUPPER "${PROJECT_NAME_}" PROJECT_NAME_UPPER_)
string(TOLOWER "${PROJECT_NAME_}" PROJECT_NAME_LOWER_)
get_property(${PROJECT_NAME_UPPER_}_INCLUDED GLOBAL PROPERTY CMI_${PROJECT_NAME_UPPER_}_INCLUDED SET)
if(${PROJECT_NAME_UPPER_}_INCLUDED)
# project already been included
return()
endif()
cmake_parse_arguments(CMI_ADD_SUBDIRECTORY "NO_CMAKE" "OPTIONAL" "" ${ARGN})
list(FIND CMI_ADD_SUBDIRECTORY_KEYWORDS_MISSING_VALUES "OPTIONAL" RESULT_)
if(NOT RESULT_ STREQUAL -1)
set(CMI_ADD_SUBDIRECTORY_OPTIONAL OFF)
endif()
set(CMI_ENABLE_PREFIX "CMI_ENABLE_")
if(DEFINED CMI_ADD_SUBDIRECTORY_OPTIONAL)
# optional => add to options
if(NOT DEFINED ${CMI_ENABLE_PREFIX}${PROJECT_NAME_UPPER_})
option(${CMI_ENABLE_PREFIX}${PROJECT_NAME_UPPER_} "" "${CMI_ADD_SUBDIRECTORY_OPTIONAL}")
endif()
else()
# not optional => force enabled
set(${CMI_ENABLE_PREFIX}${PROJECT_NAME_UPPER_} ON CACHE BOOL "" FORCE)
endif()
if(${CMI_ENABLE_PREFIX}${PROJECT_NAME_UPPER_})
get_property(${PROJECT_NAME_UPPER_}_POPULATED_ GLOBAL PROPERTY ${PROJECT_NAME_UPPER_}_POPULATED)
if(NOT ${PROJECT_NAME_UPPER_}_POPULATED_)
get_property(CMI_${PROJECT_NAME_UPPER_}_EXTERNAL_TYPE GLOBAL PROPERTY CMI_${PROJECT_NAME_UPPER_}_EXTERNAL_TYPE)
get_property(CMI_${PROJECT_NAME_UPPER_}_EXTERNAL_URL GLOBAL PROPERTY CMI_${PROJECT_NAME_UPPER_}_EXTERNAL_URL)
get_property(CMI_${PROJECT_NAME_UPPER_}_EXTERNAL_REV GLOBAL PROPERTY CMI_${PROJECT_NAME_UPPER_}_EXTERNAL_REV)
if(CMI_${PROJECT_NAME_UPPER_}_EXTERNAL_TYPE STREQUAL "archive")
cmi_add_archive_(${PROJECT_NAME_UPPER_} ${CMI_${PROJECT_NAME_UPPER_}_EXTERNAL_URL})
elseif(CMI_${PROJECT_NAME_UPPER_}_EXTERNAL_TYPE STREQUAL "git")
cmi_add_git_(${PROJECT_NAME_UPPER_} ${CMI_${PROJECT_NAME_UPPER_}_EXTERNAL_URL} ${CMI_${PROJECT_NAME_UPPER_}_EXTERNAL_REV})
elseif(CMI_${PROJECT_NAME_UPPER_}_EXTERNAL_TYPE STREQUAL "svn")
cmi_add_svn_(${PROJECT_NAME_UPPER_} ${CMI_${PROJECT_NAME_UPPER_}_EXTERNAL_URL} ${CMI_${PROJECT_NAME_UPPER_}_EXTERNAL_REV})
endif()
endif()
if(NOT DEFINED CMI_ADD_SUBDIRECTORY_OPTIONAL)
get_property(${PROJECT_NAME_UPPER_}_POPULATED_ GLOBAL PROPERTY ${PROJECT_NAME_UPPER_}_POPULATED)
if(NOT ${PROJECT_NAME_UPPER_}_POPULATED_)
message(WARNING "Can not proceed as ${PROJECT_NAME_UPPER_} is missing")
endif()
endif()
if(EXISTS ${${PROJECT_NAME_UPPER_}_DIR})
if(NOT CMI_ADD_SUBDIRECTORY_NO_CMAKE)
set_property(GLOBAL PROPERTY CMI_${PROJECT_NAME_UPPER_}_INCLUDED "TRUE")
add_subdirectory("${${PROJECT_NAME_UPPER_}_DIR}" "${CMAKE_BINARY_DIR}/externals/${PROJECT_NAME_LOWER_}")
endif()
else()
message(WARNING "Can not include ${${PROJECT_NAME_UPPER_}_DIR}")
endif()
endif()
endfunction()
# Only set property if it hasnt been set before
function(cmi_get_property PROPERTY_NAME)
cmake_parse_arguments(PROPERTY "" "DEFAULT" "" ${ARGN})
get_property(PROPERTY_DEFINED GLOBAL PROPERTY ${PROPERTY_NAME} SET)
if(NOT PROPERTY_DEFINED AND DEFINED PROPERTY_DEFAULT)
set_property(GLOBAL PROPERTY ${PROPERTY_NAME} "${PROPERTY_DEFAULT}")
endif()
get_property(PROPERTY_VALUE GLOBAL PROPERTY ${PROPERTY_NAME})
set(${PROPERTY_NAME} "${PROPERTY_VALUE}" PARENT_SCOPE)
endfunction()
function(cmi_add_update_script_ FILEPATH_)
set_property(GLOBAL APPEND PROPERTY CMI_UPDATE_LIST ${FILEPATH_})
get_property(TEST_ GLOBAL PROPERTY CMI_UPDATE_LIST)
set(UPDATER_ "${CMAKE_BINARY_DIR}/checkout.cmake")
file(WRITE "${UPDATER_}" "")
file(APPEND "${UPDATER_}" "
set(files \n")
foreach(file_ IN LISTS TEST_)
file(APPEND "${UPDATER_}" " \"${file_}\"\n")
endforeach()
if(CMAKE_GENERATOR MATCHES "Visual Studio")
set(USE_ZERO_CHECK_ 1)
else()
set(USE_ZERO_CHECK_ 0)
endif()
file(APPEND "${UPDATER_}" " )
foreach(file_ IN LISTS files)
execute_process(COMMAND \"${CMAKE_COMMAND}\" -P \"\${file_}\" OUTPUT_VARIABLE OUTPUT_)
string(REGEX REPLACE \"\\n\$\" \"\" OUTPUT_ \"\${OUTPUT_}\")
if(OUTPUT_)
message(STATUS \"Processing \${file_}\n\${OUTPUT_}\")
endif()
if(OUTPUT_ MATCHES \"Update: \")
message(\"STATUS SUCCESS \${file_}\")
if(${USE_ZERO_CHECK_})
execute_process(
COMMAND \${CMAKE_COMMAND} --build \"${CMAKE_BINARY_DIR}\" --target ZERO_CHECK
)
else()
execute_process(
COMMAND \${CMAKE_COMMAND} \"${CMAKE_BINARY_DIR}\"
)
endif()
endif()
endforeach()
")
if(NOT TARGET checkout)
add_custom_target(checkout ${CMAKE_COMMAND} -P "${CMI_CHECKOUT_SCRIPT}")
set_property(TARGET checkout PROPERTY FOLDER "${CMI_IDE_EXTERNALS}")
endif()
endfunction()
function(cmi_add_archive PROJECT_NAME_ PROJECT_URL_)
string(TOUPPER "${PROJECT_NAME_}" PROJECT_NAME_UPPER_)
cmi_get_property(CMI_${PROJECT_NAME_UPPER_}_EXTERNAL_TYPE DEFAULT "archive")
cmi_get_property(CMI_${PROJECT_NAME_UPPER_}_EXTERNAL_URL DEFAULT "${PROJECT_URL_}")
endfunction()
function(cmi_add_git PROJECT_NAME_ PROJECT_URL_ PROJECT_REV_)
string(TOUPPER "${PROJECT_NAME_}" PROJECT_NAME_UPPER_)
cmi_get_property(CMI_${PROJECT_NAME_UPPER_}_EXTERNAL_TYPE DEFAULT "git")
cmi_get_property(CMI_${PROJECT_NAME_UPPER_}_EXTERNAL_URL DEFAULT "${PROJECT_URL_}")
cmi_get_property(CMI_${PROJECT_NAME_UPPER_}_EXTERNAL_REV DEFAULT "${PROJECT_REV_}")
endfunction()
function(cmi_add_svn PROJECT_NAME_ PROJECT_URL_ PROJECT_REV_)
string(TOUPPER "${PROJECT_NAME_}" PROJECT_NAME_UPPER_)
cmi_get_property(CMI_${PROJECT_NAME_UPPER_}_EXTERNAL_TYPE DEFAULT "svn")
cmi_get_property(CMI_${PROJECT_NAME_UPPER_}_EXTERNAL_URL DEFAULT "${PROJECT_URL_}")
cmi_get_property(CMI_${PROJECT_NAME_UPPER_}_EXTERNAL_REV DEFAULT "${PROJECT_REV_}")
endfunction()
function(cmi_add_archive_ PROJECT_NAME_ PROJECT_URL_)
string(TOUPPER "${PROJECT_NAME_}" PROJECT_NAME_UPPER_)
get_property(${PROJECT_NAME_UPPER_}_POPULATED GLOBAL PROPERTY ${PROJECT_NAME_UPPER_}_POPULATED)
if(${PROJECT_NAME_UPPER_}_POPULATED)
return()
endif()
set_property(GLOBAL PROPERTY ${PROJECT_NAME_UPPER_}_POPULATED "TRUE")
if(DEFINED ${PROJECT_NAME_UPPER_}_URL_CURRENT AND NOT ("${PROJECT_URL_}" STREQUAL "${${PROJECT_NAME_UPPER_}_URL_CURRENT}"))
unset(${PROJECT_NAME_UPPER_}_DIR CACHE)
endif()
get_filename_component(${PROJECT_NAME_UPPER_}_ARCHIVE "${PROJECT_URL_}" NAME)
set(${PROJECT_NAME_UPPER_}_ARCHIVE_PATH "${CMI_EXTERNALS_DIR}/${${PROJECT_NAME_UPPER_}_ARCHIVE}")
string(REGEX REPLACE ".(tar.gz|zip|tgz)$" "" ${PROJECT_NAME_UPPER_}_ARCHIVE_TAG ${INPUT} "${${PROJECT_NAME_UPPER_}_ARCHIVE}")
set(${PROJECT_NAME_UPPER_}_DIR "${CMI_EXTERNALS_DIR}/${${PROJECT_NAME_UPPER_}_ARCHIVE_TAG}" CACHE PATH "")
if(NOT EXISTS "${${PROJECT_NAME_UPPER_}_DIR}")
if(NOT EXISTS "${${PROJECT_NAME_UPPER_}_ARCHIVE_PATH}")
cmi_file(DOWNLOAD "${PROJECT_URL_}" "${${PROJECT_NAME_UPPER_}_ARCHIVE_PATH}")
endif()
message(STATUS "Extracting ${PROJECT_NAME_UPPER_} ${${PROJECT_NAME_UPPER_}_ARCHIVE_PATH} to ${${PROJECT_NAME_UPPER_}_DIR}")
execute_process(
COMMAND "${CMAKE_COMMAND}" -E tar x "${${PROJECT_NAME_UPPER_}_ARCHIVE_PATH}"
WORKING_DIRECTORY "${CMI_EXTERNALS_DIR}"
)
endif()
set(${PROJECT_NAME_UPPER_}_URL_CURRENT "${PROJECT_URL_}" CACHE INTERNAL "")
endfunction()
function(cmi_add_git_ PROJECT_NAME_ PROJECT_URL_ PROJECT_REV_)
string(TOUPPER "${PROJECT_NAME_}" PROJECT_NAME_UPPER_)
string(TOLOWER "${PROJECT_NAME_}" PROJECT_NAME_LOWER_)
get_property(${PROJECT_NAME_UPPER_}_POPULATED GLOBAL PROPERTY ${PROJECT_NAME_UPPER_}_POPULATED)
if(${PROJECT_NAME_UPPER_}_POPULATED)
return()
endif()
set_property(GLOBAL PROPERTY ${PROJECT_NAME_UPPER_}_POPULATED "TRUE")
find_package(Git)
set(${PROJECT_NAME_UPPER_}_DIR "${CMI_EXTERNALS_DIR}/${PROJECT_NAME_LOWER_}" CACHE PATH "")
set(UPDATER_ "${CMAKE_BINARY_DIR}/checkout.${PROJECT_NAME_LOWER_}.cmake")
cmi_add_update_script_("${UPDATER_}")
# Generate copy script
file(WRITE "${UPDATER_}" "
set(GIT_EXECUTABLE \"${GIT_EXECUTABLE}\")
set(GIT_DIR \"${${PROJECT_NAME_UPPER_}_DIR}\")
set(GIT_URL \"${PROJECT_URL_}\")
set(GIT_REV \"${PROJECT_REV_}\")
set(GIT_FETCH 1)
if(EXISTS \"\${GIT_DIR}\")
execute_process(
COMMAND \${GIT_EXECUTABLE} rev-list -n 1 \${GIT_REV}
WORKING_DIRECTORY \"\${GIT_DIR}\"
RESULT_VARIABLE RESULT_
ERROR_QUIET
OUTPUT_VARIABLE TARGET_REV_
)
if(RESULT_ STREQUAL \"0\" AND NOT (\${GIT_REV} MATCHES \"^origin/.+\"))
set(GIT_FETCH 0)
endif()
endif()
# Clone repo
if(GIT_FETCH)
foreach(try RANGE 2)
if(NOT EXISTS \"\${GIT_DIR}\")
set(GIT_CLONE 1)
message(STATUS \"Clone \${GIT_DIR} \${GIT_URL} \${GIT_REV}\")
set(TMP_DIR \"\${GIT_DIR}.tmp\")
if(EXISTS \"\${TMP_DIR}\")
message(STATUS \"Removing \${TMP_DIR}\")
file(REMOVE_RECURSE \"\${TMP_DIR}\")
endif()
execute_process(
COMMAND \${GIT_EXECUTABLE} clone --no-checkout \${GIT_URL} \"\${TMP_DIR}\"
RESULT_VARIABLE RESULT_ ERROR_VARIABLE STDERR_
)
if(RESULT_ STREQUAL 0)
file(RENAME \"\${TMP_DIR}\" \"\${GIT_DIR}\")
execute_process(
COMMAND \${GIT_EXECUTABLE} -c advice.detachedHead=false checkout \${GIT_REV}
WORKING_DIRECTORY \"\${GIT_DIR}\"
RESULT_VARIABLE RESULT_
OUTPUT_VARIABLE STDOUT_
ERROR_VARIABLE STDOUT_
)
break()
endif()
# Cloning failed. Delete directory.
file(REMOVE_RECURSE \"\${TMP_DIR}\")
else()
execute_process(
COMMAND \${GIT_EXECUTABLE} rev-parse --git-dir
WORKING_DIRECTORY \"\${GIT_DIR}\"
RESULT_VARIABLE RESULT_ OUTPUT_VARIABLE STDOUT_ ERROR_VARIABLE STDERR_
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT STDOUT_ STREQUAL \".git\")
message(SEND_ERROR \"Git clone/fetch failed.\")
message(WARNING \"\${GIT_DIR} is supposed to be a git repository, but it's not. Consider deleting that folder and rerun CMake.\")
return()
endif()
message(STATUS \"Fetch \${GIT_DIR} \${GIT_URL} \${GIT_REV}\")
execute_process(
COMMAND \${GIT_EXECUTABLE} remote get-url origin
WORKING_DIRECTORY \"\${GIT_DIR}\"
RESULT_VARIABLE RESULT_ OUTPUT_VARIABLE STDOUT_ ERROR_VARIABLE STDERR_
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(RESULT_ STREQUAL 0 AND NOT STDOUT_ STREQUAL GIT_URL)
message(STATUS \"Remove origin remote \${STDOUT_}\")
execute_process(
COMMAND \${GIT_EXECUTABLE} remote remove origin
WORKING_DIRECTORY \"\${GIT_DIR}\"
)
endif()
if(NOT RESULT_ STREQUAL 0 OR NOT STDOUT_ STREQUAL GIT_URL)
message(STATUS \"Add origin remote \${GIT_URL}\")
execute_process(
COMMAND \${GIT_EXECUTABLE} remote add origin \${GIT_URL}
WORKING_DIRECTORY \"\${GIT_DIR}\"
)
endif()
execute_process(
COMMAND \${GIT_EXECUTABLE} fetch origin
WORKING_DIRECTORY \"\${GIT_DIR}\"
RESULT_VARIABLE RESULT_ ERROR_VARIABLE STDERR_
)
if(RESULT_ STREQUAL 0)
break()
endif()
endif()
message(SEND_ERROR \"Git clone/fetch failed.\")
if(\${STDERR_} MATCHES \"bad line length character: git\")
message(WARNING \"Probably missing SSH private key!\")
return()
endif()
endforeach()
endif()
# Git Checkout
# message(STATUS \"Checkout \${GIT_REV}\")
execute_process(
COMMAND \${GIT_EXECUTABLE} status -s
WORKING_DIRECTORY \"\${GIT_DIR}\"
RESULT_VARIABLE RESULT_
OUTPUT_VARIABLE STASH_NEEDED_
)
execute_process(
COMMAND \${GIT_EXECUTABLE} rev-list -n 1 HEAD
WORKING_DIRECTORY \"\${GIT_DIR}\"
RESULT_VARIABLE RESULT_
OUTPUT_VARIABLE CURRENT_REV_
)
execute_process(
COMMAND \${GIT_EXECUTABLE} rev-list -n 1 \${GIT_REV}
WORKING_DIRECTORY \"\${GIT_DIR}\"
RESULT_VARIABLE RESULT_
OUTPUT_VARIABLE TARGET_REV_
ERROR_QUIET
)
if(STASH_NEEDED_ OR (NOT CURRENT_REV_ STREQUAL TARGET_REV_))
message(STATUS \"Update: \${GIT_DIR}\")
endif()
if(NOT RESULT_ STREQUAL \"0\")
message(FATAL_ERROR \"Rev \${GIT_REV} not found.\")
endif()
if(STASH_NEEDED_)
execute_process(
COMMAND \${GIT_EXECUTABLE} stash -u
WORKING_DIRECTORY \"\${GIT_DIR}\"
RESULT_VARIABLE RESULT_
OUTPUT_VARIABLE STDOUT_
ERROR_VARIABLE STDOUT_
)
message(STATUS \"\${STDOUT_}\")
endif()
if(NOT CURRENT_REV_ STREQUAL TARGET_REV_)
execute_process(
COMMAND \${GIT_EXECUTABLE} -c advice.detachedHead=false checkout \${GIT_REV}
WORKING_DIRECTORY \"\${GIT_DIR}\"
RESULT_VARIABLE RESULT_
OUTPUT_VARIABLE STDOUT_
ERROR_VARIABLE STDOUT_
)
message(STATUS \"\${STDOUT_}\")
elseif(GIT_CLONE AND NOT GIT_REV STREQUAL TARGET_REV_)
message(STATUS \"HEAD is now at \${TARGET_REV_}\")
endif()
if(NOT (RESULT_ STREQUAL 0))
message(FATAL_ERROR \"Git checkout failed.\")
endif()
")
if(CMI_AUTO_CHECKOUT OR NOT EXISTS "${${PROJECT_NAME_UPPER_}_DIR}")
execute_process(
COMMAND ${CMAKE_COMMAND} -P "${UPDATER_}"
RESULT_VARIABLE RESULT_
)
if(NOT RESULT_ STREQUAL "0")
message(SEND_ERROR "Could not update ${GIT_DIR}")
endif()
endif()
endfunction()
function(cmi_add_svn_ PROJECT_NAME_ PROJECT_URL_ PROJECT_REV_)
string(TOUPPER "${PROJECT_NAME_}" PROJECT_NAME_UPPER_)
string(TOLOWER "${PROJECT_NAME_}" PROJECT_NAME_LOWER_)
get_property(${PROJECT_NAME_UPPER_}_POPULATED GLOBAL PROPERTY ${PROJECT_NAME_UPPER_}_POPULATED)
if(${PROJECT_NAME_UPPER_}_POPULATED)
return()
endif()
set_property(GLOBAL PROPERTY ${PROJECT_NAME_UPPER_}_POPULATED "TRUE")
find_package(Subversion)
set(${PROJECT_NAME_UPPER_}_DIR "${CMI_EXTERNALS_DIR}/${PROJECT_NAME_LOWER_}" CACHE PATH "")
set(UPDATER_ "${CMI_EXTERNALS_DIR}/checkout.${PROJECT_NAME_LOWER_}.cmake")
cmi_add_update_script_("${UPDATER_}")
# Generate copy script
file(WRITE "${UPDATER_}" "
set(SVN_EXECUTABLE \"${Subversion_SVN_EXECUTABLE}\")
set(SVN_DIR \"${${PROJECT_NAME_UPPER_}_DIR}\")
set(SVN_URL \"${PROJECT_URL_}\")
set(SVN_REV \"${PROJECT_REV_}\")
if(NOT EXISTS \"\${SVN_DIR}\")
foreach(try RANGE 2)
message(STATUS \"Checkout \${SVN_DIR} \${SVN_URL} \${SVN_REV}\")
set(TMP_DIR \"\${SVN_DIR}.tmp\")
if(EXISTS \"\${TMP_DIR}\")
message(STATUS \"Removing \${TMP_DIR}\")
file(REMOVE_RECURSE \"\${TMP_DIR}\")
endif()
execute_process(
COMMAND \"\${SVN_EXECUTABLE}\" \"checkout\" \"--ignore-externals\" \"\${SVN_URL}@\${SVN_REV}\" \"\${TMP_DIR}\"
RESULT_VARIABLE RESULT_
)
if(RESULT_ STREQUAL 0)
file(RENAME \"\${TMP_DIR}\" \"\${SVN_DIR}\")
break()
endif()
# Cloning failed. Delete directory.
message(SEND_ERROR \"SVN checkout failed.\")
file(REMOVE_RECURSE \"\${TMP_DIR}\")
endforeach()
else()
# SVN Switch
foreach(try RANGE 2)
message(STATUS \"Switch \${SVN_DIR} \${SVN_URL} \${SVN_REV}\")
execute_process(
COMMAND \"\${SVN_EXECUTABLE}\" \"switch\" \"--ignore-externals\" \"\${SVN_URL}@\${SVN_REV}\" \"\${SVN_DIR}\"
RESULT_VARIABLE RESULT_
)
if(RESULT_ STREQUAL 0)
break()
endif()
message(SEND_ERROR \"SVN switch failed.\")
endforeach()
endif()
")
if(NOT EXISTS "${${PROJECT_NAME_UPPER_}_DIR}")
execute_process(COMMAND ${CMAKE_COMMAND} -P "${UPDATER_}")
endif()
endfunction()
######################################
# COMPILER FLAGS
######################################
function(cmi_Fortran_append var name)
# Compiler presets
set(Fortran_DEBUGINFO_Generic_GNU "-g")
set(Fortran_DEBUGINFO_Generic_Intel "-g")
set(Fortran_DEBUGINFO_Windows_Intel "/debug:full")
set(Fortran_O0_Generic_GNU "-O0")
set(Fortran_O0_Generic_Intel "-O0")
set(Fortran_O0_Windows_Intel "/Od")
set(Fortran_O1_Generic_GNU "-O1")
set(Fortran_O1_Generic_Intel "-O1")
set(Fortran_O1_Windows_Intel "/O1")
set(Fortran_O2_Generic_GNU "-O2")
set(Fortran_O2_Generic_Intel "-O2")
set(Fortran_O2_Windows_Intel "/O2")
set(Fortran_O3_Generic_GNU "-O3")
set(Fortran_O3_Generic_Intel "-O3")
set(Fortran_O3_Windows_Intel "/O3")
set(Fortran_TRACEBACK_Generic_GNU "-fbacktrace")
set(Fortran_TRACEBACK_Generic_Intel "-traceback")
set(Fortran_TRACEBACK_Windows_Intel "/traceback")
set(Fortran_CONSISTENCY_Generic_GNU "")
set(Fortran_CONSISTENCY_Generic_Intel "-fimf-arch-consistency=true")
set(Fortran_CONSISTENCY_Windows_Intel "/Qimf-arch-consistency:true")
set(Fortran_CPP_Generic_GNU "-cpp")
set(Fortran_CPP_Generic_Intel "-fpp")
set(Fortran_CPP_Windows_Intel "/fpp")
set(Fortran_FPP_Generic_GNU "-cpp -ffree-line-length-none -ffixed-line-length-none")
set(Fortran_FPP_Generic_Intel "-fpp -allow nofpp-comments")
set(Fortran_FPP_Windows_Intel "/fpp")
set(Fortran_FPE0_Generic_GNU "-ffpe-trap=invalid,zero,overflow")
set(Fortran_FPE0_Generic_Intel "-fpe0")
set(Fortran_FPE0_Windows_Intel "/fpe:0")
set(Fortran_FPMODELSOURCE_Generic_GNU "")
set(Fortran_FPMODELSOURCE_Generic_Intel "-fp-model source")
set(Fortran_FPMODELSOURCE_Windows_Intel "/fp:source")
set(Fortran_FPSPECULATIONOFF_Generic_GNU "")
set(Fortran_FPSPECULATIONOFF_Generic_Intel "-fp-speculation off")
set(Fortran_FPSPECULATIONOFF_Windows_Intel "/Qfp-speculation=off")
set(Fortran_FPSPECULATIONSAFE_Generic_GNU "")
set(Fortran_FPSPECULATIONSAFE_Generic_Intel "-fp-speculation safe")
set(Fortran_FPSPECULATIONSAFE_Windows_Intel "/Qfp-speculation=safe")
set(Fortran_FPMODELSTRICT_Generic_GNU "")
set(Fortran_FPMODELSTRICT_Generic_Intel "-fp-model strict")
set(Fortran_FPMODELSTRICT_Windows_Intel "/fp:strict")
set(Fortran_OMP_Generic_GNU "-fopenmp")
set(Fortran_OMP_Generic_Intel "-qopenmp")
set(Fortran_OMP_Windows_Intel "/Qopenmp")
set(Fortran_WSRCTRUNC_Generic_GNU "-Wline-truncation")
set(Fortran_WSRCTRUNC_Generic_Intel "-warn truncated_source")
set(Fortran_WSRCTRUNC_Windows_Intel "/warn:truncated_source")
set(Fortran_EXTENDEDLINESF77_Generic_GNU "-ffixed-line-length-none")
set(Fortran_EXTENDEDLINESF77_Generic_Intel "")
set(Fortran_EXTENDEDLINESF77_Windows_Intel "")
set(Fortran_EXTENDEDLINESF90_Generic_GNU "-ffree-line-length-none")
set(Fortran_EXTENDEDLINESF90_Generic_Intel "")
set(Fortran_EXTENDEDLINESF90_Windows_Intel "")
set(Fortran_WUNUSED_Generic_GNU "-Wunused")
set(Fortran_WUNUSED_Generic_Intel "-warn unused")
set(Fortran_WUNUSED_Windows_Intel "/warn:unused")
set(Fortran_WINTERFACES_Generic_GNU "")
set(Fortran_WINTERFACES_Generic_Intel "-warn interfaces")
set(Fortran_WINTERFACES_Windows_Intel "/warn:interfaces")
set(Fortran_WDECLARATIONS_Generic_GNU "")
set(Fortran_WDECLARATIONS_Generic_Intel "-warn declarations")
set(Fortran_WDECLARATIONS_Windows_Intel "/warn:declarations")
set(Fortran_TRAPUV_Generic_GNU "-finit-real=snan -finit-integer=-1 -finit-character=0 -finit-logical=false")
set(Fortran_TRAPUV_Generic_Intel "-ftrapuv")
set(Fortran_TRAPUV_Windows_Intel "/Qtrapuv")
set(Fortran_CHECKALL_Generic_GNU "-fcheck=all")
set(Fortran_CHECKALL_Generic_Intel "-check all")
set(Fortran_CHECKALL_Windows_Intel "/check:all")
set(Fortran_CHECKNONE_Generic_GNU "-fcheck=no-all")
set(Fortran_CHECKNONE_Generic_Intel "-check none")
set(Fortran_CHECKNONE_Windows_Intel "/nocheck")
set(Fortran_DBGMIN_Generic_GNU "")
set(Fortran_DBGMIN_Generic_Intel "-debug minimal")
set(Fortran_DBGMIN_Windows_Intel "/debug:minimal")
set(Fortran_CHECKNOARGTMP_Generic_GNU "-fcheck=no-array-temps")
set(Fortran_CHECKNOARGTMP_Generic_Intel "-check noarg_temp_created")
set(Fortran_CHECKNOARGTMP_Windows_Intel "/check:noarg_temp_created")
set(Fortran_CHECKBASIC_Generic_GNU "-fcheck=pointer,bounds")
set(Fortran_CHECKBASIC_Generic_Intel "-check pointer,bounds,uninit,format,output_conversion")
set(Fortran_CHECKBASIC_Windows_Intel "/check:pointer,bounds,uninit,format,output_conversion")
set(Fortran_THREADS_Generic_GNU "-pthread")
set(Fortran_THREADS_Generic_Intel "-threads")
set(Fortran_THREADS_Windows_Intel "/threads")
set(Fortran_NOOMFP_Generic_GNU "-fno-omit-frame-pointer")
set(Fortran_NOOMFP_Generic_Intel "-fno-omit-frame-pointer")
set(Fortran_NOOMFP_Windows_Intel "/Oy-")
set(Fortran_STACK_Generic_GNU "")
set(Fortran_STACK_Generic_Intel "")
set(Fortran_STACK_Windows_Intel "/STACK:10000000,10000000")
set(Fortran_PROF_Generic_GNU "-pg")
set(Fortran_PROF_Generic_Intel "-pg")
set(Fortran_PROF_Windows_Intel "")
set(Fortran_NOFTZ_Generic_GNU "")
set(Fortran_NOFTZ_Generic_Intel "-no-ftz")
set(Fortran_NOFTZ_Windows_Intel "/Qftz-")
set(Fortran_SAVE_Generic_GNU "-fno-automatic")
set(Fortran_SAVE_Generic_Intel "-save")
set(Fortran_SAVE_Windows_Intel "/Qsave")
set(Fortran_STACKARRAYLIMIT65_Generic_GNU "") # Default 65536
set(Fortran_STACKARRAYLIMIT65_Generic_Intel "-heap-arrays 65")
set(Fortran_STACKARRAYLIMIT65_Windows_Intel "/heap-arrays:65")
set(Fortran_STDF90_Generic_GNU "")
set(Fortran_STDF90_Generic_Intel "-stand f90")
set(Fortran_STDF90_Windows_Intel "/stand:f90")
set(Fortran_STDF95_Generic_GNU "-std=f95")
set(Fortran_STDF95_Generic_Intel "-stand f95")
set(Fortran_STDF95_Windows_Intel "/stand:f95")
set(Fortran_STDF03_Generic_GNU "-std=f2003")
set(Fortran_STDF03_Generic_Intel "-stand f03")
set(Fortran_STDF03_Windows_Intel "/stand:f03")
set(Fortran_VSMP_Generic_GNU "")
set(Fortran_VSMP_Generic_Intel "")
set(Fortran_VSMP_Windows_Intel "/MP")
set(Fortran_INITZERO_Generic_GNU "-finit-real=zero -finit-integer=0")
set(Fortran_INITZERO_Generic_Intel "-init=zero")
set(Fortran_INITZERO_Windows_Intel "/Qinit:zero")
if(NOT MSVC)
set(CMAKE_SYSTEM_NAME Generic)
endif()
if(NOT DEFINED CMAKE_Fortran_COMPILER_ID)
message(SEND_ERROR "Fortran flags used, but no Fortran compiler detected (CMAKE_Fortran_COMPILER_ID undefined).")
endif()
if("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "IntelLLVM")
set(CMAKE_Fortran_COMPILER_ID Intel)
endif()
if(NOT DEFINED Fortran_${name}_${CMAKE_SYSTEM_NAME}_${CMAKE_Fortran_COMPILER_ID})
message(AUTHOR_WARNING "Fortran flag ${name} not found for ${CMAKE_Fortran_COMPILER_ID}."
"If typing is correct, the root project's cmi.cmake file needs to be updated."
)
endif()
set(NEW_FLAG "${Fortran_${name}_${CMAKE_SYSTEM_NAME}_${CMAKE_Fortran_COMPILER_ID}}")
if(NOT "${${var}}" MATCHES "${NEW_FLAG}$")
string(STRIP "${${var}} ${NEW_FLAG}" ${var})
set(${var} "${${var}}" PARENT_SCOPE)
endif()
# if(${name} STREQUAL "FPP")
# message(DEPRECATION "Fortran FPP flag has been deprecated and can be replaced by CPP and EXTENDEDLINESF90. "
# "Also consider using uppercase extension .F90, which will implicitly activate preprocessing.")
# endif()
endfunction()
function(cmi_fortran_default_mangling)
if(MSVC)
set(flag "/names:lowercase /assume:underscore")
string(FIND "${CMAKE_Fortran_FLAGS}" "${flag}" status)
if("${status}" STREQUAL "-1")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${flag}" PARENT_SCOPE)
endif()
endif()
endfunction()
macro(cmi_disable_vs_manifest_ TARGET_FLAG_)
if(MSVC)
set(flag "/MANIFEST:NO")
if(DEFINED CACHE{${TARGET_FLAG_}})
set(FLAGS "$CACHE{${FLAG_}}")
string(FIND "${FLAGS}" "${flag}" status)
if("${status}" STREQUAL "-1")
set(${TARGET_FLAG_} "${FLAGS} ${flag}" CACHE STRING "" FORCE)
endif()
endif()
endif()
endmacro()
function(cmi_disable_vs_manifest)
cmi_disable_vs_manifest_(CMAKE_EXE_LINKER_FLAGS)
cmi_disable_vs_manifest_(CMAKE_SHARED_LINKER_FLAGS)
cmi_disable_vs_manifest_(CMAKE_MODULE_LINKER_FLAGS)
endfunction()
macro(cmi_enable_vs_z7_ FLAG_)
if(DEFINED CACHE{${FLAG_}})
set(FLAGS "$CACHE{${FLAG_}}")
# Replace /Zi and /ZI by /Z7
string(REGEX REPLACE "/Z[iI]" "/Z7" FLAGS "${FLAGS}")
# Explicitly add /Z7 if /debug:full or /debug:minimal is set
string(FIND "${FLAGS}" "/Z7" status)
if("${status}" STREQUAL "-1")
string(REGEX REPLACE "/debug:full" "/debug:full /Z7" FLAGS "${FLAGS}")
string(REGEX REPLACE "/debug:minimal" "/debug:minimal /Z7" FLAGS "${FLAGS}")
endif()
string(STRIP "${FLAGS}" FLAGS)
set(${FLAG_} "${FLAGS}" CACHE STRING "" FORCE)
endif()
endmacro()
macro(cmi_disable_vs_z7_ FLAG_)
if(DEFINED CACHE{${FLAG_}})
set(FLAGS "$CACHE{${FLAG_}}")
# Remove /Z7
string(REGEX REPLACE "/Z7" "/Zi" FLAGS "${FLAGS}")
string(STRIP "${FLAGS}" FLAGS)
set(${FLAG_} "${FLAGS}" CACHE STRING "" FORCE)
endif()
endmacro()
function(cmi_enable_vs_z7)
if(MSVC)
set(LANGUAGES "C" "CXX" "Fortran")
foreach(LANGUAGE IN LISTS LANGUAGES)
foreach(CONFIGURATION IN LISTS CMAKE_CONFIGURATION_TYPES)
string(TOUPPER ${CONFIGURATION} CONFIGURATION)
cmi_enable_vs_z7_(CMAKE_${LANGUAGE}_FLAGS_${CONFIGURATION})
endforeach()
cmi_enable_vs_z7_(CMAKE_${LANGUAGE}_FLAGS)
endforeach()
endif()
endfunction()
function(cmi_disable_vs_z7)
if(MSVC)
set(LANGUAGES "C" "CXX" "Fortran")
foreach(LANGUAGE IN LISTS LANGUAGES)
foreach(CONFIGURATION IN LISTS CMAKE_CONFIGURATION_TYPES)
string(TOUPPER ${CONFIGURATION} CONFIGURATION)
cmi_disable_vs_z7_(CMAKE_${LANGUAGE}_FLAGS_${CONFIGURATION})
endforeach()
cmi_disable_vs_z7_(CMAKE_${LANGUAGE}_FLAGS)
endforeach()
endif()
endfunction()
macro(cmi_disable_vs_incremental_linker_ FLAG_)
if(DEFINED CACHE{${FLAG_}})
set(FLAGS "$CACHE{${FLAG_}}")
string(REGEX REPLACE "/INCREMENTAL(:YES)?($| )" "/INCREMENTAL:NO" FLAGS "${FLAGS}")
string(STRIP "${FLAGS}" FLAGS)
set(${FLAG_} "${FLAGS}" CACHE STRING "" FORCE)
endif()
endmacro()
function(cmi_disable_vs_incremental_linker)
if(MSVC)
foreach(CONFIGURATION IN LISTS CMAKE_CONFIGURATION_TYPES)
string(TOUPPER ${CONFIGURATION} CONFIGURATION)
cmi_disable_vs_incremental_linker_(CMAKE_EXE_LINKER_FLAGS_${CONFIGURATION})
cmi_disable_vs_incremental_linker_(CMAKE_SHARED_LINKER_FLAGS_${CONFIGURATION})
cmi_disable_vs_incremental_linker_(CMAKE_STATIC_LINKER_FLAGS_${CONFIGURATION})
cmi_disable_vs_incremental_linker_(CMAKE_MODULE_LINKER_FLAGS_${CONFIGURATION})
endforeach()
endif()
endfunction()
function(cmi_disable_vs_debug_runtime)
if(MSVC)
set(LANGUAGES "C" "CXX" "Fortran")
foreach(LANGUAGE IN LISTS LANGUAGES)
set(TARGET_FLAG "CMAKE_${LANGUAGE}_FLAGS_DEBUG")
if(DEFINED CACHE{${TARGET_FLAG}})
set(FLAGS "$CACHE{${TARGET_FLAG}}")
string(REPLACE "/dbglibs " " " FLAGS "${FLAGS} ")
string(REPLACE "/MDd " "/MD " FLAGS "${FLAGS} ")
string(REPLACE "/MTd " "/MT " FLAGS "${FLAGS} ")
string(STRIP "${FLAGS}" FLAGS)
set(${TARGET_FLAG} "${FLAGS}" CACHE STRING "" FORCE)
endif()
endforeach()
endif()
endfunction()
function(cmi_enable_vs_mp)
if(MSVC)
set(flag "/MP")
set(LANGUAGES "C" "CXX" "Fortran")
foreach(LANGUAGE IN LISTS LANGUAGES)
set(TARGET_FLAG "CMAKE_${LANGUAGE}_FLAGS")
if(DEFINED CACHE{${TARGET_FLAG}})
set(FLAGS "$CACHE{${TARGET_FLAG}}")
if(${CMAKE_VERSION} VERSION_LESS "3.19.0" AND LANGUAGE STREQUAL "Fortran")
# Skip /MP as older CMake versions can't set /Z7 to prevent corrupt PDB files
message(STATUS "CMake version 3.19.0 is required to enable parallel building of Fortran projects. Skipped.")
continue()
endif()
string(FIND "${FLAGS}" "${flag}" status)
if("${status}" STREQUAL "-1")
string(STRIP "${FLAGS}" FLAGS)
set(${TARGET_FLAG} "${FLAGS} ${flag}" CACHE STRING "" FORCE)
endif()
endif()
endforeach()
endif()
endfunction()
function(cmi_disable_vs_mp)
if(MSVC)
set(flag "/MP")
set(LANGUAGES "C" "CXX" "Fortran")
foreach(LANGUAGE IN LISTS LANGUAGES)
set(TARGET_FLAG "CMAKE_${LANGUAGE}_FLAGS")
if(DEFINED CACHE{${TARGET_FLAG}})
set(FLAGS "$CACHE{${TARGET_FLAG}}")
string(REGEX REPLACE "${flag}" "" FLAGS "${FLAGS}")
string(STRIP "${FLAGS}" FLAGS)
set(${TARGET_FLAG} "${FLAGS}" CACHE STRING "" FORCE)
endif()
endforeach()
endif()
endfunction()
######################################
# BUILD SETTINGS
######################################
# Set default path variables
macro(cmi_load_build_environment)
message(DEPRECATION "cmi_load_build_environment() deprecated. Use cmi_set_build_environment() instead.")
cmi_set_build_environment(${ARGV})
endmacro()
macro(cmi_set_build_environment)
set(CMI_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/package/$<CONFIG>" CACHE PATH "")
unset(CMI_BINARAY_OUTPUT_DIRECTORY CACHE)
if(NOT DEFINED CMI_BINARAY_OUTPUT_DIRECTORY)
set(CMI_BINARAY_OUTPUT_DIRECTORY "bin")
endif()
# Predefined target properties
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMI_OUTPUT_DIRECTORY}/${CMI_BINARAY_OUTPUT_DIRECTORY}$<0:>")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMI_OUTPUT_DIRECTORY}/${CMI_BINARAY_OUTPUT_DIRECTORY}$<0:>")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMI_OUTPUT_DIRECTORY}/${CMI_BINARAY_OUTPUT_DIRECTORY}$<0:>")
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(CMAKE_INSTALL_RPATH "@loader_path")
else()
set(CMAKE_INSTALL_RPATH "$ORIGIN")
endif()
set(CMAKE_FOLDER "${PROJECT_NAME}")
# Enabled testing by default
option(BUILD_TESTING "" OFF)
if(BUILD_TESTING)
enable_testing()
endif()
# Set a default build type if none was specified
set(DEFAULT_BUILD_TYPE_ "Release")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to '${DEFAULT_BUILD_TYPE_}' as none was specified.")