# Clarify the Documentation for CMAKE\_TRY\_COMPILE\_PLATFORM\_VARIABLES

**URL:** <https://discourse.cmake.org/t/clarify-the-documentation-for-cmake-try-compile-platform-variables/14040>\
**Category:** Code\
**Created:** [May 4, 2025, 12:32pm UTC](https://discourse.cmake.org/t/clarify-the-documentation-for-cmake-try-compile-platform-variables/14040 "2025-05-04T12:32:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![trunketh](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/t/b5a626/32.png) [@trunketh](https://discourse.cmake.org/u/trunketh)\
**Post date:** [May 4, 2025, 12:32pm UTC](https://discourse.cmake.org/t/clarify-the-documentation-for-cmake-try-compile-platform-variables/14040/1 "2025-05-04T12:32:36Z")

</div>

The documentation for [`CMAKE_TRY_COMPILE_PLATFORM_VARIABLES`](https://cmake.org/cmake/help/v4.0/variable/CMAKE_TRY_COMPILE_PLATFORM_VARIABLES.html) states (emphasis mine):

> **Variables meaningful to CMake, such as [`CMAKE_<LANG>_FLAGS`](https://cmake.org/cmake/help/v4.0/variable/CMAKE_LANG_FLAGS.html#variable:CMAKE_%3CLANG%3E_FLAGS), are propagated automatically.** The `CMAKE_TRY_COMPILE_PLATFORM_VARIABLES` variable may be set to pass custom variables that are meaningful to a toolchain file. […]

However, it is unclear to me which types of variables are _meaningful_ to CMake such that they are propagated automatically. To illustrate the issue, consider the following example toolchain file ([CE](https://godbolt.org/z/zbzc7qnY5)):

```cmake
function(my_print_variables)
  foreach(var IN LISTS ARGN)
    if(DEFINED "${var}")
      message("${var}=\"${${var}}\"")
    else()
      message("${var}=<UNDEFINED>")
    endif()
  endforeach()
endfunction()

get_property(in_try_compile GLOBAL PROPERTY IN_TRY_COMPILE)
if(in_try_compile)
  my_print_variables(
      CMAKE_SYSTEM_VERSION
      CMAKE_CROSSCOMPILING
      CMAKE_MSVC_RUNTIME_LIBRARY
      CMAKE_CXX_FLAGS)
endif()

set(CMAKE_SYSTEM_VERSION 42)
set(CMAKE_CROSSCOMPILING FALSE)
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)
set(CMAKE_CXX_FLAGS "-Wall")

```

The relevant output is:

```bash
CMAKE_SYSTEM_VERSION=<UNDEFINED>
CMAKE_CROSSCOMPILING=<UNDEFINED>
CMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded"
CMAKE_CXX_FLAGS=<UNDEFINED>

```

From this output, it appears that only `CMAKE_MSVC_RUNTIME_LIBRARY` is propagated automatically, while `CMAKE_CXX_FLAGS` is not—despite the latter being explicitly mentioned in the documentation.\[1\]

* * *

1. This post was cross-posted from the [#cmake](https://cpplang.slack.com/archives/C5Y2GDECX/p1746032217807999) channel on the Cpplang Slack.
