@@ -12,6 +12,57 @@ else()
12
12
set (cmake_3_2_USES_TERMINAL USES_TERMINAL )
13
13
endif ()
14
14
15
+ function (get_effective_platform_for_triple triple output )
16
+ string (FIND "${triple} " "macos" IS_MACOS )
17
+ if (IS_MACOS )
18
+ set (${output} "" PARENT_SCOPE )
19
+ return ()
20
+ endif ()
21
+ message (FATAL_ERROR "Not supported" )
22
+ endfunction ()
23
+
24
+ # Eliminate $(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) from a path.
25
+ #
26
+ # We do not support compiling llvm with an Xcode setting beyond the one that was
27
+ # used with build-script. This allows us to remove those paths. Right now,
28
+ # nothing here is tested for cross compiling with Xcode, but it is in principal
29
+ # possible.
30
+ function (escape_llvm_path_for_xcode path outvar )
31
+ # First check if we are using Xcode. If not, return early.
32
+ if (NOT XCODE )
33
+ set (${outvar} "${path} " PARENT_SCOPE )
34
+ return ()
35
+ endif ()
36
+
37
+ get_effective_platform_for_triple ("${SWIFT_HOST_TRIPLE} " SWIFT_EFFECTIVE_PLATFORM_NAME )
38
+ string (REPLACE "$(CONFIGURATION)" "${LLVM_BUILD_TYPE} " path "${path} " )
39
+ string (REPLACE "$(EFFECTIVE_PLATFORM_NAME)" "${SWIFT_EFFECTIVE_PLATFORM_NAME} " path "${path} " )
40
+ set (${outvar} "${path} " PARENT_SCOPE )
41
+ endfunction ()
42
+
43
+ # What this function does is go through each of the passed in imported targets
44
+ # from LLVM/Clang and changes them to use the appropriate fully expanded paths.
45
+ #
46
+ # TODO: This function needs a better name.
47
+ function (fix_imported_target_locations_for_xcode targets )
48
+ foreach (t ${targets} )
49
+ if (NOT TARGET ${t} )
50
+ message (FATAL_ERROR "${t} is not a target?!" )
51
+ endif ()
52
+
53
+ get_target_property (TARGET_TYPE ${t} TYPE )
54
+
55
+ # We only want to do this for static libraries for now.
56
+ if (NOT ${TARGET_TYPE} STREQUAL "STATIC_LIBRARY" )
57
+ continue ()
58
+ endif ()
59
+
60
+ set_target_properties (${t} PROPERTIES
61
+ IMPORTED_LOCATION_DEBUG "${LLVM_LIBRARY_OUTPUT_INTDIR} /lib${t} .a"
62
+ IMPORTED_LOCATION_RELEASE "${LLVM_LIBRARY_OUTPUT_INTDIR} /lib${t} .a" )
63
+ endforeach ()
64
+ endfunction ()
65
+
15
66
macro (swift_common_standalone_build_config_llvm product is_cross_compiling )
16
67
option (LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON )
17
68
@@ -34,7 +85,8 @@ macro(swift_common_standalone_build_config_llvm product is_cross_compiling)
34
85
35
86
# Then we import LLVMConfig. This is going to override whatever cached value
36
87
# we have for LLVM_ENABLE_ASSERTIONS.
37
- include (LLVMConfig )
88
+ find_package (LLVM REQUIRED CONFIG
89
+ HINTS "${PATH_TO_LLVM_BUILD} " NO_DEFAULT_PATH )
38
90
39
91
# If we did not have a cached value for LLVM_ENABLE_ASSERTIONS, set
40
92
# LLVM_ENABLE_ASSERTIONS_saved to be the ENABLE_ASSERTIONS value from LLVM so
@@ -54,20 +106,33 @@ macro(swift_common_standalone_build_config_llvm product is_cross_compiling)
54
106
mark_as_advanced (LLVM_ENABLE_ASSERTIONS )
55
107
56
108
precondition (LLVM_TOOLS_BINARY_DIR )
109
+ escape_llvm_path_for_xcode ("${LLVM_TOOLS_BINARY_DIR} " LLVM_TOOLS_BINARY_DIR )
57
110
precondition_translate_flag (LLVM_BUILD_LIBRARY_DIR LLVM_LIBRARY_DIR )
111
+ escape_llvm_path_for_xcode ("${LLVM_LIBRARY_DIR} " LLVM_LIBRARY_DIR )
58
112
precondition_translate_flag (LLVM_BUILD_MAIN_INCLUDE_DIR LLVM_MAIN_INCLUDE_DIR )
59
113
precondition_translate_flag (LLVM_BUILD_BINARY_DIR LLVM_BINARY_DIR )
60
114
precondition_translate_flag (LLVM_BUILD_MAIN_SRC_DIR LLVM_MAIN_SRC_DIR )
115
+ precondition (LLVM_LIBRARY_DIRS )
116
+ escape_llvm_path_for_xcode ("${LLVM_LIBRARY_DIRS} " LLVM_LIBRARY_DIRS )
61
117
62
- if (${is_cross_compiling} )
63
- find_program (SWIFT_TABLEGEN_EXE "llvm-tblgen" "${${product} _NATIVE_LLVM_TOOLS_PATH}"
64
- NO_DEFAULT_PATH )
65
- if ("${SWIFT_TABLEGEN_EXE} " STREQUAL "SWIFT_TABLEGEN_EXE-NOTFOUND" )
66
- message (FATAL_ERROR "Failed to find tablegen in ${${product} _NATIVE_LLVM_TOOLS_PATH}" )
67
- endif ()
68
- else ()
69
- set (SWIFT_TABLEGEN_EXE llvm-tblgen )
70
- set (${product} _NATIVE_LLVM_TOOLS_PATH "${PATH_TO_LLVM_TOOLS_BINARY_DIR} " )
118
+ # This could be computed using ${CMAKE_CFG_INTDIR} if we want to link Swift
119
+ # against a matching LLVM build configuration. However, we usually want to be
120
+ # flexible and allow linking a debug Swift against optimized LLVM.
121
+ set (LLVM_RUNTIME_OUTPUT_INTDIR "${LLVM_BINARY_DIR} " )
122
+ set (LLVM_LIBRARY_OUTPUT_INTDIR "${LLVM_LIBRARY_DIR} " )
123
+
124
+ if (XCODE )
125
+ fix_imported_target_locations_for_xcode ("${LLVM_EXPORTED_TARGETS} " )
126
+ endif ()
127
+
128
+ if (NOT ${is_cross_compiling} )
129
+ set (${product} _NATIVE_LLVM_TOOLS_PATH "${LLVM_TOOLS_BINARY_DIR} " )
130
+ endif ()
131
+
132
+ find_program (SWIFT_TABLEGEN_EXE "llvm-tblgen" "${${product} _NATIVE_LLVM_TOOLS_PATH}"
133
+ NO_DEFAULT_PATH )
134
+ if ("${SWIFT_TABLEGEN_EXE} " STREQUAL "SWIFT_TABLEGEN_EXE-NOTFOUND" )
135
+ message (FATAL_ERROR "Failed to find tablegen in ${${product} _NATIVE_LLVM_TOOLS_PATH}" )
71
136
endif ()
72
137
73
138
include (AddLLVM )
@@ -85,6 +150,7 @@ macro(swift_common_standalone_build_config_llvm product is_cross_compiling)
85
150
"Version number that will be placed into the libclang library , in the form XX.YY" )
86
151
87
152
foreach (INCLUDE_DIR ${LLVM_INCLUDE_DIRS} )
153
+ escape_llvm_path_for_xcode ("${INCLUDE_DIR} " INCLUDE_DIR )
88
154
include_directories (${INCLUDE_DIR} )
89
155
endforeach ()
90
156
@@ -128,10 +194,9 @@ macro(swift_common_standalone_build_config_clang product is_cross_compiling)
128
194
list (APPEND CMAKE_MODULE_PATH ${path} )
129
195
endforeach ()
130
196
131
- # Then include ClangTargets.cmake. If Clang adds a ClangConfig.cmake, this is
132
- # where it will be included. By including ClangTargets.cmake, we at least get
133
- # the right dependency ordering for clang libraries.
134
- include (ClangTargets )
197
+ # Then include Clang.
198
+ find_package (Clang REQUIRED CONFIG
199
+ HINTS "${PATH_TO_CLANG_BUILD} " NO_DEFAULT_PATH )
135
200
136
201
if (NOT EXISTS "${PATH_TO_CLANG_SOURCE} /include/clang/AST/Decl.h" )
137
202
message (FATAL_ERROR "Please set ${product} _PATH_TO_CLANG_SOURCE to the root directory of Clang's source code." )
@@ -144,11 +209,15 @@ macro(swift_common_standalone_build_config_clang product is_cross_compiling)
144
209
set (CLANG_BUILD_INCLUDE_DIR "${PATH_TO_CLANG_BUILD} /tools/clang/include" )
145
210
146
211
if (NOT ${is_cross_compiling} )
147
- set (${product} _NATIVE_CLANG_TOOLS_PATH "${PATH_TO_LLVM_TOOLS_BINARY_DIR } " )
212
+ set (${product} _NATIVE_CLANG_TOOLS_PATH "${LLVM_TOOLS_BINARY_DIR } " )
148
213
endif ()
149
214
150
215
set (CLANG_MAIN_INCLUDE_DIR "${CLANG_MAIN_SRC_DIR} /include" )
151
216
217
+ if (XCODE )
218
+ fix_imported_target_locations_for_xcode ("${CLANG_EXPORTED_TARGETS} " )
219
+ endif ()
220
+
152
221
include_directories ("${CLANG_BUILD_INCLUDE_DIR} "
153
222
"${CLANG_MAIN_INCLUDE_DIR} " )
154
223
endmacro ()
0 commit comments