mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-06 05:40:54 -06:00
Projects use `try_compile` to check if they will be able to compile some particular source code. When a language standard variable like `CMAKE_CXX_STANDARD` is set, then the project intends to compile source code using a compiler mode for that standard. Therefore it makes sense for `try_compile` to use that standard in the test project too. Unfortunately this was not done when support for the `CMAKE_CXX_STANDARD` variable was first implemented. Add a policy to introduce the improved behavior in a compatible way. Closes: #16456
41 lines
1.3 KiB
CMake
41 lines
1.3 KiB
CMake
enable_language(C)
|
|
|
|
set(CMAKE_POLICY_WARNING_CMP0067 ON)
|
|
message("before try_compile with CMP0067 WARN-enabled but no variables")
|
|
try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR}
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src.c
|
|
)
|
|
message("after try_compile with CMP0067 WARN-enabled but no variables")
|
|
set(CMAKE_POLICY_WARNING_CMP0067 OFF)
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
set(CMAKE_C_STANDARD 90)
|
|
|
|
message("before try_compile with CMP0067 WARN-default")
|
|
try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR}
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src.c
|
|
)
|
|
message("after try_compile with CMP0067 WARN-default")
|
|
|
|
set(CMAKE_POLICY_WARNING_CMP0067 ON)
|
|
message("before try_compile with CMP0067 WARN-enabled")
|
|
try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR}
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src.c
|
|
)
|
|
message("after try_compile with CMP0067 WARN-enabled")
|
|
|
|
cmake_policy(SET CMP0067 OLD)
|
|
message("before try_compile with CMP0067 OLD")
|
|
try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR}
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src.c
|
|
)
|
|
message("after try_compile with CMP0067 OLD")
|
|
|
|
cmake_policy(SET CMP0066 NEW)
|
|
message("before try_compile with CMP0067 NEW")
|
|
try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR}
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src.c
|
|
)
|
|
message("after try_compile with CMP0067 NEW")
|