Skip to content

Commit cfbd5c3

Browse files
author
Chris B
authored
Merge pull request #5181 from llvm-beanz/fix-codesign-dep-take2
[CMake] Fix codesign dependency (take 2)
2 parents 114d836 + 2dae432 commit cfbd5c3

File tree

1 file changed

+34
-25
lines changed

1 file changed

+34
-25
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -388,12 +388,20 @@ endfunction()
388388
# source_targets... # The source targets whose outputs will be
389389
# # lipo'd into the output.
390390
# )
391-
function(_add_swift_lipo_target sdk target output)
392-
precondition(sdk MESSAGE "sdk is required")
393-
precondition(target MESSAGE "target is required")
394-
precondition(output MESSAGE "output is required")
391+
function(_add_swift_lipo_target)
392+
cmake_parse_arguments(
393+
LIPO # prefix
394+
"CODESIGN" # options
395+
"SDK;TARGET;OUTPUT" # single-value args
396+
"" # multi-value args
397+
${ARGN})
398+
399+
precondition(LIPO_SDK MESSAGE "sdk is required")
400+
precondition(LIPO_TARGET MESSAGE "target is required")
401+
precondition(LIPO_OUTPUT MESSAGE "output is required")
402+
precondition(LIPO_UNPARSED_ARGUMENTS MESSAGE "one or more inputs are required")
395403

396-
set(source_targets ${ARGN})
404+
set(source_targets ${LIPO_UNPARSED_ARGUMENTS})
397405

398406
# Gather the source binaries.
399407
set(source_binaries)
@@ -408,20 +416,24 @@ function(_add_swift_lipo_target sdk target output)
408416
endif()
409417
endforeach()
410418

411-
is_darwin_based_sdk("${sdk}" IS_DARWIN)
419+
is_darwin_based_sdk("${LIPO_SDK}" IS_DARWIN)
412420
if(IS_DARWIN)
421+
if(LIPO_CODESIGN)
422+
set(codesign_command COMMAND "codesign" "-f" "-s" "-" "${LIPO_OUTPUT}")
423+
endif()
413424
# Use lipo to create the final binary.
414425
add_custom_command_target(unused_var
415-
COMMAND "${LIPO}" "-create" "-output" "${output}" ${source_binaries}
416-
CUSTOM_TARGET_NAME "${target}"
417-
OUTPUT "${output}"
426+
COMMAND "${LIPO}" "-create" "-output" "${LIPO_OUTPUT}" ${source_binaries}
427+
${codesign_command}
428+
CUSTOM_TARGET_NAME "${LIPO_TARGET}"
429+
OUTPUT "${LIPO_OUTPUT}"
418430
DEPENDS ${source_targets})
419431
else()
420432
# We don't know how to create fat binaries for other platforms.
421433
add_custom_command_target(unused_var
422-
COMMAND "${CMAKE_COMMAND}" "-E" "copy" "${source_binaries}" "${output}"
423-
CUSTOM_TARGET_NAME "${target}"
424-
OUTPUT "${output}"
434+
COMMAND "${CMAKE_COMMAND}" "-E" "copy" "${source_binaries}" "${LIPO_OUTPUT}"
435+
CUSTOM_TARGET_NAME "${LIPO_TARGET}"
436+
OUTPUT "${LIPO_OUTPUT}"
425437
DEPENDS ${source_targets})
426438
endif()
427439
endfunction()
@@ -1473,18 +1485,15 @@ function(add_swift_library name)
14731485
endif()
14741486

14751487
set(lipo_target "${name}-${SWIFT_SDK_${sdk}_LIB_SUBDIR}")
1476-
_add_swift_lipo_target(
1477-
${sdk}
1478-
${lipo_target}
1479-
${UNIVERSAL_LIBRARY_NAME}
1480-
${THIN_INPUT_TARGETS})
1481-
14821488
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin" AND SWIFTLIB_SHARED)
1483-
# Ad-hoc sign stdlib dylibs
1484-
add_custom_command(TARGET "${name}-${SWIFT_SDK_${sdk}_LIB_SUBDIR}"
1485-
POST_BUILD
1486-
COMMAND "codesign" "-f" "-s" "-" "${UNIVERSAL_LIBRARY_NAME}")
1489+
set(codesign_arg CODESIGN)
14871490
endif()
1491+
_add_swift_lipo_target(
1492+
SDK ${sdk}
1493+
TARGET ${lipo_target}
1494+
OUTPUT ${UNIVERSAL_LIBRARY_NAME}
1495+
${codesign_arg}
1496+
${THIN_INPUT_TARGETS})
14881497

14891498
# Cache universal libraries for dependency purposes
14901499
set(UNIVERSAL_LIBRARY_NAMES_${SWIFT_SDK_${sdk}_LIB_SUBDIR}
@@ -1534,9 +1543,9 @@ function(add_swift_library name)
15341543
set(UNIVERSAL_LIBRARY_NAME
15351544
"${SWIFTSTATICLIB_DIR}/${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${name}${CMAKE_STATIC_LIBRARY_SUFFIX}")
15361545
_add_swift_lipo_target(
1537-
${sdk}
1538-
${lipo_target_static}
1539-
"${UNIVERSAL_LIBRARY_NAME}"
1546+
SDK ${sdk}
1547+
TARGET ${lipo_target_static}
1548+
OUTPUT "${UNIVERSAL_LIBRARY_NAME}"
15401549
${THIN_INPUT_TARGETS_STATIC})
15411550
swift_install_in_component("${SWIFTLIB_INSTALL_IN_COMPONENT}"
15421551
FILES "${UNIVERSAL_LIBRARY_NAME}"

0 commit comments

Comments
 (0)