@@ -3,28 +3,37 @@ include(SwiftXcodeSupport)
3
3
4
4
include (CheckCXXCompilerFlag )
5
5
6
- macro (swift_common_standalone_build_config_llvm product )
6
+ macro (swift_common_standalone_build_config_llvm product is_cross_compiling )
7
7
option (LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON )
8
8
9
+ precondition_translate_flag (${product} _PATH_TO_LLVM_SOURCE PATH_TO_LLVM_SOURCE )
10
+ precondition_translate_flag (${product} _PATH_TO_LLVM_BUILD PATH_TO_LLVM_BUILD )
11
+
12
+ file (TO_CMAKE_PATH "${PATH_TO_LLVM_BUILD} " PATH_TO_LLVM_BUILD )
13
+
14
+ set (SWIFT_LLVM_CMAKE_PATHS
15
+ "${PATH_TO_LLVM_BUILD} /share/llvm/cmake"
16
+ "${PATH_TO_LLVM_BUILD} /lib/cmake/llvm" )
17
+
18
+ # Add all LLVM CMake paths to our cmake module path.
19
+ foreach (path ${SWIFT_LLVM_CMAKE_PATHS} )
20
+ list (APPEND CMAKE_MODULE_PATH ${path} )
21
+ endforeach ()
22
+
9
23
# If we already have a cached value for LLVM_ENABLE_ASSERTIONS, save the value.
10
- if (DEFINED LLVM_ENABLE_ASSERTIONS )
24
+ if (DEFINED LLVM_ENABLE_ASSERTIONS )
11
25
set (LLVM_ENABLE_ASSERTIONS_saved "${LLVM_ENABLE_ASSERTIONS} " )
12
26
endif ()
13
27
14
28
# Then we import LLVMConfig. This is going to override whatever cached value
15
29
# we have for LLVM_ENABLE_ASSERTIONS.
16
- find_package (LLVM CONFIG REQUIRED NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH )
17
- list (APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR} " )
18
-
19
- set (LLVM_MAIN_SRC_DIR "${LLVM_BUILD_MAIN_SRC_DIR} "
20
- CACHE PATH "Path to LLVM source tree" )
21
- set (LLVM_MAIN_INCLUDE_DIR "${LLVM_BUILD_MAIN_INCLUDE_DIR} "
22
- CACHE PATH "Path to llvm/include" )
30
+ find_package (LLVM REQUIRED CONFIG
31
+ HINTS "${PATH_TO_LLVM_BUILD} " NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH )
23
32
24
33
# If we did not have a cached value for LLVM_ENABLE_ASSERTIONS, set
25
34
# LLVM_ENABLE_ASSERTIONS_saved to be the ENABLE_ASSERTIONS value from LLVM so
26
35
# we follow LLVMConfig.cmake's value by default if nothing is provided.
27
- if (NOT DEFINED LLVM_ENABLE_ASSERTIONS_saved )
36
+ if (NOT DEFINED LLVM_ENABLE_ASSERTIONS_saved )
28
37
set (LLVM_ENABLE_ASSERTIONS_saved "${LLVM_ENABLE_ASSERTIONS} " )
29
38
endif ()
30
39
@@ -40,10 +49,11 @@ macro(swift_common_standalone_build_config_llvm product)
40
49
41
50
precondition (LLVM_TOOLS_BINARY_DIR )
42
51
escape_path_for_xcode ("${LLVM_BUILD_TYPE} " "${LLVM_TOOLS_BINARY_DIR} " LLVM_TOOLS_BINARY_DIR )
43
-
44
52
precondition_translate_flag (LLVM_BUILD_LIBRARY_DIR LLVM_LIBRARY_DIR )
45
53
escape_path_for_xcode ("${LLVM_BUILD_TYPE} " "${LLVM_LIBRARY_DIR} " LLVM_LIBRARY_DIR )
46
-
54
+ precondition_translate_flag (LLVM_BUILD_MAIN_INCLUDE_DIR LLVM_MAIN_INCLUDE_DIR )
55
+ precondition_translate_flag (LLVM_BUILD_BINARY_DIR LLVM_BINARY_DIR )
56
+ precondition_translate_flag (LLVM_BUILD_MAIN_SRC_DIR LLVM_MAIN_SRC_DIR )
47
57
precondition (LLVM_LIBRARY_DIRS )
48
58
escape_path_for_xcode ("${LLVM_BUILD_TYPE} " "${LLVM_LIBRARY_DIRS} " LLVM_LIBRARY_DIRS )
49
59
@@ -54,41 +64,18 @@ macro(swift_common_standalone_build_config_llvm product)
54
64
set (LLVM_BINARY_OUTPUT_INTDIR "${LLVM_TOOLS_BINARY_DIR} " )
55
65
set (LLVM_LIBRARY_OUTPUT_INTDIR "${LLVM_LIBRARY_DIR} " )
56
66
57
- if (XCODE )
67
+ if (XCODE )
58
68
fix_imported_targets_for_xcode ("${LLVM_EXPORTED_TARGETS} " )
59
69
endif ()
60
70
61
- if (NOT CMAKE_CROSSCOMPILING )
71
+ if (NOT ${is_cross_compiling} )
62
72
set (${product} _NATIVE_LLVM_TOOLS_PATH "${LLVM_TOOLS_BINARY_DIR} " )
63
73
endif ()
64
74
65
- if (CMAKE_CROSSCOMPILING )
66
- set (LLVM_NATIVE_BUILD "${LLVM_BINARY_DIR} /NATIVE" )
67
- if (NOT EXISTS "${LLVM_NATIVE_BUILD} " )
68
- message (FATAL_ERROR
69
- "Attempting to cross-compile swift standalone but no native LLVM build
70
- found. Please cross-compile LLVM as well." )
71
- endif ()
72
-
73
- if (CMAKE_HOST_SYSTEM_NAME MATCHES Windows )
74
- set (HOST_EXECUTABLE_SUFFIX ".exe" )
75
- endif ()
76
-
77
- if (NOT CMAKE_CONFIGURATION_TYPES )
78
- set (LLVM_TABLEGEN_EXE
79
- "${LLVM_NATIVE_BUILD_DIR} /bin/llvm-tblgen${HOST_EXECUTABLE_SUFFIX} " )
80
- else ()
81
- # NOTE: LLVM NATIVE build is always built Release, as is specified in
82
- # CrossCompile.cmake
83
- set (LLVM_TABLEGEN_EXE
84
- "${LLVM_NATIVE_BUILD_DIR} /Release/bin/llvm-tblgen${HOST_EXECUTABLE_SUFFIX} " )
85
- endif ()
86
- else ()
87
- find_program (LLVM_TABLEGEN_EXE "llvm-tblgen" HINTS ${LLVM_TOOLS_BINARY_DIR}
88
- NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH )
89
- if (LLVM_TABLEGEN_EXE STREQUAL "LLVM_TABLEGEN_EXE-NOTFOUND" )
90
- message (FATAL_ERROR "Failed to find tablegen in ${LLVM_TOOLS_BINARY_DIR} " )
91
- endif ()
75
+ find_program (LLVM_TABLEGEN_EXE "llvm-tblgen" "${${product} _NATIVE_LLVM_TOOLS_PATH}"
76
+ NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH )
77
+ if ("${LLVM_TABLEGEN_EXE} " STREQUAL "LLVM_TABLEGEN_EXE-NOTFOUND" )
78
+ message (FATAL_ERROR "Failed to find tablegen in ${${product} _NATIVE_LLVM_TOOLS_PATH}" )
92
79
endif ()
93
80
94
81
include (AddLLVM )
@@ -119,7 +106,7 @@ macro(swift_common_standalone_build_config_llvm product)
119
106
"${PACKAGE_VERSION_MAJOR} .${PACKAGE_VERSION_MINOR} " CACHE STRING
120
107
"Version number that will be placed into the libclang library , in the form XX.YY" )
121
108
122
- foreach (INCLUDE_DIR ${LLVM_INCLUDE_DIRS} )
109
+ foreach (INCLUDE_DIR ${LLVM_INCLUDE_DIRS} )
123
110
escape_path_for_xcode ("${LLVM_BUILD_TYPE} " "${INCLUDE_DIR} " INCLUDE_DIR )
124
111
include_directories (${INCLUDE_DIR} )
125
112
endforeach ()
@@ -147,18 +134,52 @@ macro(swift_common_standalone_build_config_llvm product)
147
134
endif ()
148
135
endmacro ()
149
136
150
- macro (swift_common_standalone_build_config_clang product )
151
- find_package (Clang CONFIG REQUIRED NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH )
137
+ macro (swift_common_standalone_build_config_clang product is_cross_compiling )
138
+ set (${product} _PATH_TO_CLANG_SOURCE "${PATH_TO_LLVM_SOURCE} /tools/clang"
139
+ CACHE PATH "Path to Clang source code." )
140
+ set (${product} _PATH_TO_CLANG_BUILD "${PATH_TO_LLVM_BUILD} " CACHE PATH
141
+ "Path to the directory where Clang was built or installed." )
142
+
143
+ set (PATH_TO_CLANG_SOURCE "${${product} _PATH_TO_CLANG_SOURCE}" )
144
+ set (PATH_TO_CLANG_BUILD "${${product} _PATH_TO_CLANG_BUILD}" )
145
+
146
+ file (TO_CMAKE_PATH "${PATH_TO_CLANG_SOURCE} " PATH_TO_CLANG_SOURCE )
147
+ file (TO_CMAKE_PATH "${PATH_TO_CLANG_BUILD} " PATH_TO_CLANG_BUILD )
148
+
149
+ # Add all Clang CMake paths to our cmake module path.
150
+ set (SWIFT_CLANG_CMAKE_PATHS
151
+ "${PATH_TO_CLANG_BUILD} /share/clang/cmake"
152
+ "${PATH_TO_CLANG_BUILD} /lib/cmake/clang" )
153
+ foreach (path ${SWIFT_CLANG_CMAKE_PATHS} )
154
+ list (APPEND CMAKE_MODULE_PATH ${path} )
155
+ endforeach ()
156
+
157
+ # Then include Clang.
158
+ find_package (Clang REQUIRED CONFIG
159
+ HINTS "${PATH_TO_CLANG_BUILD} " NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH )
152
160
153
- if (NOT CMAKE_CROSSCOMPILING )
161
+ if (NOT EXISTS "${PATH_TO_CLANG_SOURCE} /include/clang/AST/Decl.h" )
162
+ message (FATAL_ERROR "Please set ${product} _PATH_TO_CLANG_SOURCE to the root directory of Clang's source code." )
163
+ endif ()
164
+ get_filename_component (CLANG_MAIN_SRC_DIR "${PATH_TO_CLANG_SOURCE} " ABSOLUTE )
165
+
166
+ if (NOT EXISTS "${PATH_TO_CLANG_BUILD} /tools/clang/include/clang/Basic/Version.inc" )
167
+ message (FATAL_ERROR "Please set ${product} _PATH_TO_CLANG_BUILD to a directory containing a Clang build." )
168
+ endif ()
169
+ set (CLANG_BUILD_INCLUDE_DIR "${PATH_TO_CLANG_BUILD} /tools/clang/include" )
170
+
171
+ if (NOT ${is_cross_compiling} )
154
172
set (${product} _NATIVE_CLANG_TOOLS_PATH "${LLVM_TOOLS_BINARY_DIR} " )
155
173
endif ()
156
174
157
- if (XCODE )
175
+ set (CLANG_MAIN_INCLUDE_DIR "${CLANG_MAIN_SRC_DIR} /include" )
176
+
177
+ if (XCODE )
158
178
fix_imported_targets_for_xcode ("${CLANG_EXPORTED_TARGETS} " )
159
179
endif ()
160
180
161
- include_directories (${CLANG_INCLUDE_DIRS} )
181
+ include_directories ("${CLANG_BUILD_INCLUDE_DIR} "
182
+ "${CLANG_MAIN_INCLUDE_DIR} " )
162
183
endmacro ()
163
184
164
185
macro (swift_common_standalone_build_config_cmark product )
@@ -197,9 +218,9 @@ endmacro()
197
218
#
198
219
# is_cross_compiling
199
220
# Whether this is cross-compiling host tools.
200
- macro (swift_common_standalone_build_config product )
201
- swift_common_standalone_build_config_llvm (${product} )
202
- swift_common_standalone_build_config_clang (${product} )
221
+ macro (swift_common_standalone_build_config product is_cross_compiling )
222
+ swift_common_standalone_build_config_llvm (${product} ${is_cross_compiling} )
223
+ swift_common_standalone_build_config_clang (${product} ${is_cross_compiling} )
203
224
swift_common_standalone_build_config_cmark (${product} )
204
225
205
226
# Enable groups for IDE generators (Xcode and MSVC).
0 commit comments