Xcode: TARGET_FILE, TARGET_BUNDLE_DIR, incorrect in POST_BUILD when using CMAKE_SYSTEM_NAME=iOS
The generator expressions $<TARGET_FILE:tgt> and $<TARGET_BUNDLE_DIR:tgt> return an incorrect path when used with cross compilation to iOS, when used as a POST_BUILD event. This issue is very similar than #20938 yet very different result.
Take the following very simple CMake file
cmake_minimum_required(VERSION 3.24)
project(Test LANGUAGES CXX VERSION 1.0.0.1)
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO")
add_executable(Test MACOSX_BUNDLE test.cpp)
add_custom_command(
TARGET Test
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "############ Target file: $<TARGET_FILE:Test>"
COMMAND ${CMAKE_COMMAND} -E echo "############ Target bundle dir: $<TARGET_BUNDLE_DIR:Test>"
VERBATIM
)
No cross-compilation
- Generate the solution like this:
cmake -H. -B_build -GXcode
- Go to _build and run
cmake --build .
- The output will correctly give:
- The full path to the file:
/.../_build/Debug/Test.app/test
- The full path to the bundle:
/.../_build/Debug/Test.app
- The full path to the file:
With iOS cross-compilation
- Generate the solution with iOS cross-compilation:
cmake -H. -B_build -GXcode -DCMAKE_SYSTEM_NAME=iOS
- Go to _build and run
cmake --build
- The output will give paths containing an unexpanded variable:
- File:
/.../_build/Debug${EFFECTIVE_PLATFORM_NAME}/Test.app/test
- Bundle:
/.../_build/Debug${EFFECTIVE_PLATFORM_NAME}/Test.app
- File:
All commands that rely on the generation expression TARGET_NAME or TARGET_BUNDLE_DIR thus fail to find the binary (like copy_directory or such).
(I think it's best to keep both my reported issues as the use cases are different, maybe it's possible to link/relate them or something equivalent)