@@ -3,37 +3,28 @@ include(SwiftXcodeSupport)
3
3
4
4
include (CheckCXXCompilerFlag )
5
5
6
- macro (swift_common_standalone_build_config_llvm product is_cross_compiling )
6
+ macro (swift_common_standalone_build_config_llvm product )
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
-
23
9
# If we already have a cached value for LLVM_ENABLE_ASSERTIONS, save the value.
24
- if (DEFINED LLVM_ENABLE_ASSERTIONS )
10
+ if (DEFINED LLVM_ENABLE_ASSERTIONS )
25
11
set (LLVM_ENABLE_ASSERTIONS_saved "${LLVM_ENABLE_ASSERTIONS} " )
26
12
endif ()
27
13
28
14
# Then we import LLVMConfig. This is going to override whatever cached value
29
15
# we have for LLVM_ENABLE_ASSERTIONS.
30
- find_package (LLVM REQUIRED CONFIG
31
- HINTS "${PATH_TO_LLVM_BUILD} " NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH )
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" )
32
23
33
24
# If we did not have a cached value for LLVM_ENABLE_ASSERTIONS, set
34
25
# LLVM_ENABLE_ASSERTIONS_saved to be the ENABLE_ASSERTIONS value from LLVM so
35
26
# we follow LLVMConfig.cmake's value by default if nothing is provided.
36
- if (NOT DEFINED LLVM_ENABLE_ASSERTIONS_saved )
27
+ if (NOT DEFINED LLVM_ENABLE_ASSERTIONS_saved )
37
28
set (LLVM_ENABLE_ASSERTIONS_saved "${LLVM_ENABLE_ASSERTIONS} " )
38
29
endif ()
39
30
@@ -49,11 +40,10 @@ macro(swift_common_standalone_build_config_llvm product is_cross_compiling)
49
40
50
41
precondition (LLVM_TOOLS_BINARY_DIR )
51
42
escape_path_for_xcode ("${LLVM_BUILD_TYPE} " "${LLVM_TOOLS_BINARY_DIR} " LLVM_TOOLS_BINARY_DIR )
43
+
52
44
precondition_translate_flag (LLVM_BUILD_LIBRARY_DIR LLVM_LIBRARY_DIR )
53
45
escape_path_for_xcode ("${LLVM_BUILD_TYPE} " "${LLVM_LIBRARY_DIR} " LLVM_LIBRARY_DIR )
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 )
46
+
57
47
precondition (LLVM_LIBRARY_DIRS )
58
48
escape_path_for_xcode ("${LLVM_BUILD_TYPE} " "${LLVM_LIBRARY_DIRS} " LLVM_LIBRARY_DIRS )
59
49
@@ -64,18 +54,41 @@ macro(swift_common_standalone_build_config_llvm product is_cross_compiling)
64
54
set (LLVM_BINARY_OUTPUT_INTDIR "${LLVM_TOOLS_BINARY_DIR} " )
65
55
set (LLVM_LIBRARY_OUTPUT_INTDIR "${LLVM_LIBRARY_DIR} " )
66
56
67
- if (XCODE )
57
+ if (XCODE )
68
58
fix_imported_targets_for_xcode ("${LLVM_EXPORTED_TARGETS} " )
69
59
endif ()
70
60
71
- if (NOT ${is_cross_compiling} )
61
+ if (NOT CMAKE_CROSSCOMPILING )
72
62
set (${product} _NATIVE_LLVM_TOOLS_PATH "${LLVM_TOOLS_BINARY_DIR} " )
73
63
endif ()
74
64
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}" )
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 ()
79
92
endif ()
80
93
81
94
include (AddLLVM )
@@ -106,7 +119,7 @@ macro(swift_common_standalone_build_config_llvm product is_cross_compiling)
106
119
"${PACKAGE_VERSION_MAJOR} .${PACKAGE_VERSION_MINOR} " CACHE STRING
107
120
"Version number that will be placed into the libclang library , in the form XX.YY" )
108
121
109
- foreach (INCLUDE_DIR ${LLVM_INCLUDE_DIRS} )
122
+ foreach (INCLUDE_DIR ${LLVM_INCLUDE_DIRS} )
110
123
escape_path_for_xcode ("${LLVM_BUILD_TYPE} " "${INCLUDE_DIR} " INCLUDE_DIR )
111
124
include_directories (${INCLUDE_DIR} )
112
125
endforeach ()
@@ -134,52 +147,18 @@ macro(swift_common_standalone_build_config_llvm product is_cross_compiling)
134
147
endif ()
135
148
endmacro ()
136
149
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 )
150
+ macro (swift_common_standalone_build_config_clang product )
151
+ find_package (Clang CONFIG REQUIRED NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH )
160
152
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} )
153
+ if (NOT CMAKE_CROSSCOMPILING )
172
154
set (${product} _NATIVE_CLANG_TOOLS_PATH "${LLVM_TOOLS_BINARY_DIR} " )
173
155
endif ()
174
156
175
- set (CLANG_MAIN_INCLUDE_DIR "${CLANG_MAIN_SRC_DIR} /include" )
176
-
177
- if (XCODE )
157
+ if (XCODE )
178
158
fix_imported_targets_for_xcode ("${CLANG_EXPORTED_TARGETS} " )
179
159
endif ()
180
160
181
- include_directories ("${CLANG_BUILD_INCLUDE_DIR} "
182
- "${CLANG_MAIN_INCLUDE_DIR} " )
161
+ include_directories (${CLANG_INCLUDE_DIRS} )
183
162
endmacro ()
184
163
185
164
macro (swift_common_standalone_build_config_cmark product )
@@ -218,9 +197,9 @@ endmacro()
218
197
#
219
198
# is_cross_compiling
220
199
# Whether this is cross-compiling host tools.
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} )
200
+ macro (swift_common_standalone_build_config product )
201
+ swift_common_standalone_build_config_llvm (${product} )
202
+ swift_common_standalone_build_config_clang (${product} )
224
203
swift_common_standalone_build_config_cmark (${product} )
225
204
226
205
# Enable groups for IDE generators (Xcode and MSVC).
0 commit comments