# try\_compile does not honor own variables

**URL:** <https://discourse.cmake.org/t/try-compile-does-not-honor-own-variables/5386>\
**Category:** Code\
**Created:** [April 6, 2022, 12:17pm UTC](https://discourse.cmake.org/t/try-compile-does-not-honor-own-variables/5386 "2022-04-06T12:17:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)\
**Post date:** [April 6, 2022, 12:17pm UTC](https://discourse.cmake.org/t/try-compile-does-not-honor-own-variables/5386/1 "2022-04-06T12:17:48Z")

</div>

Hi,

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:

```auto
cmake_minimum_required(VERSION 3.22)

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

project ( MyProject LANGUAGES C )

include ( CheckIPOSupported )
check_ipo_supported ( RESULT _IPO_SUPPORTED OUTPUT IPO_SUPPORTED_CHECK_OUTPUT LANGUAGES C )

```

But still I get:

```auto
System is unknown to cmake, create:
Platform/XXX to use this system, please post your config file on discourse.cmake.org 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?

---

<div class="post-metadata">

**Author:** ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)\
**Post date:** [April 6, 2022, 12:23pm UTC](https://discourse.cmake.org/t/try-compile-does-not-honor-own-variables/5386/2 "2022-04-06T12:23:16Z")

</div>

Note: These messages come from the try\_compile(), not from project() in the main project!

---

<div class="post-metadata">

**Author:** ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)\
**Post date:** [April 6, 2022, 1:09pm UTC](https://discourse.cmake.org/t/try-compile-does-not-honor-own-variables/5386/3 "2022-04-06T13:09:36Z")

</div>

> 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!

---

<div class="post-metadata">

**Author:** ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)\
**Post date:** [April 6, 2022, 2:09pm UTC](https://discourse.cmake.org/t/try-compile-does-not-honor-own-variables/5386/4 "2022-04-06T14:09:56Z")

</div>

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

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?
