Clarify the Documentation for CMAKE_TRY_COMPILE_PLATFORM_VARIABLES

The documentation for CMAKE_TRY_COMPILE_PLATFORM_VARIABLES states (emphasis mine):

Variables meaningful to CMake, such as CMAKE_<LANG>_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):

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:

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 channel on the Cpplang Slack. ↩︎