Delay use of CMAKE_GENERATOR_TOOLSET until the CMakeSystem.cmake file has been configured and loaded during the first project() or enable_language() command. This gives the toolchain file named by CMAKE_TOOLCHAIN_FILE a chance to set CMAKE_GENERATOR_TOOLSET. This point is still early enough to set the generator toolset prior to the initialization of any languages that might use the toolset. The cmake::GeneratorToolset member variable remains an indication of what was specified by the -T option or loaded from the cache. It does not need to be updated based on the toolchain file setting. The cmMakefile::TryCompile can still pass cmake::GeneratorToolset into the inner instance because the try-compiled project will do platform and language initialization using the CMakeSystem module configured for the outer project. Extend the RunCMake.GeneratorToolset test with cases that use a toolchain file to set CMAKE_GENERATOR_TOOLSET.
29 lines
896 B
CMake
29 lines
896 B
CMake
include(RunCMake)
|
|
|
|
set(RunCMake_GENERATOR_TOOLSET "")
|
|
run_cmake(NoToolset)
|
|
|
|
if("${RunCMake_GENERATOR}" MATCHES "Visual Studio 1[012]|Xcode" AND NOT XCODE_BELOW_3)
|
|
set(RunCMake_GENERATOR_TOOLSET "Test Toolset")
|
|
run_cmake(TestToolset)
|
|
else()
|
|
set(RunCMake_GENERATOR_TOOLSET "Bad Toolset")
|
|
run_cmake(BadToolset)
|
|
endif()
|
|
|
|
set(RunCMake_GENERATOR_TOOLSET "")
|
|
|
|
set(RunCMake_TEST_OPTIONS -T "Extra Toolset")
|
|
run_cmake(TwoToolsets)
|
|
unset(RunCMake_TEST_OPTIONS)
|
|
|
|
if("${RunCMake_GENERATOR}" MATCHES "Visual Studio 1[012]|Xcode" AND NOT XCODE_BELOW_3)
|
|
set(RunCMake_TEST_OPTIONS -DCMAKE_TOOLCHAIN_FILE=${RunCMake_SOURCE_DIR}/TestToolset-toolchain.cmake)
|
|
run_cmake(TestToolsetToolchain)
|
|
unset(RunCMake_TEST_OPTIONS)
|
|
else()
|
|
set(RunCMake_TEST_OPTIONS -DCMAKE_TOOLCHAIN_FILE=${RunCMake_SOURCE_DIR}/BadToolset-toolchain.cmake)
|
|
run_cmake(BadToolsetToolchain)
|
|
unset(RunCMake_TEST_OPTIONS)
|
|
endif()
|