We have a MSVC toolchain at work. In the toolchain we have the following code:
# Define the target system and version
set(CMAKE_SYSTEM_NAME "Windows" CACHE INTERNAL "")
set(CMAKE_SYSTEM_VERSION "10.0.${AMD_WINDOWS_VERSION}.0" CACHE INTERNAL "")
However, this causes us issues since it enables CMAKE_CROSSCOMPILING:
“This variable will be set to true by CMake if the CMAKE_SYSTEM_NAME variable has been set manually (i.e. in a toolchain file or as a cache entry from the cmake command line).”
The reason this is an issue is because it enables the NATIVE builds for our dependency LLVM:
# https://github.com/llvm/llvm-project/blob/main/llvm/CMakeLists.txt
if(CMAKE_CROSSCOMPILING OR (LLVM_OPTIMIZED_TABLEGEN AND (LLVM_ENABLE_ASSERTIONS OR CMAKE_CONFIGURATION_TYPES)))
set(LLVM_USE_HOST_TOOLS ON)
endif()
...
# when crosscompiling import the executable targets from a file
if(LLVM_USE_HOST_TOOLS)
include(CrossCompile)
llvm_create_cross_target(LLVM NATIVE "" Release)
endif(LLVM_USE_HOST_TOOLS)
LLVM will generate a native build if CMAKE_CROSSCOMPILING is set to true.
However, this is unfavorable because it isn’t necessary and drastically increases the configuration/build time for our building situation. Since our CMAKE_SYSTEM_NAME == CMAKE_HOST_SYSTEM_NAME and our CMAKE_SYSTEM_PROCESSOR == CMAKE_HOST_SYSTEM_PROCESSOR.
A possible workaround is to disable the CMAKE_SYSTEM_NAME code setting.
# Define the target system and version
# Commenting out the CMAKE_SYSTEM_NAME
# set(CMAKE_SYSTEM_NAME "Windows" CACHE INTERNAL "")
set(CMAKE_SYSTEM_VERSION "10.0.${AMD_WINDOWS_VERSION}.0" CACHE INTERNAL "")
This way CMAKE_CROSSCOMPILING will be set to FALSE. And LLVM won’t generate native builds.
However, I’m unsure if it’s legal to not specify the CMAKE_SYSTEM_NAME in a toolchain file.