-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathaui.boot.cmake
1049 lines (909 loc) · 43.4 KB
/
aui.boot.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#
# =====================================================================================================================
# Copyright (c) 2021 Alex2772
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
# Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# Original code located at https://github.com/aui-framework/aui
# =====================================================================================================================
#
cmake_minimum_required(VERSION 3.16)
function(_auib_fix_multiconfiguration)
get_property(_tmp GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if (NOT _tmp)
return()
endif()
message(STATUS "\nMulti configuration generator detected (https://github.com/aui-framework/aui/issues/133)"
"\nPlease use ninja generator if possible")
if (CMAKE_BUILD_TYPE)
message(STATUS "CMAKE_CONFIGURATION_TYPES overridden to CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
set(CMAKE_CONFIGURATION_TYPES ${CMAKE_BUILD_TYPE} PARENT_SCOPE)
return()
endif()
list(LENGTH CMAKE_CONFIGURATION_TYPES _tmp)
if (_tmp EQUAL 1)
# CMAKE_CONFIGURATION_TYPES is set to one configuration - it is perfect for us. Just initialize CMAKE_BUILD_TYPE
# for compatibility
set(CMAKE_BUILD_TYPE ${CMAKE_CONFIGURATION_TYPES} PARENT_SCOPE)
return()
endif()
if (CMAKE_DEFAULT_BUILD_TYPE)
message(WARNING "CMAKE_CONFIGURATION_TYPES overridden to CMAKE_DEFAULT_BUILD_TYPE = ${CMAKE_DEFAULT_BUILD_TYPE}")
set(CMAKE_CONFIGURATION_TYPES ${CMAKE_BUILD_TYPE} PARENT_SCOPE)
set(CMAKE_BUILD_TYPE ${CMAKE_DEFAULT_BUILD_TYPE} PARENT_SCOPE)
return()
endif()
message(WARNING "CMAKE_CONFIGURATION_TYPES overridden to Debug")
set(CMAKE_CONFIGURATION_TYPES Debug PARENT_SCOPE)
set(CMAKE_BUILD_TYPE Debug PARENT_SCOPE)
return()
endfunction()
option(AUIB_DISABLE "Disables AUI.Boot and replaces it's calls to find_package" OFF)
option(AUIB_LOCAL_CACHE "Redirects AUI.Boot cache dir from the home directory to CMAKE_BINARY_DIR/aui.boot" OFF)
set(CMAKE_POLICY_DEFAULT_CMP0074 NEW) # allows find_package to use packages pulled by aui.boot
define_property(GLOBAL PROPERTY AUIB_IMPORTED_TARGETS
BRIEF_DOCS "Global list of imported targets"
FULL_DOCS "Global list of imported targets (since CMake 3.21)")
define_property(GLOBAL PROPERTY AUIB_FORWARDABLE_VARS
BRIEF_DOCS "Global list of forwarded vars"
FULL_DOCS "Global list of forwarded vars")
# fix "Failed to get the hash for HEAD" error
if(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/aui.boot-deps)
file(REMOVE_RECURSE ${CMAKE_CURRENT_BINARY_DIR}/aui.boot-deps)
endif()
if (NOT AUIB_DISABLE)
_auib_fix_multiconfiguration()
endif()
if (DEFINED BUILD_SHARED_LIBS)
set(_build_shared ${BUILD_SHARED_LIBS})
else()
if (ANDROID OR IOS)
set(_build_shared OFF)
message(STATUS "Forcing static build because you are building for mobile platform.")
else()
set(_build_shared ON)
endif()
endif()
set(BUILD_SHARED_LIBS ${_build_shared})
if (MSVC)
if (NOT CMAKE_MSVC_RUNTIME_LIBRARY)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
message(STATUS "AUI.Boot CMAKE_MSVC_RUNTIME_LIBRARY is not set - defaulting to ${CMAKE_MSVC_RUNTIME_LIBRARY}")
endif()
endif()
# rpath fix
if (APPLE)
set(CMAKE_MACOSX_RPATH 1)
set(CMAKE_INSTALL_NAME_DIR "@rpath")
set(CMAKE_INSTALL_RPATH "@loader_path/../lib")
elseif(UNIX AND NOT ANDROID)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,$ORIGIN/../lib")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
else()
set(CMAKE_INSTALL_RPATH $ORIGIN/../lib)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
endif()
endif()
define_property(GLOBAL PROPERTY AUI_BOOT_ROOT_ENTRIES
BRIEF_DOCS "Global list of aui boot root entries"
FULL_DOCS "Global list of aui boot root entries")
define_property(GLOBAL PROPERTY AUI_BOOT_DEPS
BRIEF_DOCS "Global list of auib_import commands"
FULL_DOCS "Global list of auib_import commands")
# checking host system not by WIN32 because of cross compilation
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
set(HOME_DIR $ENV{USERPROFILE})
else()
set(HOME_DIR $ENV{HOME})
endif()
if (NOT CMAKE_CXX_COMPILER_ID)
message(FATAL_ERROR "CMAKE_CXX_COMPILER_ID is not set.\nnote: Please include aui.boot AFTER project() call.")
endif()
if (ANDROID_ABI)
set(AUI_TARGET_ARCH_NAME "android-${ANDROID_ABI}")
set(AUI_TARGET_ABI "${AUI_TARGET_ARCH_NAME}" CACHE INTERNAL "COMPILER-PROCESSOR pair")
elseif (IOS)
set(AUI_TARGET_ARCH_NAME "ios-${CMAKE_SYSTEM_PROCESSOR}")
set(AUI_TARGET_ABI "${AUI_TARGET_ARCH_NAME}" CACHE INTERNAL "COMPILER-PROCESSOR pair")
else()
if (NOT CMAKE_SYSTEM_PROCESSOR)
message(FATAL_ERROR "CMAKE_SYSTEM_PROCESSOR is not set")
endif()
if (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)|(amd64)|(AMD64)")
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(AUI_TARGET_ARCH_NAME "x86_64")
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(AUI_TARGET_ARCH_NAME "x86")
endif()
else ()
set(AUI_TARGET_ARCH_NAME ${CMAKE_SYSTEM_PROCESSOR})
endif()
string(TOLOWER "${CMAKE_CXX_COMPILER_ID}-${AUI_TARGET_ARCH_NAME}" _tmp)
set(AUI_TARGET_ABI "${_tmp}" CACHE INTERNAL "COMPILER-PROCESSOR pair")
endif()
# checking if custom cache dir is set for the system
if(DEFINED ENV{AUIB_CACHE_DIR})
string(REPLACE "\\" "/" _tmp $ENV{AUIB_CACHE_DIR}) # little hack to handle Windows paths
else()
set(_tmp ${HOME_DIR}/.aui)
endif()
if(AUIB_LOCAL_CACHE)
set(_tmp ${CMAKE_BINARY_DIR}/aui.boot)
endif()
set(AUIB_CACHE_DIR ${_tmp} CACHE PATH "Path to AUI.Boot cache")
message(STATUS "AUI.Boot cache: ${AUIB_CACHE_DIR}")
message(STATUS "AUI.Boot target ABI: ${AUI_TARGET_ABI}")
set(AUI_BOOT_SOURCEDIR_COMPAT OFF)
if(${CMAKE_VERSION} VERSION_LESS "3.21.0")
message(STATUS "Dependencies will be cloned to build directory, not to ${AUIB_CACHE_DIR} because you're using CMake older"
" than 3.21. See https://github.com/aui-framework/aui/issues/6 for details.")
set(AUI_BOOT_SOURCEDIR_COMPAT ON)
endif()
# create all required dirs
if (NOT EXISTS ${AUIB_CACHE_DIR})
file(MAKE_DIRECTORY ${AUIB_CACHE_DIR})
endif()
if (NOT EXISTS ${AUIB_CACHE_DIR}/prefix)
file(MAKE_DIRECTORY ${AUIB_CACHE_DIR}/prefix)
endif()
if (NOT EXISTS ${AUIB_CACHE_DIR}/repo)
file(MAKE_DIRECTORY ${AUIB_CACHE_DIR}/repo)
endif()
macro(_auib_copy_runtime_dependencies)
# create links to runtime dependencies
if (WIN32)
set(LIB_EXT dll)
elseif(APPLE)
set(LIB_EXT dylib)
else()
set(LIB_EXT so*)
endif()
file(GLOB_RECURSE DEP_RUNTIME LIST_DIRECTORIES false ${DEP_INSTALL_PREFIX}/*.${LIB_EXT})
if (WIN32)
# sometimes it's empty
if (NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
endif()
set(DESTINATION_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
else()
# sometimes it's empty
if (NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
endif()
set(DESTINATION_DIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
endif()
if (NOT EXISTS ${DESTINATION_DIR})
file(MAKE_DIRECTORY ${DESTINATION_DIR})
endif()
foreach(_item ${DEP_RUNTIME})
get_filename_component(FILENAME ${_item} NAME)
if (CMAKE_CONFIGURATION_TYPES)
foreach(_config ${CMAKE_CONFIGURATION_TYPES})
set(_copy ${DESTINATION_DIR}/${_config}/${FILENAME})
if (NOT EXISTS ${_copy})
message(STATUS "[AUI.BOOT/Runtime Dependency] ${_item} -> ${DESTINATION_DIR}/${_config}/${FILENAME}")
file(MAKE_DIRECTORY ${DESTINATION_DIR}/${_config})
file(COPY ${_item} DESTINATION ${DESTINATION_DIR}/${_config})
endif()
endforeach()
else()
if (NOT EXISTS ${DESTINATION_DIR}/${FILENAME})
message(STATUS "[AUI.BOOT/Runtime Dependency] ${_item} -> ${DESTINATION_DIR}/${FILENAME}")
file(COPY ${_item} DESTINATION ${DESTINATION_DIR})
endif()
endif()
endforeach()
endmacro()
macro(_auib_update_imported_targets_list) # used for displaying imported target names
get_property(_imported_targets_before GLOBAL PROPERTY AUIB_IMPORTED_TARGETS)
get_property(_imported_targets_after DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY IMPORTED_TARGETS)
# find the new targets by excluding _imported_targets_before from _imported_targets_after
list(REMOVE_ITEM _imported_targets_after ${_imported_targets_before})
list(APPEND _imported_targets_before ${_imported_targets_after})
set_property(GLOBAL PROPERTY AUIB_IMPORTED_TARGETS ${_imported_targets_before})
endmacro()
function(_auib_validate_target_installation _target)
if (AUIB_NO_PRECOMPILED)
return()
endif()
if (NOT TARGET ${_target})
message(FATAL_ERROR "${_target} expected to be a target")
endif()
get_target_property(_v ${_target} TYPE)
if (NOT _v MATCHES "_LIBRARY") # skip executables
return()
endif()
get_target_property(_v ${_target} INTERFACE_AUIB_SYSTEM_LIB)
if (_v) # skip system libraries
return()
endif()
foreach(_property IMPORTED_LOCATION IMPORTED_LOCATION_${CMAKE_BUILD_TYPE} IMPORTED_IMPLIB IMPORTED_OBJECTS INTERFACE_LINK_DIRECTORIES INTERFACE_INCLUDE_DIRECTORIES INTERFACE_LINK_LIBRARIES)
get_target_property(_v ${_target} ${_property})
if (NOT _v)
continue()
endif()
string(REPLACE "/" "\/" _match_str "^${AUIB_CACHE_DIR}")
foreach (_property_item ${_v})
if (TARGET ${_property_item})
continue()
endif()
if (NOT _property_item MATCHES "(.:)?[\/\\]")
# does not contain path
continue()
endif()
if (NOT _property_item MATCHES ${_match_str})
message(FATAL_ERROR
"While importing ${AUI_MODULE_NAME}:\n"
"Imported target ${_target} has dependency on a system file\n${_property_item} IN ${_property}\n"
"This effectively means that the library (and thus your project) is not portable.\n"
"CMake targets should be used instead of hardcoded paths.\n"
"You can silence this error by setting -DAUIB_NO_PRECOMPILED=TRUE\n"
"(https://aui-framework.github.io/develop/md_docs_AUI_configure_flags.html)\n"
"but you would probably encounter issues while deploying your app.")
endif()
endforeach()
endforeach ()
endfunction()
function(_auib_import_subdirectory DEP_SOURCE_DIR AUI_MODULE_NAME) # helper function to keep scope
set(AUI_BOOT TRUE)
add_subdirectory(${DEP_SOURCE_DIR} "aui.boot-build-${AUI_MODULE_NAME}")
endfunction()
function(_auib_precompiled_archive_name _output_var _project_name)
if (NOT DEFINED _build_shared_libs)
set(_build_shared_libs ${BUILD_SHARED_LIBS})
endif()
if (_build_shared_libs)
set(SHARED_OR_STATIC shared)
else()
set(SHARED_OR_STATIC static)
endif()
set(_tmp "${_project_name}_${CMAKE_SYSTEM_NAME}-${AUI_TARGET_ABI}-${SHARED_OR_STATIC}-${CMAKE_BUILD_TYPE}")
string(TOLOWER ${_tmp} _tmp)
set(${_output_var} ${_tmp} PARENT_SCOPE)
endfunction()
macro(_auib_try_find)
set(_mode CONFIG)
while(TRUE)
if (AUIB_IMPORT_COMPONENTS)
find_package(${AUI_MODULE_NAME} COMPONENTS ${AUIB_IMPORT_COMPONENTS} ${FINDPACKAGE_QUIET} ${_mode})
else()
find_package(${AUI_MODULE_NAME} ${FINDPACKAGE_QUIET} ${_mode})
endif()
if (NOT (${AUI_MODULE_NAME}_FOUND OR ${AUI_MODULE_NAME_UPPER}_FOUND))
if (_mode STREQUAL MODULE)
break()
endif()
if (AUIB_IMPORT_CONFIG_ONLY)
break()
else()
set(_mode MODULE)
endif()
else()
break()
endif()
endwhile()
unset(_mode)
# expose result ignoring case sensitivity
if (${AUI_MODULE_NAME}_FOUND OR ${AUI_MODULE_NAME_UPPER}_FOUND OR ${AUI_MODULE_NAME_LOWER}_FOUND)
set(${AUI_MODULE_NAME}_FOUND TRUE)
else()
set(${AUI_MODULE_NAME}_FOUND FALSE)
endif()
endmacro()
function(_auib_try_download_precompiled_binary)
_auib_precompiled_archive_name(_archive_name ${AUI_MODULE_NAME})
if (AUIB_IMPORT_PRECOMPILED_URL_PREFIX)
set(_binary_download_urls "${AUIB_IMPORT_PRECOMPILED_URL_PREFIX}/${_archive_name}.tar.gz")
message(STATUS "Checking for precompiled binary...")
else()
if (TAG_OR_HASH STREQUAL "latest")
set(TAG_OR_HASH master)
endif()
set(_binary_download_urls "${URL}/releases/download/${TAG_OR_HASH}/${_archive_name}.tar.gz" "${URL}/releases/download/refs%2Fheads%2F${TAG_OR_HASH}/${_archive_name}.tar.gz")
message(STATUS "GitHub detected, checking for precompiled binary...")
endif()
foreach(_binary_download_url ${_binary_download_urls})
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.19)
# since CMake 3.19 there's a way to check for file existence
file(DOWNLOAD ${_binary_download_url} STATUS _status)
list(GET _status 0 _status)
if (NOT _status STREQUAL 0)
continue()
endif()
endif()
file(DOWNLOAD ${_binary_download_url} ${CMAKE_CURRENT_BINARY_DIR}/binary.tar.gz SHOW_PROGRESS STATUS _status)
list(GET _status 0 _status)
if (NOT _status STREQUAL 0)
continue()
endif()
message(STATUS "Unpacking precompiled binary for ${AUI_MODULE_NAME}...")
file(MAKE_DIRECTORY ${DEP_INSTALL_PREFIX})
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xzf ${CMAKE_CURRENT_BINARY_DIR}/binary.tar.gz
WORKING_DIRECTORY ${DEP_INSTALL_PREFIX})
_auib_try_find()
file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/binary.tar.gz)
if (${AUI_MODULE_NAME}_FOUND)
set(_skip_compilation TRUE PARENT_SCOPE)
file(TOUCH ${DEP_INSTALLED_FLAG})
return()
endif()
endforeach()
if (AUIB_DEBUG_PRECOMPILED STREQUAL ${AUI_MODULE_NAME})
message(FATAL_ERROR "Precompiled binary for ${AUI_MODULE_NAME} is not available"
"\ntrace: download urls: ${_binary_download_urls}")
endif()
message(STATUS "Precompiled binary for ${AUI_MODULE_NAME} is not available")
endfunction()
function(_auib_dump_with_prefix PREFIX PATH)
file(READ "${PATH}" contents)
STRING(REPLACE ";" "\\\\;" contents "${contents}")
STRING(REPLACE "\n" ";" contents "${contents}")
foreach (line ${contents})
message("${PREFIX} ${line}")
endforeach ()
endfunction()
function(_auib_find_git)
auib_use_system_libs_begin()
find_package(Git QUIET)
set(GIT_EXECUTABLE ${GIT_EXECUTABLE} PARENT_SCOPE)
endfunction()
# TODO add a way to provide file access to the repository
function(auib_import AUI_MODULE_NAME URL)
if (AUIB_DISABLE)
if (AUIB_IMPORT_COMPONENTS)
find_package(${AUI_MODULE_NAME} COMPONENTS ${AUIB_IMPORT_COMPONENTS} REQUIRED)
else()
find_package(${AUI_MODULE_NAME} REQUIRED)
endif()
return()
endif()
get_property(AUI_BOOT_IMPORTED_MODULES GLOBAL PROPERTY AUI_BOOT_IMPORTED_MODULES)
# these constants are needed to ignore case on *nix platforms
string(TOLOWER "${AUI_MODULE_NAME}" AUI_MODULE_NAME_LOWER)
string(TOUPPER "${AUI_MODULE_NAME}" AUI_MODULE_NAME_UPPER)
if (${AUI_MODULE_NAME_LOWER} IN_LIST AUI_BOOT_IMPORTED_MODULES)
# the module is already imported; skipping
return()
endif()
unset(_local_repo)
if(EXISTS ${URL})
# url is a local file
set(_local_repo TRUE)
get_filename_component(URL ${URL} ABSOLUTE)
endif()
set(_locked FALSE)
set(FINDPACKAGE_QUIET QUIET)
if (AUI_BOOT_VERBOSE)
set(FINDPACKAGE_QUIET "")
endif()
cmake_policy(SET CMP0087 NEW)
cmake_policy(SET CMP0074 NEW)
# https://stackoverflow.com/a/46057018
if (CMAKE_CROSSCOMPILING)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH)
set(ONLY_CMAKE_FIND_ROOT_PATH TRUE)
endif()
set(CMAKE_FIND_USE_CMAKE_SYSTEM_PATH FALSE)
set(CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH FALSE)
set(options ADD_SUBDIRECTORY ARCHIVE CONFIG_ONLY IMPORTED_FROM_CONFIG)
set(oneValueArgs VERSION CMAKE_WORKING_DIR CMAKELISTS_CUSTOM PRECOMPILED_URL_PREFIX LINK)
set(multiValueArgs CMAKE_ARGS COMPONENTS REQUIRES)
cmake_parse_arguments(AUIB_IMPORT "${options}" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN} )
# save arguments for later use by dependent modules
if (NOT AUIB_IMPORT_IMPORTED_FROM_CONFIG)
string(REPLACE ";" " " _forwarded_import_args "${ARGV}")
set_property(GLOBAL APPEND_STRING PROPERTY AUI_BOOT_DEPS "auib_import(${_forwarded_import_args} IMPORTED_FROM_CONFIG)\n")
endif()
# check for dependencies
foreach (_dep ${AUIB_IMPORT_REQUIRES})
set(_dep_root_var ${_dep}_ROOT)
if (NOT DEFINED ${_dep_root_var})
message(FATAL_ERROR "${AUI_MODULE_NAME} requires ${_dep}, but it's not available (${_dep_root_var} is not set)")
endif()
set(_dep_root_value ${${_dep_root_var}})
set(_dep_root_value_installed ${_dep_root_value}/INSTALLED)
if (NOT EXISTS ${_dep_root_value_installed})
message(FATAL_ERROR "${AUI_MODULE_NAME} requires ${_dep}, but it's not available (${_dep_root_value_installed} does not exist)")
endif()
# add it to AUI_BOOT_ROOT_ENTRIES if needed
get_property(AUI_BOOT_ROOT_ENTRIES GLOBAL PROPERTY AUI_BOOT_ROOT_ENTRIES)
list(JOIN AUI_BOOT_ROOT_ENTRIES , AUI_BOOT_ROOT_ENTRIES)
if (NOT "${AUI_BOOT_ROOT_ENTRIES}" MATCHES ".*${_dep_root_var}.*")
set_property(GLOBAL APPEND PROPERTY AUI_BOOT_ROOT_ENTRIES "${_dep_root_var}=${_dep_root_value}")
endif ()
endforeach()
if (AUIB_IMPORT_ARCHIVE AND AUIB_IMPORT_VERSION)
message(FATAL_ERROR "ARCHIVE and VERSION arguments are incompatible")
endif()
if (AUIB_${AUI_MODULE_NAME_UPPER}_AS OR AUIB_ALL_AS OR AUIB_IMPORT_ADD_SUBDIRECTORY)
set(DEP_ADD_SUBDIRECTORY TRUE)
else()
set(DEP_ADD_SUBDIRECTORY FALSE)
endif()
set(AUI_MODULE_PREFIX ${AUI_MODULE_NAME_LOWER})
set(TAG_OR_HASH latest)
if (AUIB_IMPORT_ARCHIVE)
set(TAG_OR_HASH ${AUI_MODULE_PREFIX})
elseif (AUIB_IMPORT_HASH)
set(TAG_OR_HASH ${AUIB_IMPORT_HASH})
elseif(AUIB_IMPORT_VERSION)
set(TAG_OR_HASH ${AUIB_IMPORT_VERSION})
endif()
# should restrict version length; in order to make equal "f116a123b9b44f362c96632ad5cec980aab8b46c" and "f116a123"
string(LENGTH ${TAG_OR_HASH} _length)
if (_length GREATER 16)
string(SUBSTRING ${TAG_OR_HASH} 0 7 TAG_OR_HASH)
endif()
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()
if (NOT DEFINED BUILD_SHARED_LIBS)
# default it to ON
set(BUILD_SHARED_LIBS ON)
endif()
# process LINK argument
if (AUIB_IMPORT_LINK)
if (AUIB_IMPORT_LINK STREQUAL "STATIC")
set(_build_shared_libs FALSE)
elseif (AUIB_IMPORT_LINK STREQUAL "SHARED")
set(_build_shared_libs TRUE)
else()
message(FATAL_ERROR "invalid value \"${AUIB_IMPORT_LINK}\" for LINK argument")
endif()
else()
set(_build_shared_libs ${BUILD_SHARED_LIBS})
endif()
if (_build_shared_libs)
set(SHARED_OR_STATIC shared)
else()
set(SHARED_OR_STATIC static)
set(CMAKE_POSITION_INDEPENDENT_CODE ON) # -fPIC required on linux
endif()
set(BUILD_SPECIFIER "${TAG_OR_HASH}/${AUI_TARGET_ABI}-${CMAKE_BUILD_TYPE}-${SHARED_OR_STATIC}/${CMAKE_GENERATOR}")
# convert BUILD_SPECIFIER to hash; on windows msvc path length restricted by 260 chars
string(MD5 BUILD_SPECIFIER ${BUILD_SPECIFIER})
# append module name to build specifier in order to distinguish modules in prefix/ dir
set(BUILD_SPECIFIER "${AUI_MODULE_NAME_LOWER}/${BUILD_SPECIFIER}")
set(DEP_INSTALL_PREFIX "${AUIB_CACHE_DIR}/prefix/${BUILD_SPECIFIER}")
# append our location to module path
#if (NOT "${DEP_INSTALL_PREFIX}" IN_LIST CMAKE_PREFIX_PATH)
# list(APPEND CMAKE_PREFIX_PATH ${DEP_INSTALL_PREFIX})
#endif()
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.21)
_auib_update_imported_targets_list()
endif()
if (DEP_ADD_SUBDIRECTORY)
# the AUI_MODULE_NAME is used to hint IDEs (i.e. CLion) about actual project's name
set(DEP_SOURCE_DIR "${AUIB_CACHE_DIR}/repo/${AUI_MODULE_PREFIX}/as/${TAG_OR_HASH}/${AUI_MODULE_NAME_LOWER}")
else()
set(DEP_SOURCE_DIR "${AUIB_CACHE_DIR}/repo/${AUI_MODULE_PREFIX}/src")
endif()
set(DEP_BINARY_DIR "${AUIB_CACHE_DIR}/repo/${AUI_MODULE_PREFIX}/build/${BUILD_SPECIFIER}")
# invalidate all previous values.
foreach(_v2 FOUND
INCLUDE_DIR
LIBRARY
LIBRARY_DEBUG
LIBRARY_RELEASE
ROOT
DIR)
foreach(_v1 ${AUI_MODULE_NAME} ${AUI_MODULE_NAME_UPPER})
unset(${_v1}_${_v2} PARENT_SCOPE)
unset(${_v1}_${_v2} CACHE)
endforeach()
endforeach()
# variable is CACHE here in order to make it as global as possible.
set(${AUI_MODULE_NAME}_ROOT ${DEP_INSTALL_PREFIX} CACHE FILEPATH "Path to ${AUI_MODULE_NAME} provided by AUI.Boot.")
set(${AUI_MODULE_NAME}_ROOT_DIR ${DEP_INSTALL_PREFIX} CACHE FILEPATH "Path to ${AUI_MODULE_NAME} provided by AUI.Boot.")
# creating uppercase variables in order to ease the case insensitive checks
set(${AUI_MODULE_NAME}_DIR ${DEP_INSTALL_PREFIX} PARENT_SCOPE)
set(${AUI_MODULE_NAME_UPPER}_DIR ${DEP_INSTALL_PREFIX} PARENT_SCOPE)
set(${AUI_MODULE_NAME_UPPER}_ROOT ${DEP_INSTALL_PREFIX} PARENT_SCOPE)
set(${AUI_MODULE_NAME_UPPER}_ROOT_DIR ${DEP_INSTALL_PREFIX} PARENT_SCOPE)
set(${AUI_MODULE_NAME_UPPER}_ROOT_DIR ${DEP_INSTALL_PREFIX} CACHE FILEPATH "Path to ${AUI_MODULE_NAME} provided by AUI.Boot.")
set(DEP_INSTALLED_FLAG ${DEP_INSTALL_PREFIX}/INSTALLED)
# TODO add protocol check
if(AUI_BOOT_SOURCEDIR_COMPAT)
unset(SOURCE_BINARY_DIRS_ARG)
else()
if (NOT AUI_BOOT AND NOT AUIB_SKIP_REPOSITORY_WAIT AND NOT AUIB_IMPORT_IMPORTED_FROM_CONFIG) # recursive deadlock fix
if (NOT _locked)
set(_locked TRUE)
file(LOCK "${AUIB_CACHE_DIR}/repo.lock" RESULT_VARIABLE _error TIMEOUT 1) # try lock without the message
if (_error)
message(STATUS "Waiting for repository... (simultaneous configure processes may break something!)")
file(LOCK "${AUIB_CACHE_DIR}/repo.lock")
endif()
endif()
endif()
set(SOURCE_BINARY_DIRS_ARG SOURCE_DIR ${DEP_SOURCE_DIR}
BINARY_DIR ${DEP_BINARY_DIR})
endif()
if (AUIB_IMPORT_CMAKELISTS_CUSTOM)
# validate the CMAKELISTS_CUSTOM param
set(_tmp "${CMAKE_CURRENT_LIST_DIR}/${AUIB_IMPORT_CMAKELISTS_CUSTOM}")
if (NOT EXISTS "${AUIB_IMPORT_CMAKELISTS_CUSTOM}" AND EXISTS "${_tmp}")
set(AUIB_IMPORT_CMAKELISTS_CUSTOM "${_tmp}")
endif()
if (NOT EXISTS "${AUIB_IMPORT_CMAKELISTS_CUSTOM}")
message(FATAL_ERROR "CMAKELISTS_CUSTOM does not exist (tried: ${AUIB_IMPORT_CMAKELISTS_CUSTOM} ${_tmp})")
endif()
endif()
if (AUIB_IMPORT_CMAKELISTS_CUSTOM)
# validate the CMAKELISTS_CUSTOM param
set(_tmp "${CMAKE_CURRENT_LIST_DIR}/${AUIB_IMPORT_CMAKELISTS_CUSTOM}")
if (NOT EXISTS "${AUIB_IMPORT_CMAKELISTS_CUSTOM}" AND EXISTS "${_tmp}")
set(AUIB_IMPORT_CMAKELISTS_CUSTOM "${_tmp}")
endif()
if (NOT EXISTS "${AUIB_IMPORT_CMAKELISTS_CUSTOM}")
message(FATAL_ERROR "CMAKELISTS_CUSTOM does not exist (tried: ${AUIB_IMPORT_CMAKELISTS_CUSTOM} ${_tmp})")
endif()
endif()
if (NOT DEP_ADD_SUBDIRECTORY)
# avoid compilation if we have existing installation
if (EXISTS ${DEP_INSTALLED_FLAG})
_auib_try_find()
endif()
endif()
if ((NOT EXISTS ${DEP_INSTALLED_FLAG} OR NOT ${AUI_MODULE_NAME}_FOUND AND NOT DEP_ADD_SUBDIRECTORY) OR ((NOT EXISTS ${DEP_SOURCE_DIR}/CMakeLists.txt) AND DEP_ADD_SUBDIRECTORY))
# some shit with INSTALLED flag because find_package finds by ${AUI_MODULE_NAME}_ROOT only if REQUIRED flag is set
# so we have to compile and install
if (NOT DEP_ADD_SUBDIRECTORY)
if (NOT EXISTS ${DEP_INSTALLED_FLAG})
message(STATUS "${AUI_MODULE_NAME}: building because ${DEP_INSTALLED_FLAG} does not exist")
else()
message(STATUS "${AUI_MODULE_NAME}: building because find_package could not find package in ${DEP_INSTALL_PREFIX}")
endif()
else()
if (EXISTS ${DEP_SOURCE_DIR})
file(REMOVE_RECURSE ${DEP_SOURCE_DIR})
endif()
endif()
set(${AUI_MODULE_NAME}_FOUND FALSE) # reset the FOUND flag; in some cases it may have been TRUE here
message(STATUS "Fetching ${AUI_MODULE_NAME} (${TAG_OR_HASH})")
set(_skip_fetch FALSE)
if (EXISTS "${DEP_SOURCE_DIR}/.git")
# let's try to checkout a local repository
_auib_find_git()
if(GIT_EXECUTABLE)
execute_process(COMMAND ${GIT_EXECUTABLE} checkout -f ${AUIB_IMPORT_VERSION}
WORKING_DIRECTORY ${DEP_SOURCE_DIR}
RESULT_VARIABLE _errored
OUTPUT_QUIET
ERROR_QUIET)
if (NOT _errored)
message(STATUS "${DEP_SOURCE_DIR}: checkout'ed ${AUIB_IMPORT_VERSION}")
set(_skip_fetch TRUE)
endif()
endif()
endif()
if (NOT _skip_fetch)
file(REMOVE_RECURSE ${DEP_SOURCE_DIR})
endif()
file(REMOVE_RECURSE ${DEP_BINARY_DIR})
# check for local existence
if (EXISTS ${URL})
get_filename_component(DEP_SOURCE_DIR ${URL} ABSOLUTE)
message(STATUS "Using local: ${DEP_SOURCE_DIR}")
else()
unset(_skip_compilation) # set by _auib_try_download_precompiled_binary
# check for GitHub Release
if ((URL MATCHES "^https://github.com/" OR AUIB_IMPORT_PRECOMPILED_URL_PREFIX) AND NOT AUIB_NO_PRECOMPILED AND NOT DEP_ADD_SUBDIRECTORY)
_auib_try_download_precompiled_binary()
endif()
if (NOT _skip_compilation)
include(FetchContent)
if (AUIB_IMPORT_ARCHIVE)
set(_import_type URL)
else()
set(_import_type GIT_REPOSITORY)
endif()
if (NOT _skip_fetch)
FetchContent_Declare(${AUI_MODULE_NAME}_FC
PREFIX "${CMAKE_BINARY_DIR}/aui.boot-deps/${AUI_MODULE_NAME}"
${_import_type} "${URL}"
GIT_TAG ${AUIB_IMPORT_VERSION}
GIT_PROGRESS TRUE # show progress of download
USES_TERMINAL_DOWNLOAD TRUE # show progress in ninja generator
USES_TERMINAL_UPDATE TRUE # show progress in ninja generator
${SOURCE_BINARY_DIRS_ARG}
)
FetchContent_Populate(${AUI_MODULE_NAME}_FC)
FetchContent_GetProperties(${AUI_MODULE_NAME}_FC
BINARY_DIR DEP_BINARY_DIR
SOURCE_DIR DEP_SOURCE_DIR
)
message(STATUS "Fetched ${AUI_MODULE_NAME} to ${DEP_SOURCE_DIR}")
endif()
endif()
endif()
if (NOT _skip_compilation)
if (AUIB_IMPORT_CMAKE_WORKING_DIR)
set(DEP_SOURCE_DIR "${DEP_SOURCE_DIR}/${AUIB_IMPORT_CMAKE_WORKING_DIR}")
endif()
if (NOT DEP_ADD_SUBDIRECTORY)
if (AUIB_IMPORT_CMAKELISTS_CUSTOM)
configure_file(${AUIB_IMPORT_CMAKELISTS_CUSTOM} ${DEP_SOURCE_DIR}/CMakeLists.txt COPYONLY)
endif()
message(STATUS "Compiling ${AUI_MODULE_NAME}")
get_property(AUI_BOOT_ROOT_ENTRIES GLOBAL PROPERTY AUI_BOOT_ROOT_ENTRIES)
unset(FORWARDED_LIBS)
foreach (_entry ${AUI_BOOT_ROOT_ENTRIES})
list(APPEND FORWARDED_LIBS "-D${_entry}")
endforeach()
set(FINAL_CMAKE_ARGS
-DAUI_BOOT=TRUE
${FORWARDED_LIBS}
${AUIB_IMPORT_CMAKE_ARGS}
-DCMAKE_INSTALL_PREFIX:PATH=${DEP_INSTALL_PREFIX}
-G "${CMAKE_GENERATOR}")
if (AUIB_IMPORT_COMPONENTS)
list(JOIN AUIB_IMPORT_COMPONENTS "\\\;" TMP_LIST)
set(FINAL_CMAKE_ARGS
${FINAL_CMAKE_ARGS}
-DAUIB_COMPONENTS=${TMP_LIST})
endif()
unset(_forwardable_vars)
get_property(_forwardable_vars GLOBAL PROPERTY AUIB_FORWARDABLE_VARS)
if(ANDROID)
list(APPEND _forwardable_vars
CMAKE_EXPORT_COMPILE_COMMANDS
ANDROID_PLATFORM
ANDROID_ABI
CMAKE_ANDROID_ARCH_ABI
ANDROID_NDK
CMAKE_ANDROID_NDK
)
endif()
get_cmake_property(CACHE_VARS CACHE_VARIABLES)
foreach(CACHE_VAR ${CACHE_VARS})
if(_forwardable)
list(APPEND _forwardable_vars ${CACHE_VAR})
endif()
endforeach()
if(MSVC)
# force msvc compiler to parallel build
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
endif()
if (IOS)
# fix multiple definitions on ios
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error-implicit-function-declaration")
endif()
# forward all necessary variables to child cmake build
foreach(_varname
AUIB_NO_PRECOMPILED
AUIB_TRACE_BUILD_SYSTEM
AUIB_SKIP_REPOSITORY_WAIT
AUIB_CACHE_DIR
CMAKE_C_FLAGS
CMAKE_CXX_FLAGS
CMAKE_GENERATOR_PLATFORM
CMAKE_VS_PLATFORM_NAME
CMAKE_BUILD_TYPE
CMAKE_CONFIGURATION_TYPES
CMAKE_CROSSCOMPILING
CMAKE_CROSSCOMPILING_EMULATOR
CMAKE_MACOSX_RPATH
CMAKE_SYSTEM_NAME
CMAKE_SYSTEM_VERSION
CMAKE_SYSTEM_PROCESSOR
CMAKE_INSTALL_NAME_DIR
CMAKE_INSTALL_RPATH
CMAKE_MAKE_PROGRAM
CMAKE_MSVC_RUNTIME_LIBRARY
CMAKE_FIND_PACKAGE_PREFER_CONFIG
CMAKE_FIND_ROOT_PATH_MODE_PROGRAM
CMAKE_FIND_ROOT_PATH_MODE_LIBRARY
CMAKE_FIND_ROOT_PATH_MODE_INCLUDE
CMAKE_FIND_ROOT_PATH_MODE_PACKAGE
ONLY_CMAKE_FIND_ROOT_PATH
CMAKE_OSX_DEPLOYMENT_TARGET
DEPLOYMENT_TARGET
CMAKE_POLICY_DEFAULT_CMP0074 # find_package uses *_ROOT variables
PLATFORM
CMAKE_OSX_ARCHITECTURES
XCODE_VERSION
SDK_VERSION
APPLE_TARGET_TRIPLE
AUI_IOS_CODE_SIGNING_REQUIRED
CMAKE_POSITION_INDEPENDENT_CODE
${_forwardable_vars})
# ${_varname} can be possibly false (e.g. -DBUILD_SHARED_LIBS=FALSE) so using STREQUAL check instead for
# emptiness
if (NOT ${_varname} STREQUAL "")
list(APPEND FINAL_CMAKE_ARGS "-D${_varname}=${${_varname}}")
endif()
endforeach()
if (CMAKE_TOOLCHAIN_FILE) # resolve absolute path to the toolchain file - it's possibly relative thus invalid
get_filename_component(_toolchain ${CMAKE_TOOLCHAIN_FILE} ABSOLUTE)
list(APPEND FINAL_CMAKE_ARGS "-DCMAKE_TOOLCHAIN_FILE=${_toolchain}")
endif()
list(APPEND FINAL_CMAKE_ARGS "-DBUILD_SHARED_LIBS=${_build_shared_libs}")
file(MAKE_DIRECTORY ${DEP_INSTALL_PREFIX})
file(MAKE_DIRECTORY ${DEP_BINARY_DIR})
message("Configuring CMake ${AUI_MODULE_NAME}:${CMAKE_COMMAND} ${DEP_SOURCE_DIR} ${FINAL_CMAKE_ARGS}")
execute_process(COMMAND ${CMAKE_COMMAND} ${DEP_SOURCE_DIR} ${FINAL_CMAKE_ARGS}
WORKING_DIRECTORY "${DEP_BINARY_DIR}"
RESULT_VARIABLE STATUS_CODE
OUTPUT_FILE ${DEP_INSTALL_PREFIX}/configure.log
)
_auib_dump_with_prefix("[Configuring ${AUI_MODULE_NAME}]" ${DEP_INSTALL_PREFIX}/configure.log)
if (NOT STATUS_CODE EQUAL 0)
message(STATUS "Dependency CMake configure failed, clearing dir and trying again...")
file(REMOVE_RECURSE ${DEP_BINARY_DIR})
file(MAKE_DIRECTORY ${DEP_BINARY_DIR})
execute_process(COMMAND ${CMAKE_COMMAND} ${DEP_SOURCE_DIR} ${FINAL_CMAKE_ARGS}
WORKING_DIRECTORY "${DEP_BINARY_DIR}"
RESULT_VARIABLE STATUS_CODE
OUTPUT_FILE ${DEP_INSTALL_PREFIX}/configure.log
)
_auib_dump_with_prefix("[Configuring ${AUI_MODULE_NAME} (2)]" ${DEP_INSTALL_PREFIX}/configure.log)
if (NOT STATUS_CODE EQUAL 0)
message(FATAL_ERROR "CMake configure failed: ${STATUS_CODE}\nnote: check build logs in ${DEP_INSTALL_PREFIX}")
endif()
endif()
message(STATUS "Building ${AUI_MODULE_NAME}")
set(_flags "")
if (NOT MSVC)
LIST(APPEND _flags "--parallel") # --parallel breaks multithread build for MSVC
endif()
execute_process(COMMAND
${CMAKE_COMMAND}
--build ${DEP_BINARY_DIR} ${_flags}
--config ${CMAKE_BUILD_TYPE} # fix vs and xcode generators
WORKING_DIRECTORY "${DEP_BINARY_DIR}"
RESULT_VARIABLE ERROR_CODE
OUTPUT_FILE ${DEP_INSTALL_PREFIX}/build.log
)
_auib_dump_with_prefix("[Building ${AUI_MODULE_NAME}]" ${DEP_INSTALL_PREFIX}/build.log)
if (NOT STATUS_CODE EQUAL 0)
message(FATAL_ERROR "Dependency build failed: ${AUI_MODULE_NAME}\nnote: check build logs in ${DEP_INSTALL_PREFIX}")
endif()
message(STATUS "Installing ${AUI_MODULE_NAME}")
execute_process(COMMAND
${CMAKE_COMMAND}
--install .
--config ${CMAKE_BUILD_TYPE} # fix vs and xcode generators
WORKING_DIRECTORY "${DEP_BINARY_DIR}"
RESULT_VARIABLE ERROR_CODE
OUTPUT_FILE ${DEP_INSTALL_PREFIX}/install.log
OUTPUT_QUIET)
_auib_dump_with_prefix("[Installing ${AUI_MODULE_NAME}]" ${DEP_INSTALL_PREFIX}/install.log)
if (NOT STATUS_CODE EQUAL 0)
message(FATAL_ERROR "CMake build failed: ${STATUS_CODE}\nnote: check build logs in ${DEP_INSTALL_PREFIX}")
endif()
if (NOT EXISTS ${DEP_INSTALL_PREFIX})
message(FATAL_ERROR "Dependency failed to install: ${AUI_MODULE_NAME}\nnote: check build logs in ${DEP_INSTALL_PREFIX}")
endif()
file(TOUCH ${DEP_INSTALLED_FLAG})
message(STATUS "Cleaning up build directory")
file(REMOVE_RECURSE ${DEP_BINARY_DIR})
endif()
endif()
endif()
if (_locked)
set(_locked FALSE)
file(LOCK "${AUIB_CACHE_DIR}/repo.lock" RELEASE)
endif()
if (DEP_ADD_SUBDIRECTORY)
set(${AUI_MODULE_NAME}_ROOT ${DEP_SOURCE_DIR})
if (AUIB_IMPORT_CMAKELISTS_CUSTOM)
configure_file(${AUIB_IMPORT_CMAKELISTS_CUSTOM} ${DEP_SOURCE_DIR}/CMakeLists.txt COPYONLY)
endif()
_auib_import_subdirectory(${DEP_SOURCE_DIR} ${AUI_MODULE_NAME})
message(STATUS "${AUI_MODULE_NAME} imported as a subdirectory: ${DEP_SOURCE_DIR}")
elseif(NOT ${AUI_MODULE_NAME}_FOUND)
_auib_try_find()
if (NOT ${AUI_MODULE_NAME}_FOUND)
# print verbosely find procedure
set(CMAKE_FIND_DEBUG_MODE TRUE)
# a slight modified _auib_try_find macro to verbosely print debug info
set(_mode CONFIG)
message("[AUI.BOOT] Verbose output:")
while(TRUE)
if (AUIB_IMPORT_COMPONENTS)
find_package(${AUI_MODULE_NAME} COMPONENTS ${AUIB_IMPORT_COMPONENTS} ${FINDPACKAGE_QUIET} ${_mode})
else()
find_package(${AUI_MODULE_NAME} ${FINDPACKAGE_QUIET} ${_mode})
endif()
if (NOT (${AUI_MODULE_NAME}_FOUND OR ${AUI_MODULE_NAME_UPPER}_FOUND))
if (_mode STREQUAL MODULE)
message("[AUI.BOOT] Dependency not found - giving up")
break()
endif()
if (AUIB_IMPORT_CONFIG_ONLY)
break()
else()
set(_mode MODULE)
endif()
message("[AUI.BOOT] Using config instead")
else()
break()
endif()
endwhile()
unset(_mode)
# list possible find_package names if available
file(GLOB_RECURSE _find "${DEP_INSTALL_PREFIX}/*onfig.cmake")
unset(possible_names)
foreach(_i ${_find})
get_filename_component(_name ${_i} NAME)
string(REGEX REPLACE "-?([Cc]onfig)\\.cmake" "" _name ${_name})
list(APPEND possible_names "\"${_name}\"")
endforeach()
# construct error message
set(error_message "AUI.Boot could not resolve dependency: ${AUI_MODULE_NAME}\nnote: check build logs in ${DEP_INSTALL_PREFIX}")
set(error_message "${error_message}\nnote: package names are case sensitive")
if (possible_names)
string(JOIN " or " possible_names_joined ${possible_names})
set(error_message "${error_message}\nnote: did you mean " ${possible_names_joined} ?)
else()
set(error_message "${error_message}\nnote: looks like a config file does not exist for your project (${AUI_MODULE_NAME}Config.cmake or ${AUI_MODULE_NAME}-config.cmake).")
endif()
message(FATAL_ERROR ${error_message})
endif()
endif()
_auib_copy_runtime_dependencies()
if (NOT DEP_ADD_SUBDIRECTORY)
set_property(GLOBAL APPEND PROPERTY AUI_BOOT_ROOT_ENTRIES "${AUI_MODULE_NAME}_ROOT=${${AUI_MODULE_NAME}_ROOT}")
set_property(GLOBAL APPEND PROPERTY AUI_BOOT_ROOT_ENTRIES "${AUI_MODULE_NAME}_DIR=${${AUI_MODULE_NAME}_DIR}")
endif()
set_property(GLOBAL APPEND PROPERTY AUI_BOOT_IMPORTED_MODULES ${AUI_MODULE_NAME_LOWER})
# display the imported targets (available since CMake 3.21)
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.21)
_auib_update_imported_targets_list()
message(STATUS "Imported: ${AUI_MODULE_NAME} (${_imported_targets_after}) (${${AUI_MODULE_NAME}_ROOT}) (version ${TAG_OR_HASH})")