Files
CMake/Tests/RunCMake/try_compile/CMP0067.cmake
Brad King f72ba42b7c try_compile: Add policy CMP0067 to honor language standards
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
2016-12-06 08:58:42 -05:00

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")