-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathCMakeLists.txt
1428 lines (1262 loc) · 43.7 KB
/
CMakeLists.txt
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
# This file is part of OpenOrienteering.
# Copyright 2016-2020 Kai Pastor
#
# Redistribution and use is allowed according to the terms of the BSD license:
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
cmake_minimum_required(VERSION 3.10)
project(Superbuild C)
set(documentation
COPYING
README.md
)
set(ci
ci/azure-pipelines.yml
ci/build.yml
ci/build-iwyu.yml
ci/filter-stderr.sed
ci/publish.yml
ci/setup-macos.yml
ci/setup-msys2.yml
ci/setup-ubuntu.yml
ci/shell.sh
ci/source.yml
)
set(SUPERBUILD_DOWNLOAD_DIR "${PROJECT_SOURCE_DIR}" CACHE PATH
"Directory path where to put and find downloads"
)
set(SUPERBUILD_HANDLE_ENV "" CACHE STRING
"Additional environment variables to be passed to packages."
)
list(APPEND SUPERBUILD_HANDLE_ENV
CPP
CPPFLAGS
CC
CFLAGS
CXX
CXXFLAGS
LDFLAGS
LIBS
LD_LIBRARY_PATH
PATH
PKG_CONFIG
)
if(APPLE)
list(APPEND SUPERBUILD_HANDLE_ENV SDKROOT)
endif()
list(REMOVE_DUPLICATES SUPERBUILD_HANDLE_ENV)
set(SUPERBUILD_STEP_TARGETS "" CACHE STRING
"CMake ExternalProject step targets to be created")
set(SUPERBUILD_DISABLE_DEPENDENCIES FALSE CACHE BOOL
"Disable dependencies between binary packages")
mark_as_advanced(SUPERBUILD_DISABLE_DEPENDENCIES)
include(CMakeParseArguments)
include(ExternalProject)
# Silence warnings about unused variables (Qt Creator)
set(no_warn_unused
${CMAKE_CXX_COMPILER}
${SUPERBUILD_DISABLE_DEPENDENCIES}
)
# Global utilities
function(sb_install_dir var system_name)
if(DEFINED ${system_name}_INSTALL_DIR)
set(${var} "${${system_name}_INSTALL_DIR}" PARENT_SCOPE)
else()
set(${var} "${PROJECT_BINARY_DIR}/${system_name}/install" PARENT_SCOPE)
endif()
endfunction()
function(sb_install_stamp_dir var system_name)
set(${var} "${PROJECT_BINARY_DIR}/${system_name}/install/tmp" PARENT_SCOPE)
endfunction()
function(sb_toolchain_dir var system_name)
if(DEFINED ${system_name}_TOOLCHAIN_DIR)
set(${var} "${${system_name}_TOOLCHAIN_DIR}" PARENT_SCOPE)
else()
set(${var} "${PROJECT_BINARY_DIR}/${system_name}/toolchain" PARENT_SCOPE)
endif()
endfunction()
function(sb_toolchain_stamp_dir var system_name)
set(${var} "${PROJECT_BINARY_DIR}/${system_name}/toolchain/tmp" PARENT_SCOPE)
endfunction()
function(sb_install_prefix var system_name)
if(DEFINED ${system_name}_INSTALL_PREFIX)
set(${var} "${${system_name}_INSTALL_PREFIX}" PARENT_SCOPE)
else()
set(${var} "" PARENT_SCOPE)
endif()
endfunction()
function(_sb_write_var_if_different filepath var)
file(WRITE "${filepath}.raw" "${${var}}")
# Create a proper build rule for Ninja et al.
configure_file("${filepath}.raw" "${filepath}" COPYONLY)
file(REMOVE "${filepath}.raw")
endfunction()
function(_sb_write_if_different filepath)
string(CONCAT output ${ARGN})
_sb_write_var_if_different(${filepath} output)
endfunction()
function(_sb_get_build_command var)
if(ARGC GREATER 1)
_sb_get_build_command_2(result "${ARGV1}")
set(${var} ${result} PARENT_SCOPE)
elseif(CMAKE_GENERATOR MATCHES "Make")
set(${var} "$(MAKE)" PARENT_SCOPE)
else()
set(${var} "${CMAKE_COMMAND}" --build . PARENT_SCOPE)
endif()
endfunction()
function(_sb_get_build_command_2 var target)
if(CMAKE_GENERATOR MATCHES "Make")
set(${var} "$(MAKE)" "${target}" PARENT_SCOPE)
else()
set(${var} "${CMAKE_COMMAND}" --build . --target "${target}" PARENT_SCOPE)
endif()
endfunction()
function(_sb_write_debian_patch_script)
option(IGNORE_REVERSED_PATCHES
"Ignore patches which appear to be reversed or already applied." OFF)
set (APPLY_PATCHES_SERIES "${PROJECT_BINARY_DIR}/source/apply-debian-patches.cmake")
_sb_write_if_different("${APPLY_PATCHES_SERIES}" [[
# Created by ]] ${CMAKE_CURRENT_LIST_FILE} [[
#
# Synopsis:
# "${CMAKE_COMMAND}" -Dpackage=foo-patches-1.3.2 -P "${APPLY_PATCHES_SERIES}"
if(NOT package)
message(FATAL_ERROR "Variable 'package' must specify an existing package.")
endif()
set(dir "]] "${PROJECT_BINARY_DIR}" [[/source/${package}")
if(EXISTS "${dir}/patches/series")
set(IGNORE_REVERSED_PATCHES "]] ${IGNORE_REVERSED_PATCHES} [[")
file(STRINGS "${dir}/patches/series" series)
foreach(line ${series})
string(STRIP "${line}" line)
if(line MATCHES "^#")
continue()
endif()
message(STATUS "Applying ${line}")
execute_process(
COMMAND patch -N -p1 --binary
INPUT_FILE "${dir}/patches/${line}"
RESULT_VARIABLE exit_code
OUTPUT_VARIABLE output
)
if(IGNORE_REVERSED_PATCHES
AND output MATCHES "Reversed.* patch detected")
continue()
endif()
if(NOT exit_code EQUAL 0)
message(FATAL_ERROR "Could not apply patch ${line}")
endif()
endforeach()
else()
message(STATUS "No patches series in ${package}.")
if(NOT EXISTS "${dir}/control")
message(FATAL_ERROR "No control file - maybe wrong package?")
endif()
endif()
]] )
set (APPLY_PATCHES_SERIES "${APPLY_PATCHES_SERIES}" PARENT_SCOPE)
endfunction()
function(_sb_write_config dir)
set(output [[
# Created by ]] ${CMAKE_CURRENT_LIST_FILE} [[
if (NOT DEFINED SYSTEM_NAME)
message(FATAL_ERROR "SYSTEM_NAME must be defined when using ${CMAKE_CURRENT_LIST_FILE}")
endif()
]])
foreach(name ${ARGN})
list(APPEND output "set(${name}")
foreach(item IN LISTS ${name})
string(REPLACE [["]] [[\"]] escaped "${item}")
list(APPEND output " \"${escaped}\"")
endforeach()
list(APPEND output ")\n")
endforeach()
list(APPEND output [[
function(sb_test_build_condition)
set(BUILD_CONDITION 1)
]] "${SB_PACKAGE_BUILD_CONDITION}" [[
set(BUILD_CONDITION ${BUILD_CONDITION} PARENT_SCOPE)
endfunction()
if(NOT SUPERBUILD_CC)
set(SUPERBUILD_CC ${CMAKE_C_COMPILER})
endif()
if(NOT SUPERBUILD_CXX)
set(SUPERBUILD_CXX ${CMAKE_CXX_COMPILER})
endif()
# Publish some properties to a target, for use in generator expressions.
# This approximately reproduces the processing order of cmake's
# find_file and find_library.
set(SUPERBUILD_CPPFLAGS "${SUPERBUILD_CPPFLAGS} ")
macro(check_include_dir subdir)
foreach(path ${CMAKE_FIND_ROOT_PATH} "")
string(REGEX REPLACE "//*" "/" include_dir "${path}${subdir}")
string(REGEX REPLACE "/\$" "" include_dir "${include_dir}")
if(EXISTS "${include_dir}"
AND (path OR NOT CMAKE_FIND_ROOT_PATH)
AND NOT "${SUPERBUILD_CPPFLAGS}" MATCHES " -I${include_dir} "
AND NOT include_dir IN_LIST CMAKE_IGNORE_PATH
AND NOT include_dir IN_LIST CMAKE_SYSTEM_IGNORE_PATH
AND NOT include_dir IN_LIST CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES)
set(SUPERBUILD_CPPFLAGS "${SUPERBUILD_CPPFLAGS}-I${include_dir} ")
endif()
endforeach()
endmacro()
set(SUPERBUILD_LDFLAGS "${SUPERBUILD_LDFLAGS} ")
macro(check_lib_dir subdir)
foreach(path ${CMAKE_FIND_ROOT_PATH} "")
string(REGEX REPLACE "//*" "/" lib_dir "${path}${subdir}")
string(REGEX REPLACE "/\$" "" lib_dir "${lib_dir}")
if(EXISTS "${lib_dir}"
AND (path OR NOT CMAKE_FIND_ROOT_PATH)
AND NOT "${SUPERBUILD_LDFLAGS}" MATCHES " -L${lib_dir} "
AND NOT lib_dir IN_LIST CMAKE_IGNORE_PATH
AND NOT lib_dir IN_LIST CMAKE_SYSTEM_IGNORE_PATH
AND NOT lib_dir IN_LIST CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES)
set(SUPERBUILD_LDFLAGS "${SUPERBUILD_LDFLAGS}-L${lib_dir} ")
endif()
endforeach()
endmacro()
foreach(subdir ${CMAKE_PREFIX_PATH})
check_include_dir("${subdir}/include/${CMAKE_LIBRARY_ARCHITECTURE}")
check_include_dir("${subdir}/include")
check_lib_dir("${subdir}/lib")
endforeach()
foreach(subdir ${CMAKE_INCLUDE_PATH})
check_include_dir("${subdir}")
endforeach()
foreach(subdir ${CMAKE_LIBRARY_PATH})
check_lib_dir("${subdir}")
endforeach()
foreach(subdir ${CMAKE_INSTALL_PREFIX} ${CMAKE_SYSTEM_PREFIX_PATH})
check_include_dir("${subdir}/include/${CMAKE_LIBRARY_ARCHITECTURE}")
check_include_dir("${subdir}/include")
check_lib_dir("${subdir}/lib")
endforeach()
foreach(subdir ${CMAKE_SYSTEM_INCLUDE_PATH})
check_include_dir("${subdir}")
endforeach()
foreach(subdir ${CMAKE_SYSTEM_LIBRARY_PATH})
check_lib_dir("${subdir}")
endforeach()
set(SUPERBUILD_CFLAGS "${CMAKE_C_FLAGS}")
set(SUPERBUILD_CXXFLAGS "${CMAKE_CXX_FLAGS}")
if(CMAKE_BUILD_TYPE)
string(TOUPPER "${CMAKE_BUILD_TYPE}" config)
set(SUPERBUILD_CFLAGS "${SUPERBUILD_CFLAGS} ${CMAKE_C_FLAGS_${config}}")
set(SUPERBUILD_CXXFLAGS "${SUPERBUILD_CXXFLAGS} ${CMAKE_CXX_FLAGS_${config}}")
endif()
]])
_sb_write_if_different("${dir}/${package}-config.cmake" ${output})
endfunction()
function(_sb_write_generator)
set(output
"# Created by ${CMAKE_CURRENT_LIST_FILE}
cmake_minimum_required(VERSION ${CMAKE_MINIMUM_REQUIRED_VERSION})
if(NOT SYSTEM_NAME OR NOT PACKAGE)
message(FATAL_ERROR \"SYSTEM_NAME and PACKAGE must be given\")
else()
message(STATUS \"Generating \${PACKAGE} for system \${SYSTEM_NAME}\")
endif()
project(\${PACKAGE}-\${SYSTEM_NAME}-generator NONE)
set_property(GLOBAL PROPERTY RULE_MESSAGES 0)
set_property(GLOBAL PROPERTY TARGET_MESSAGES 0)
include(\"${PROJECT_BINARY_DIR}/config/\${PACKAGE}-config.cmake\")
if(PACKAGE STREQUAL \"toolchain-info\")
set(LANGUAGES \"C CXX\")
set(TOOLCHAIN_INFO \"
include(\\\"${PROJECT_BINARY_DIR}/source/toolchain-info.cmake\\\")
print_toolchain_info()
write_toolchain_info(\\\"\\\${BINARY_DIR}/info.txt\\\")
\")
else()
set(LANGUAGES \"C CXX\") # TODO: Provide configuration
set(TOOLCHAIN_INFO )
endif()
file(READ \"${PROJECT_BINARY_DIR}/config/\${PACKAGE}-CMakeLists.txt.in\" config)
string(CONFIGURE \"\${config}\" config @ONLY)
file(GENERATE OUTPUT \"\${TMP_DIR}/CMakeLists.txt\"
CONTENT \"\${config}\"
)
# Silence warnings in case these variables are not used.
set(no_warn_unused
${SYSTEM_NAME}_INSTALL_DIR
)
")
_sb_write_if_different("${PROJECT_BINARY_DIR}/config/CMakeLists.txt" ${output})
endfunction()
function(_sb_write_build dir)
if(NOT SB_PACKAGE_BUILD)
set(SB_PACKAGE_BUILD [[
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
]] )
endif()
set(output
"# Template created by ${CMAKE_CURRENT_LIST_FILE}
# Instance created by @CMAKE_CURRENT_LIST_FILE@
# for system @SYSTEM_NAME@
cmake_minimum_required(VERSION ${CMAKE_MINIMUM_REQUIRED_VERSION})
message(STATUS \"Configuring @PACKAGE@ for system @SYSTEM_NAME@\")
project(${package}-@SYSTEM_NAME@ @LANGUAGES@)
set_property(GLOBAL PROPERTY RULE_MESSAGES 0)
set_property(GLOBAL PROPERTY TARGET_MESSAGES 0)
set(SYSTEM_NAME \"@SYSTEM_NAME@\")
set(INSTALL_DIR \"@INSTALL_DIR@\")
set(TOOLCHAIN_DIR \"@TOOLCHAIN_DIR@\")
set(CMAKE_BUILD_TYPE \"@CMAKE_BUILD_TYPE@\")
include(\"${dir}/${package}-config.cmake\")
if(CMAKE_GENERATOR MATCHES \"Make\")
set(DESTDIR \"\$(DESTDIR)\")
else()
set(DESTDIR \"\")
endif()
@TOOLCHAIN_INFO@
sb_test_build_condition()
if(NOT BUILD_CONDITION)
message(STATUS \"Not building ${SB_PACKAGE_NAME} for @SYSTEM_NAME@ toolchain\")
add_custom_target(${package}-@SYSTEM_NAME@-system
ALL
COMMAND \${CMAKE_COMMAND} -E make_directory \"\${TMP_DIR}/stamp\"
COMMAND \${CMAKE_COMMAND} -E echo \"Not building ${SB_PACKAGE_NAME} for @SYSTEM_NAME@ toolchain\"
)
add_custom_target(${package}-@SYSTEM_NAME@-package)
return()
endif()
include(ExternalProject)
ExternalProject_Add(${package}-@SYSTEM_NAME@
DOWNLOAD_DIR \"\${DOWNLOAD_DIR}\"
SOURCE_DIR \"\${SOURCE_DIR}\"
BINARY_DIR \"\${BINARY_DIR}\"
TMP_DIR \"\${TMP_DIR}\"
STAMP_DIR \"\${TMP_DIR}/stamp\"
INSTALL_DIR \"\${INSTALL_DIR}\"
DOWNLOAD_COMMAND \"${CMAKE_COMMAND}\" -E touch_nocreate \"<SOURCE_DIR>/placeholder/@STAMP@\"
${SB_PACKAGE_BUILD})
ExternalProject_Add_StepDependencies(${package}-@SYSTEM_NAME@ configure
\"" [[${CMAKE_CURRENT_LIST_FILE}]] "\"
\"${CMAKE_CURRENT_LIST_FILE}\"
)
if(CMAKE_TOOLCHAIN_FILE)
ExternalProject_Add_StepDependencies(${package}-@SYSTEM_NAME@ configure
\"" [[${CMAKE_TOOLCHAIN_FILE}]] "\"
)
endif()
set(stamp_dir \"@INSTALL_STAMP_DIR@\")
if(stamp_dir)
set(stamp \"\${stamp_dir}/${package}.stamp\")
add_custom_command(OUTPUT \"\${stamp}\"
COMMAND \"${CMAKE_COMMAND}\" -E make_directory \"\${stamp_dir}\"
COMMAND \"${CMAKE_COMMAND}\" -E touch \"\${stamp}\"
)
ExternalProject_Add_StepDependencies(${package}-@SYSTEM_NAME@ install
\"\${stamp}\"
)
endif()
")
if(SUPERBUILD_STEP_TARGETS)
string(REPLACE ";" " " step_targets "${SUPERBUILD_STEP_TARGETS}")
list(APPEND output "
ExternalProject_Add_StepTargets(${package}-@SYSTEM_NAME@ ${step_targets})
")
endif()
if(SB_PACKAGE_PACKAGE)
list(APPEND output "
ExternalProject_Add_Step(${package}-@SYSTEM_NAME@ package
EXCLUDE_FROM_MAIN 1
ALWAYS 1
WORKING_DIRECTORY <BINARY_DIR>
${SB_PACKAGE_PACKAGE}
)
ExternalProject_Add_StepTargets(${package}-@SYSTEM_NAME@ package)
")
endif()
_sb_write_if_different("${dir}/${package}-CMakeLists.txt.in" ${output})
endfunction()
function(_sb_source_write list_name dir rel_path var)
if(NOT var MATCHES "^[-_.+A-Za-z0-9]")
message(FATAL_ERROR "Invalid variable name '${var}'")
endif()
get_filename_component(out_path "${dir}/${rel_path}" ABSOLUTE)
_sb_write_var_if_different("${out_path}" "${var}")
list(APPEND ${list_name} "${out_path}")
if(ARGC GREATER 4)
_sb_source_write(${list_name} "${dir}" ${ARGN})
endif()
set(${list_name} ${${list_name}} PARENT_SCOPE)
endfunction()
function(_sb_create_main_c)
_sb_write_if_different("${PROJECT_BINARY_DIR}/source/main.c"
"// Placeholder file\n"
"int main(int argc, char** argv) { return 0\; }\n"
)
endfunction()
function(_sb_create_pkg_config_wrapper)
string(CONCAT cmakelists_txt [[
# Generated by ]] "${CMAKE_CURRENT_LIST_FILE}\n" [[
cmake_minimum_required(VERSION 3.7)
project(pkg-config-wrapper NONE)
set(libdir "${CMAKE_STAGING_PREFIX}/lib/pkgconfig" "${CMAKE_STAGING_PREFIX}/share/pkgconfig")
if(MSYS)
set(libdir "`cygpath -up '${libdir}'`")
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
file(TO_NATIVE_PATH "${libdir}" libdir)
else()
string(REPLACE ";" ":" libdir "${libdir}")
endif()
file(GENERATE
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/superbuild-${SYSTEM_NAME}-pkg-config
CONTENT "#!/bin/sh
# Generated by ${CMAKE_CURRENT_LIST_FILE}
export PKG_CONFIG_PATH=
export PKG_CONFIG_LIBDIR=\"${libdir}\"
export PKG_CONFIG_SYSROOT_DIR=\"${INSTALL_DIR}\"
exec pkg-config $@
")
install(
PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/superbuild-${SYSTEM_NAME}-pkg-config
DESTINATION "${TOOLCHAIN_DIR}/bin"
)
if(WIN32 AND NOT CMAKE_CROSSCOMPILING)
file(GENERATE
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/superbuild-${SYSTEM_NAME}-pkg-config.cmd
CONTENT "@sh %~dpn0 %*"
)
install(
PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/superbuild-${SYSTEM_NAME}-pkg-config.cmd
DESTINATION "${TOOLCHAIN_DIR}/bin"
)
endif()
]])
superbuild_package(
NAME pkg-config
VERSION wrapper
SOURCE_WRITE
CMakeLists.txt cmakelists_txt
BUILD [[
CMAKE_ARGS
"-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}"
INSTALL_COMMAND
"${CMAKE_COMMAND}" --build . --target install/fast
]]
)
endfunction()
function(_sb_create_toolchain_info)
string(REPLACE ";" " " env_vars "${SUPERBUILD_HANDLE_ENV}")
_sb_write_if_different("${PROJECT_BINARY_DIR}/source/toolchain-info.cmake" [[
# Created by ]] "${CMAKE_CURRENT_LIST_FILE}\n" [[
function(toolchain_info_helper out_var headline)
set(output "${headline}\n\n")
foreach(var ${ARGN})
if(var MATCHES "^ENV{")
string(REPLACE "ENV{" "" var "${var}")
string(REPLACE "}" "" var "${var}")
if(DEFINED ENV{${var}})
set(output "${output}ENV{${var}}=\"$ENV{${var}}\"\n")
else()
set(output "${output}ENV{${var}} - not set\n")
endif()
elseif(DEFINED ${var})
set(output "${output}${var}=\"${${var}}\"\n")
else()
set(output "${output}${var} - not set\n")
endif()
endforeach()
set(${out_var} "${output}\n" PARENT_SCOPE)
endfunction()
set(toolchain_info_groups )
list(APPEND toolchain_info_groups toolchain_info_var_information)
set(toolchain_info_var_information "Variables that provide information"
CMAKE_COMMAND
CMAKE_CROSSCOMPILING
CMAKE_GENERATOR
CMAKE_MAKE_PROGRAM
CMAKE_SIZEOF_VOID_P
CMAKE_TOOLCHAIN_FILE
CMAKE_VERSION
CMAKE_XCODE_PLATFORM_TOOLSET
PROJECT_BINARY_DIR
PROJECT_SOURCE_DIR
)
list(APPEND toolchain_info_groups toolchain_info_var_behavior)
set(toolchain_info_var_behavior "Variables that change behavior"
BUILD_SHARED_LIBS
CMAKE_BUILD_TYPE
CMAKE_SYSROOT
CMAKE_FIND_ROOT_PATH
CMAKE_FIND_ROOT_PATH_MODE_INCLUDE
CMAKE_FIND_ROOT_PATH_MODE_LIBRARY
CMAKE_FIND_ROOT_PATH_MODE_PACKAGE
CMAKE_FIND_ROOT_PATH_MODE_PROGRAM
CMAKE_FIND_APPBUNDLE
CMAKE_FIND_FRAMEWORK
CMAKE_INSTALL_PREFIX
CMAKE_STAGING_PREFIX
CMAKE_PREFIX_PATH
CMAKE_APPBUNDLE_PATH
CMAKE_FRAMEWORK_PATH
CMAKE_IGNORE_PATH
CMAKE_INCLUDE_PATH
CMAKE_LIBRARY_PATH
CMAKE_PROGRAM_PATH
CMAKE_SYSTEM_PREFIX_PATH
CMAKE_SYSTEM_APPBUNDLE_PATH
CMAKE_SYSTEM_FRAMEWORK_PATH
CMAKE_SYSTEM_IGNORE_PATH
CMAKE_SYSTEM_INCLUDE_PATH
CMAKE_SYSTEM_LIBRARY_PATH
CMAKE_SYSTEM_PROGRAM_PATH
)
list(APPEND toolchain_info_groups toolchain_info_var_system)
set(toolchain_info_var_system "Variables that describe the system"
CMAKE_HOST_SYSTEM_NAME
CMAKE_HOST_SYSTEM_VERSION
CMAKE_HOST_SYSTEM_PROCESSOR
CMAKE_HOST_APPLE
CMAKE_HOST_UNIX
CMAKE_HOST_WIN32
CMAKE_SYSTEM_NAME
CMAKE_SYSTEM_VERSION
CMAKE_SYSTEM_PROCESSOR
CMAKE_LIBRARY_ARCHITECTURE
ANDROID
APPLE
MINGW
MSYS
UNIX
WIN32
)
if(ANDROID)
list(APPEND toolchain_info_var_system
ANDROID_SDK_ROOT
ANDROID_NDK_ROOT
ANDROID_ABI
ANDROID_NATIVE_API_LEVEL
ANDROID_STL
ANDROID_TOOLCHAIN
ANDROID_TOOLCHAIN_NAME
ANDROID_KEYSTORE_URL
ANDROID_KEYSTORE_ALIAS
)
elseif(APPLE)
list(APPEND toolchain_info_var_system
XCODE_VERSION
CMAKE_OSX_SYSROOT
)
endif()
list(APPEND toolchain_info_groups toolchain_info_var_build)
set(toolchain_info_var_build "Variables that control the build"
CMAKE_EXE_LINKER_FLAGS
CMAKE_EXE_LINKER_FLAGS_DEBUG
CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO
CMAKE_EXE_LINKER_FLAGS_RELEASE
CMAKE_EXE_LINKER_FLAGS_MINSIZEREL
CMAKE_INSTALL_NAME_DIR
CMAKE_OSX_DEPLOYMENT_TARGET
CMAKE_POSITION_INDEPENDENT_CODE
)
list(APPEND toolchain_info_groups toolchain_info_var_languages)
set(toolchain_info_var_languages "Variables for languages"
CMAKE_C_COMPILER
CMAKE_C_COMPILER_VERSION
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL
CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES
CMAKE_C_IMPLICIT_LINK_DIRECTORIES
CMAKE_CXX_COMPILER
CMAKE_CXX_COMPILER_VERSION
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES
CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES
CMAKE_INTERNAL_PLATFORM_ABI
CMAKE_RC_COMPILER
)
list(APPEND toolchain_info_groups toolchain_info_var_configure)
set(toolchain_info_var_configure "Variables for traditional `configure`"
SUPERBUILD_TOOLCHAIN_TRIPLET
SUPERBUILD_CC
SUPERBUILD_CXX
SUPERBUILD_CPPFLAGS
SUPERBUILD_CFLAGS
SUPERBUILD_CXXFLAGS
SUPERBUILD_LDFLAGS
)
list(APPEND toolchain_info_groups toolchain_info_var_superbuild)
set(toolchain_info_var_superbuild "Variables provided by superbuild"
HOST_DIR
INSTALL_DIR
PACKAGE_NAME
SOURCE_DIR
SYSTEM_NAME
TOOLCHAIN_DIR
)
list(APPEND toolchain_info_groups toolchain_info_var_env)
set(toolchain_info_var_env "Environment variables")
foreach(var ]] "${env_vars}" [[)
list(APPEND toolchain_info_var_env "ENV{${var}}")
endforeach()
if(APPLE)
list(APPEND toolchain_info_var_env
ENV{MACOSX_DEPLOYMENT_TARGET}
)
endif()
function(print_toolchain_info)
foreach(group ${toolchain_info_groups})
toolchain_info_helper(info ${${group}})
string(REPLACE "toolchain-info" "<PACKAGE_NAME>-<VERSION>" info "${info}")
message(STATUS "${info}");
endforeach()
endfunction()
function(write_toolchain_info file)
set(out "")
foreach(group ${toolchain_info_groups})
toolchain_info_helper(info ${${group}})
string(REPLACE "toolchain-info" "<PACKAGE_NAME>-<VERSION>" info "${info}")
string(REPLACE "\;" "\\\;" info "${info}")
list(APPEND out "${info}\n");
endforeach()
file(WRITE "${file}" ${out})
endfunction()
]])
superbuild_package(
NAME toolchain
VERSION info
)
endfunction()
# Provide default toolchain settings, if not existing
function(_sb_create_default_toolchain)
set(local_build FALSE)
if(NOT DEFINED default_INSTALL_DIR)
sb_install_dir(default_INSTALL_DIR "default")
set(default_INSTALL_DIR "${default_INSTALL_DIR}" PARENT_SCOPE)
set(local_build TRUE)
endif()
if(NOT DEFINED default_PREFIX_PATH)
set(default_PREFIX_PATH "${CMAKE_PREFIX_PATH}")
set(default_PREFIX_PATH "${default_PREFIX_PATH}" PARENT_SCOPE)
endif()
if(NOT DEFINED default_INSTALL_PREFIX)
if(local_build)
set(default_INSTALL_PREFIX "${default_INSTALL_DIR}")
set(default_INSTALL_PREFIX "${default_INSTALL_PREFIX}" PARENT_SCOPE)
set(default_INSTALL_DIR "")
set(default_INSTALL_DIR "${default_INSTALL_DIR}" PARENT_SCOPE)
else()
sb_install_prefix(default_INSTALL_PREFIX "default")
set(default_INSTALL_PREFIX "${default_INSTALL_PREFIX}" PARENT_SCOPE)
endif()
endif()
if(NOT DEFINED default_TOOLCHAIN_DIR)
sb_toolchain_dir(default_TOOLCHAIN_DIR "default")
set(default_TOOLCHAIN_DIR "${default_TOOLCHAIN_DIR}" PARENT_SCOPE)
endif()
if(NOT DEFINED default_FIND_APPBUNDLE
AND DEFINED CMAKE_FIND_APPBUNDLE)
set(default_FIND_APPBUNDLE "${CMAKE_FIND_APPBUNDLE}")
set(default_FIND_APPBUNDLE "${default_FIND_APPBUNDLE}" PARENT_SCOPE)
endif()
if(NOT DEFINED default_FIND_FRAMEWORK
AND DEFINED CMAKE_FIND_FRAMEWORK)
set(default_FIND_FRAMEWORK "${CMAKE_FIND_FRAMEWORK}")
set(default_FIND_FRAMEWORK "${default_FIND_FRAMEWORK}" PARENT_SCOPE)
endif()
set(toolchain_content [[
# Generated by ]] "${CMAKE_CURRENT_LIST_FILE}\n" [[
set(SYSTEM_NAME "default")
# TOOLCHAIN_DIR will be changed for building toolchains,
# so it must be cached for the default toolchain
set(TOOLCHAIN_DIR "]] "${default_TOOLCHAIN_DIR}" [["
CACHE PATH "The install root for this toolchain")
# INSTALL_DIR will be changed for building toolchains,
# so it must be cached for the default toolchain
set(INSTALL_DIR "]] "${default_INSTALL_DIR}" [["
CACHE PATH "The Superbuild install root for the output of this toolchain")
set(CMAKE_PREFIX_PATH "]] "${default_PREFIX_PATH}" [["
CACHE PATH "Path used for searching by FIND_XXX()")
set(CMAKE_INSTALL_PREFIX "]] "${default_INSTALL_PREFIX}" [["
CACHE PATH "Run-time install path prefix, prepended onto install directories")
set(CMAKE_STAGING_PREFIX "${INSTALL_DIR}${CMAKE_INSTALL_PREFIX}"
CACHE PATH "Build-time install path prefix, prepended onto install directories")
if(APPLE AND NOT CMAKE_INSTALL_NAME_DIR)
set(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib")
endif()
set(CMAKE_RULE_MESSAGES OFF CACHE BOOL "Whether to report a message for each make rule")
set(CMAKE_TARGET_MESSAGES OFF CACHE BOOL "Whether to report a message for each target")
set(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "Enable verbose output from Makefile builds")
]])
if(APPLE)
list(APPEND toolchain_content [[
list(APPEND CMAKE_SYSTEM_IGNORE_PATH
/usr/include
/usr/lib
/usr/local/bin
/usr/local/include
/usr/local/lib
/usr/X11R6/bin
/usr/X11R6/include
/usr/X11R6/lib
)
set(CMAKE_FIND_APPBUNDLE "]] "${default_FIND_APPBUNDLE}" [[")
set(CMAKE_FIND_FRAMEWORK "]] "${default_FIND_FRAMEWORK}" [[")
]])
endif()
if(ENV{PKG_CONFIG} AND NOT default_ENV_PKG_CONFIG)
set(default_ENV_PKG_CONFIG "$ENV{PKG_CONFIG}" PARENT_SCOPE)
elseif(WIN32 AND NOT default_ENV_PKG_CONFIG)
set(default_ENV_PKG_CONFIG "superbuild-default-pkg-config" PARENT_SCOPE)
list(APPEND toolchain_content [[
set(PKG_CONFIG_EXECUTABLE "superbuild-default-pkg-config.cmd"
CACHE PATH "pkg-config to be used by FindPkgConfig module")
]])
endif()
if(CMAKE_TOOLCHAIN_FILE)
set(toolchain_content "include(\"${CMAKE_TOOLCHAIN_FILE}\")\n")
endif()
set(toolchain_file "${default_TOOLCHAIN_DIR}/toolchain.cmake")
_sb_write_if_different("${toolchain_file}" "${toolchain_content}")
add_custom_command(OUTPUT "${toolchain_file}"
COMMAND "${CMAKE_COMMAND}" .
)
add_custom_target(default-toolchain
DEPENDS "${toolchain_file}"
)
set_property(TARGET default-toolchain PROPERTY SB_PACKAGE_SYSTEM_NAME default)
endfunction()
# Provide host toolchain settings, if not existing
function(_sb_create_host_toolchain)
# TODO This is just a stub
set(local_build FALSE)
if(NOT DEFINED host_INSTALL_DIR)
sb_install_dir(host_INSTALL_DIR "default")
set(host_INSTALL_DIR "${host_INSTALL_DIR}" PARENT_SCOPE)
set(local_build TRUE)
endif()
if(NOT DEFINED host_INSTALL_PREFIX)
if(local_build AND NOT "${host_INSTALL_DIR}" STREQUAL "")
set(host_INSTALL_PREFIX "${host_INSTALL_DIR}")
set(host_INSTALL_PREFIX "${host_INSTALL_PREFIX}" PARENT_SCOPE)
set(host_INSTALL_DIR "")
set(host_INSTALL_DIR "${host_INSTALL_DIR}" PARENT_SCOPE)
else()
sb_install_prefix(host_INSTALL_PREFIX "default")
set(host_INSTALL_PREFIX "${host_INSTALL_PREFIX}" PARENT_SCOPE)
endif()
endif()
set(HOST_DIR "${host_INSTALL_DIR}${host_INSTALL_PREFIX}" PARENT_SCOPE)
endfunction()
# Read all definitions
function(_sb_read_packages)
file(GLOB sb_definitions RELATIVE ${PROJECT_SOURCE_DIR} *.cmake)
foreach(sb_definition ${sb_definitions})
if(sb_definition STREQUAL "cmake_install.cmake")
continue()
endif()
include(${sb_definition})
endforeach()
endfunction()
# Setup package dependencies
function(_sb_resolve_dependencies)
set(suffix "${ARGV0}")
get_property(packages GLOBAL PROPERTY SB_PACKAGES)
foreach(package ${packages})
if(NOT TARGET ${package}${suffix})
continue()
endif()
# Source dependencies
if(TARGET ${package}-source)
add_dependencies(${package}${suffix} ${package}-source)
endif()
# Build dependencies
get_property(dependencies TARGET ${package} PROPERTY SB_PACKAGE_DEPENDS)
foreach(dependency ${dependencies})
if(dependency MATCHES "^host:")
if(SUPERBUILD_DISABLE_DEPENDENCIES)
continue()
endif()
string(REGEX REPLACE "^host:" "" real_dependency ${dependency})
set(real_suffix "")
set(real_package ${package}${suffix})
elseif(dependency MATCHES "^source:")
# We add source dependencies to the source package,
# so they can be used for download, patch and update steps.
string(REGEX REPLACE "^source:" "" real_dependency ${dependency})
set(real_suffix "-source")
set(real_package ${package}-source)
else()
if(SUPERBUILD_DISABLE_DEPENDENCIES)
continue()
endif()
set(real_dependency ${dependency})
set(real_suffix ${suffix})
set(real_package ${package}${suffix})
endif()
get_property(default_version GLOBAL PROPERTY SB_DEFAULT_${real_dependency})
if(TARGET ${real_dependency}${real_suffix})
add_dependencies(${real_package} ${real_dependency}${real_suffix})
elseif(TARGET ${real_dependency}-${default_version}${real_suffix})
add_dependencies(${real_package} ${real_dependency}-${default_version}${real_suffix})
elseif(NOT suffix)
message(SEND_ERROR "No rule to satisfy dependency '${dependency}' for package '${package}'")
endif()
endforeach()
endforeach()
endfunction()
# Toolchain handling
function(_sb_handle_toolchains)
set(regular_packages)
set(virtual_packages)
set(toolchains)
get_property(packages GLOBAL PROPERTY SB_PACKAGES)
foreach(package ${packages})
get_property(SYSTEM_NAME TARGET ${package} PROPERTY SB_PACKAGE_SYSTEM_NAME)
get_property(build_ TARGET ${package} PROPERTY SB_PACKAGE_BUILD)
get_property(depends_ TARGET ${package} PROPERTY SB_PACKAGE_DEPENDS)
if(SYSTEM_NAME)
list(APPEND toolchains ${package})
elseif(build_ OR package MATCHES "toolchain-info")
list(APPEND regular_packages ${package})
elseif(depends_)
list(APPEND virtual_packages ${package})
endif()
endforeach()
foreach(toolchain ${toolchains})
foreach(package ${regular_packages})
_sb_make_toolchained_build(${package} ${toolchain})
endforeach()
foreach(package ${virtual_packages})
_sb_make_toolchained_virtual(${package} ${toolchain})
endforeach()
get_property(SYSTEM_NAME TARGET ${toolchain} PROPERTY SB_PACKAGE_SYSTEM_NAME)
_sb_resolve_dependencies("-${SYSTEM_NAME}")
endforeach()
endfunction()
# Create ExternalProject for handling the source
function(_sb_make_source package)
set(TMP_DIR "${PROJECT_BINARY_DIR}/tmp/${package}")
list(LENGTH SB_PACKAGE_SOURCE length)