Skip to content

Commit 60edee9

Browse files
committed
[cmake] Only add lipo targets for Darwin
Swift's CMake build system creates "fat" binaries for Swift libraries, so long as the host machine used to compile the libraries is a macOS machine. However, when a non-Darwin target, such as Android, is being compiled on a macOS host, this doesn't work. Instead, only add lipo targets if the *target* is Darwin.
1 parent 66da45b commit 60edee9

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,12 +357,15 @@ endfunction()
357357
#
358358
# Usage:
359359
# _add_swift_lipo_target(
360+
# sdk # The name of the SDK the target was created for.
361+
# # Examples include "OSX", "IOS", "ANDROID", etc.
360362
# target # The name of the target to create
361363
# output # The file to be created by this target
362364
# source_targets... # The source targets whose outputs will be
363365
# # lipo'd into the output.
364366
# )
365-
function(_add_swift_lipo_target target output)
367+
function(_add_swift_lipo_target sdk target output)
368+
precondition(sdk MESSAGE "sdk is required")
366369
precondition(target MESSAGE "target is required")
367370
precondition(output MESSAGE "output is required")
368371

@@ -381,7 +384,8 @@ function(_add_swift_lipo_target target output)
381384
endif()
382385
endforeach()
383386

384-
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
387+
is_darwin_based_sdk("${sdk}" IS_DARWIN)
388+
if(IS_DARWIN)
385389
# Use lipo to create the final binary.
386390
add_custom_command_target(unused_var
387391
COMMAND "${LIPO}" "-create" "-output" "${output}" ${source_binaries}
@@ -1456,6 +1460,7 @@ function(add_swift_library name)
14561460
endif()
14571461

14581462
_add_swift_lipo_target(
1463+
${sdk}
14591464
${lipo_target}${unsigned}
14601465
"${UNIVERSAL_LIBRARY_NAME}${unsigned}"
14611466
${THIN_INPUT_TARGETS})
@@ -1518,6 +1523,7 @@ function(add_swift_library name)
15181523
set(UNIVERSAL_LIBRARY_NAME
15191524
"${SWIFTSTATICLIB_DIR}/${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${name}${CMAKE_STATIC_LIBRARY_SUFFIX}")
15201525
_add_swift_lipo_target(
1526+
${sdk}
15211527
${lipo_target_static}
15221528
"${UNIVERSAL_LIBRARY_NAME}"
15231529
${THIN_INPUT_TARGETS_STATIC})

0 commit comments

Comments
 (0)