-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathYCMEPHelper.cmake
1772 lines (1515 loc) · 65.6 KB
/
YCMEPHelper.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
# SPDX-FileCopyrightText: 2012-2021 Istituto Italiano di Tecnologia (IIT)
# SPDX-License-Identifier: BSD-3-Clause
#[=======================================================================[.rst:
YCMEPHelper
-----------
A helper for :module:`ExternalProject`::
ycm_ep_helper(<name>
[DOCS]
[TYPE <type>]
[STYLE <style>]
[COMPONENT <component>] (default = "external")
[FOLDER <folder>] (default = "<component>")
[REPOSITORY <repo>]
[EXCLUDE_FROM_ALL <0|1>]
#--Git only arguments-----------
[SHALLOW <bool>]
#--Git and Hg only arguments-----------
[TAG <tag>]
#--Svn only arguments-----------
[REVISION <revision>]
[USERNAME <username>]
[PASSWORD <password>]
[TRUST_CERT <0|1>]
#--CMake arguments---------
[CMAKE_GENERATOR]
[CMAKE_GENERATOR_PLATFORM]
[CMAKE_GENERATOR_TOOLSET]
[CMAKE_GENERATOR_INSTANCE]
[CMAKE_ARGS]
[CMAKE_CACHE_ARGS]
[CMAKE_CACHE_DEFAULT_ARGS]
[DEPENDS]
[DOWNLOAD_COMMAND]
[UPDATE_COMMAND]
[PATCH_COMMAND]
[CONFIGURE_COMMAND]
[BUILD_COMMAND]
[BUILD_ALWAYS] (default = TRUE, while for ExternalProject the default is FALSE)
[INSTALL_COMMAND]
[TEST_COMMAND]
[CLEAN_COMMAND] (not in ExternalProject)
[TEST_AFTER_INSTALL]
[TEST_BEFORE_INSTALL]
[TEST_EXCLUDE_FROM_MAIN]
)
YCM_BOOTSTRAP()
.. variable:: NON_INTERACTIVE_BUILD
.. variable:: YCM_BOOTSTRAP_BASE_ADDRESS
.. variable:: YCM_SKIP_HASH_CHECK
.. variable:: YCM_BOOTSTRAP_VERBOSE
.. variable:: YCM_EP_INSTALL_DIR
.. variable:: YCM_EP_ADDITIONAL_CMAKE_ARGS
.. variable:: YCM_<COMPONENT>_COLOR
.. variable:: YCM_<COMPONENT>_BGCOLOR
.. variable:: YCM_<COMPONENT>_NODECOLOR
TODO Add variable YCM_INSTALL_PREFIX
#]=======================================================================]
if(DEFINED __YCMEPHELPER_INCLUDED)
return()
endif()
set(__YCMEPHELPER_INCLUDED TRUE)
# Handle CMP0114 (see https://cmake.org/cmake/help/latest/policy/CMP0114.html
# and https://github.com/robotology/ycm-cmake-modules/pull/452)
get_property(_yeph_YCM_USE_CMAKE_NEXT GLOBAL PROPERTY YCM_USE_CMAKE_NEXT)
if(_yeph_YCM_USE_CMAKE_NEXT OR CMAKE_VERSION VERSION_LESS 3.18)
# If we are using the vendored ExternalProject or CMake is 3.16 or 3.17, let's use NO_DEPENDS
set_property(GLOBAL PROPERTY _yeph_NO_DEPENDS "NO_DEPENDS")
set_property(GLOBAL PROPERTY _yeph_INDEPENDENT "")
else()
# Otherwise let's use INDEPENDENT
set_property(GLOBAL PROPERTY _yeph_NO_DEPENDS "")
set_property(GLOBAL PROPERTY _yeph_INDEPENDENT "INDEPENDENT")
endif()
########################################################################
# Hashes of YCM files to be checked
# Files downloaded during YCM bootstrap
set(_ycm_CMakeParseArguments_sha1sum 0c4d3f7ed248145cbeb67cbd6fd7190baf2e4517)
set(_ycm_ExternalProject_sha1sum ba8c547caa118c5ace50857c7839f76914926ef7)
# Files in all projects that need to bootstrap YCM
set(_ycm_IncludeUrl_sha1sum 997de3554f0d03ae22952a64fe26cdad118e8199)
set(_ycm_YCMBootstrap_sha1sum 59c6dfc84ec36518c5be5aef13af252a8250bad7)
########################################################################
# _YCM_INCLUDE
#
# Internal macro to include files from cmake-next.
# If YCM was not found, we are bootstrapping, therefore we need to
# download and use these modules instead of the ones found by cmake
# This must be a macro and not a function in order not to enclose in a
# new scope the variables added by the included files.
macro(_YCM_INCLUDE _module)
if(YCM_FOUND OR DEFINED __USEYCMFROMSOURCE_INCLUDED)
include(${_module})
else()
# We assume that YCMEPHelper was included using include_url, or that at
# least the IncludeUrl module can be found by CMake.
if(NOT COMMAND include_url)
include(IncludeUrl)
endif()
unset(_expected_hash_args)
if(NOT YCM_SKIP_HASH_CHECK)
set(_expected_hash_args EXPECTED_HASH SHA1=${_ycm_${_module}_sha1sum})
endif()
include_url(${YCM_BOOTSTRAP_BASE_ADDRESS}/cmake-next/proposed/${_module}.cmake
${_expected_hash_args}
DOWNLOAD_ONCE
STATUS _download_status)
if(NOT _download_status EQUAL 0)
list(GET 0 _download_status _download_status_0)
list(GET 1 _download_status _download_status_1)
message(FATAL_ERROR "Download failed with ${_download_status_0}: ${_download_status_1}")
endif()
unset(_expected_hash_args)
unset(_download_status)
unset(_download_status_0)
unset(_download_status_1)
endif()
endmacro()
########################################################################
# _YCM_HASH_CHECK
#
# Internal function to check if a module in user repository is updated
# at the latest version and eventually print an AUTHOR_WARNING.
#
# if the variable YCM_SKIP_HASH_CHECK is set it does nothing
function(_YCM_HASH_CHECK _module)
if(YCM_SKIP_HASH_CHECK)
return()
endif()
unset(_error_message)
# FIXME is there a way to find the module without including it?
include(${_module} RESULT_VARIABLE _module_file OPTIONAL)
if(_module_file)
file(SHA1 ${_module_file} _module_sha1sum)
if(NOT "${_module_sha1sum}" STREQUAL "${_ycm_${_module}_sha1sum}")
set(_error_message "YCM_BOOTSTRAP HASH mismatch
for file: [${_module_file}]
expected hash: [${_ycm_${_module}_sha1sum}]
actual hash: [${_module_sha1sum}]
Perhaps it is outdated or you have local modification. Please consider upgrading it, or contributing your changes to YCM.
")
if(WIN32)
file(READ ${_module_file} _tmp)
# On windows, the file could have windows-style EOL
# This should work for any git configuration for core.autocrlf
string(REPLACE "/r/n" "/n" _tmp "${_tmp}")
string(SHA1 _module_sha1sum "${_tmp}")
if("${_module_sha1sum}" STREQUAL "${_ycm_${_module}_sha1sum}")
unset(_error_message)
endif()
endif()
endif()
if(DEFINED _error_message)
message(AUTHOR_WARNING ${_error_message})
endif()
endif()
endfunction()
########################################################################
# _YCM_SETUP
#
# Internal function to perform generic setup.
# This must be a macro and not a function in order not to enclose in a
# new scope the variables added by the included files.
unset(__YCM_SETUP_CALLED)
macro(_YCM_SETUP)
if(DEFINED __YCM_SETUP_CALLED)
return()
endif()
set(__YCM_SETUP_CALLED 1)
_ycm_include(CMakeParseArguments)
_ycm_include(ExternalProject)
if(NOT NON_INTERACTIVE_BUILD)
# Non interactive builds should always perform the update step
set_property(DIRECTORY PROPERTY EP_UPDATE_DISCONNECTED 1)
endif()
set_property(DIRECTORY PROPERTY CMAKE_PARSE_ARGUMENTS_DEFAULT_SKIP_EMPTY FALSE)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Disable CMake cache registry.
set(CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY 1)
set(CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY 1)
option(YCM_EP_EXPERT_MODE "Enable all targets for projects in development mode" OFF)
option(YCM_EP_MAINTAINER_MODE "Enable all targets for projects in development mode" OFF)
mark_as_advanced(YCM_EP_EXPERT_MODE
YCM_EP_MAINTAINER_MODE)
if("${CMAKE_GENERATOR}" MATCHES "^(Visual Studio|Xcode)")
set(_update-all ALL_UPDATE)
set(_fetch-all ALL_FETCH)
set(_status-all ALL_STATUS)
set(_clean-all ALL_CLEAN)
set(_print-directories-all ALL_PRINT_DIRECTORIES)
else()
set(_update-all update-all)
set(_fetch-all fetch-all)
set(_status-all status-all)
set(_clean-all clean-all)
set(_print-directories-all print-directories-all)
endif()
if(NOT (YCM_FOUND OR DEFINED __USEYCMFROMSOURCE_INCLUDED)) # Useless if we don't need to bootstrap
set(YCM_BOOTSTRAP_BASE_ADDRESS "https://raw.github.com/robotology/ycm/HEAD/" CACHE STRING "Base address of YCM repository")
mark_as_advanced(YCM_BOOTSTRAP_BASE_ADDRESS)
endif()
# Install directory for all sub-projects
# TODO Make this a cached variable for installation outside build
# directory
set(YCM_EP_INSTALL_DIR "${CMAKE_BINARY_DIR}/install" CACHE PATH "Path to the superbuild installation directory. WARNING: If this path is not writable by the user, you will have to build as superuser")
mark_as_advanced(YCM_EP_INSTALL_DIR)
set(YCM_EP_ADDITIONAL_CMAKE_ARGS "" CACHE STRING "Additional CMake arguments that are passed to all CMake subprojects of the superbuild.")
mark_as_advanced(YCM_EP_ADDITIONAL_CMAKE_ARGS)
# ExternalProject does not handle correctly arguments containing ";" passed
# using CMAKE_ARGS, and instead splits them into several arguments. This is
# a workaround that replaces ";" with "|" and sets LIST_SEPARATOR "|" in
# order to interpret them correctly.
#
# TODO FIXME check what happens when the "*_COMMAND" arguments are passed.
file(TO_CMAKE_PATH "$ENV{CMAKE_PREFIX_PATH}" _CMAKE_PREFIX_PATH)
list(INSERT _CMAKE_PREFIX_PATH 0 ${YCM_EP_INSTALL_DIR})
list(REMOVE_DUPLICATES _CMAKE_PREFIX_PATH)
string(REPLACE ";" "|" _CMAKE_PREFIX_PATH "${_CMAKE_PREFIX_PATH}")
set(_YCM_EP_ALL_CMAKE_ARGS LIST_SEPARATOR "|")
# YCM_EP_ADDITIONAL_CMAKE_ARGS contains the specified CMake options in a human-readable form,
# so different options are separated by spaces, while lists are separated by ";", for example
# -DYCM_EP_ADDITIONAL_CMAKE_ARGS:STRING="-DBUILD_TESTING:BOOL=ON -DTYPE_SUPPORTED=ZIP;QTIFW"
# For this reason, first we substitute ";" with "|", and only later " " with ";"
set(_YCM_EP_ADDITIONAL_CMAKE_ARGS ${YCM_EP_ADDITIONAL_CMAKE_ARGS})
string(REPLACE ";" "|" _YCM_EP_ADDITIONAL_CMAKE_ARGS "${_YCM_EP_ADDITIONAL_CMAKE_ARGS}")
string(REPLACE " " ";" _YCM_EP_ADDITIONAL_CMAKE_ARGS "${_YCM_EP_ADDITIONAL_CMAKE_ARGS}")
# Default CMAKE_ARGS (Passed to the command line)
set(_YCM_EP_CMAKE_ARGS "--no-warn-unused-cli"
"-DCMAKE_PREFIX_PATH:PATH=${_CMAKE_PREFIX_PATH}") # Path used by cmake for finding stuff
list(APPEND _YCM_EP_CMAKE_ARGS ${_YCM_EP_ADDITIONAL_CMAKE_ARGS})
# If CMAKE_EXPORT_COMPILE_COMMANDS is defined, pass it along to the sub-projects
# See https://github.com/robotology/robotology-superbuild/issues/1596
if(DEFINED CMAKE_EXPORT_COMPILE_COMMANDS AND CMAKE_EXPORT_COMPILE_COMMANDS)
list(APPEND _YCM_EP_CMAKE_ARGS "-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=${CMAKE_EXPORT_COMPILE_COMMANDS}")
endif()
# Default CMAKE_CACHE_ARGS (Initial cache, forced)
set(_YCM_EP_CMAKE_CACHE_ARGS "-DCMAKE_INSTALL_PREFIX:PATH=${YCM_EP_INSTALL_DIR}") # Where to do the installation
if(DEFINED CMAKE_TOOLCHAIN_FILE)
list(APPEND _YCM_EP_CMAKE_CACHE_ARGS "-DCMAKE_TOOLCHAIN_FILE:PATH=${CMAKE_TOOLCHAIN_FILE}")
endif()
# Default CMAKE_CACHE_DEFAULT_ARGS (Initial cache, default)
unset(_YCM_EP_CMAKE_CACHE_DEFAULT_ARGS)
if(NOT CMAKE_BUILD_TYPE STREQUAL "") # CMAKE_BUILD_TYPE is always defined
list(APPEND _YCM_EP_CMAKE_CACHE_DEFAULT_ARGS "-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}") # If there is a CMAKE_BUILD_TYPE it is important to ensure it is passed down.
endif()
if(DEFINED CMAKE_SKIP_RPATH)
list(APPEND _YCM_EP_CMAKE_CACHE_DEFAULT_ARGS "-DCMAKE_SKIP_RPATH:PATH=${CMAKE_SKIP_RPATH}")
endif()
if(DEFINED CMAKE_SKIP_INSTALL_RPATH)
list(APPEND _YCM_EP_CMAKE_CACHE_DEFAULT_ARGS "-DCMAKE_SKIP_INSTALL_RPATH:PATH=${CMAKE_SKIP_INSTALL_RPATH}")
endif()
if(DEFINED BUILD_SHARED_LIBS)
list(APPEND _YCM_EP_CMAKE_CACHE_DEFAULT_ARGS "-DBUILD_SHARED_LIBS:PATH=${BUILD_SHARED_LIBS}")
endif()
endmacro()
########################################################################
# _YCM_SETUP_GIT
#
# Internal function to perform GIT setup.
unset(__YCM_GIT_SETUP_CALLED CACHE)
function(_YCM_SETUP_GIT)
if(DEFINED __YCM_GIT_SETUP_CALLED)
return()
endif()
set(__YCM_GIT_SETUP_CALLED 1 CACHE INTERNAL "")
find_package(Git QUIET)
if(NOT GIT_EXECUTABLE)
message(FATAL_ERROR "Please install Git")
endif()
execute_process(COMMAND ${GIT_EXECUTABLE} config --get user.name
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
RESULT_VARIABLE _error_code
OUTPUT_VARIABLE _output_name
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT NON_INTERACTIVE_BUILD AND _error_code)
message(FATAL_ERROR "Failed to get git name. Please set it with \"git config --global user.name Firstname Lastname\" or from your favorite git gui.")
endif()
execute_process(COMMAND ${GIT_EXECUTABLE} config --get user.email
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
RESULT_VARIABLE _error_code
OUTPUT_VARIABLE _output_email
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT NON_INTERACTIVE_BUILD AND _error_code)
message(FATAL_ERROR "Failed to get git email. Please set it with \"git config --global user.email [email protected]\" or from your favorite git gui.")
endif()
set(YCM_GIT_COMMIT_NAME "${_output_name}" CACHE STRING "Name to use for git commits")
set(YCM_GIT_COMMIT_EMAIL "${_output_email}" CACHE STRING "Email address to use for git commits")
mark_as_advanced(YCM_GIT_COMMIT_NAME YCM_GIT_COMMIT_EMAIL)
endfunction()
########################################################################
# _YCM_SETUP_SVN
#
# Internal function to perform SVN setup.
unset(__YCM_SVN_SETUP_CALLED CACHE)
function(_YCM_SETUP_SVN)
if(DEFINED __YCM_SVN_SETUP_CALLED)
return()
endif()
set(__YCM_SVN_SETUP_CALLED 1 CACHE INTERNAL "")
find_package(Subversion QUIET)
if(NOT Subversion_SVN_EXECUTABLE)
message(FATAL_ERROR "Please install Svn")
endif()
endfunction()
########################################################################
# _YCM_SETUP_HG
#
# Internal function to perform HG setup.
unset(__YCM_HG_SETUP_CALLED CACHE)
function(_YCM_SETUP_HG)
if(DEFINED __YCM_HG_SETUP_CALLED)
return()
endif()
set(__YCM_GIT_SETUP_CALLED 1 CACHE INTERNAL "")
find_package(Hg QUIET)
if(NOT HG_EXECUTABLE)
message(FATAL_ERROR "Please install Mercurial")
endif()
endfunction()
########################################################################
# _YCM_EP_ADD_UPDATE_STEP
#
# Add "update" step for any repository.
function(_YCM_EP_ADD_UPDATE_STEP)
if(NOT TARGET ${_update-all})
add_custom_target(${_update-all})
set_property(TARGET ${_update-all} PROPERTY FOLDER "YCMTargets")
endif()
get_property(_yeph_NO_DEPENDS GLOBAL PROPERTY _yeph_NO_DEPENDS)
# The update step is automatically created, we just need to explicitly
# make it a target
ExternalProject_Add_StepTargets(${_name} ${_yeph_NO_DEPENDS} update)
add_dependencies(${_update-all} ${_name}-update)
endfunction()
########################################################################
# _YCM_EP_ADD_CONFIGURE_STEP
#
# Add "configure" step for any repository.
function(_YCM_EP_ADD_CONFIGURE_STEP)
# The configure step is automatically created, we just need to explicitly
# make it a target
ExternalProject_Add_StepTargets(${_name} configure)
endfunction()
########################################################################
# _YCM_EP_ADD_TEST_STEP
#
# Add "test" step for any repository.
function(_YCM_EP_ADD_TEST_STEP)
if(DEFINED _YH_${_name}_TEST_COMMAND
OR _YH_${_name}_TEST_BEFORE_INSTALL
OR _YH_${_name}_TEST_AFTER_INSTALL
OR _YH_${_name}_TEST_EXCLUDE_FROM_MAIN)
# The test step is automatically created if one of the test
# variables is set, we just need to explicitly make it a target
ExternalProject_Add_StepTargets(${_name} test)
# The test target does not exist, therefore add_dependencies
# cannot be used. Instead we add a test.
add_test(NAME ${_name}_test
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR} --config ${CMAKE_CFG_INTDIR} --target ${_name}-test
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
set_property(TEST ${_name}_test APPEND PROPERTY LABELS ${_name})
set_property(TEST ${_name}_test PROPERTY DEPENDS ${_name})
endif()
endfunction()
########################################################################
# _YCM_EP_ADD_FETCH_STEP
#
# Add "fetch" step for git repositories.
function(_YCM_EP_ADD_FETCH_STEP _name)
if("${_YH_${_name}_TYPE}" STREQUAL "GIT")
if(NOT TARGET ${_fetch-all})
add_custom_target(${_fetch-all})
set_property(TARGET ${_fetch-all} PROPERTY FOLDER "YCMTargets")
endif()
get_property(_yeph_NO_DEPENDS GLOBAL PROPERTY _yeph_NO_DEPENDS)
get_property(_yeph_INDEPENDENT GLOBAL PROPERTY _yeph_INDEPENDENT)
ExternalProject_Add_Step(${_name} fetch
COMMAND ${GIT_EXECUTABLE} fetch --all --prune
WORKING_DIRECTORY ${${_name}_SOURCE_DIR}
COMMENT "Performing fetch step for '${_name}'"
DEPENDEES download
${_yeph_INDEPENDENT}
EXCLUDE_FROM_MAIN 1
ALWAYS 1)
ExternalProject_Add_StepTargets(${_name} ${_yeph_NO_DEPENDS} fetch)
add_dependencies(${_fetch-all} ${_name}-fetch)
endif()
endfunction()
########################################################################
# _YCM_EP_ADD_STATUS_STEP
#
# Add "status" step for git, svn and hg repositories.
function(_YCM_EP_ADD_STATUS_STEP _name)
unset(_cmd)
if("${_YH_${_name}_TYPE}" STREQUAL "GIT")
set(_cmd COMMAND ${GIT_EXECUTABLE} status)
elseif("${_YH_${_name}_TYPE}" STREQUAL "SVN")
set(_cmd COMMAND ${Subversion_SVN_EXECUTABLE} status)
elseif("${_YH_${_name}_TYPE}" STREQUAL "HG")
set(_cmd COMMAND ${HG_EXECUTABLE} status)
endif()
if(DEFINED _cmd)
if(NOT TARGET ${_status-all})
add_custom_target(${_status-all})
set_property(TARGET ${_status-all} PROPERTY FOLDER "YCMTargets")
endif()
get_property(_yeph_NO_DEPENDS GLOBAL PROPERTY _yeph_NO_DEPENDS)
get_property(_yeph_INDEPENDENT GLOBAL PROPERTY _yeph_INDEPENDENT)
if(CMAKE_GENERATOR STREQUAL "Unix Makefiles")
set(_command_echo_color_if_supported cmake_echo_color --switch=$\(COLOR\) --cyan)
else()
set(_command_echo_color_if_supported "echo")
endif()
ExternalProject_Get_Property(${_name} source_dir)
ExternalProject_Add_Step(${_name} status
COMMAND ${CMAKE_COMMAND} -E ${_command_echo_color_if_supported} "Working directory: ${source_dir}"
${_cmd}
WORKING_DIRECTORY ${source_dir}
DEPENDEES download
${_yeph_INDEPENDENT}
EXCLUDE_FROM_MAIN 1
ALWAYS 1)
ExternalProject_Add_StepTargets(${_name} ${_yeph_NO_DEPENDS} status)
add_dependencies(${_status-all} ${_name}-status)
unset(_cmd)
endif()
endfunction()
########################################################################
# _YCM_EP_ADD_CLEAN_STEP
#
# Add "clean" step for any repository.
function(_YCM_EP_ADD_CLEAN_STEP _name)
unset(_cmd)
# FIXME is _YH_${_name}_CLEAN_COMMAND to the function?
# FIXME check if this works on MSVC and Xcode
if(NOT DEFINED _YH_${_name}_CLEAN_COMMAND OR _YH_${_name}_CLEAN_COMMAND STREQUAL "_")
set(_cmd ${CMAKE_COMMAND} --build ${${_name}_BINARY_DIR} --config ${CMAKE_CFG_INTDIR} --target clean)
elseif(NOT "${_YH_${_name}_CLEAN_COMMAND}" STREQUAL "")
set(_cmd ${_YH_${_name}_CLEAN_COMMAND})
endif()
if(DEFINED _cmd)
if(NOT TARGET ${_clean-all})
add_custom_target(${_clean-all})
set_property(TARGET ${_clean-all} PROPERTY FOLDER "YCMTargets")
endif()
get_property(_yeph_NO_DEPENDS GLOBAL PROPERTY _yeph_NO_DEPENDS)
get_property(_yeph_INDEPENDENT GLOBAL PROPERTY _yeph_INDEPENDENT)
ExternalProject_Add_Step(${_name} clean
COMMAND ${_cmd}
WORKING_DIRECTORY ${${_name}_BINARY_DIR}
COMMENT "Performing clean step for '${_name}'"
DEPENDEES configure
EXCLUDE_FROM_MAIN 1
${_yeph_INDEPENDENT}
ALWAYS 1)
ExternalProject_Add_StepTargets(${_name} ${_yeph_NO_DEPENDS} clean)
add_dependencies(${_clean-all} ${_name}-clean)
unset(_cmd)
endif()
endfunction()
########################################################################
# _YCM_EP_ADD_DEPENDEES_STEPS
#
# Add "dependees" and "dependees-update" steps for all the `DEPENDS` of any
# repository, if these are in development mode.
function(_YCM_EP_ADD_DEPENDEES_STEPS _name)
get_property(_depends_set TARGET ${_name} PROPERTY _EP_DEPENDS SET)
get_property(_yeph_NO_DEPENDS GLOBAL PROPERTY _yeph_NO_DEPENDS)
get_property(_yeph_INDEPENDENT GLOBAL PROPERTY _yeph_INDEPENDENT)
if(_depends_set)
get_property(_binary_dir TARGET ${_name} PROPERTY _EP_BINARY_DIR)
get_property(_depends TARGET ${_name} PROPERTY _EP_DEPENDS)
# dependees step (build all packages required by this package)
ExternalProject_Add_Step(${_name} dependees
WORKING_DIRECTORY ${_binary_dir}
COMMENT "Dependencies for '${_name}' built."
EXCLUDE_FROM_MAIN 1
${_yeph_INDEPENDENT}
ALWAYS 1)
ExternalProject_Add_StepTargets(${_name} ${_yeph_NO_DEPENDS} dependees)
foreach(_dep ${_depends})
if(TARGET ${_dep})
ExternalProject_Add_StepDependencies(${_name} dependees ${_dep})
endif()
endforeach()
# dependees-update step (update all packages required by this package)
ExternalProject_Add_Step(${_name} dependees-update
WORKING_DIRECTORY ${binary_dir}
COMMENT "Dependencies for '${_name}' updated."
EXCLUDE_FROM_MAIN 1
${_yeph_INDEPENDENT}
ALWAYS 1)
ExternalProject_Add_StepTargets(${_name} ${_yeph_NO_DEPENDS} dependees-update)
foreach(_dep ${_depends})
if(TARGET ${_dep}-update) # only if the target update exists for the dependency
ExternalProject_Add_StepDependencies(${_name} dependees-update ${_dep}-update)
endif()
endforeach()
endif()
endfunction()
########################################################################
# _YCM_EP_ADD_DEPENDERS_STEPS
#
# Add "dependers" and "dependers-update" steps for any "DEPENDS" of this
# repository.
function(_YCM_EP_ADD_DEPENDERS_STEPS _name)
get_property(_depends_set TARGET ${_name} PROPERTY _EP_DEPENDS SET)
get_property(_yeph_NO_DEPENDS GLOBAL PROPERTY _yeph_NO_DEPENDS)
get_property(_yeph_INDEPENDENT GLOBAL PROPERTY _yeph_INDEPENDENT)
if(_depends_set)
get_property(_depends TARGET ${_name} PROPERTY _EP_DEPENDS)
foreach(_dep ${_depends})
if(TARGET ${_dep})
get_property(is_ep TARGET ${_dep} PROPERTY _EP_IS_EXTERNAL_PROJECT)
if(is_ep)
if(YCM_EP_DEVEL_MODE_${_dep} OR YCM_EP_MAINTAINER_MODE)
get_property(_dep_binary_dir TARGET ${_dep} PROPERTY _EP_BINARY_DIR)
# dependers step (build all packages that require this package)
if(NOT TARGET ${_dep}-dependers)
ExternalProject_Add_Step(${_dep} dependers
WORKING_DIRECTORY ${_dep_binary_dir}
COMMENT "Dependers for '${_dep}' built."
EXCLUDE_FROM_MAIN 1
${_yeph_INDEPENDENT}
ALWAYS 1)
ExternalProject_Add_StepTargets(${_dep} ${_yeph_NO_DEPENDS} dependers)
endif()
ExternalProject_Add_StepDependencies(${_dep} dependers ${_name})
# dependers-update step (update all packages that require this package)
if(TARGET ${_name}-update)
if(NOT TARGET ${_dep}-dependers-update)
ExternalProject_Add_Step(${_dep} dependers-update
WORKING_DIRECTORY ${${_dep}_BINARY_DIR}
COMMENT "Dependers for '${_dep}' updated."
EXCLUDE_FROM_MAIN 1
${_yeph_INDEPENDENT}
ALWAYS 1)
ExternalProject_Add_StepTargets(${_dep} ${_yeph_NO_DEPENDS} dependers-update)
endif()
ExternalProject_Add_StepDependencies(${_dep} dependers-update ${_name}-update)
endif()
endif()
endif()
endif()
endforeach()
endif()
endfunction()
########################################################################
# _YCM_EP_ADD_EDIT_CACHE_STEP
#
# Add "edit_cache" step for cmake repositories.
function(_YCM_EP_ADD_EDIT_CACHE_STEP _name)
# edit cache target for cmake projects
_ep_get_configure_command_id(${_name} _${_name}_configure_command_id)
if(_${_name}_configure_command_id STREQUAL "cmake")
get_property(_yeph_NO_DEPENDS GLOBAL PROPERTY _yeph_NO_DEPENDS)
get_property(_yeph_INDEPENDENT GLOBAL PROPERTY _yeph_INDEPENDENT)
get_property(_source_dir TARGET ${_name} PROPERTY _EP_SOURCE_DIR)
get_property(_source_subdir TARGET ${_name} PROPERTY _EP_SOURCE_SUBDIR)
get_property(_binary_dir TARGET ${_name} PROPERTY _EP_BINARY_DIR)
ExternalProject_Add_Step(${_name} edit_cache
COMMAND ${CMAKE_EDIT_COMMAND} -H${_source_dir}${_source_subdir} -B${_binary_dir}
WORKING_DIRECTORY ${_binary_dir}
DEPENDEES configure
EXCLUDE_FROM_MAIN 1
COMMENT "Running CMake cache editor for ${_name}..."
${_yeph_INDEPENDENT}
ALWAYS 1)
ExternalProject_Add_StepTargets(${_name} ${_yeph_NO_DEPENDS} edit_cache)
endif()
endfunction()
########################################################################
# _YCM_EP_ADD_PRINT_DIRECTORIES_STEP
#
# Add "print-directories" step for any repository.
# This step prints source and build directories for an external project.
function(_YCM_EP_ADD_PRINT_DIRECTORIES_STEP _name)
if(NOT TARGET ${_print-directories-all})
add_custom_target(${_print-directories-all})
set_property(TARGET ${_print-directories-all} PROPERTY FOLDER "YCMTargets")
endif()
get_property(_source_dir TARGET ${_name} PROPERTY _EP_SOURCE_DIR)
get_property(_source_subdir TARGET ${_name} PROPERTY _EP_SOURCE_SUBDIR)
get_property(_binary_dir TARGET ${_name} PROPERTY _EP_BINARY_DIR)
get_property(_yeph_NO_DEPENDS GLOBAL PROPERTY _yeph_NO_DEPENDS)
get_property(_yeph_INDEPENDENT GLOBAL PROPERTY _yeph_INDEPENDENT)
if(CMAKE_GENERATOR STREQUAL "Unix Makefiles")
set(_command_echo_color_if_supported "cmake_echo_color --switch=$\(COLOR\) --cyan")
else()
set(_command_echo_color_if_supported "echo")
endif()
if("${_source_dir}" STREQUAL "${_source_subdir}")
set(_source_cmd COMMAND ${CMAKE_COMMAND} -E ${_command_echo_color_if_supported} "${_name} SOURCE directory: "
COMMAND ${CMAKE_COMMAND} -E echo " ${_source_dir}")
else()
set(_source_cmd COMMAND ${CMAKE_COMMAND} -E ${_command_echo_color_if_supported} "${_name} REPOSITORY directory: "
COMMAND ${CMAKE_COMMAND} -E echo " ${_source_dir}"
COMMAND ${CMAKE_COMMAND} -E echo ""
COMMAND ${CMAKE_COMMAND} -E ${_command_echo_color_if_supported} "${_name} SOURCE directory: "
COMMAND ${CMAKE_COMMAND} -E echo " ${_source_subdir}")
endif()
set(_binary_cmd COMMAND ${CMAKE_COMMAND} -E ${_command_echo_color_if_supported} "${_name} BINARY directory: "
COMMAND ${CMAKE_COMMAND} -E echo " ${_binary_dir}")
ExternalProject_Add_Step(${_name} print-directories
COMMAND ${CMAKE_COMMAND} -E echo ""
${_source_cmd}
COMMAND ${CMAKE_COMMAND} -E echo ""
${_binary_cmd}
COMMAND ${CMAKE_COMMAND} -E echo ""
WORKING_DIRECTORY ${_source_dir}
EXCLUDE_FROM_MAIN 1
COMMENT "Directories for ${_name}"
${_yeph_INDEPENDENT}
ALWAYS 1)
ExternalProject_Add_StepTargets(${_name} ${_yeph_NO_DEPENDS} print-directories)
add_dependencies(${_print-directories-all} ${_name}-print-directories)
endfunction()
########################################################################
# _YCM_EP_ADD_OPEN_STEP
#
# Add "open" step for any repository.
# This step opens the external project for editing
function(_YCM_EP_ADD_OPEN_STEP _name)
get_property(_binary_dir TARGET ${_name} PROPERTY _EP_BINARY_DIR)
unset(_cmd)
if("${CMAKE_GENERATOR}" MATCHES "Xcode")
set(_cmd open "${_binary_dir}/${_name}.xcodeproj")
elseif("${CMAKE_GENERATOR}" MATCHES "Visual Studio")
set(_cmd "${_binary_dir}/${_name}.sln")
endif()
if(DEFINED _cmd)
get_property(_yeph_NO_DEPENDS GLOBAL PROPERTY _yeph_NO_DEPENDS)
get_property(_yeph_INDEPENDENT GLOBAL PROPERTY _yeph_INDEPENDENT)
ExternalProject_Add_Step(${_name} open
COMMAND ${CMAKE_COMMAND} -E echo \"\"
COMMAND ${_cmd}
WORKING_DIRECTORY "${_binary_dir}"
DEPENDEES configure
EXCLUDE_FROM_MAIN 1
COMMENT "Opening ${_name}..."
${_yeph_INDEPENDENT}
ALWAYS 1)
ExternalProject_Add_StepTargets(${_name} ${_yeph_NO_DEPENDS} open)
endif()
endfunction()
########################################################################
# _YCM_EP_ADD_INSTALLATION
#
# Add the project to the "install" target in the main build.
# This by default works only for CMake projects, but project using other
# build systems can be enabled by just by creating a
# `cmake_install.cmake` file in the build directory.
function(_YCM_EP_ADD_INSTALLATION _name)
get_property(_binary_dir TARGET ${_name} PROPERTY _EP_BINARY_DIR)
install(CODE "if(NOT CMAKE_INSTALL_LOCAL_ONLY AND EXISTS \"${_binary_dir}/cmake_install.cmake\")
include(\"${_binary_dir}/cmake_install.cmake\")
endif()"
COMPONENT ${_name})
endfunction()
########################################################################
# _YCM_EP_WRITE_GITCLONE_SCRIPT
#
# Helper function to generate a gitclone script for download repos without deleting it
# inspired from https://gitlab.kitware.com/cmake/cmake/-/blob/v3.30.2/Modules/ExternalProject/shared_internal_commands.cmake#L381
function(_ycm_ep_write_gitclone_script
script_filename
source_dir
git_EXECUTABLE
git_repository
git_tag
git_remote_name
init_submodules
git_submodules_recurse
git_submodules
git_shallow
git_progress
git_config
src_name
work_dir
gitclone_infofile
gitclone_stampfile
tls_version
tls_verify
)
if(NOT GIT_VERSION_STRING VERSION_LESS 1.8.5)
# Use `git checkout <tree-ish> --` to avoid ambiguity with a local path.
set(git_checkout_explicit-- "--")
else()
# Use `git checkout <branch>` even though this risks ambiguity with a
# local path. Unfortunately we cannot use `git checkout <tree-ish> --`
# because that will not search for remote branch names, a common use case.
set(git_checkout_explicit-- "")
endif()
if("${git_tag}" STREQUAL "")
message(FATAL_ERROR "Tag for git checkout should not be empty.")
endif()
if(GIT_VERSION_STRING VERSION_LESS 2.20 OR
2.21 VERSION_LESS_EQUAL GIT_VERSION_STRING)
set(git_clone_options "--no-checkout")
else()
set(git_clone_options)
endif()
if(git_shallow)
if(NOT GIT_VERSION_STRING VERSION_LESS 1.7.10)
list(APPEND git_clone_options "--depth 1 --no-single-branch")
else()
list(APPEND git_clone_options "--depth 1")
endif()
endif()
if(git_progress)
list(APPEND git_clone_options --progress)
endif()
foreach(config IN LISTS git_config)
list(APPEND git_clone_options --config \"${config}\")
endforeach()
if(NOT ${git_remote_name} STREQUAL "origin")
list(APPEND git_clone_options --origin \"${git_remote_name}\")
endif()
# The clone config option is sticky, it will apply to all subsequent git
# update operations. The submodules config option is not sticky, because
# git doesn't provide any way to do that. Thus, we will have to pass the
# same config option in the update step too for submodules, but not for
# the main git repo.
set(git_submodules_config_options "")
if(NOT "x${tls_version}" STREQUAL "x")
list(APPEND git_clone_options -c http.sslVersion=tlsv${tls_version})
list(APPEND git_submodules_config_options -c http.sslVersion=tlsv${tls_version})
endif()
if(NOT "x${tls_verify}" STREQUAL "x")
if(tls_verify)
# Default git behavior is "true", but the user might have changed the
# global default to "false". Since TLS_VERIFY was given, ensure we honor
# the specified setting regardless of what the global default might be.
list(APPEND git_clone_options -c http.sslVerify=true)
list(APPEND git_submodules_config_options -c http.sslVerify=true)
else()
list(APPEND git_clone_options -c http.sslVerify=false)
list(APPEND git_submodules_config_options -c http.sslVerify=false)
endif()
endif()
string (REPLACE ";" " " git_clone_options "${git_clone_options}")
# Once we can require CMake >= 3.17 this can be substituted with ${CMAKE_CURRENT_FUNCTION_LIST_DIR}
configure_file(
${YCM_MODULE_DIR}/modules/YCMEPHelper/gitsafeclone.txt.in
${script_filename}
@ONLY
)
endfunction()
########################################################################
# YCM_EP_HELPER
#
# Helper function to add a repository using ExternalProject
function(YCM_EP_HELPER _name)
# Adding target twice is not allowed
if(TARGET ${_name})
message(WARNING "Failed to add target ${_name}. A target with the same name already exists.!!!")
return()
endif()
# Check arguments
set(_options )
set(_oneValueArgs TYPE
STYLE
COMPONENT
FOLDER
EXCLUDE_FROM_ALL
SHALLOW # GIT only
REPOSITORY # GIT, SVN and HG
TAG # GIT and HG only
REVISION # SVN only
USERNAME # SVN only
PASSWORD # SVN only
TRUST_CERT # SVN only
TEST_BEFORE_INSTALL
TEST_AFTER_INSTALL
TEST_EXCLUDE_FROM_MAIN
CONFIGURE_SOURCE_DIR # DEPRECATED Since YCM 0.10
SOURCE_SUBDIR
CMAKE_GENERATOR
CMAKE_GENERATOR_PLATFORM
CMAKE_GENERATOR_TOOLSET
CMAKE_GENERATOR_INSTANCE
BUILD_ALWAYS)
set(_multiValueArgs CMAKE_ARGS
CMAKE_CACHE_ARGS
CMAKE_CACHE_DEFAULT_ARGS
DEPENDS
DOWNLOAD_COMMAND
UPDATE_COMMAND
PATCH_COMMAND
CONFIGURE_COMMAND
BUILD_COMMAND
INSTALL_COMMAND
TEST_COMMAND
CLEAN_COMMAND)
cmake_parse_arguments(_YH_${_name} "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" "${ARGN}")
# HACK: set(var "" PARENT_SCOPE) before CMake 3.0.0 did not set an empty
# string, but instead unset the variable.
# For compatibility with older versions, cmake_parse_arguments, keeps
# the same behaviour, therefore they are not set.
foreach(_step DOWNLOAD
UPDATE
PATCH
CONFIGURE
BUILD
INSTALL
TEST
CLEAN)
if("${ARGN}" MATCHES ";?${_step}_COMMAND;" AND NOT DEFINED _YH_${_name}_${_step}_COMMAND)
set(_YH_${_name}_${_step}_COMMAND "")
endif()
endforeach()
# Allow to override parameters by setting variables
foreach(_arg ${_oneValueArgs} ${_multiValueArgs})
if(DEFINED ${_name}_${_arg})
set(_YH_${_name}_${_arg} ${${_name}_${_arg}})
endif()
endforeach()
# Check that all required arguments are set
if(NOT DEFINED _YH_${_name}_TYPE)
message(FATAL_ERROR "Missing TYPE argument")
endif()
if(NOT "x${_YH_${_name}_TYPE}" MATCHES "^x(GIT|SVN|HG)$")
message(FATAL_ERROR "Unsupported VCS TYPE:\n ${_YH_${_name}_TYPE}\n")
endif()
if("${_YH_${_name}_TYPE}" STREQUAL "GIT")
# TODO Check GIT arguments
elseif("${_YH_${_name}_TYPE}" STREQUAL "SVN")
# TODO Check SVN arguments
elseif("${_YH_${_name}_TYPE}" STREQUAL "HG")
# TODO Check HG arguments
endif()
if(NOT DEFINED _YH_${_name}_STYLE)
message(FATAL_ERROR "Missing STYLE argument")
endif()
include(Style${_YH_${_name}_STYLE} OPTIONAL)
if(NOT DEFINED _YH_${_name}_REPOSITORY)
message(FATAL_ERROR "Missing REPOSITORY argument")
endif()
if(NOT DEFINED _YH_${_name}_COMPONENT)
set(_YH_${_name}_COMPONENT external)
elseif(_YH_${_name}_COMPONENT STREQUAL "build")
message(AUTHOR_WARNING "Using \"build\" is dangerous, you should choose another name for the component.")
endif()
if(NOT DEFINED _YH_${_name}_FOLDER)
set(_YH_${_name}_FOLDER "${_YH_${_name}_COMPONENT}")
elseif(_YH_${_name}_FOLDER STREQUAL "build")
message(AUTHOR_WARNING "Using \"build\" is dangerous, you should choose another name for the folder.")
endif()