Custom variable not passed to toolschain file
Seen in cmake version: 3.15.3 and 3.19.0-rc3 (windows x64)
According to the documentation here: https://cmake.org/cmake/help/v3.15/variable/CMAKE_TRY_COMPILE_PLATFORM_VARIABLES.html variables passed with the -D option to cmake are passed to the toolschain file also for the try compile step:
If a user passes -DMY_CUSTOM_VARIABLE=SomeValue to CMake then this setting will be made visible to the toolchain file both for the main project and for test projects generated by the try_compile() command source file signature.
Given these demo files, it does not work as expected:
CMakeLists.txt
cmake_minimum_required(VERSION 3.15)
project(test_project C)
test_toolschain.cmake
if(NOT DEFINED MY_OWN_VAR)
message(FATAL_ERROR "MY OWN VAR NOT DEFINED")
else()
message("ALL GOOD")
endif()
commandline:
mkdir build
cd build
cmake --version
cmake -DCMAKE_TOOLCHAIN_FILE="../test_toolschain.cmake" -DMY_OWN_VAR="test" ..
output:
-- Building for: Visual Studio 15 2017
ALL GOOD
ALL GOOD
-- The C compiler identification is MSVC 19.16.27026.1
-- Detecting C compiler ABI info
CMake Error at D:/git/test_cmake/test_toolschain.cmake:2 (message):
MY OWN VAR NOT DEFINED
Call Stack (most recent call first):
D:/git/test_cmake/build/CMakeFiles/3.19.0-rc3/CMakeSystem.cmake:6 (include)
D:/git/test_cmake/build/CMakeFiles/CMakeTmp/CMakeLists.txt:3 (project)