Skip to content

Commit f03cd0e

Browse files
committed
build: convert out parameter to target
Rework `_add_host_variant_c_compile_link_flags` to apply the flags directly rather than to compute the value and have the caller apply.
1 parent 9c8be74 commit f03cd0e

File tree

1 file changed

+11
-28
lines changed

1 file changed

+11
-28
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,8 @@ function(is_darwin_based_sdk sdk_name out_var)
7777
endfunction()
7878

7979
# Usage:
80-
# _add_host_variant_c_compile_link_flags(
81-
# RESULT_VAR_NAME result_var_name
82-
# )
83-
function(_add_host_variant_c_compile_link_flags)
84-
set(oneValueArgs RESULT_VAR_NAME)
85-
cmake_parse_arguments(CFLAGS
86-
""
87-
"${oneValueArgs}"
88-
""
89-
${ARGN})
90-
91-
set(result ${${CFLAGS_RESULT_VAR_NAME}})
92-
80+
# _add_host_variant_c_compile_link_flags(name)
81+
function(_add_host_variant_c_compile_link_flags name)
9382
is_darwin_based_sdk("${SWIFT_HOST_VARIANT_SDK}" IS_DARWIN)
9483
if(IS_DARWIN)
9584
set(DEPLOYMENT_VERSION "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_DEPLOYMENT_VERSION}")
@@ -100,49 +89,45 @@ function(_add_host_variant_c_compile_link_flags)
10089
get_target_triple(target target_variant "${SWIFT_HOST_VARIANT_SDK}" "${SWIFT_HOST_VARIANT_ARCH}"
10190
MACCATALYST_BUILD_FLAVOR ""
10291
DEPLOYMENT_VERSION "${DEPLOYMENT_VERSION}")
103-
list(APPEND result "-target" "${target}")
92+
target_compile_options(${name} PRIVATE -target;${target})
10493
endif()
10594

10695
set(_sysroot
10796
"${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_PATH}")
10897
if(IS_DARWIN)
109-
list(APPEND result "-isysroot" "${_sysroot}")
98+
target_compile_options(${name} PRIVATE -isysroot;${_sysroot})
11099
elseif(NOT SWIFT_COMPILER_IS_MSVC_LIKE AND NOT "${_sysroot}" STREQUAL "/")
111-
list(APPEND result "--sysroot=${_sysroot}")
100+
target_compile_options(${name} PRIVATE --sysroot=${_sysroot})
112101
endif()
113102

114103
if(SWIFT_HOST_VARIANT_SDK STREQUAL ANDROID)
115104
# lld can handle targeting the android build. However, if lld is not
116105
# enabled, then fallback to the linker included in the android NDK.
117106
if(NOT SWIFT_ENABLE_LLD_LINKER)
118107
swift_android_tools_path(${SWIFT_HOST_VARIANT_ARCH} tools_path)
119-
list(APPEND result "-B" "${tools_path}")
108+
target_compile_options(${name} PRIVATE -B${tools_path})
120109
endif()
121110
endif()
122111

123112
if(IS_DARWIN)
124113
# We collate -F with the framework path to avoid unwanted deduplication
125114
# of options by target_compile_options -- this way no undesired
126115
# side effects are introduced should a new search path be added.
127-
list(APPEND result
128-
"-arch" "${SWIFT_HOST_VARIANT_ARCH}"
116+
target_compile_options(${name} PRIVATE
117+
-arch ${SWIFT_HOST_VARIANT_ARCH}
129118
"-F${SWIFT_SDK_${SWIFT_HOST_VARIANT_ARCH}_PATH}/../../../Developer/Library/Frameworks"
130119
"-m${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_VERSION_MIN_NAME}-version-min=${DEPLOYMENT_VERSION}")
131120
endif()
132121

133122
_compute_lto_flag("${SWIFT_TOOLS_ENABLE_LTO}" _lto_flag_out)
134123
if (_lto_flag_out)
135-
list(APPEND result "${_lto_flag_out}")
124+
target_compile_options(${name} PRIVATE ${_lto_flag_out})
136125
endif()
137-
138-
set("${CFLAGS_RESULT_VAR_NAME}" "${result}" PARENT_SCOPE)
139126
endfunction()
140127

141128

142129
function(_add_host_variant_c_compile_flags target)
143-
_add_host_variant_c_compile_link_flags(RESULT_VAR_NAME result)
144-
target_compile_options(${target} PRIVATE
145-
${result})
130+
_add_host_variant_c_compile_link_flags(${target})
146131

147132
is_build_type_optimized("${CMAKE_BUILD_TYPE}" optimized)
148133
if(optimized)
@@ -305,9 +290,7 @@ function(_add_host_variant_c_compile_flags target)
305290
endfunction()
306291

307292
function(_add_host_variant_link_flags target)
308-
_add_host_variant_c_compile_link_flags(RESULT_VAR_NAME result)
309-
target_link_options(${target} PRIVATE
310-
${result})
293+
_add_host_variant_c_compile_link_flags(${target})
311294

312295
if(SWIFT_HOST_VARIANT_SDK STREQUAL LINUX)
313296
target_link_libraries(${target} PRIVATE

0 commit comments

Comments
 (0)