@@ -3,37 +3,28 @@ include(SwiftXcodeSupport)
33
44include (CheckCXXCompilerFlag)
55
6- macro (swift_common_standalone_build_config_llvm product is_cross_compiling )
6+ macro (swift_common_standalone_build_config_llvm product)
77 option (LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON )
88
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-
239 # 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)
2511 set (LLVM_ENABLE_ASSERTIONS_saved "${LLVM_ENABLE_ASSERTIONS} " )
2612 endif ()
2713
2814 # Then we import LLVMConfig. This is going to override whatever cached value
2915 # 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" )
3223
3324 # If we did not have a cached value for LLVM_ENABLE_ASSERTIONS, set
3425 # LLVM_ENABLE_ASSERTIONS_saved to be the ENABLE_ASSERTIONS value from LLVM so
3526 # 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)
3728 set (LLVM_ENABLE_ASSERTIONS_saved "${LLVM_ENABLE_ASSERTIONS} " )
3829 endif ()
3930
@@ -49,11 +40,10 @@ macro(swift_common_standalone_build_config_llvm product is_cross_compiling)
4940
5041 precondition(LLVM_TOOLS_BINARY_DIR )
5142 escape_path_for_xcode("${LLVM_BUILD_TYPE} " "${LLVM_TOOLS_BINARY_DIR} " LLVM_TOOLS_BINARY_DIR )
43+
5244 precondition_translate_flag(LLVM_BUILD_LIBRARY_DIR LLVM_LIBRARY_DIR)
5345 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+
5747 precondition(LLVM_LIBRARY_DIRS)
5848 escape_path_for_xcode("${LLVM_BUILD_TYPE} " "${LLVM_LIBRARY_DIRS} " LLVM_LIBRARY_DIRS)
5949
@@ -64,18 +54,41 @@ macro(swift_common_standalone_build_config_llvm product is_cross_compiling)
6454 set (LLVM_BINARY_OUTPUT_INTDIR "${LLVM_TOOLS_BINARY_DIR} " )
6555 set (LLVM_LIBRARY_OUTPUT_INTDIR "${LLVM_LIBRARY_DIR} " )
6656
67- if (XCODE)
57+ if (XCODE)
6858 fix_imported_targets_for_xcode("${LLVM_EXPORTED_TARGETS} " )
6959 endif ()
7060
71- if (NOT ${is_cross_compiling} )
61+ if (NOT CMAKE_CROSSCOMPILING )
7262 set (${product} _NATIVE_LLVM_TOOLS_PATH "${LLVM_TOOLS_BINARY_DIR} " )
7363 endif ()
7464
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 ()
7992 endif ()
8093
8194 include (AddLLVM)
@@ -106,7 +119,7 @@ macro(swift_common_standalone_build_config_llvm product is_cross_compiling)
106119 "${PACKAGE_VERSION_MAJOR} .${PACKAGE_VERSION_MINOR} " CACHE STRING
107120 "Version number that will be placed into the libclang library , in the form XX.YY" )
108121
109- foreach (INCLUDE_DIR ${LLVM_INCLUDE_DIRS} )
122+ foreach (INCLUDE_DIR ${LLVM_INCLUDE_DIRS} )
110123 escape_path_for_xcode("${LLVM_BUILD_TYPE} " "${INCLUDE_DIR} " INCLUDE_DIR)
111124 include_directories (${INCLUDE_DIR} )
112125 endforeach ()
@@ -134,52 +147,18 @@ macro(swift_common_standalone_build_config_llvm product is_cross_compiling)
134147 endif ()
135148endmacro ()
136149
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 )
160152
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 )
172154 set (${product} _NATIVE_CLANG_TOOLS_PATH "${LLVM_TOOLS_BINARY_DIR} " )
173155 endif ()
174156
175- set (CLANG_MAIN_INCLUDE_DIR "${CLANG_MAIN_SRC_DIR} /include" )
176-
177- if (XCODE)
157+ if (XCODE)
178158 fix_imported_targets_for_xcode("${CLANG_EXPORTED_TARGETS} " )
179159 endif ()
180160
181- include_directories ("${CLANG_BUILD_INCLUDE_DIR} "
182- "${CLANG_MAIN_INCLUDE_DIR} " )
161+ include_directories (${CLANG_INCLUDE_DIRS} )
183162endmacro ()
184163
185164macro (swift_common_standalone_build_config_cmark product)
@@ -218,9 +197,9 @@ endmacro()
218197#
219198# is_cross_compiling
220199# 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} )
224203 swift_common_standalone_build_config_cmark(${product} )
225204
226205 # Enable groups for IDE generators (Xcode and MSVC).
0 commit comments