Skip to content

Commit c2645d0

Browse files
committed
[cmake] Expand $(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) from all LLVM/Clang imported target locations.
Normally when building in Xcode, Xcode will assume that LLVM/Clang use the same configuration as Swift and will try to pull in the sources from that configuration's build directory. This is incorrect when we are compiling a Release LLVM with a Debug Swift. This commit uses our escaping functionality from 0a48857 and the new imported targets to fix this issue. rdar://27062396
1 parent 0a48857 commit c2645d0

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -384,12 +384,6 @@ if(NOT EXISTS "${CLANG_MAIN_INCLUDE_DIR}/clang/AST/Decl.h")
384384
message(FATAL_ERROR "Clang is missing from llvm/tools subdirectory.")
385385
endif()
386386

387-
# This could be computed using ${CMAKE_CFG_INTDIR} if we want to link Swift
388-
# against a matching LLVM build configuration. However, we usually want to be
389-
# flexible and allow linking a debug Swift against optimized LLVM.
390-
set(LLVM_RUNTIME_OUTPUT_INTDIR "${LLVM_BINARY_DIR}")
391-
set(LLVM_LIBRARY_OUTPUT_INTDIR "${LLVM_LIBRARY_DIR}")
392-
393387
set(SWIFT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
394388
set(SWIFT_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
395389

cmake/modules/SwiftSharedCMakeConfig.cmake

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,29 @@ function(escape_llvm_path_for_xcode path outvar)
4040
set(${outvar} "${path}" PARENT_SCOPE)
4141
endfunction()
4242

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+
4366
macro(swift_common_standalone_build_config_llvm product is_cross_compiling)
4467
option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
4568

@@ -92,6 +115,16 @@ macro(swift_common_standalone_build_config_llvm product is_cross_compiling)
92115
precondition(LLVM_LIBRARY_DIRS)
93116
escape_llvm_path_for_xcode("${LLVM_LIBRARY_DIRS}" LLVM_LIBRARY_DIRS)
94117

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+
95128
if(NOT ${is_cross_compiling})
96129
set(${product}_NATIVE_LLVM_TOOLS_PATH "${LLVM_TOOLS_BINARY_DIR}")
97130
endif()
@@ -181,6 +214,10 @@ macro(swift_common_standalone_build_config_clang product is_cross_compiling)
181214

182215
set(CLANG_MAIN_INCLUDE_DIR "${CLANG_MAIN_SRC_DIR}/include")
183216

217+
if (XCODE)
218+
fix_imported_target_locations_for_xcode("${CLANG_EXPORTED_TARGETS}")
219+
endif()
220+
184221
include_directories("${CLANG_BUILD_INCLUDE_DIR}"
185222
"${CLANG_MAIN_INCLUDE_DIR}")
186223
endmacro()

0 commit comments

Comments
 (0)