Xcode: TARGET_FILE incorrect when using CMAKE_SYSTEM_NAME=iOS
The generator expression $<TARGET_FILE:tgt> returns an incorrect path when used with cross compilation to iOS.
Take the following very simple CMake file
cmake_minimum_required(VERSION 3.17.3)
project(test LANGUAGES C CXX VERSION 1.0.0.1)
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO")
add_executable(${PROJECT_NAME} ${PROJECT_NAME}.cpp)
set(TEST_SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/test_$<CONFIG>_script.cmake")
string(APPEND TEST_SCRIPT_CONTENT
"message(\"=============================\")\n"
"message(\"TARGET_FILE: $<TARGET_FILE:${PROJECT_NAME}>\")\n"
"message(\"=============================\")\n"
)
file(GENERATE
OUTPUT ${TEST_SCRIPT}
CONTENT ${TEST_SCRIPT_CONTENT}
)
add_custom_command(TARGET ${PROJECT_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -P ${TEST_SCRIPT}
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
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 the same path but it is incorrect: The output folder is appended with the cross compilation sdk (eg.
Debug-iphoneos
)
All commands that rely on the generation expression TARGET_NAME thus fail to find the binary.
I don't know if this is a cross compilation general issue or just for iOS. Tested with CMake 3.17.3 on macOS.
Edited by Christophe