macOS: INTERFACE_SOURCES and bundling resources in consumers
Hi,
I've an INTERFACE
library that needs to copy files into a macOS bundle executable before Xcode codesigning step (POST_BUILD custom command is not an option). I believe the correct way to handle this is to set the INTERFACE_SOURCES
target property and set the source property MACOSX_PACKAGE_LOCATION
for the files I want to be copied into the bundle during Xcode build copy step (which happens before code signing).
Unfortunately set_source_files_properties is scope limited. Also the new DIRECTORY
option is not solving the issue as the interface library has no way of knowing all the folders it will be used in (the library is consumed by other targets).
As an example, consider the following:
cmake_minimum_required(VERSION 3.19)
project(test LANGUAGES CXX VERSION 1.0.0.1)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
# Include definition for an interface library
add_subdirectory(interfaceLib)
## Main app consuming the interface library (possibly in a sub folder)
add_executable(app MACOSX_BUNDLE app.cpp)
target_link_libraries(app PRIVATE interfaceLibrary)
and the interface library script:
## Interface lib
set(INT_FILE_PATH "${CMAKE_CURRENT_LIST_DIR}/myFile.txt")
set_source_files_properties(${INT_FILE_PATH} PROPERTIES MACOSX_PACKAGE_LOCATION MyDataFolder)
add_library(interfaceLibrary INTERFACE IMPORTED GLOBAL)
set_target_properties(interfaceLibrary PROPERTIES INTERFACE_SOURCES "${INT_FILE_PATH}")
Possible fixes:
- add a
PARENT_SCOPE
keyword to set_source_files_properties that will define the source properties to the parent as well (and forward down the tree afterwards) - add a
TARGET_SCOPE
keyword to set_source_files_properties that will define the source properties everywhere the target using this source file is consumed - automatically globally set source properties when they are linked to a target property (maybe it's just MACOSX_PACKAGE_LOCATION that requires this)
Any other possibility? Thanks