Generator expressions do not work inside the path with target_sources
I am trying to generate a zip file next to the executable. I am trying to do it like this:
set(outpack "${CMAKE_BINARY_DIR}/$<CONFIGURATION>/${ARGS_TARGET}.rvedata")
add_custom_command(
POST_BUILD
OUTPUT "${outpack}"
DEPENDS ${assets}
COMMENT "Packing resources for ${ARGS_TARGET}"
COMMAND ${CMAKE_COMMAND} -E tar "cfv" "${outpack}" --format=zip ${ARGS_TARGET}
VERBATIM
)
set_source_files_properties("${outpack}" PROPERTIES
MACOSX_PACKAGE_LOCATION Resources
GENERATED TRUE
XCODE_EXPLICIT_FILE_TYPE "archive.ar"
)
target_sources("${ARGS_TARGET}" PUBLIC "${outpack}")
I need to use target_sources
so that on Apple platforms, the zip file is placed within the bundle's Resources
directory. However, this results in the following error:
CMake Error at CMakeLists.txt:75 (add_executable):
Cannot find source file:
/Users/admin/Documents/RavEngine-Samples/build/mac/NOCONFIG/RavEngineSceneViewer.rvedata
Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm .h
.hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .hip .ispc
Call Stack (most recent call first):
CMakeLists.txt:272 (add_sample)
If I change the outpack
variable to any other string that does not include $<CONFIGURATION>
, then CMake does not have an error in generation. However, I need $<CONFIGURATION>
to know which configuration is currently being built inside an IDE. Depending on which configuration is built, different optimization levels are applied to the assets, so I can't use a shared zip in the CMAKE_BINARY_DIR
.