try_compile does not honor own variables


I have a toolchain file that sets a custom CMAKE_SYSTEM_NAME. I also have the Platform/-Files that I need. The problem is that try_compile() cannot see those.

I tried:

cmake_minimum_required(VERSION 3.22)

set ( CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_LIST_DIR}/CMakeModules/toolchain.cmake )

project ( MyProject LANGUAGES C )

include ( CheckIPOSupported )

But still I get:

System is unknown to cmake, create:
Platform/XXX to use this system, please post your config file on so it can be added to cmake

The system itself is not of public interest. More interesting is that I also use --debug-trycompile and the IPO test does NOT have CMAKE_MODULE_PATH in its CMakeCache.txt file (CMakeFiles/_CMakeLTOTest-C/bin/CMakeCache.txt).
This means that CMAKE_TRY_COMPILE_PLATFORM_VARIABLES essentially does not work.
I also tried another variable name and this also does not appear in the try-compile cache file.

Any insights?

Note: These messages come from the try_compile(), not from project() in the main project!

This means that CMAKE_TRY_COMPILE_PLATFORM_VARIABLES essentially does not work.

It is always dangerous to make such definitive statements without carefully considering the question…

CheckIPOSupported relies on the project mode of try_compile command and the documentation of this command clearly states, regarding CMAKE_TRY_COMPILE_PLATFORM_VARIABLES:

This variable is meant for use only in toolchain files and is only honored by the try_compile() command for the source files form, not when given a whole project.

So, it is perfectly normal that your setting is ignored!

Sorry, didn’t wanted to blame anyone. Thanks for solving this mystery :slight_smile:

So what shall we do about the project mode as used in CheckIPOSupported?
Is it feasible to process the CMAKE_TRY_COMPILE_PLATFORM_VARIABLES in the CheckIPOSupported cmake file and ammend the CMAKE_ARGS list?