Skip to content

Commit b2e91be

Browse files
committed
Skip adding alias targets when they don't exist
The CMake uses the concept of a "primary variant" which isn't necessarily aligned with either the host or target. In some cases, like cross-compiling an iOS compiler toolchain for macosx-arm64, the expected "primary variant" target will be missing and so CMake will fail. We can skip adding the alias since build-script will call the more specific target anyway.
1 parent fbe2ca9 commit b2e91be

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

stdlib/CMakeLists.txt

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,23 @@ function(swift_create_stdlib_targets name variant define_all_alias)
196196
if(NOT define_all_alias)
197197
set(ALL_keyword ALL)
198198
endif()
199-
add_custom_target(${name}${variant}
200-
${ALL_keyword}
201-
DEPENDS
202-
${name}${SWIFT_PRIMARY_VARIANT_SUFFIX}${variant})
203-
set_target_properties(${name}${variant}
204-
PROPERTIES
205-
FOLDER "Swift libraries/Aggregate")
199+
200+
# When cross-compiling host tools for multiple architectures, targeting a
201+
# different SDK, the primary variant is not one of the variants being built,
202+
# so it can't be added as a target here. build-script will invoke the
203+
# more-specific target, so just skip creating this target and warn in case
204+
# someone is using the CMake more directly.
205+
if(TARGET ${name}${SWIFT_PRIMARY_VARIANT_SUFFIX}${variant})
206+
add_custom_target(${name}${variant}
207+
${ALL_keyword}
208+
DEPENDS
209+
${name}${SWIFT_PRIMARY_VARIANT_SUFFIX}${variant})
210+
set_target_properties(${name}${variant}
211+
PROPERTIES
212+
FOLDER "Swift libraries/Aggregate")
213+
else()
214+
message(WARNING "Primary variant is not being built, target ${name}${SWIFT_PRIMARY_VARIANT_SUFFIX}${variant} does not exist, not creating ${name}${variant} alias target.")
215+
endif()
206216
endfunction()
207217

208218
swift_create_stdlib_targets("swift-stdlib" "" TRUE)

0 commit comments

Comments
 (0)