[CMAKE] Add Plist creation to swiftCore (#77960)

* update Resync to copy plist template

* include Plist in linked library for Darwin platforms

* only embedd plist on apple platforms

* formatting fix
This commit is contained in:
Justice Adams
2024-12-17 15:49:54 -08:00
committed by GitHub
parent a7dcab5045
commit 4666a418e0
4 changed files with 47 additions and 0 deletions

View File

@@ -68,6 +68,7 @@ include(DefaultSettings)
include(EmitSwiftInterface)
include(PlatformInfo)
include(gyb)
include(Plist)
include("${SwiftCore_VENDOR_MODULE_DIR}/Settings.cmake" OPTIONAL)

View File

@@ -0,0 +1,31 @@
function(generate_plist project_name project_version target)
set(PLIST_INFO_PLIST "Info.plist")
set(PLIST_INFO_NAME "${project_name}")
# Underscores aren't permitted in the bundle identifier.
string(REPLACE "_" "" PLIST_INFO_UTI "com.apple.dt.runtime.${PLIST_INFO_NAME}")
set(PLIST_INFO_VERSION "${project_version}")
set(PLIST_INFO_BUILD_VERSION "${project_version}")
set(PLIST_INFO_PLIST_OUT "${PLIST_INFO_PLIST}")
set(PLIST_INFO_PLIST_IN "${PROJECT_SOURCE_DIR}/${PLIST_INFO_PLIST}.in")
if(APPLE)
target_link_options(${target} PRIVATE
"SHELL:-Xlinker -sectcreate -Xlinker __TEXT -Xlinker __info_plist -Xlinker ${CMAKE_CURRENT_BINARY_DIR}/${PLIST_INFO_PLIST_OUT}")
endif()
configure_file(
"${PLIST_INFO_PLIST_IN}"
"${PLIST_INFO_PLIST_OUT}"
@ONLY
NEWLINE_STYLE UNIX)
set_property(TARGET ${target} APPEND PROPERTY LINK_DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${PLIST_INFO_PLIST_OUT}")
# If Application Extensions are enabled, pass the linker flag marking
# the dylib as safe.
if (CXX_SUPPORTS_FAPPLICATION_EXTENSION AND (NOT DISABLE_APPLICATION_EXTENSION))
list(APPEND link_flags "-Wl,-application_extension")
endif()
endfunction()

View File

@@ -347,6 +347,9 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/Swift.swiftmodule"
emit_swift_interface(swiftCore)
install_swift_interface(swiftCore)
# Configure plist creation for Darwin platforms.
generate_plist("${CMAKE_PROJECT_NAME}" "${CMAKE_PROJECT_VERSION}" swiftCore)
include("${SwiftCore_VENDOR_MODULE_DIR}/swiftCore.cmake" OPTIONAL)
# TODO: Embedded SwiftCore builds

View File

@@ -59,6 +59,18 @@ copy_library_sources(include "" "Core")
# Copy magic linker symbols
copy_library_sources("linker-support" "" "Core")
# Copy Plist
message(STATUS "plist[${StdlibSources}/Info.plist.in] -> Core/Info.plist.in")
file(COPY_FILE
"${StdlibSources}/Info.plist.in" # From
"${CMAKE_CURRENT_LIST_DIR}/Core/Info.plist.in" # To
RESULT _output
ONLY_IF_DIFFERENT)
if(_output)
message(SEND_ERROR
"Copy ${StdlibSources}/Info.plist.in] -> Core/Info.plist.in Failed: ${_output}")
endif()
set(CoreLibs
LLVMSupport
SwiftShims