forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
1022 lines (865 loc) · 37.6 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
cmake_minimum_required(VERSION 2.8)
include(CMakeParseArguments)
# Support building Swift as a standalone project, using LLVM as an
# external library.
if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
project(Swift)
# Rely on llvm-config.
set(CONFIG_OUTPUT)
find_program(LLVM_CONFIG "llvm-config")
if(LLVM_CONFIG)
message(STATUS "Found LLVM_CONFIG as ${LLVM_CONFIG}")
set(CONFIG_COMMAND ${LLVM_CONFIG}
"--assertion-mode"
"--bindir"
"--libdir"
"--includedir"
"--prefix"
"--src-root")
execute_process(
COMMAND ${CONFIG_COMMAND}
RESULT_VARIABLE HAD_ERROR
OUTPUT_VARIABLE CONFIG_OUTPUT
)
if(NOT HAD_ERROR)
string(REGEX REPLACE
"[ \t]*[\r\n]+[ \t]*" ";"
CONFIG_OUTPUT ${CONFIG_OUTPUT})
else()
string(REPLACE ";" " " CONFIG_COMMAND_STR "${CONFIG_COMMAND}")
message(STATUS "${CONFIG_COMMAND_STR}")
message(FATAL_ERROR "llvm-config failed with status ${HAD_ERROR}")
endif()
else()
message(FATAL_ERROR "llvm-config not found -- ${LLVM_CONFIG}")
endif()
list(GET CONFIG_OUTPUT 0 ENABLE_ASSERTIONS)
list(GET CONFIG_OUTPUT 1 TOOLS_BINARY_DIR)
list(GET CONFIG_OUTPUT 2 LIBRARY_DIR)
list(GET CONFIG_OUTPUT 3 INCLUDE_DIR)
list(GET CONFIG_OUTPUT 4 LLVM_OBJ_ROOT)
list(GET CONFIG_OUTPUT 5 MAIN_SRC_DIR)
if(NOT MSVC_IDE)
set(LLVM_ENABLE_ASSERTIONS ${ENABLE_ASSERTIONS}
CACHE BOOL "Enable assertions")
# Assertions should follow llvm-config's.
mark_as_advanced(LLVM_ENABLE_ASSERTIONS)
endif()
set(LLVM_TOOLS_BINARY_DIR ${TOOLS_BINARY_DIR} CACHE PATH "Path to llvm/bin")
set(LLVM_LIBRARY_DIR ${LIBRARY_DIR} CACHE PATH "Path to llvm/lib")
set(LLVM_MAIN_INCLUDE_DIR ${INCLUDE_DIR} CACHE PATH "Path to llvm/include")
set(LLVM_BINARY_DIR ${LLVM_OBJ_ROOT} CACHE PATH "Path to LLVM build tree")
set(LLVM_MAIN_SRC_DIR ${MAIN_SRC_DIR} CACHE PATH "Path to LLVM source tree")
find_program(LLVM_TABLEGEN_EXE "llvm-tblgen" ${LLVM_TOOLS_BINARY_DIR}
NO_DEFAULT_PATH)
set(LLVM_CMAKE_PATH "${LLVM_BINARY_DIR}/share/llvm/cmake")
set(LLVMCONFIG_FILE "${LLVM_CMAKE_PATH}/LLVMConfig.cmake")
if(EXISTS ${LLVMCONFIG_FILE})
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}")
include(${LLVMCONFIG_FILE})
else()
message(FATAL_ERROR "Not found: ${LLVMCONFIG_FILE}")
endif()
# Clang
set(SWIFT_PATH_TO_LLVM_SOURCE "${LLVM_MAIN_SRC_DIR}")
set(SWIFT_PATH_TO_LLVM_BUILD "${LLVM_BINARY_DIR}")
set(PATH_TO_LLVM_SOURCE "${SWIFT_PATH_TO_LLVM_SOURCE}")
set(PATH_TO_LLVM_BUILD "${SWIFT_PATH_TO_LLVM_BUILD}")
set(SWIFT_PATH_TO_CLANG_SOURCE "${SWIFT_PATH_TO_LLVM_SOURCE}/tools/clang"
CACHE PATH "Path to Clang source code.")
set(SWIFT_PATH_TO_CLANG_BUILD "" CACHE PATH
"Path to the directory where Clang was built or installed.")
if( NOT EXISTS "${SWIFT_PATH_TO_CLANG_SOURCE}/include/clang/AST/Decl.h" )
message(FATAL_ERROR "Please set SWIFT_PATH_TO_CLANG_SOURCE to the root directory of Clang's source code.")
else()
get_filename_component(CLANG_MAIN_SRC_DIR ${SWIFT_PATH_TO_CLANG_SOURCE}
ABSOLUTE)
endif()
if(EXISTS "${SWIFT_PATH_TO_CLANG_BUILD}/include/clang/Basic/Version.inc")
set(CLANG_BUILD_INCLUDE_DIR "${SWIFT_PATH_TO_CLANG_BUILD}/include")
elseif(EXISTS "${SWIFT_PATH_TO_CLANG_BUILD}/tools/clang/include/clang/Basic/Version.inc")
set(CLANG_BUILD_INCLUDE_DIR "${SWIFT_PATH_TO_CLANG_BUILD}/tools/clang/include")
else()
message(FATAL_ERROR "Please set SWIFT_PATH_TO_CLANG_BUILD to a directory containing a Clang build.")
endif()
if (CLANG_MAIN_INCLUDE_DIR)
get_filename_component(CLANG_MAIN_SRC_DIR ${SWIFT_PATH_TO_CLANG_SOURCE}
ABSOLUTE)
endif()
message("${CLANG_MAIN_INCLUDE_DIR}")
list(APPEND CMAKE_MODULE_PATH "${SWIFT_PATH_TO_LLVM_BUILD}/share/llvm/cmake")
get_filename_component(PATH_TO_LLVM_BUILD ${SWIFT_PATH_TO_LLVM_BUILD}
ABSOLUTE)
get_filename_component(PATH_TO_CLANG_BUILD ${SWIFT_PATH_TO_CLANG_BUILD}
ABSOLUTE)
# MSVC has a gazillion warnings with this.
if( MSVC )
set(LLVM_ENABLE_WARNINGS "Enable compiler warnings." OFF)
else( MSVC )
set(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
endif()
include(AddLLVM)
include(TableGen)
include(HandleLLVMOptions)
include(LLVMParseArguments)
set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}")
set(LLVM_MAIN_INCLUDE_DIR "${LLVM_MAIN_SRC_DIR}/include")
set(CLANG_MAIN_INCLUDE_DIR "${CLANG_MAIN_SRC_DIR}/include")
set(LLVM_BINARY_DIR ${CMAKE_BINARY_DIR})
set(CMAKE_INCLUDE_CURRENT_DIR ON)
include_directories("${PATH_TO_LLVM_BUILD}/include"
"${LLVM_MAIN_INCLUDE_DIR}"
"${CLANG_BUILD_INCLUDE_DIR}"
"${CLANG_MAIN_INCLUDE_DIR}")
link_directories("${LLVM_LIBRARY_DIR}"
"${PATH_TO_CLANG_BUILD}/${CMAKE_CFG_INTDIR}/lib")
set(LIT_ARGS_DEFAULT "-sv")
if (MSVC OR XCODE)
set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
endif()
set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin )
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib )
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib )
set( LLVM_INCLUDE_TESTS ON )
set( LLVM_INCLUDE_DOCS ON )
set( SWIFT_BUILT_STANDALONE 1 )
else()
set(PATH_TO_LLVM_SOURCE "${CMAKE_SOURCE_DIR}")
set(PATH_TO_LLVM_BUILD "${CMAKE_BINARY_DIR}")
set(SWIFT_PATH_TO_CLANG_BUILD "${CMAKE_BINARY_DIR}")
set(PATH_TO_CLANG_BUILD "${SWIFT_PATH_TO_CLANG_BUILD}")
set(CLANG_MAIN_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/tools/clang/include")
set(CLANG_BUILD_INCLUDE_DIR "${CMAKE_BINARY_DIR}/tools/clang/include")
if( NOT EXISTS "${CLANG_MAIN_INCLUDE_DIR}/clang/AST/Decl.h" )
message(FATAL_ERROR "Clang is missing from llvm/tools subdirectory.")
endif()
include_directories("${CLANG_BUILD_INCLUDE_DIR}"
"${CLANG_MAIN_INCLUDE_DIR}")
check_cxx_compiler_flag("-Werror -Wnested-anon-types" CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG)
if( CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-nested-anon-types" )
endif()
endif()
set(LLVM_RUNTIME_OUTPUT_INTDIR ${PATH_TO_LLVM_BUILD}/${CMAKE_CFG_INTDIR}/bin)
set(LLVM_LIBRARY_OUTPUT_INTDIR ${PATH_TO_LLVM_BUILD}/${CMAKE_CFG_INTDIR}/lib)
set(SWIFT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(SWIFT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(SWIFT_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin)
set(SWIFT_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib)
set(SWIFT_INCLUDE_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/include)
option(SWIFT_OPTIMIZED "Enable optimization for Swift source files" YES)
option(SWIFT_STDLIB_INTERNAL_CHECKS "Enable internal checks for the Swift standard library" YES)
option(SWIFT_RUNTIME_CHECKS "Enable overflow checks for the Swift standard library" YES)
option(SWIFT_VERIFY_ALL "Run SIL verification after each transform when building Swift files in the build process" NO)
option(SWIFT_STDLIB_USE_ASSERT_CONFIG_RELEASE "Should the stdlib be build with assert config set to release" NO)
option(SWIFT_EMIT_SORTED_SIL "Sort SIL output by name to enable diffing of output" NO)
set(SWIFT_MODULE_CACHE_PATH "" CACHE PATH
"Directory to use as the Clang module cache when building Swift source files")
option(SWIFT_NEW_DRIVER "Enable the new Swift driver" ON)
option(SWIFT_SPLIT_OBJC_SELECTORS
"Split Objective-C selectors when building the standard library" NO)
option(SWIFT_BUILD_TOOLS "Build Swift tools" YES)
option(SWIFT_BUILD_STDLIB "Build Swift stdlib" YES)
set(SWIFT_RUN_LONG_TESTS OFF CACHE BOOL "Run tests that can take a long time to finish")
set(SWIFT_ASAN_BUILD OFF CACHE BOOL "This is an AddressSanitizer build")
set(SWIFT_EXTRA_FLAGS "" CACHE STRING
"Extra flags to pass when compiling swift files")
set(PATH_TO_SWIFT_BUILD "" CACHE FILEPATH "Path to existing Swift build")
if ( PATH_TO_SWIFT_BUILD STREQUAL "" )
set(SWIFT_COMPILER "swift")
else()
set(SWIFT_COMPILER "${PATH_TO_SWIFT_BUILD}/${CMAKE_CFG_INTDIR}/bin/swift")
endif()
# FIXME: unify with CLANG_HAVE_LIBXML, which is set in LLVM anyway.
find_package(LibXml2)
if(LIBXML2_FOUND)
set(SWIFT_HAVE_LIBXML 1)
endif()
# Xcode: use libc++ and c++11 using proper build settings.
if ( XCODE )
# Force usage of Clang.
set(CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.llvm.clang.1_0"
CACHE STRING "Xcode Compiler")
# Use C++'11.
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++11"
CACHE STRING "Xcode C++ Language Standard")
# Use libc++.
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++"
CACHE STRING "Xcode C++ Standard Library")
# Enable some warnings not enabled by default. These
# mostly reset clang back to its default settings, since
# Xcode passes -Wno... for many warnings that are not enabled
# by default.
set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_ABOUT_RETURN_TYPE "YES")
set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_ABOUT_MISSING_NEWLINE "YES")
set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNUSED_VALUE "YES")
set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNUSED_VARIABLE "YES")
set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_SIGN_COMPARE "YES")
set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNUSED_FUNCTION "YES")
set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS "YES")
set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNINITIALIZED_AUTOS "YES")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_DOCUMENTATION_COMMENTS "YES")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_BOOL_CONVERSION "YES")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_EMPTY_BODY "YES")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_ENUM_CONVERSION "YES")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_INT_CONVERSION "YES")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_CONSTANT_CONVERSION "YES")
set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_NON_VIRTUAL_DESTRUCTOR "YES")
# Disable RTTI
set(CMAKE_XCODE_ATTRIBUTE_GCC_ENABLE_CPP_RTTI "NO")
# Disable exceptions
set(CMAKE_XCODE_ATTRIBUTE_GCC_ENABLE_CPP_EXCEPTIONS "NO")
else ()
# Compile with C++11, without RTTI, exceptions
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++ -fno-rtti -fno-exceptions")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -stdlib=libc++")
endif ()
# Add additional warnings.
check_cxx_compiler_flag("-Werror -Wdocumentation" CXX_SUPPORTS_DOCUMENTATION_FLAG)
append_if(CXX_SUPPORTS_DOCUMENTATION_FLAG "-Wdocumentation" CMAKE_CXX_FLAGS)
check_cxx_compiler_flag("-Werror -Wimplicit-fallthrough" CXX_SUPPORTS_IMPLICIT_FALLTHROUGH_FLAG)
append_if(CXX_SUPPORTS_IMPLICIT_FALLTHROUGH_FLAG "-Wimplicit-fallthrough" CMAKE_CXX_FLAGS)
# Check for -Wunreachable-code-aggressive instead of -Wunreachable-code, as that indicates
# that we have the newer -Wunreachable-code implementation.
check_cxx_compiler_flag("-Werror -Wunreachable-code-aggressive" CXX_SUPPORTS_UNREACHABLE_CODE_FLAG)
append_if(CXX_SUPPORTS_UNREACHABLE_CODE_FLAG "-Wunreachable-code" CMAKE_CXX_FLAGS)
check_cxx_compiler_flag("-Werror -Woverloaded-virtual" CXX_SUPPORTS_OVERLOADED_VIRTUAL)
append_if(CXX_SUPPORTS_OVERLOADED_VIRTUAL "-Woverloaded-virtual" CMAKE_CXX_FLAGS)
# Check for '-fapplication-extension'. On OSX/iOS we wish to link all
# dynamic libraries with this flag.
check_cxx_compiler_flag("-fapplication-extension" CXX_SUPPORTS_FAPPLICATION_EXTENSION)
# Set sizeof(void*) if cross-compiling.
if (CMAKE_CROSSCOMPILING AND NOT CMAKE_SIZEOF_VOID_P)
if (CMAKE_SYSTEM_PROCESSOR MATCHES "64$")
set(CMAKE_SIZEOF_VOID_P 8)
else()
set(CMAKE_SIZEOF_VOID_P 4)
endif()
endif()
# Reset CMAKE_SYSTEM_PROCESSOR if not cross-compiling.
# CMake refuses to use `uname -m` on OS X
# http://public.kitware.com/Bug/view.php?id=10326
if (NOT CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_PROCESSOR STREQUAL "i386")
execute_process(COMMAND uname -m
OUTPUT_VARIABLE CMAKE_SYSTEM_PROCESSOR
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
# Compile a swift file into an object file (as a library).
#
# Usage:
# compile_swift_files(OUTPUT objfile # Name of the resulting object file
# SOURCES swift_src [swift_src...] # Swift source files to compile
# FLAGS -module-name foo # Flags to add to the compilation
# [DEPENDS cmake_target...] # CMake targets on which the object file depends
# [IS_MAIN] # This is an executable, not a library
# [IS_STDLIB_CORE]) # This is the core standard library
function(compile_swift_files)
parse_arguments(SWIFTFILE "OUTPUT;SOURCES;FLAGS;DEPENDS" "IS_MAIN;IS_STDLIB_CORE"
${ARGN})
if(SWIFTFILE_IS_MAIN AND SWIFTFILE_IS_STDLIB_CORE)
error(SEND_ERROR "Cannot set both IS_MAIN and IS_STDLIB_CORE")
endif()
set(swift_flags ${SWIFTFILE_FLAGS})
set(source_files)
foreach(file ${SWIFTFILE_SOURCES})
# Determine where this file is.
get_filename_component(file_path ${file} PATH)
if(IS_ABSOLUTE "${file_path}")
list(APPEND source_files "${file}")
else()
list(APPEND source_files "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
endif()
endforeach()
# Compute flags to be passed down to swift when compiling a swift
# file.
if(SWIFT_OPTIMIZED)
list(APPEND swift_flags "-O2")
else()
list(APPEND swift_flags "-O0")
endif()
if (SWIFT_SPLIT_OBJC_SELECTORS)
list(APPEND swift_flags "-split-objc-selectors")
endif()
# FIXME: Temporary, until this flag goes away
list(APPEND swift_flags "-Xfrontend" "-strict-keyword-arguments")
# FIXME: We shouldn't /have/ to build things in a single process.
# <rdar://problem/15972329>
list(APPEND swift_flags "-force-single-frontend-invocation")
# Don't include libarclite in any build products by default.
list(APPEND swift_flags "-no-link-objc-runtime")
if(NOT SWIFT_RUNTIME_CHECKS)
# FIXME: Should this be exposed at the driver level?
list(APPEND swift_flags "-Xfrontend" "-disable-all-runtime-checks")
endif()
if (SWIFT_STDLIB_INTERNAL_CHECKS)
list(APPEND swift_flags "-Xfrontend" "-D" "-Xfrontend" "INTERNAL_CHECKS_ENABLED")
endif()
if(SWIFT_VERIFY_ALL)
list(APPEND swift_flags "-Xfrontend" "-sil-verify-all")
endif()
if (SWIFT_STDLIB_USE_ASSERT_CONFIG_RELEASE)
list(APPEND swift_flags "-assert-config" "Release")
endif()
if (SWIFT_EMIT_SORTED_SIL_OUTPUT)
list(APPEND swift_flags "-Xfrontend" "-emit-sorted-sil")
endif()
# Allow import of other Swift modules we just built.
list(APPEND swift_flags "-resource-dir" "${SWIFTLIB_DIR}")
# Turn on debug symbols in appropriate builds.
if(CMAKE_BUILD_TYPE MATCHES "Debug|.*DebInfo.*")
list(APPEND swift_flags "-g")
endif()
# If we have a modules SDK, use it for building.
if (MODULES_SDK)
list(APPEND swift_flags "-sdk" "${MODULES_SDK}")
endif()
# If we have a host triple, use it.
if (SWIFT_HOST_TRIPLE)
list(APPEND swift_flags "-target" "${SWIFT_HOST_TRIPLE}")
endif()
# If we have a custom module cache path, use it.
if (SWIFT_MODULE_CACHE_PATH)
list(APPEND swift_flags "-module-cache-path" "${SWIFT_MODULE_CACHE_PATH}")
endif()
list(APPEND swift_flags ${SWIFT_EXTRA_FLAGS})
# FIXME: Cleaner way to do this?
if(NOT SWIFTFILE_IS_MAIN)
list(APPEND swift_flags -parse-as-library)
endif()
if(SWIFTFILE_IS_STDLIB_CORE)
list(APPEND swift_flags -nostdimport -parse-stdlib -module-name "Swift" -Xfrontend -sil-serialize-all)
endif()
set(objfile ${SWIFTFILE_OUTPUT})
if (NOT IS_ABSOLUTE ${objfile})
set(objfile
"${CMAKE_CURRENT_BINARY_DIR}/${objfile}")
endif()
if(SWIFTFILE_IS_MAIN)
set(module_file)
set(create_module_dir)
else()
get_filename_component(module_name ${objfile} NAME_WE)
set(arch_subdir "")
if(NOT SWIFT_HOST_TRIPLE MATCHES "64")
set(arch_subdir "/32")
endif()
set(module_dir ${SWIFTLIB_DIR}/${SWIFTLIB_SUBDIR}${arch_subdir})
set(module_file ${module_dir}/${module_name}.swiftmodule)
set(module_doc_file ${module_dir}/${module_name}.swiftdoc)
list(APPEND swift_flags -emit-module -emit-module-path ${module_file})
set(create_module_dir
COMMAND ${CMAKE_COMMAND} -E make_directory ${module_dir})
install(FILES ${module_file} ${module_doc_file}
DESTINATION lib${LLVM_LIBDIR_SUFFIX}/swift/${SWIFTLIB_SUBDIR}${arch_subdir})
endif()
set(stdlib_dep)
# Make sure that standard library does not depend on itself.
if(NOT SWIFTFILE_IS_STDLIB_CORE)
set(stdlib_dep swift_stdlib_core)
endif()
set(line_directive_tool "${SWIFT_SOURCE_DIR}/utils/line-directive")
if (TARGET "${SWIFT_COMPILER}")
set(swift_compiler_path "${SWIFT_RUNTIME_OUTPUT_INTDIR}/${SWIFT_COMPILER}")
else()
set(swift_compiler_path "${SWIFT_COMPILER}")
endif()
add_custom_command(
OUTPUT ${objfile} ${module_file}
${create_module_dir}
COMMAND "${line_directive_tool}" ${source_files} --
"${swift_compiler_path}" "-c" ${swift_flags} "-o" "${objfile}" ${source_files}
DEPENDS "${SWIFT_COMPILER}" ${stdlib_dep} ${source_files} ${SWIFTFILE_DEPENDS}
# MAIN_DEPENDENCY ${target}
COMMENT "Compiling ${objfile}")
# Make sure the build system knows the file is a generated object file.
set_source_files_properties(${objfile}
PROPERTIES
GENERATED true
EXTERNAL_OBJECT true
LANGUAGE C
OBJECT_DEPENDS "${source_files}")
# Make sure this object file gets cleaned up.
set_directory_properties(
PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${objfile};${module_file}")
endfunction()
# Process the sources within the given variable, pulling out any Swift
# sources to be compiled with 'swift' directly. This updates
# ${sourcesvar} in place with the resulting list and ${externalvar} with the
# list of externally-build sources.
#
# Usage:
# handle_swift_sources(sourcesvar externalvar target)
function(handle_swift_sources sourcesvar externalvar target)
parse_arguments(SWIFTSOURCES "DEPENDS" "IS_MAIN;IS_STDLIB_CORE" ${ARGN})
set(result)
set(swift_sources)
set(asm_sources)
foreach(src ${${sourcesvar}})
get_filename_component(extension ${src} EXT)
if(extension STREQUAL ".swift")
list(APPEND swift_sources ${src})
else()
list(APPEND result ${src})
endif()
endforeach()
set(swift_flags)
set(IS_MAIN_arg)
if (SWIFTSOURCES_IS_MAIN)
set(IS_MAIN_arg IS_MAIN)
else()
set(swift_flags -module-link-name "${target}")
endif()
set(IS_STDLIB_CORE_arg)
if(SWIFTSOURCES_IS_STDLIB_CORE)
set(IS_STDLIB_CORE_arg IS_STDLIB_CORE)
endif()
if(swift_sources)
# Special-case hack to create swift.o for the swift_stdlib_* targets
if(target STREQUAL swift_stdlib_core)
set(swift_obj_base "Swift")
else()
# Otherwise, get the name from the first swift input file. Also
# a hack!
list(GET swift_sources 0 swift_obj_base)
get_filename_component(swift_obj_base ${swift_obj_base} NAME_WE)
endif()
set(swift_obj "${swift_obj_base}${CMAKE_C_OUTPUT_EXTENSION}")
compile_swift_files(OUTPUT ${swift_obj}
SOURCES ${swift_sources}
DEPENDS ${SWIFTSOURCES_DEPENDS}
FLAGS ${swift_flags}
${IS_MAIN_arg} ${IS_STDLIB_CORE_arg})
list(APPEND result ${swift_obj})
endif()
llvm_process_sources(result ${result})
set(${sourcesvar} "${result}" PARENT_SCOPE)
set(${externalvar} ${swift_sources} ${asm_sources} PARENT_SCOPE)
endfunction()
# Set SWIFTLIB_DIR to the directory in the build tree where Swift resource files
# should be placed. Note that $CMAKE_CFG_INTDIR expands to "." for
# single-configuration builds.
set(SWIFTLIB_DIR "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib/swift")
set(SWIFTSTATICLIB_DIR "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib/swift_static")
# Set SWIFTLIB_SUBDIR to the subdirectory inside SWIFTLIB_DIR
# where Swift .swiftmodules and libraries should be placed.
# This is changed later based on SWIFT_DEPLOYMENT_OS.
# The OS is currently needed in lieu of proper SDK support.
set(SWIFTLIB_SUBDIR ".")
# Configuration flags passed to all of our invocations of gyb. Try to
# avoid making up new variable names here if you can find a CMake
# variable that will do the job.
set(SWIFT_GYB_FLAGS
"-DCMAKE_SIZEOF_VOID_P=${CMAKE_SIZEOF_VOID_P}"
"-DCMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}"
"-DunicodeGraphemeBreakPropertyFile=${SWIFT_SOURCE_DIR}/utils/UnicodeData/GraphemeBreakProperty.txt"
"-DunicodeGraphemeBreakTestFile=${SWIFT_SOURCE_DIR}/utils/UnicodeData/GraphemeBreakTest.txt"
"--test" # Run gyb's self-tests whenever we use it. They're cheap
# enough and it keeps us honest.
)
# replace, in ${sourcesvar}, the given .gyb-suffixed sources with
# their un-suffixed intermediate files, which will be generated by
# processing the .gyb files with gyb.
function(handle_gyb_sources sourcesvar)
set(de_gybbed_sources)
set(gyb_sources)
set(gyb_tool "${SWIFT_SOURCE_DIR}/utils/gyb")
foreach (src ${${sourcesvar}})
string(REGEX REPLACE "[.]gyb$" "" src_sans_gyb "${src}")
if(src STREQUAL src_sans_gyb)
list(APPEND de_gybbed_sources "${src}")
else()
set(output_file "${CMAKE_CURRENT_BINARY_DIR}/${src_sans_gyb}")
list(APPEND de_gybbed_sources "${output_file}")
add_custom_command(
OUTPUT "${output_file}"
COMMAND "${gyb_tool}" ${SWIFT_GYB_FLAGS} -o "${output_file}" "${src}"
DEPENDS "${gyb_tool}" "${src}"
COMMENT "Generating ${src_sans_gyb} from ${src}"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)
endif()
endforeach()
set(${sourcesvar} "${de_gybbed_sources}" PARENT_SCOPE)
endfunction()
# Add a new Swift library.
#
# Usage:
# add_swift_library(name # Name of the library (e.g., swiftParse)
# [DEPENDS dep1 ...] # Libraries this library depends on
# [COMPONENT_DEPENDS comp1 ...] # LLVM components this library depends on
# [FILE_DEPENDS target1 ...] # Additional files this library depends on
# [INSTALL] # Install library to lib/swift
# [IS_STDLIB_CORE] # Compile as the standard library core
# [NO_LLVM_COMMON_LIBS] # Turn off linking of LLVM Common Libs.
# source1 [source2 source3 ...]) # Sources to add into this library
macro(add_swift_library name)
parse_arguments(SWIFTLIB "DEPENDS;COMPONENT_DEPENDS;FILE_DEPENDS" "INSTALL;IS_STDLIB_CORE;NO_LLVM_COMMON_LIBS"
${ARGN})
set(SWIFTLIB_SOURCES ${SWIFTLIB_DEFAULT_ARGS})
handle_gyb_sources(SWIFTLIB_SOURCES)
if(MSVC_IDE OR XCODE)
string( REGEX MATCHALL "/[^/]+" split_path ${CMAKE_CURRENT_SOURCE_DIR})
list( GET split_path -1 dir)
file( GLOB_RECURSE SWIFTLIB_HEADERS
${SWIFT_SOURCE_DIR}/include/swift${dir}/*.h
${SWIFT_SOURCE_DIR}/include/swift${dir}/*.def)
file( GLOB_RECURSE SWIFTLIB_TDS
${SWIFT_SOURCE_DIR}/include/swift${dir}/*.td)
source_group("TableGen descriptions" FILES ${SWIFTLIB_TDS})
set(SWIFTLIB_SOURCES ${SWIFTLIB_SOURCES} ${SWIFTLIB_HEADERS} ${SWIFTLIB_TDS})
endif(MSVC_IDE OR XCODE)
if (MODULE)
set(libkind MODULE)
elseif (SHARED_LIBRARY)
set(libkind SHARED)
else()
set(libkind)
endif()
set(IS_STDLIB_CORE_arg)
if(SWIFTLIB_IS_STDLIB_CORE)
set(IS_STDLIB_CORE_arg IS_STDLIB_CORE)
endif()
handle_swift_sources(SWIFTLIB_SOURCES SWIFTLIB_EXTERNAL_SOURCES ${name}
DEPENDS ${SWIFTLIB_FILE_DEPENDS}
${IS_STDLIB_CORE_arg})
add_library( ${name} ${libkind}
${SWIFTLIB_SOURCES}
${SWIFTLIB_EXTERNAL_SOURCES})
set_source_files_properties(
${SWIFTLIB_SOURCES}
PROPERTIES OBJECT_DEPENDS "${SWIFTLIB_FILE_DEPENDS}")
set_output_directory(${name} ${SWIFT_RUNTIME_OUTPUT_INTDIR} ${SWIFT_LIBRARY_OUTPUT_INTDIR})
if (ENABLE_SWIFT_STATIC_RUNTIME AND SWIFTLIB_INSTALL)
set(name_static "${name}_static")
add_library( ${name_static} STATIC
${SWIFTLIB_SOURCES}
${SWIFTLIB_EXTERNAL_SOURCES})
set_target_properties(${name_static} PROPERTIES OUTPUT_NAME ${name})
add_dependencies(${name_static} ${name})
set_output_directory(${name_static} ${SWIFT_RUNTIME_OUTPUT_INTDIR} ${SWIFT_LIBRARY_OUTPUT_INTDIR})
endif()
if (MODULE)
set_target_properties(${name} PROPERTIES
PREFIX ""
SUFFIX ${LLVM_PLUGIN_EXT}
)
endif()
if( LLVM_COMMON_DEPENDS )
add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
endif( LLVM_COMMON_DEPENDS )
# Add Swift source files to the project.
source_group("Swift Sources" FILES ${SWIFTLIB_EXTERNAL_SOURCES})
# ...and for now, mark them as HEADER_FILE_ONLY, so that Xcode doesn't try
# to build them itself.
set_source_files_properties(${SWIFTLIB_EXTERNAL_SOURCES} PROPERTIES
HEADER_FILE_ONLY true)
target_link_libraries( ${name} "-L${SWIFTLIB_DIR}/${SWIFTLIB_SUBDIR}" ${SWIFTLIB_DEPENDS} )
llvm_config( ${name} ${SWIFTLIB_COMPONENT_DEPENDS} )
if (NOT NO_LLVM_COMMON_LIBS)
target_link_libraries( ${name} ${LLVM_COMMON_LIBS} )
endif()
if(MSVC)
get_target_property(cflag ${name} COMPILE_FLAGS)
if(NOT cflag)
set(cflag "")
endif(NOT cflag)
set(cflag "${cflag} /Za")
set_target_properties(${name} PROPERTIES COMPILE_FLAGS ${cflag})
endif(MSVC)
if(SWIFTLIB_INSTALL)
# Install runtime libraries to lib/swift instead of lib. This works around
# the fact that -isysroot prevents linking to libraries in the system
# /usr/lib if Swift is installed in /usr.
set_target_properties(${name} PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${SWIFTLIB_DIR}/${SWIFTLIB_SUBDIR}
ARCHIVE_OUTPUT_DIRECTORY ${SWIFTLIB_DIR}/${SWIFTLIB_SUBDIR} )
if (name_static)
set_target_properties(${name_static} PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${SWIFTSTATICLIB_DIR}/${SWIFTLIB_SUBDIR}
ARCHIVE_OUTPUT_DIRECTORY ${SWIFTSTATICLIB_DIR}/${SWIFTLIB_SUBDIR} )
endif()
foreach(config ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${config} config_upper)
# Hack to deal with the fact that ${SWIFTLIB_DIR} contains the build-time
# variable $(CONFIGURATION). Note that this fix is Xcode-specific.
# You might think you could just replace ${CMAKE_CFG_INTDIR} here, but
# that can actually have other things mangled into it besides just the
# configuration. This at least doesn't pretend to do the right thing
# outside of Xcode.
string(REPLACE "$(CONFIGURATION)" ${config} config_lib_dir
${SWIFTLIB_DIR})
set_target_properties(${name} PROPERTIES
LIBRARY_OUTPUT_DIRECTORY_${config_upper} ${config_lib_dir}/${SWIFTLIB_SUBDIR}
ARCHIVE_OUTPUT_DIRECTORY_${config_upper} ${config_lib_dir}/${SWIFTLIB_SUBDIR})
# Do the same for static libraries.
if (name_static)
string(REPLACE "$(CONFIGURATION)" ${config} config_lib_dir
${SWIFTSTATICLIB_DIR})
set_target_properties(${name_static} PROPERTIES
LIBRARY_OUTPUT_DIRECTORY_${config_upper} ${config_lib_dir}/${SWIFTLIB_SUBDIR}
ARCHIVE_OUTPUT_DIRECTORY_${config_upper} ${config_lib_dir}/${SWIFTLIB_SUBDIR})
endif()
endforeach()
install(TARGETS ${name}
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}/swift/${SWIFTLIB_SUBDIR}
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}/swift/${SWIFTLIB_SUBDIR})
if (name_static)
install(TARGETS ${name_static}
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}/swift_static/${SWIFTLIB_SUBDIR}
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}/swift_static/${SWIFTLIB_SUBDIR})
endif()
# FIXME: Install .swift files so they can be parsed on import.
# Really we want to install a preparsed metadata file.
foreach(external_source ${SWIFTLIB_EXTERNAL_SOURCES})
get_filename_component(extension ${external_source} EXT)
if(extension STREQUAL ".swift")
set(filename ${external_source})
endif()
endforeach(external_source)
endif(SWIFTLIB_INSTALL)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set_target_properties(${name}
PROPERTIES
INSTALL_NAME_DIR "@rpath"
BUILD_WITH_INSTALL_RPATH YES)
endif()
# Configure plist creation for OS X.
set (PLIST_INFO_PLIST "Info.plist" CACHE STRING "Plist name")
if (APPLE AND SHARED_LIBRARY)
set(PLIST_INFO_NAME ${name})
set(PLIST_INFO_UTI "com.apple.dt.runtime.${name}")
set(PLIST_INFO_VERSION "1.0")
if (LLVM_SUBMIT_VERSION)
set(PLIST_INFO_BUILD_VERSION
"${LLVM_SUBMIT_VERSION}.${LLVM_SUBMIT_SUBVERSION}")
endif()
set(PLIST_INFO_PLIST_OUT "${PLIST_INFO_PLIST}")
target_link_libraries(${name}
"-Wl,-sectcreate,__TEXT,__info_plist,${CMAKE_CURRENT_BINARY_DIR}/${PLIST_INFO_PLIST_OUT}")
configure_file("${SWIFT_SOURCE_DIR}/stdlib/${PLIST_INFO_PLIST}.in" "${PLIST_INFO_PLIST_OUT}" @ONLY)
# If Application Extensions are enabled, pass the linker flag marking
# the dylib as safe.
if (CXX_SUPPORTS_FAPPLICATION_EXTENSION AND (NOT DISABLE_APPLICATION_EXTENSION))
target_link_libraries(${name} "-Wl,-application_extension")
endif()
set(PLIST_INFO_UTI)
set(PLIST_INFO_NAME)
set(PLIST_INFO_VERSION)
set(PLIST_INFO_BUILD_VERSION)
endif()
set_target_properties(${name} PROPERTIES FOLDER "Swift libraries")
endmacro(add_swift_library)
# Add a new Swift executable.
#
# Usage:
# add_swift_executable(name # Name of the executable (e.g., swift)
# [DEPENDS dep1 ...] # Libraries this executable depends on
# [COMPONENT_DEPENDS comp1 ...] # LLVM components this executable
# # depends on
# [FILE_DEPENDS target1 ...] # Additional files this executable
# # depends on
# [EXCLUDE_FROM_ALL] # Whether to exclude this executable from
# # the ALL_BUILD target
# source1 [source2 source3 ...]) # Sources to add into this library
macro(add_swift_executable name)
# Parse the arguments we were given.
parse_arguments(SWIFTEXE "DEPENDS;COMPONENT_DEPENDS" "EXCLUDE_FROM_ALL"
${ARGN})
set(SWIFTEXE)
handle_swift_sources(SWIFTEXE_DEFAULT_ARGS SWIFTEXE_EXTERNAL_SOURCES ${name}
DEPENDS ${SWIFTEXE_FILE_DEPENDS}
IS_MAIN)
# Add the executable
if (${SWIFTEXE_EXCLUDE_FROM_ALL})
add_executable(${name} EXCLUDE_FROM_ALL ${SWIFTEXE_DEFAULT_ARGS} ${SWIFTEXE_EXTERNAL_SOURCES})
else()
add_executable(${name} ${SWIFTEXE_DEFAULT_ARGS} ${SWIFTEXE_EXTERNAL_SOURCES})
endif()
set_source_files_properties(
${SWIFTEXE_DEFAULT_ARGS}
PROPERTIES OBJECT_DEPENDS "${SWIFTEXE_FILE_DEPENDS}")
set_output_directory(${name} ${SWIFT_RUNTIME_OUTPUT_INTDIR} ${SWIFT_LIBRARY_OUTPUT_INTDIR})
# Add Swift source files to the project.
source_group("Swift Sources" FILES ${SWIFTEXE_EXTERNAL_SOURCES})
# ...and for now, mark them as HEADER_FILE_ONLY, so that Xcode doesn't try
# to build them itself.
set_source_files_properties(${SWIFTEXE_EXTERNAL_SOURCES} PROPERTIES
HEADER_FILE_ONLY true)
# Add appropriate dependencies
if( LLVM_COMMON_DEPENDS )
add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
endif( LLVM_COMMON_DEPENDS )
target_link_libraries( ${name} "-L${SWIFTLIB_DIR}/${SWIFTLIB_SUBDIR}" ${SWIFTEXE_DEPENDS} )
llvm_config( ${name} ${SWIFTEXE_COMPONENT_DEPENDS} )
target_link_libraries( ${name} ${LLVM_COMMON_LIBS} )
set_target_properties(${name} PROPERTIES FOLDER "Swift executables")
# ASan does not play well with exported_symbol option. This should be fixed soon.
if(NOT SWIFT_ASAN_BUILD)
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
set_target_properties(${name}
PROPERTIES
LINK_FLAGS "-Xlinker -exported_symbol -Xlinker _main -Xlinker -rpath -Xlinker @executable_path/../lib/swift/${SWIFTLIB_SUBDIR} ")
endif()
else()
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
set_target_properties(${name}
PROPERTIES
LINK_FLAGS "-Xlinker -rpath -Xlinker @executable_path/../lib/swift/${SWIFTLIB_SUBDIR} ")
endif()
endif()
endmacro(add_swift_executable)
# Add compiler flags for a target.
#
# Usage:
# add_swift_compiler_flags(name # Name of the target
# flags ) # compiler flags string
function(add_swift_compiler_flags name flags)
set_property(TARGET ${name} APPEND_STRING PROPERTY COMPILE_FLAGS " ${flags}")
endfunction()
# Add compiler flags for a target when SWIFT_OPTIMIZED is enabled.
#
# Usage:
# add_swift_optimization_flags(name) # Name of the target
macro(add_swift_optimization_flags name)
if(SWIFT_OPTIMIZED)
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "i386")
add_swift_compiler_flags(${name} "-momit-leaf-frame-pointer")
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
add_swift_compiler_flags(${name} "-momit-leaf-frame-pointer")
endif()
endif()
endmacro(add_swift_optimization_flags)
macro(manpage PODFILE DESC MANFILE SECTION)
find_program(POD2MAN pod2man)
if(POD2MAN)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${MANFILE}.${SECTION}
DEPENDS ${PODFILE}
COMMAND ${POD2MAN}
ARGS --section ${SECTION} --center ${DESC} --release --stderr --name ${MANFILE}
${PODFILE} > ${CMAKE_CURRENT_BINARY_DIR}/${MANFILE}.${SECTION}
)
set(MANPAGE_TARGET "man-${MANFILE}")
add_custom_target(${MANPAGE_TARGET} ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${MANFILE}.${SECTION})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${MANFILE}.${SECTION}
DESTINATION share/man/man${SECTION} )
else()
message(WARNING "Need pod2man installed to generate man page")
endif()
endmacro(manpage)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# Choose an SDK if none was set.
set(MODULES_SDK "" CACHE PATH
"Path to the modules-enabled SDK to use")
if (NOT MODULES_SDK)
execute_process(COMMAND xcrun --sdk macosx --show-sdk-path
OUTPUT_VARIABLE MODULES_SDK
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
if(NOT EXISTS "${MODULES_SDK}/System/Library/Frameworks/module.map")
message(FATAL_ERROR "A modules-enabled SDK is required for Swift on OS X.")
endif()
# Choose a deployment target if none was set.
set(SWIFT_DEPLOYMENT_TARGET "" CACHE STRING
"Deployment target for Swift compiler and libraries.")
if (NOT SWIFT_DEPLOYMENT_TARGET)
execute_process(COMMAND sw_vers -productVersion
OUTPUT_VARIABLE SWIFT_DEPLOYMENT_TARGET
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REGEX MATCH "[0-9]+\\.[0-9]+" SWIFT_DEPLOYMENT_TARGET ${SWIFT_DEPLOYMENT_TARGET})
endif()
# Choose a deployment OS if none was set.
set(SWIFT_DEPLOYMENT_OS "macosx" CACHE STRING
"Deployment OS for Swift compiler and libraries [macosx, iphoneos, iphonesimulator].")
# Sadly there are three OS naming conventions.
# xcrun SDK name: macosx iphoneos iphonesimulator (+ "internal" or version)
# -mOS-version-min: macosx ios ios-simulator
# swift -triple: macosx ios ios
if (SWIFT_DEPLOYMENT_OS MATCHES "^iphoneos")
set(version_min_os "ios")
set(triple_os "ios")
elseif (SWIFT_DEPLOYMENT_OS MATCHES "^iphonesimulator")
set(version_min_os "ios-simulator")
set(triple_os "ios")
elseif (SWIFT_DEPLOYMENT_OS MATCHES "^macosx")
set(version_min_os "macosx")
set(triple_os "macosx")
else()
message(FATAL_ERROR "Can't understand SWIFT_DEPLOYMENT_OS '${SWIFT_DEPLOYMENT_OS}';")
endif()
# Add host triple to swift compiler flags.
set(SWIFT_HOST_TRIPLE "${CMAKE_SYSTEM_PROCESSOR}-apple-${triple_os}${SWIFT_DEPLOYMENT_TARGET}" CACHE STRING "triple")
# Add deployment target to C/C++ compiler and linker flags.
# FIXME: CMAKE_OSX_DEPLOYMENT_TARGET falls over when used for iOS versions.
if (XCODE)
if (${SWIFT_DEPLOYMENT_OS} MATCHES "^macosx")
set(CMAKE_XCODE_ATTRIBUTE_MACOSX_DEPLOYMENT_TARGET ${SWIFT_DEPLOYMENT_TARGET})
else()
set(CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET ${SWIFT_DEPLOYMENT_TARGET})
endif()
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m${version_min_os}-version-min=${SWIFT_DEPLOYMENT_TARGET}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m${version_min_os}-version-min=${SWIFT_DEPLOYMENT_TARGET}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m${version_min_os}-version-min=${SWIFT_DEPLOYMENT_TARGET}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m${version_min_os}-version-min=${SWIFT_DEPLOYMENT_TARGET}")
endif()
# Add OS name to stdlib install directory
set(SWIFTLIB_SUBDIR "${SWIFT_DEPLOYMENT_OS}")
endif()
# We'll need this once we have generated headers
include_directories(BEFORE
${CMAKE_CURRENT_BINARY_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/include
)
# Add all of the subdirectories, where we actually do work.
if (SWIFT_BUILD_TOOLS)
add_subdirectory(include)
add_subdirectory(lib)
add_subdirectory(tools)
add_subdirectory(utils)
endif (SWIFT_BUILD_TOOLS)
if (SWIFT_BUILD_STDLIB)
add_subdirectory(stdlib)
endif (SWIFT_BUILD_STDLIB)
add_subdirectory(examples)
option(SWIFT_INCLUDE_TESTS "Create targets for building/running tests." "${LLVM_INCLUDE_TESTS}")
if (SWIFT_INCLUDE_TESTS)
add_subdirectory(test)
add_subdirectory(unittests)
endif()
option(SWIFT_INCLUDE_DOCS "Create targets for building docs." "${LLVM_INCLUDE_DOCS}")
if (SWIFT_INCLUDE_DOCS)
add_subdirectory(docs)
endif()
add_subdirectory(benchmark)
endif()
# Add a documentation target so that documentation shows up in the
# Xcode project.
if(XCODE)
add_custom_target(Documentation
SOURCES README.txt
docs/LangRef.html
docs/toc.js)
file(GLOB SWIFT_TOPLEVEL_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/include/swift${dir}/*.h
${CMAKE_CURRENT_SOURCE_DIR}/include/swift${dir}/*.td