summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/try_compile/CMP0056.cmake
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2014-12-03 16:02:31 (GMT)
committerBrad King <brad.king@kitware.com>2014-12-03 20:30:22 (GMT)
commit88eb5824da12940e78d57fe254f17f64cdacd659 (patch)
tree24d535cb4d88f076e69c9a85870aaaff3d1204e8 /Tests/RunCMake/try_compile/CMP0056.cmake
parenta4f9b6f0ca9248530b9749b7fa9628053a3f8f98 (diff)
downloadCMake-88eb5824da12940e78d57fe254f17f64cdacd659.zip
CMake-88eb5824da12940e78d57fe254f17f64cdacd659.tar.gz
CMake-88eb5824da12940e78d57fe254f17f64cdacd659.tar.bz2
try_compile: Pass linker flags into test project (#14066)
Copy CMAKE_EXE_LINKER_FLAGS into the test project generated by try_compile, just like we already copy CMAKE_<LANG>_FLAGS. Add CMake Policy CMP0056 to activate this behavior in a compatible way, but do not warn by default when the policy is not set since it will affect all try_compile calls. Extend the RunCMake.try_compile test with a case covering this behavior for each policy setting.
Diffstat (limited to 'Tests/RunCMake/try_compile/CMP0056.cmake')
-rw-r--r--Tests/RunCMake/try_compile/CMP0056.cmake67
1 files changed, 67 insertions, 0 deletions
diff --git a/Tests/RunCMake/try_compile/CMP0056.cmake b/Tests/RunCMake/try_compile/CMP0056.cmake
new file mode 100644
index 0000000..e8d3d4a
--- /dev/null
+++ b/Tests/RunCMake/try_compile/CMP0056.cmake
@@ -0,0 +1,67 @@
+enable_language(C)
+set(obj "${CMAKE_C_OUTPUT_EXTENSION}")
+if(BORLAND)
+ set(pre -)
+endif()
+set(CMAKE_EXE_LINKER_FLAGS ${pre}BADFLAG${obj})
+
+#-----------------------------------------------------------------------------
+message("before try_compile with CMP0056 WARN-default")
+try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+ OUTPUT_VARIABLE out
+ )
+string(REPLACE "\n" "\n " out " ${out}")
+if(NOT RESULT)
+ message(FATAL_ERROR "try_compile failed but should have passed:\n${out}")
+elseif("x${out}" MATCHES "BADFLAG")
+ message(FATAL_ERROR "try_compile output mentions BADFLAG:\n${out}")
+else()
+ message(STATUS "try_compile with CMP0056 WARN-default worked as expected")
+endif()
+message("after try_compile with CMP0056 WARN-default")
+
+#-----------------------------------------------------------------------------
+set(CMAKE_POLICY_WARNING_CMP0056 ON)
+try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+ OUTPUT_VARIABLE out
+ )
+string(REPLACE "\n" "\n " out " ${out}")
+if(NOT RESULT)
+ message(FATAL_ERROR "try_compile failed but should have passed:\n${out}")
+elseif("x${out}" MATCHES "BADFLAG")
+ message(FATAL_ERROR "try_compile output mentions BADFLAG:\n${out}")
+else()
+ message(STATUS "try_compile with CMP0056 WARN-enabled worked as expected")
+endif()
+
+#-----------------------------------------------------------------------------
+cmake_policy(SET CMP0056 OLD)
+try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+ OUTPUT_VARIABLE out
+ )
+string(REPLACE "\n" "\n " out " ${out}")
+if(NOT RESULT)
+ message(FATAL_ERROR "try_compile failed but should have passed:\n${out}")
+elseif("x${out}" MATCHES "BADFLAG")
+ message(FATAL_ERROR "try_compile output mentions BADFLAG:\n${out}")
+else()
+ message(STATUS "try_compile with CMP0056 OLD worked as expected")
+endif()
+
+#-----------------------------------------------------------------------------
+cmake_policy(SET CMP0056 NEW)
+try_compile(RESULT ${CMAKE_CURRENT_BINARY_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/src.c
+ OUTPUT_VARIABLE out
+ )
+string(REPLACE "\n" "\n " out " ${out}")
+if(RESULT)
+ message(FATAL_ERROR "try_compile passed but should have failed:\n${out}")
+elseif(NOT "x${out}" MATCHES "BADFLAG")
+ message(FATAL_ERROR "try_compile did not fail with BADFLAG:\n${out}")
+else()
+ message(STATUS "try_compile with CMP0056 NEW worked as expected")
+endif()