Skip to content

Commit 0a48857

Browse files
committed
[cmake] Expand $(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) in LLVM CMake paths.
In order to support swapping build types without reconfiguring, Swift's CMake generated Xcode project has one directory for each cmake build type. This behavior is implemented by placing in variables for Xcode to expand at build time. This causes issues with our build, namely that our cmake scripts like to "poke" around the LLVM build directory at configure time. Since the xcode variables from the commit title are not expanded, failures occur since the unexpanded paths do not exist. This patch fixes this problem by expanding out those variables at configure time from specific LLVM paths. This is essentially tieing LLVM to the specific build-script build mode used. This is reasonable since we do not support building in Xcode for configurations that were not selected at build-script time. rdar://27062396
1 parent 523312e commit 0a48857

File tree

1 file changed

+42
-10
lines changed

1 file changed

+42
-10
lines changed

cmake/modules/SwiftSharedCMakeConfig.cmake

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,34 @@ else()
1212
set(cmake_3_2_USES_TERMINAL USES_TERMINAL)
1313
endif()
1414

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+
1543
macro(swift_common_standalone_build_config_llvm product is_cross_compiling)
1644
option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
1745

@@ -55,20 +83,23 @@ macro(swift_common_standalone_build_config_llvm product is_cross_compiling)
5583
mark_as_advanced(LLVM_ENABLE_ASSERTIONS)
5684

5785
precondition(LLVM_TOOLS_BINARY_DIR)
86+
escape_llvm_path_for_xcode("${LLVM_TOOLS_BINARY_DIR}" LLVM_TOOLS_BINARY_DIR)
5887
precondition_translate_flag(LLVM_BUILD_LIBRARY_DIR LLVM_LIBRARY_DIR)
88+
escape_llvm_path_for_xcode("${LLVM_LIBRARY_DIR}" LLVM_LIBRARY_DIR)
5989
precondition_translate_flag(LLVM_BUILD_MAIN_INCLUDE_DIR LLVM_MAIN_INCLUDE_DIR)
6090
precondition_translate_flag(LLVM_BUILD_BINARY_DIR LLVM_BINARY_DIR)
6191
precondition_translate_flag(LLVM_BUILD_MAIN_SRC_DIR LLVM_MAIN_SRC_DIR)
92+
precondition(LLVM_LIBRARY_DIRS)
93+
escape_llvm_path_for_xcode("${LLVM_LIBRARY_DIRS}" LLVM_LIBRARY_DIRS)
6294

63-
if(${is_cross_compiling})
64-
find_program(SWIFT_TABLEGEN_EXE "llvm-tblgen" "${${product}_NATIVE_LLVM_TOOLS_PATH}"
65-
NO_DEFAULT_PATH)
66-
if ("${SWIFT_TABLEGEN_EXE}" STREQUAL "SWIFT_TABLEGEN_EXE-NOTFOUND")
67-
message(FATAL_ERROR "Failed to find tablegen in ${${product}_NATIVE_LLVM_TOOLS_PATH}")
68-
endif()
69-
else()
70-
set(SWIFT_TABLEGEN_EXE llvm-tblgen)
71-
set(${product}_NATIVE_LLVM_TOOLS_PATH "${PATH_TO_LLVM_TOOLS_BINARY_DIR}")
95+
if(NOT ${is_cross_compiling})
96+
set(${product}_NATIVE_LLVM_TOOLS_PATH "${LLVM_TOOLS_BINARY_DIR}")
97+
endif()
98+
99+
find_program(SWIFT_TABLEGEN_EXE "llvm-tblgen" "${${product}_NATIVE_LLVM_TOOLS_PATH}"
100+
NO_DEFAULT_PATH)
101+
if ("${SWIFT_TABLEGEN_EXE}" STREQUAL "SWIFT_TABLEGEN_EXE-NOTFOUND")
102+
message(FATAL_ERROR "Failed to find tablegen in ${${product}_NATIVE_LLVM_TOOLS_PATH}")
72103
endif()
73104

74105
include(AddLLVM)
@@ -86,6 +117,7 @@ macro(swift_common_standalone_build_config_llvm product is_cross_compiling)
86117
"Version number that will be placed into the libclang library , in the form XX.YY")
87118

88119
foreach (INCLUDE_DIR ${LLVM_INCLUDE_DIRS})
120+
escape_llvm_path_for_xcode("${INCLUDE_DIR}" INCLUDE_DIR)
89121
include_directories(${INCLUDE_DIR})
90122
endforeach ()
91123

@@ -144,7 +176,7 @@ macro(swift_common_standalone_build_config_clang product is_cross_compiling)
144176
set(CLANG_BUILD_INCLUDE_DIR "${PATH_TO_CLANG_BUILD}/tools/clang/include")
145177

146178
if (NOT ${is_cross_compiling})
147-
set(${product}_NATIVE_CLANG_TOOLS_PATH "${PATH_TO_LLVM_TOOLS_BINARY_DIR}")
179+
set(${product}_NATIVE_CLANG_TOOLS_PATH "${LLVM_TOOLS_BINARY_DIR}")
148180
endif()
149181

150182
set(CLANG_MAIN_INCLUDE_DIR "${CLANG_MAIN_SRC_DIR}/include")

0 commit comments

Comments
 (0)