Xcode: build-time environment
I have a project which targets iOS (among other things), but needs to also generate an executable for the host to run during compilation. I achieve this with add_custom_command
as follows, that generates a second config for the host to build and run:
add_custom_command(
PRE_BUILD
WORKING_DIRECTORY ${TOOLS_DIR}
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/deps/RGL/CMakeLists.txt"
COMMAND ${CMAKE_COMMAND} ${CC_GENERATOR} -DCMAKE_BUILD_TYPE=Release ${HT_ENABLE_WGSL} "${CMAKE_CURRENT_SOURCE_DIR}/deps/RGL"
OUTPUT "${TOOLS_DIR}/CMakeCache.txt"
)
and I generate the top-level Xcode project by setting -DCMAKE_SYSTEM_NAME=iOS
on the command line.
However, this causes the add_custom_command
to generate an iOS Xcode project, causing a failure when the host tries to run the resulting binary. I added a command in the subproject to print the environment variables that CMake is receiving, like this:
execute_process(COMMAND "${CMAKE_COMMAND}" "-E" "environment")
which showed that something is setting some environment variables when it invokes the custom command:
TARGET_DEVICE_OS_VERSION=17.0
TARGET_DEVICE_PLATFORM_NAME=iphonesimulator
...
DEVELOPER_SDK_DIR=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs
I want the custom command to have a "stock" environment, similar to if I invoked it from a fresh shell. Is this possible to do with add_custom_command
?