|
| 1 | +function(generate_plist project_name project_version target) |
| 2 | + set(PLIST_INFO_PLIST "Info.plist") |
| 3 | + set(PLIST_INFO_NAME "${project_name}") |
| 4 | + |
| 5 | + # Underscores aren't permitted in the bundle identifier. |
| 6 | + string(REPLACE "_" "" PLIST_INFO_UTI "com.apple.dt.runtime.${PLIST_INFO_NAME}") |
| 7 | + set(PLIST_INFO_VERSION "${project_version}") |
| 8 | + set(PLIST_INFO_BUILD_VERSION "${project_version}") |
| 9 | + |
| 10 | + set(PLIST_INFO_PLIST_OUT "${PLIST_INFO_PLIST}") |
| 11 | + set(PLIST_INFO_PLIST_IN "${PROJECT_SOURCE_DIR}/${PLIST_INFO_PLIST}.in") |
| 12 | + |
| 13 | + if(APPLE) |
| 14 | + target_link_options(${target} PRIVATE |
| 15 | + "SHELL:-Xlinker -sectcreate -Xlinker __TEXT -Xlinker __info_plist -Xlinker ${CMAKE_CURRENT_BINARY_DIR}/${PLIST_INFO_PLIST_OUT}") |
| 16 | + endif() |
| 17 | + |
| 18 | + configure_file( |
| 19 | + "${PLIST_INFO_PLIST_IN}" |
| 20 | + "${PLIST_INFO_PLIST_OUT}" |
| 21 | + @ONLY |
| 22 | + NEWLINE_STYLE UNIX) |
| 23 | + |
| 24 | + set_property(TARGET ${target} APPEND PROPERTY LINK_DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${PLIST_INFO_PLIST_OUT}") |
| 25 | + |
| 26 | + # If Application Extensions are enabled, pass the linker flag marking |
| 27 | + # the dylib as safe. |
| 28 | + if (CXX_SUPPORTS_FAPPLICATION_EXTENSION AND (NOT DISABLE_APPLICATION_EXTENSION)) |
| 29 | + list(APPEND link_flags "-Wl,-application_extension") |
| 30 | + endif() |
| 31 | +endfunction() |
| 32 | + |
| 33 | +if(NOT DEFINED CMAKE_MT) |
| 34 | + find_program(CMAKE_MT NAMES mt llvm-mt) |
| 35 | +endif() |
| 36 | + |
| 37 | +function(embed_manifest target) |
| 38 | + get_target_property(_EM_TARGET_TYPE ${target} TYPE) |
| 39 | + if(NOT "${_EM_TARGET_TYPE}" MATCHES "SHARED_LIBRARY|EXECUTABLE") |
| 40 | + return() |
| 41 | + endif() |
| 42 | + |
| 43 | + get_target_property(_EM_BINARY_DIR ${target} BINARY_DIR) |
| 44 | + get_target_property(_EM_NAME ${target} NAME) |
| 45 | + |
| 46 | + # Evaluate variables |
| 47 | + file(CONFIGURE |
| 48 | + OUTPUT ${_EM_BINARY_DIR}/${_EM_NAME}-${PROJECT_VERSION}.1.manifest.in |
| 49 | + CONTENT [[<?xml version="1.0" encoding="utf-8" standalone="yes"?> |
| 50 | +<assembly manifestversion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1"> |
| 51 | + <assemblyIdentity |
| 52 | + name="$<TARGET_NAME:@target@>" |
| 53 | + processorArchitecture="@CMAKE_SYSTEM_PROCESSOR@" |
| 54 | + type="win32" |
| 55 | + version="@PROJECT_VERSION@" /> |
| 56 | + <file name="$<TARGET_FILE_NAME:@target@>" /> |
| 57 | +</assembly>]]) |
| 58 | + # Evaluate generator expression |
| 59 | + file(GENERATE |
| 60 | + OUTPUT ${_EM_BINARY_DIR}/${_EM_NAME}-${PROJECT_VERSION}.1.manifest |
| 61 | + INPUT ${_EM_BINARY_DIR}/${_EM_NAME}-${PROJECT_VERSION}.1.manifest.in) |
| 62 | + |
| 63 | + if(WIN32) |
| 64 | + add_custom_command(TARGET ${target} POST_BUILD |
| 65 | + COMMAND ${CMAKE_MT} -nologo -manifest "${_EM_BINARY_DIR}/${_EM_NAME}-${PROJECT_VERSION}.1.manifest" "-outputresource:$<TARGET_FILE:${target}>;#1") |
| 66 | + endif() |
| 67 | +endfunction() |
0 commit comments