forked from iauns/cpm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CPM.cmake
1886 lines (1631 loc) · 75.2 KB
/
CPM.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
# CPM - Cmake based C++ Package Manager
# Requires at least CMake 2.8.
#
# A CMake module for managing external dependencies.
# CPM can be used to build traditional C/C++ libraries and CPM modules.
# In contrast to traditional C++ libraries, CPM modules have namespace
# alteration and allow for multiple different versions of the same library to
# be statically linked together and easily used without namespace conflicts.
# CPM modules use add_subdirectory for CPM modules and ExternalProject for
# traditional builds. CPM is inspired by Node.js' NPM package manager.
#
# CPM's primary function is CPM_AddModule(...).
# CPM_AddModule accepts a few of the same parameters as ExternalProject
# alongside adding a few of its own.
#
# The following variables are created in / appended to PARENT_SCOPE whenever
# the add module function is called:
#
# CPM_INCLUDE_DIRS - All module search paths.
# CPM_LIBRARIES - All targets to link against.
# CPM_DEPENDENCIES - All dependencies. In some cases, this is different than CPM_LIBRARIES.
# CPM_DEFINITIONS - Definitions for all CPM namespaces.
#
# Add module function reference:
# CPM_AddModule(<name> # Required - Module target name.
# [GIT_TAG tag] # Git tag to checkout when repository is downloaded. Tags, shas, and branches all work.
# [GIT_REPOSITORY repo] # Git repository to fetch source data from.
# [USE_EXISTING_VER truth] # If set to true then the module will attempt to use a pre-existing version of the module.
# [SOURCE_DIR dir] # Uses 'dir' as the source directory as opposed to downloading.
# [SOURCE_GHOST_GIT_REPO repo] # Ghost repository when using SOURCE_DIR.
# [SOURCE_GHOST_GIT_TAG tag] # Ghost git tag when using SOURCE_DIR.
# [EXPORT_MODULE truth] # If true, then the module's definitions and includes will be exported to the consumer.
# [FORWARD_DECLARATION truth] # If true, then only the module's preprocessor definition (that the <name> argument above is used to generate) is exported to the consumer of the module. This is useful for situations where you only need to forward declare a module's classes in your interface classes and not actually include any of the target module's interface headers. This is preferred over EXPORT_MODULE as it is much lighter.
# )
#
# When using SOURCE_DIR, SOURCE_GHOST_GIT_REPO and SOURCE_GHOST_GIT_TAG are used
# only when generating unique identifiers for the module. In this way, you can
# use GHOST repositories and tags to ensure CPM generates consistent unique IDs.
# For an example of using these parameters (mostly in testing), see
# https://github.com/SCIInstitute/spire. Particularly the batch renderer's
# CMakeLists.txt file.
#
# Define CPM_SHOW_HIERARCHY to see all modules and their dependencies in a
# hierarchical fashion. The output from defining this is usually best viewed
# after all of the modules have cloned their source.
#
# Many settings are automatically applied for modules. Setting SOURCE_DIR is
# not recommeneded unless you are managing the header locations for the source
# directory manually. If you set the source directory the project will not be
# downloaded and will not be updated using git. You must manage that manually.
#
# Also remember: you will probably want to use add_dependencies with the
# ${CPM_LIBRARIES}.
#
# The following is a reference for CPM_EnsureRepoCurrent, a utility function
# that allows CPM users to ensure a repository is available at some target
# directory location. This function is useful for creating modules for external
# header only libraries.
#
# CPM_EnsureRepoIsCurrent(
# [TARGET_DIR dir] # Required - Directory to place repository.
# [GIT_REPOSITORY repo] # Git repository to clone and update in TARGET_DIR.
# [GIT_TAG tag] # Git tag to checkout.
# [HG_REPOSITORY repo] # HG repository to clone and update in TARGET_DIR.
# [HG_TAG rev] # HG tag.
# [SVN_REPOSITORY repo] # SVN repository to checkout.
# [SVN_REVISION rev] # SVN revision.
# [SVN_TRUST_CERT 1] # Trust the Subversion server site certificate
# [USE_CACHING 1] # Enables caching of repositories if the user has specified CPM_MODULE_CACHING_DIR. Not enabled by default.
# )
#
# CPM also adds the following variables to the global namespace for CPM script
# purposes only. These variables are unlikely to be useful to you.
#
# CPM_DIR_OF_CPM - Variable that stores the location of *this*
# file.
# CPM_KV_MOD_VERSION_MAP_* - A key/value module version mapping.
# Key: Unique path (no version)
# Val: The most recently added module version.
# This is used to enforce, if requested, that
# only one version of a particular module exists
# in the build.
# CPM_KV_LIST_MOD_VERSION_MAP - A list of entries in CPM_KV_MOD_VERSION_MAP.
# This list is used to propagate information to
# the parent_scope when CPM_INIT_MODULE is
# called and at the end of the AddModule
# function.
# CPM_KV_SOURCE_ADDED_MAP_* - Key/value added source map. Ensures we don't
# add the same module twice.
# Key: Full unique path.
# Value: Module's chosen name. This name is used
# to generate a preprocessor token when
# the module is exported.
# CPM_KV_LIST_SOURCE_ADDED_MAP - A list of entries in CPM_KV_SOURCE_ADDED_MAP.
# Used to ensure we don't issue duplicate
# add_subdirectory calls.
# CPM_KV_PREPROC_NS_MAP_* - A key/value C preprocessor namespace mapping.
# Key: C Preprocessor name.
# Val: The *full* unique ID of the module.
# This ensures that namespace definitions do not
# overlap on one another. Either by accident by
# naming different modules the same, or through
# an imported modules interface (modules can
# force you to import a particular version of a
# module if they expose it in their interface).
# CPM_KV_LIST_PREPROC_NS_MAP - A list of entries in CPM_KV_PREPROC_NS_MAP.
# This list is used to clear the map when
# descending the build hierarchy using
# add_subdirectory.
# CPM_KV_INCLUDE_MAP_* - A key/value mapping from unique id to a
# list of include files.
# Key: unique path (with version)
# Value: List of include statements.
# Used only for determining includes that are
# associated with an exported module.
# CPM_KV_LIST_INCLUDE_MAP - A list of entries in CPM_KV_INCLUDE_MAP.
#
# CPM_KV_DEFINITION_MAP_* - A key/value mapping from unique id to
# definitions.
# Key: unique path (with version)
# Value: List of definitions.
# Used only for determining definitions that are
# associated with an exported module.
# CPM_KV_LIST_DEFINITION_MAP - A list of values in the definition map.
#
# CPM_KV_LIB_TARGET_MAP_* - A key/value mapping from unique id to
# additional targets to link against.
# Key: unique path (with version).
# Value: List of additional targets.
# Used to determine the list of additional
# targets associated with an exported module.
# CPM_KV_LIST_LIB_TARGET_MAP - A list of all key values in the library
# target map (CPM_KV_LIB_TARGET_MAP_*).
# CPM_KV_FORWARD_DECL_MAP_* - A key/value mapping of unique id to forward
# declaration pairs. This map is also used
# during the export module process to determine
# what the module was named by the exporter
# module.
# Key: unique path (with version)
# Value: Pairs consisting of the following:
# (unique_id_for_fwd_decl, new_name).
# CPM_KV_LIST_FORWARD_DECL_MAP - A list of entries in CPM_KV_FORWARD_DECL_MAP.
#
# CPM_KV_EXPORT_MAP_* - A key/value mapping of all exported modules
# from a module.
# Key: unique path (with version).
# Value: A list of modules that have been
# exported. In particular, this value is
# their full unique id.
# CPM_KV_LIST_EXPORT_MAP - List of values from exported module map.
#
# CPM_KV_UNID_MAP_* - Map of full unique IDs. This map is cleared
# everytime CPM is included.
# Key: User defined name of the module.
# Value: Unique ID of the module.
# CPM_KV_LIST_UNID_MAP - List of user defined module names that have
# been added to the unid map.
#
# CPM_KV_SOURCEDIR_MAP_* - Map of source directories. This map is cleared
# everytime CPM is included.
# Key: User defined name of the module.
# Value: Source directory.
# CPM_KV_LIST_SOURCEDIR_MAP - List of user defined module names that have
# been added to the sourcedir map.
#
# CPM_EXPORTED_MODULES - Used to determine what modules are exported.
#
# CPM_HIERARCHY_LEVEL - Contains current CPM hierarchy level.
#
# NOTE: End users aren't required to finalize their modules after they add them
# because all appropriate constraints do not need to be propogated further then
# the top level file.
#
# Additional functions and macros.
#
# CPM_ExportAdditionalDefinition <def>
#
# Exports an additional definition in the parent scope, from the module.
# Use sparingly. Primarily used to expose mandatory external project
# definitions to the parent module.
#
# CPM_ExportAdditionalIncludeDir <dir>
#
# Exposes an additional include directory to the consumer of a module.
# Use sparingly. Primarily used to expose external project directories
# to module consumers.
#
# CPM_ExportAdditionalLibraryTarget <target>
#
# This function is mostly used to avoid having to name targets
# per the ${CPM_TARGET_NAME} convention in CPM. For an example of its use
# see http://github.com/iauns/cpm-google-test. Google test generates
# its own target name when included as a subdirectory, so we must use
# that name.
#
# CPM_ForceOnlyOneModuleVersion
#
# When called from a module, this function ensures that we use only one
# version of that module throughout our static linkage. This is mandatory
# for modules which import code not written as a CPM module. Such as
# code built with CMake's ExternalProject.
#
# CPM_GetSourceDir <variable_to_set> <name>
#
# Retrieves the source directory for the module.
#
#
#
# TODO: Consolidate the definitions, includes, and target_lib map lists.
# TODO: Add ability to patch source directories after we download them.
if(CMAKE_VERSION VERSION_EQUAL 3.1 OR CMAKE_VERSION VERSION_GREATER 3.1)
cmake_policy(SET CMP0054 NEW)
endif()
#-------------------------------------------------------------------------------
# Pre-compute a regex to match documented keywords for each command.
#-------------------------------------------------------------------------------
# This code parses the *current* file and extracts parameter key words from the
# documentation given above. It will match "# ... [...] # ..." style
# statements, or "# <funcname>(" style statements. This code was pretty much
# lifted directly from KitWare's ExternalProject.cmake, but then I documented
# what it's doing. It's not exactly straight forward.
# Based on the current line in *this* file (CPM.cmake), we calc the number
# of lines the documentation header consumes. Including this comment, that is
# 12 lines upwards.
math(EXPR _cpm_documentation_line_count "${CMAKE_CURRENT_LIST_LINE} - 13")
# Run a regex to extract parameter names from the *this* file (CPM.cmake).
# Stuff the results into 'lines'.
file(STRINGS "${CMAKE_CURRENT_LIST_FILE}" lines
LIMIT_COUNT ${_cpm_documentation_line_count}
REGEX "^# ( \\[[A-Z0-9_]+ [^]]*\\] +#.*$|[A-Za-z0-9_]+\\()")
# Iterate over the results we obtained
foreach(line IN LISTS lines)
# Check to see if we have found a function which is two spaces followed by
# any number of alphanumeric chararcters followed by a '('.
if("${line}" MATCHES "^# [A-Za-z0-9_]+\\(")
# Are we already parsing a function?
if(_cpm_func)
# We are parsing a function, save the current list of keywords in
# _cpm_keywords_<function_name> in preparation to parse a new function.
set(_cpm_keywords_${_cpm_func} "${_cpm_keywords_${_cpm_func}})$")
endif()
# Note that _cpm_func gets *set* HERE. See 'cmake --help-command string'.
# In this case, we are extracting the function's name into _cpm_func.
string(REGEX REPLACE "^# ([A-Za-z0-9_]+)\\(.*" "\\1" _cpm_func "${line}")
#message("function [${_cpm_func}]")
# Clear vars (we will be building a REGEX in _cpm_keywords, hence
# the ^(. _cpm_keyword_sep is only use to inject a separator at appropriate
# places while we are building the regex. In essence, we are skipping the
# first '|' that would usually be inserted.
set(_cpm_keywords_${_cpm_func} "^(")
set(_cpm_keyword_sep)
else()
# Otherwise we must be parsing a parameter of the function. Extract the name
# of the parameter into _cpm_key
string(REGEX REPLACE "^# \\[([A-Z0-9_]+) .*" "\\1" _cpm_key "${line}")
# Syntax highlighting gets a little wonky around this regex, need this - "
#message(" keyword [${_cpm_key}]")
set(_cpm_keywords_${_cpm_func}
"${_cpm_keywords_${_cpm_func}}${_cpm_keyword_sep}${_cpm_key}")
set(_cpm_keyword_sep "|")
endif()
endforeach()
# Duplicate of the 'Are we already parsing a function?' code above.
# Just completes the regex.
if(_cpm_func)
set(_cpm_keywords_${_cpm_func} "${_cpm_keywords_${_cpm_func}})$")
endif()
# Include dependencies
find_package(Git)
if(NOT GIT_FOUND)
message(FATAL_ERROR "CPM requires Git.")
endif()
macro(_cpm_debug_log debug)
if ((DEFINED _CPM_DEBUG_LOG) AND (_CPM_DEBUG_LOG))
message("== ${debug}")
endif()
endmacro()
# Check to see if the CPM_CACHE_DIR environment variable is set, but
# CPM_MODULE_CACHE_DIR is not set yet.
if ((NOT DEFINED CPM_MODULE_CACHE_DIR) AND (NOT "$ENV{CPM_CACHE_DIR}" STREQUAL ""))
set(CPM_MODULE_CACHE_DIR "$ENV{CPM_CACHE_DIR}")
endif()
# Record where this list file is located. We pass this directory into our
# modules so they can also include SpirePM.
# We do NOT want to access CMAKE_CURRENT_LIST_DIR from a function invokation.
# If we do, then CMAKE_CURRENT_LIST_DIR will contain the calling CMakeLists.txt
# file. See: http://stackoverflow.com/questions/12802377/in-cmake-how-can-i-find-the-directory-of-an-included-file
set(CPM_DIR_OF_CPM ${CMAKE_CURRENT_LIST_DIR})
# Clear out any definitions a parent_scope might have declared.
set(CPM_DEFINITIONS)
# Clear out any include directories.
set(CPM_INCLUDE_DIRS)
# Clear out exported modules from the parent.
set(CPM_EXPORTED_MODULES)
# Ensure we add an entry in the forward declaration map list for ourselves
# (even if we don't even add a forward declaration).
set(CPM_KV_LIST_FORWARD_DECL_MAP ${CPM_KV_LIST_FORWARD_DECL_MAP} ${CPM_UNIQUE_ID})
# Increment the module hierarchy level if it exists.
if (NOT DEFINED CPM_HIERARCHY_LEVEL)
set(CPM_HIERARCHY_LEVEL 0)
endif()
# Initial display of the hierarchy if the user requested it.
if ((DEFINED CPM_SHOW_HIERARCHY) AND (CPM_SHOW_HIERARCHY))
if (CPM_HIERARCHY_LEVEL EQUAL 0)
message("CPM Module Dependency Hierarchy:")
message("Root")
endif()
endif()
# Clear out the old CPM_KV_PREPROC_NS_MAP
foreach(_cpm_kvName IN LISTS CPM_KV_LIST_PREPROC_NS_MAP)
set(CPM_KV_PREPROC_NS_MAP_${_cpm_kvName})
endforeach()
# Clear out both the list, and the 'for' variable
set(CPM_KV_LIST_PREPROC_NS_MAP)
set(_cpm_kvName)
# Clear out the old CPM_KV_UNID_MAP
foreach(_cpm_kvName IN LISTS CPM_KV_LIST_UNID_MAP)
set(CPM_KV_UNID_MAP_${_cpm_kvName})
endforeach()
# Clear out both the list, and the 'for' variable
set(CPM_KV_LIST_UNID_MAP)
set(_cpm_kvName)
# Clear out the old CPM_KV_SOURCEDIR_MAP
foreach(_cpm_kvName IN LISTS CPM_KV_LIST_SOURCEDIR_MAP)
set(CPM_KV_SOURCEDIR_MAP_${_cpm_kvName})
endforeach()
# Clear out both the list, and the 'for' variable
set(CPM_KV_LIST_SOURCEDIR_MAP)
set(_cpm_kvName)
set(CPM_ADDITIONAL_INCLUDE_DIRS)
set(CPM_ADDITIONAL_DEFINITIONS)
# Function for parsing arguments and values coming into the specified function
# name 'f'. 'name' is the target name. 'ns' (namespace) is a value prepended
# onto the key name before being added to the target namespace. 'args' list of
# arguments to process.
function(_cpm_parse_arguments f ns args)
# Transfer the arguments to this function into target properties for the new
# custom target we just added so that we can set up all the build steps
# correctly based on target properties.
#
# We loop through ARGN and consider the namespace starting with an upper-case
# letter followed by at least two more upper-case letters, numbers or
# underscores to be keywords.
set(key)
foreach(arg IN LISTS args)
set(is_value 1)
# Check to see if we have a keyword. Otherwise, we will have a value
# associated with a keyword. Confirm that the arg doesn't match a few
# common exceptions.
if(arg MATCHES "^[A-Z][A-Z0-9_][A-Z0-9_]+$" AND
NOT ((arg STREQUAL "${key}") AND (key STREQUAL "COMMAND")) AND
NOT arg MATCHES "^(TRUE|FALSE)$")
# Now check to see if the argument is in our list of approved keywords.
# If is, then make sure we don't treat it as a value.
if(_cpm_keywords_${f} AND arg MATCHES "${_cpm_keywords_${f}}")
set(is_value 0)
endif()
endif()
if(is_value)
if(key)
# We have a key / value pair. Set the appropriate property.
if(NOT arg STREQUAL "")
# Set the variable in both scopes so we can test for existance
# and update as needed.
set(${ns}${key} "${arg}")
set(${ns}${key} "${arg}" PARENT_SCOPE)
#message("Set ${ns}${key} to ${arg}")
else()
if (${ns}${key})
# If we already have a value for this key, generated a semi-colon
# separated list.
set(value ${${ns}${key}})
set(${ns}${key} "${value};${arg}")
set(${ns}${key} "${value};${arg}" PARENT_SCOPE)
#message("Set2 ${ns}${key} to ${value};${arg}")
else()
set(${ns}${key} "${arg}")
set(${ns}${key} "${arg}" PARENT_SCOPE)
endif()
endif()
else()
# Missing Keyword
message(AUTHOR_WARNING "value '${arg}' with no previous keyword in ${f}")
endif()
else()
# Set the key to use in the next iteration.
set(key "${arg}")
endif()
endforeach()
endfunction()
# Function for clearing parsed arguments. Used directly before calling
# add_subdirectory on a child module.
function(_cpm_clear_arguments f ns args)
# Transfer the arguments to this function into target properties for the new
# custom target we just added so that we can set up all the build steps
# correctly based on target properties.
#
# We loop through ARGN and consider the namespace starting with an upper-case
# letter followed by at least two more upper-case letters, numbers or
# underscores to be keywords.
set(key)
foreach(arg IN LISTS args)
set(is_value 1)
# Check to see if we have a keyword. Otherwise, we will have a value
# associated with a keyword. Confirm that the arg doesn't match a few
# common exceptions.
if(arg MATCHES "^[A-Z][A-Z0-9_][A-Z0-9_]+$" AND
NOT ((arg STREQUAL "${key}") AND (key STREQUAL "COMMAND")) AND
NOT arg MATCHES "^(TRUE|FALSE)$")
# Now check to see if the argument is in our list of approved keywords.
# If is, then make sure we don't treat it as a value.
if(_cpm_keywords_${f} AND arg MATCHES "${_cpm_keywords_${f}}")
set(is_value 0)
endif()
endif()
if(is_value)
if(key)
set(${ns}${key} PARENT_SCOPE)
else()
# Missing Keyword
message(AUTHOR_WARNING "value '${arg}' with no previous keyword in ${f}")
endif()
else()
# Set the key to use in the next iteration.
set(key "${arg}")
endif()
endforeach()
endfunction()
# See: http://stackoverflow.com/questions/7747857/in-cmake-how-do-i-work-around-the-debug-and-release-directories-visual-studio-2
# This is only for CMake files.
function(_cpm_build_target_output_dirs parent_var_to_update output_dir)
set(outputs)
set(outputs ${outputs} "-DCMAKE_RUNTIME_OUTPUT_DIRECTORY:STRING=${output_dir}")
set(outputs ${outputs} "-DCMAKE_LIBRARY_OUTPUT_DIRECTORY:STRING=${output_dir}")
set(outputs ${outputs} "-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY:STRING=${output_dir}")
# Second, for multi-config builds (e.g. msvc)
foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG_UPPER)
set(outputs ${outputs} "-DCMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG_UPPER}:STRING=${output_dir}/${OUTPUTCONFIG}")
set(outputs ${outputs} "-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG_UPPER}:STRING=${output_dir}/${OUTPUTCONFIG}")
set(outputs ${outputs} "-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG_UPPER}:STRING=${output_dir}/${OUTPUTCONFIG}")
endforeach(OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES)
set(${parent_var_to_update} ${outputs} PARENT_SCOPE)
endfunction()
# Same as above but places the output directories in the parent scope.
function(_cpm_set_target_output_dirs parent_var_to_update output_dir)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${output_dir}" PARENT_SCOPE)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${output_dir}" PARENT_SCOPE)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${output_dir}" PARENT_SCOPE)
# Second, for multi-config builds (e.g. msvc)
foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG_UPPER)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG_UPPER} "${output_dir}/${OUTPUTCONFIG}" PARENT_SCOPE)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG_UPPER} "${output_dir}/${OUTPUTCONFIG}" PARENT_SCOPE)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG_UPPER} "${output_dir}/${OUTPUTCONFIG}" PARENT_SCOPE)
endforeach(OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES)
endfunction()
# Builds the preprocessor name from 'name' and stores it in 'parentVar'.
function(_cpm_build_preproc_name name parentVar)
string(TOUPPER ${name} CPM_UPPER_CASE_NAME)
set(${parentVar} "CPM_${CPM_UPPER_CASE_NAME}_NS" PARENT_SCOPE)
endfunction()
macro(_cpm_propogate_version_map_up)
# Use CPM_KV_LIST_MOD_VERSION_MAP to propogate constraints up into the
# parent CPM_AddModule function's namespace. CPM_AddModule will
# propogate the versioning information up again to it's parent's namespace.
if (NOT CPM_HIERARCHY_LEVEL EQUAL 0)
foreach(_cpm_kvName IN LISTS CPM_KV_LIST_MOD_VERSION_MAP)
set(CPM_KV_MOD_VERSION_MAP_${_cpm_kvName} ${CPM_KV_MOD_VERSION_MAP_${_cpm_kvName}} PARENT_SCOPE)
endforeach()
set(_cpm_kvName) # Clear kvName
# Now propogate the list itself upwards.
set(CPM_KV_LIST_MOD_VERSION_MAP ${CPM_KV_LIST_MOD_VERSION_MAP} PARENT_SCOPE)
endif()
endmacro()
# Propogates the list of directories we have sourced upwards.
macro(_cpm_propogate_source_added_map_up)
if (NOT CPM_HIERARCHY_LEVEL EQUAL 0)
foreach(_cpm_kvName IN LISTS CPM_KV_LIST_SOURCE_ADDED_MAP)
set(CPM_KV_SOURCE_ADDED_MAP_${_cpm_kvName} ${CPM_KV_SOURCE_ADDED_MAP_${_cpm_kvName}} PARENT_SCOPE)
endforeach()
set(_cpm_kvName) # Clear kvName
# Now propogate the list itself upwards.
set(CPM_KV_LIST_SOURCE_ADDED_MAP ${CPM_KV_LIST_SOURCE_ADDED_MAP} PARENT_SCOPE)
endif()
endmacro()
# Propogates include map up.
macro(_cpm_propogate_include_map_up)
if (NOT CPM_HIERARCHY_LEVEL EQUAL 0)
foreach(_cpm_kvName IN LISTS CPM_KV_LIST_INCLUDE_MAP)
set(CPM_KV_INCLUDE_MAP_${_cpm_kvName} ${CPM_KV_INCLUDE_MAP_${_cpm_kvName}} PARENT_SCOPE)
endforeach()
set(_cpm_kvName) # Clear kvName
# Now propogate the list itself upwards.
set(CPM_KV_LIST_INCLUDE_MAP ${CPM_KV_LIST_INCLUDE_MAP} PARENT_SCOPE)
endif()
endmacro()
# Propogates definition map up.
macro(_cpm_propogate_definition_map_up)
if (NOT CPM_HIERARCHY_LEVEL EQUAL 0)
foreach(_cpm_kvName IN LISTS CPM_KV_LIST_DEFINITION_MAP)
set(CPM_KV_DEFINITION_MAP_${_cpm_kvName} ${CPM_KV_DEFINITION_MAP_${_cpm_kvName}} PARENT_SCOPE)
endforeach()
set(_cpm_kvName) # Clear kvName
# Now propogate the list itself upwards.
set(CPM_KV_LIST_DEFINITION_MAP ${CPM_KV_LIST_DEFINITION_MAP} PARENT_SCOPE)
endif()
endmacro()
# Propogates forward declaration map up.
macro(_cpm_propogate_forward_decl_map_up)
if (NOT CPM_HIERARCHY_LEVEL EQUAL 0)
foreach(_cpm_kvName IN LISTS CPM_KV_LIST_FORWARD_DECL_MAP)
set(CPM_KV_FORWARD_DECL_MAP_${_cpm_kvName} ${CPM_KV_FORWARD_DECL_MAP_${_cpm_kvName}} PARENT_SCOPE)
endforeach()
set(_cpm_kvName) # Clear kvName
# Now propogate the list itself upwards.
set(CPM_KV_LIST_FORWARD_DECL_MAP ${CPM_KV_LIST_FORWARD_DECL_MAP} PARENT_SCOPE)
endif()
endmacro()
# Propogates target library map up.
macro(_cpm_propogate_target_lib_map_up)
if (NOT CPM_HIERARCHY_LEVEL EQUAL 0)
foreach(_cpm_kvName IN LISTS CPM_KV_LIST_LIB_TARGET_MAP)
set(CPM_KV_LIB_TARGET_MAP_${_cpm_kvName} ${CPM_KV_LIB_TARGET_MAP_${_cpm_kvName}} PARENT_SCOPE)
endforeach()
set(_cpm_kvName) # Clear kvName
# Now propogate the list itself upwards.
set(CPM_KV_LIST_LIB_TARGET_MAP ${CPM_KV_LIST_LIB_TARGET_MAP} PARENT_SCOPE)
endif()
endmacro()
# Propogates export module map up.
macro(_cpm_propogate_export_map_up)
if (NOT CPM_HIERARCHY_LEVEL EQUAL 0)
foreach(_cpm_kvName IN LISTS CPM_KV_LIST_EXPORT_MAP)
set(CPM_KV_EXPORT_MAP_${_cpm_kvName} ${CPM_KV_EXPORT_MAP_${_cpm_kvName}} PARENT_SCOPE)
endforeach()
set(_cpm_kvName) # Clear kvName
# Now propogate the list itself upwards.
set(CPM_KV_LIST_EXPORT_MAP ${CPM_KV_LIST_EXPORT_MAP} PARENT_SCOPE)
endif()
endmacro()
# This macro initializes a CPM module. We use a macro for this code so that
# we can set variables in the parent namespace (if any).
# name - Same as the name parameter in CPM_AddModule. A preprocessor definition
# using this name will be generated for namespaces.
macro(CPM_InitModule)
# Check to see if we have any optional arguments if CPM_MODULE_NAME
# is not set.
if(NOT DEFINED CPM_MODULE_NAME)
# Check for optional name argument
set (extra_macro_args ${ARGN})
list(LENGTH extra_macro_args num_extra_args)
if (${num_extra_args} GREATER 0)
list(GET extra_macro_args 0 optional_arg)
set(CPM_MODULE_NAME ${optional_arg})
else()
message(FATAL_ERROR "CPM_InitModule: CPM_MODULE_NAME not set and no optional name argument provided.")
endif()
endif()
# Ensure the parent function knows what we decided to name ourselves.
# This name will correspond to our module's namespace directives.
if (NOT CPM_HIERARCHY_LEVEL EQUAL 0)
set(CPM_LAST_MODULE_NAME ${CPM_MODULE_NAME} PARENT_SCOPE)
endif()
# Build the appropriate definition for the module. We stored the unique ID
_cpm_build_preproc_name(${CPM_MODULE_NAME} __CPM_TMP_VAR)
if (NOT DEFINED CPM_UNIQUE_ID)
set(CPM_UNIQUE_ID CPM_TESTING_UPPER_LEVEL_NAMESPACE)
endif()
add_definitions("-D${__CPM_TMP_VAR}=${CPM_UNIQUE_ID}")
set(__CPM_TMP_VAR) # Clean up
# Propogate our exported modules up.
if (DEFINED CPM_EXPORTED_MODULES)
set(CPM_EXPORTED_MODULES ${CPM_EXPORTED_MODULES} PARENT_SCOPE)
endif()
# Propogate up additional definitions and includes.
# (the reason we propogate this up: addition definitions can be modified
# from the CPM_AddModule function one scope down)
set(CPM_ADDITIONAL_DEFINITIONS ${CPM_ADDITIONAL_DEFINITIONS} PARENT_SCOPE)
# Setup the export map.
set(CPM_KV_EXPORT_MAP_${CPM_UNIQUE_ID} ${CPM_EXPORTED_MODULES})
set(CPM_KV_LIST_EXPORT_MAP ${CPM_KV_LIST_EXPORT_MAP} ${CPM_UNIQUE_ID})
_cpm_propogate_source_added_map_up()
_cpm_propogate_version_map_up()
_cpm_propogate_include_map_up()
_cpm_propogate_definition_map_up()
_cpm_propogate_target_lib_map_up()
_cpm_propogate_export_map_up()
_cpm_propogate_forward_decl_map_up()
# Propogate CPM_LIBRARIES upwards and remove any duplicates that may exist.
# Added so only one target_link_libraries will be required at the application
# level instead of calling target_link_libraries in every module.
if (CPM_LIBRARIES)
set(CPM_LIBRARIES ${CPM_LIBRARIES} PARENT_SCOPE)
endif()
# Setup the module with appropriate definitions and includes.
# We can do this because we are not in a new scope; instead, we are in a macro
# which executes in the parent scope (since it is literally inserted into
# the parent scope).
add_definitions(${CPM_DEFINITIONS})
include_directories(SYSTEM ${CPM_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
# TODO: Remove the following line when we upgrade SCIRun.
include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/3rdParty)
endmacro()
# This macro is meant to be used only by the root of the CPM dependency
# hierarchy (C++ code that uses modules, but is not a module itself).
macro(CPM_Finish)
# Ensure the parent function knows what we decided to name ourselves.
# This name will correspond to our module's namespace directives.
if (NOT CPM_HIERARCHY_LEVEL EQUAL 0)
message(FATAL_ERROR "You can only call CPM_Finish from the top level of the dependency hierarchy.")
endif()
# Setup appropriate definitions and include directories.
add_definitions(${CPM_DEFINITIONS})
include_directories(SYSTEM ${CPM_INCLUDE_DIRS})
# Ensure CPM.cmake is current. CPM_Finish will always be called at
# the end of setting up the entire hierarchy chain. So this
# won't affect what the modules include.
if (NOT ((DEFINED CPM_NO_UPDATE) AND (CPM_NO_UPDATE)))
CPM_EnsureRepoIsCurrent(
TARGET_DIR ${CPM_DIR_OF_CPM}
GIT_REPOSITORY "https://github.com/iauns/cpm"
GIT_TAG "origin/master"
USE_CACHING FALSE
)
endif()
endmacro()
# This macro forces one, and only one, version of a module to be linked into
# a program. If any part of the build chain uses a different version of the
# module, then the CMake configure step will fail with a verbose error.
macro(CPM_ForceOnlyOneModuleVersion)
# Set a flag in the parent namespace to force a check against module name
# and version.
set(CPM_FORCE_ONLY_ONE_MODULE_VERSION TRUE PARENT_SCOPE)
endmacro()
# This macro allows modules to expose additional include directories to
# consumers. This is necessary for externals, and only exposes the include
# definition to the direct consumer of the module. None of the consumer's
# parents.
macro(CPM_ExportAdditionalIncludeDir)
foreach (item ${ARGV})
get_filename_component(tmp_src_dir ${item} ABSOLUTE)
set(CPM_ADDITIONAL_INCLUDE_DIRS ${CPM_ADDITIONAL_INCLUDE_DIRS} "${tmp_src_dir}" PARENT_SCOPE)
set(CPM_ADDITIONAL_INCLUDE_DIRS ${CPM_ADDITIONAL_INCLUDE_DIRS} "${tmp_src_dir}")
endforeach()
endmacro()
# This macro allows modules to expose additional definitions.
# As with ExportAdditionalIncludeDirectory, this only exposes the definition
# to the direct consumer of the module. None of the consumer's parents.
macro(CPM_ExportAdditionalDefinition)
foreach (item ${ARGV})
set(CPM_ADDITIONAL_DEFINITIONS ${CPM_ADDITIONAL_DEFINITIONS} ${item} PARENT_SCOPE)
set(CPM_ADDITIONAL_DEFINITIONS ${CPM_ADDITIONAL_DEFINITIONS} ${item})
endforeach()
endmacro()
macro(CPM_ExportAdditionalLibraryTarget)
foreach (item ${ARGV})
set(CPM_ADDITIONAL_TARGET_LIBS ${CPM_ADDITIONAL_TARGET_LIBS} ${item} PARENT_SCOPE)
set(CPM_ADDITIONAL_TARGET_LIBS ${CPM_ADDITIONAL_TARGET_LIBS} ${item})
endforeach()
endmacro()
# We use this code in multiple places to check that we don't have preprocessor
# conflicts, and if we don't, then add the appropriate defintion.
macro(_cpm_check_and_add_preproc defShortName fullUNID)
_cpm_build_preproc_name(${defShortName} __CPM_LAST_MODULE_PREPROC)
# Ensure that we don't have a name conflict
if (DEFINED CPM_KV_PREPROC_NS_MAP_${__CPM_LAST_MODULE_PREPROC})
if (NOT ${CPM_KV_PREPROC_NS_MAP_${__CPM_LAST_MODULE_PREPROC}} STREQUAL ${fullUNID})
message("CPM namespace conflict.")
message(" Current module name: ${name}.")
message(" Conflicting propressor macro: ${__CPM_LAST_MODULE_PREPROC}.")
message(" Our module UNID: ${fullUNID}.")
message(" Conflicting UNID: ${CPM_KV_PREPROC_NS_MAP_${__CPM_LAST_MODULE_PREPROC}}.")
message(FATAL_ERROR "CPM cannot continue without resolving namespace conflict.")
endif()
else()
set(CPM_KV_PREPROC_NS_MAP_${__CPM_LAST_MODULE_PREPROC} ${fullUNID} PARENT_SCOPE)
set(CPM_KV_LIST_PREPROC_NS_MAP ${CPM_KV_LIST_PREPROC_NS_MAP} ${__CPM_LAST_MODULE_PREPROC} PARENT_SCOPE)
set(CPM_KV_LIST_PREPROC_NS_MAP ${CPM_KV_LIST_PREPROC_NS_MAP} ${__CPM_LAST_MODULE_PREPROC})
endif()
# Add the interface definition to our list of preprocessor definitions.
# We don't set this in the parent scope because definitions will be propogated
# up to the parent at the end of our function.
set(CPM_DEFINITIONS ${CPM_DEFINITIONS} "-D${__CPM_LAST_MODULE_PREPROC}=${fullUNID}")
# Clear our variable.
set(__CPM_LAST_MODULE_PREPROC)
endmacro()
function(_cpm_print_with_hierarchy_level msg)
# while ${number} is between 0 and 11
if (DEFINED CPM_HIERARCHY_LEVEL)
set(number 1)
set(spacing " ")
while( number GREATER 0 AND number LESS ${CPM_HIERARCHY_LEVEL} )
set(spacing "${spacing} ")
math( EXPR number "${number} + 1" ) # decrement number
endwhile()
message("${spacing}| ${msg}")
else()
message(msg)
endif()
endfunction()
macro(_cpm_make_valid_unid_or_path variable)
if (NOT "${${variable}}" STREQUAL "")
string(REGEX REPLACE "https://github.com/" "github_" ${variable} ${${variable}})
string(REGEX REPLACE "http://github.com/" "github_" ${variable} ${${variable}})
string(REGEX REPLACE "https://bitbucket.org/" "bitbucket_" ${variable} ${${variable}})
string(REGEX REPLACE "http://bitbucket.org/" "bitbucket_" ${variable} ${${variable}})
# Strip off .git extension, if any.
string(REGEX REPLACE "\\.git$" "" ${variable} ${${variable}})
string(REGEX REPLACE "/" "_" ${variable} ${${variable}})
string(REGEX REPLACE "[:/\\.?-]" "" ${variable} ${${variable}})
string(TOLOWER ${${variable}} ${variable})
endif()
endmacro()
macro(_cpm_obtain_version_from_params parentVar)
if ((DEFINED _CPM_USE_EXISTING_VER) AND (_CPM_USE_EXISTING_VER))
# Attempt to pull existing version from module hierarchy. If we don't
# find any, and the user has defined a version, then use that version
# (this constitutes falling through without setting parentVar).
if (DEFINED _CPM_GIT_REPOSITORY)
# Modify the git repository.
set(__CPM_TMP_VAR ${_CPM_GIT_REPOSITORY})
_cpm_make_valid_unid_or_path(__CPM_TMP_VAR)
if (DEFINED CPM_KV_MOD_VERSION_MAP_${__CPM_TMP_VAR})
set(${parentVar} ${CPM_KV_MOD_VERSION_MAP_${__CPM_TMP_VAR}})
endif()
set(__CPM_TMP_VAR)
elseif(DEFINED _CPM_SOURCE_DIR)
if (DEFINED _CPM_SOURCE_GHOST_GIT_REPO)
set(__CPM_TMP_VAR ${_CPM_SOURCE_GHOST_GIT_REPO})
_cpm_make_valid_unid_or_path(__CPM_TMP_VAR)
if (DEFINED CPM_KV_MOD_VERSION_MAP_${__CPM_TMP_VAR})
set(${parentVar} ${CPM_KV_MOD_VERSION_MAP_${__CPM_TMP_VAR}})
endif()
set(__CPM_TMP_VAR)
endif()
endif()
endif()
# Sane default for GIT_TAG if it is not specified
if (NOT DEFINED ${parentVar})
if (DEFINED _CPM_GIT_TAG)
set(${parentVar} ${_CPM_GIT_TAG})
else()
if (DEFINED _CPM_SOURCE_GHOST_GIT_TAG)
set(${parentVar} ${_CPM_SOURCE_GHOST_GIT_TAG})
else()
set(${parentVar} "origin/master")
endif()
endif()
endif()
endmacro()
macro(_cpm_clone_hg_repo repo dir tag)
# Simply clones the hg repository at ${repo} into ${dir}
# No other checks are performed.
message(STATUS "Cloning hg repo (${repo} @ ${tag})")
# Much of this clone code is taken from external project's generation
# of its *gitclone.cmake files. (and copied again for hg)
# Try the clone 3 times (from External Project source).
# We don't set a timeout here because we absolutely need to clone the
# directory in order to continue with the build process.
set(error_code 1)
set(number_of_tries 0)
while(error_code AND number_of_tries LESS 3)
execute_process(
COMMAND "${HG_EXECUTABLE}" clone "${repo}" "${dir}"
WORKING_DIRECTORY "${CPM_DIR_OF_CPM}"
RESULT_VARIABLE error_code
OUTPUT_QUIET
ERROR_QUIET
)
math(EXPR number_of_tries "${number_of_tries} + 1")
endwhile()
# Check to see if we really have cloned the repository.
if(number_of_tries GREATER 1)
message(STATUS "Had to hg clone more than once: ${number_of_tries} times.")
endif()
if(error_code)
message("Hg error for directory '${dir}'")
message(FATAL_ERROR "Failed to clone repository: '${repo}'")
endif()
# Checkout the appropriate tag.
execute_process(
COMMAND "${HG_EXECUTABLE}" checkout ${tag}
WORKING_DIRECTORY "${dir}"
RESULT_VARIABLE error_code
OUTPUT_QUIET
ERROR_QUIET
)
if(error_code)
message(FATAL_ERROR "Failed to checkout tag: '${tag}'")
endif()
# subrepositories in hg are not supported right now
endmacro()
macro(_cpm_clone_git_repo repo dir tag)
# Simply clones the git repository at ${repo} into ${dir}
# No other checks are performed.
message(STATUS "Cloning repo (${repo} @ ${tag})")
# Much of this clone code is taken from external project's generation
# of its *gitclone.cmake files.
# Try the clone 3 times (from External Project source).
# We don't set a timeout here because we absolutely need to clone the
# directory in order to continue with the build process.
set(error_code 1)
set(number_of_tries 0)
while(error_code AND number_of_tries LESS 3)
execute_process(
COMMAND "${GIT_EXECUTABLE}" clone "${repo}" "${dir}"
WORKING_DIRECTORY "${CPM_DIR_OF_CPM}"
RESULT_VARIABLE error_code
OUTPUT_QUIET
ERROR_QUIET
)
math(EXPR number_of_tries "${number_of_tries} + 1")
endwhile()
# Check to see if we really have cloned the repository.
if(number_of_tries GREATER 1)
message(STATUS "Had to git clone more than once: ${number_of_tries} times.")
endif()
if(error_code)
message("Git error for directory '${dir}'")
message(FATAL_ERROR "Failed to clone repository: '${repo}'")
endif()
# Checkout the appropriate tag.
execute_process(
COMMAND "${GIT_EXECUTABLE}" checkout ${tag}
WORKING_DIRECTORY "${dir}"
RESULT_VARIABLE error_code
OUTPUT_QUIET
ERROR_QUIET
)
if(error_code)
message(FATAL_ERROR "Failed to checkout tag: '${tag}'")
endif()
# Initialize and update any submodules that may be present in the repo.
execute_process(
COMMAND "${GIT_EXECUTABLE}" submodule init
WORKING_DIRECTORY "${dir}"
RESULT_VARIABLE error_code
)
if(error_code)
message(FATAL_ERROR "Failed to init submodules in: '${dir}'")
endif()
execute_process(
COMMAND "${GIT_EXECUTABLE}" submodule update --recursive
WORKING_DIRECTORY "${dir}"
RESULT_VARIABLE error_code
)
if(error_code)
message(FATAL_ERROR "Failed to update submodules in: '${dir}'")
endif()
endmacro()
macro(_cpm_update_hg_repo dir tag)
message(STATUS "updating hg repository (${dir} @ ${tag})")
execute_process(
COMMAND "${HG_EXECUTABLE}" update
WORKING_DIRECTORY "${dir}"
RESULT_VARIABLE error_code)
if(error_code)
message("could not update hg repo in : '${dir}'")
endif()
execute_process(
COMMAND "${HG_EXECUTABLE}" checkout "${tag}"
WORKING_DIRECTORY "${dir}"
RESULT_VARIABLE error_code
)
if(error_code)
message(FATAL_ERROR "could not checkout sepcified tag: '${tag}'" )
endif()
endmacro()
macro(_cpm_update_git_repo dir tag)
# Attempt to update with a timeout.
execute_process(
COMMAND "${GIT_EXECUTABLE}" rev-list --max-count=1 HEAD
WORKING_DIRECTORY "${dir}"
RESULT_VARIABLE error_code
OUTPUT_VARIABLE head_sha
)
if(error_code)
message(FATAL_ERROR "Failed to get the hash for HEAD")
endif()
execute_process(
COMMAND "${GIT_EXECUTABLE}" show-ref ${tag}
WORKING_DIRECTORY "${dir}"