Skip to content

Commit b42b7f4

Browse files
committed
[cmake] Combine apply_xcode_substitutions and escape_llvm_path_for_xcode into a better escape_path_for_xcode that can be reused across cmake.
1 parent 455d3a1 commit b42b7f4

File tree

3 files changed

+14
-27
lines changed

3 files changed

+14
-27
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ function(_add_swift_library_single target name)
678678

679679
foreach(config ${CMAKE_CONFIGURATION_TYPES})
680680
string(TOUPPER ${config} config_upper)
681-
apply_xcode_substitutions("${config}" "${SWIFTLIB_DIR}" config_lib_dir)
681+
escape_path_for_xcode("${config}" "${SWIFTLIB_DIR}" config_lib_dir)
682682
set_target_properties(${target} PROPERTIES
683683
LIBRARY_OUTPUT_DIRECTORY_${config_upper} ${config_lib_dir}/${SWIFTLIB_SINGLE_SUBDIR}
684684
ARCHIVE_OUTPUT_DIRECTORY_${config_upper} ${config_lib_dir}/${SWIFTLIB_SINGLE_SUBDIR})
@@ -732,7 +732,7 @@ function(_add_swift_library_single target name)
732732

733733
foreach(config ${CMAKE_CONFIGURATION_TYPES})
734734
string(TOUPPER ${config} config_upper)
735-
apply_xcode_substitutions(
735+
escape_path_for_xcode(
736736
"${config}" "${SWIFTSTATICLIB_DIR}" config_lib_dir)
737737
set_target_properties(${target_static} PROPERTIES
738738
LIBRARY_OUTPUT_DIRECTORY_${config_upper} ${config_lib_dir}/${SWIFTLIB_SINGLE_SUBDIR}

cmake/modules/SwiftSharedCMakeConfig.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ macro(swift_common_standalone_build_config_llvm product is_cross_compiling)
5757
mark_as_advanced(LLVM_ENABLE_ASSERTIONS)
5858

5959
precondition(LLVM_TOOLS_BINARY_DIR)
60-
escape_llvm_path_for_xcode("${LLVM_TOOLS_BINARY_DIR}" LLVM_TOOLS_BINARY_DIR)
60+
escape_path_for_xcode("${LLVM_BUILD_TYPE}" "${LLVM_TOOLS_BINARY_DIR}" LLVM_TOOLS_BINARY_DIR)
6161
precondition_translate_flag(LLVM_BUILD_LIBRARY_DIR LLVM_LIBRARY_DIR)
62-
escape_llvm_path_for_xcode("${LLVM_LIBRARY_DIR}" LLVM_LIBRARY_DIR)
62+
escape_path_for_xcode("${LLVM_BUILD_TYPE}" "${LLVM_LIBRARY_DIR}" LLVM_LIBRARY_DIR)
6363
precondition_translate_flag(LLVM_BUILD_MAIN_INCLUDE_DIR LLVM_MAIN_INCLUDE_DIR)
6464
precondition_translate_flag(LLVM_BUILD_BINARY_DIR LLVM_BINARY_DIR)
6565
precondition_translate_flag(LLVM_BUILD_MAIN_SRC_DIR LLVM_MAIN_SRC_DIR)
6666
precondition(LLVM_LIBRARY_DIRS)
67-
escape_llvm_path_for_xcode("${LLVM_LIBRARY_DIRS}" LLVM_LIBRARY_DIRS)
67+
escape_path_for_xcode("${LLVM_BUILD_TYPE}" "${LLVM_LIBRARY_DIRS}" LLVM_LIBRARY_DIRS)
6868

6969
# This could be computed using ${CMAKE_CFG_INTDIR} if we want to link Swift
7070
# against a matching LLVM build configuration. However, we usually want to be
@@ -102,7 +102,7 @@ macro(swift_common_standalone_build_config_llvm product is_cross_compiling)
102102
"Version number that will be placed into the libclang library , in the form XX.YY")
103103

104104
foreach (INCLUDE_DIR ${LLVM_INCLUDE_DIRS})
105-
escape_llvm_path_for_xcode("${INCLUDE_DIR}" INCLUDE_DIR)
105+
escape_path_for_xcode("${LLVM_BUILD_TYPE}" "${INCLUDE_DIR}" INCLUDE_DIR)
106106
include_directories(${INCLUDE_DIR})
107107
endforeach ()
108108

cmake/modules/SwiftXcodeSupport.cmake

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
# This file contains cmake configuration specifically related to support for the
22
# Xcode generator in CMake.
33

4-
function(apply_xcode_substitutions config path result_var_name)
5-
# Hack to deal with the fact that paths contain the build-time
6-
# variables. Note that this fix is Xcode-specific.
7-
string(REPLACE "$(CONFIGURATION)" "${config}" result "${path}")
8-
string(REPLACE "$(EFFECTIVE_PLATFORM_NAME)" "" result "${result}")
9-
10-
set("${result_var_name}" "${result}" PARENT_SCOPE)
11-
endfunction()
12-
134
function(get_effective_platform_for_triple triple output)
145
string(FIND "${triple}" "macos" IS_MACOS)
156
if (IS_MACOS)
@@ -19,23 +10,19 @@ function(get_effective_platform_for_triple triple output)
1910
message(FATAL_ERROR "Not supported")
2011
endfunction()
2112

22-
# Eliminate $(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) from a path.
23-
#
24-
# We do not support compiling llvm with an Xcode setting beyond the one that was
25-
# used with build-script. This allows us to remove those paths. Right now,
26-
# nothing here is tested for cross compiling with Xcode, but it is in principal
27-
# possible.
28-
function(escape_llvm_path_for_xcode path outvar)
29-
# First check if we are using Xcode. If not, return early.
13+
function(escape_path_for_xcode config path result_var_name)
14+
# If we are not using the Xcode generator, be defensive and early exit.
3015
if (NOT XCODE)
31-
set(${outvar} "${path}" PARENT_SCOPE)
16+
set(${result_var_name} "${path}" PARENT_SCOPE)
3217
return()
3318
endif()
3419

3520
get_effective_platform_for_triple("${SWIFT_HOST_TRIPLE}" SWIFT_EFFECTIVE_PLATFORM_NAME)
36-
string(REPLACE "$(CONFIGURATION)" "${LLVM_BUILD_TYPE}" path "${path}")
37-
string(REPLACE "$(EFFECTIVE_PLATFORM_NAME)" "${SWIFT_EFFECTIVE_PLATFORM_NAME}" path "${path}")
38-
set(${outvar} "${path}" PARENT_SCOPE)
21+
# Hack to deal with the fact that paths contain the build-time
22+
# variables. Note that this fix is Xcode-specific.
23+
string(REPLACE "$(CONFIGURATION)" "${config}" result "${path}")
24+
string(REPLACE "$(EFFECTIVE_PLATFORM_NAME)" "${SWIFT_EFFECTIVE_PLATFORM_NAME}" result "${result}")
25+
set("${result_var_name}" "${result}" PARENT_SCOPE)
3926
endfunction()
4027

4128
function(get_imported_library_prefix outvar target prefix)

0 commit comments

Comments
 (0)