summaryrefslogtreecommitdiffstats
path: root/Tests/Module/WriteCompilerDetectionHeader
diff options
context:
space:
mode:
authorRolf Eike Beer <eike@sf-mail.de>2017-01-25 19:32:59 (GMT)
committerRolf Eike Beer <eike@sf-mail.de>2017-01-30 18:19:44 (GMT)
commitc8703e9d7b6c3f7ad58429317a6bf75c1e415568 (patch)
treea157ef44e4066cbbe6de035ee350f71c2617fdc2 /Tests/Module/WriteCompilerDetectionHeader
parent0de9c3985004ef802aac97e20b4efde49989794c (diff)
downloadCMake-c8703e9d7b6c3f7ad58429317a6bf75c1e415568.zip
CMake-c8703e9d7b6c3f7ad58429317a6bf75c1e415568.tar.gz
CMake-c8703e9d7b6c3f7ad58429317a6bf75c1e415568.tar.bz2
WCDH: optionally omit error code for unknown compilers or compiler versions
This allows one to generate a header that will basically always work. In case an unknown compiler or compiler version is encountered it simply falls back to the unsupported case.
Diffstat (limited to 'Tests/Module/WriteCompilerDetectionHeader')
-rw-r--r--Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt30
1 files changed, 29 insertions, 1 deletions
diff --git a/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt b/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt
index 8b251d7..9f229f9 100644
--- a/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt
+++ b/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt
@@ -4,6 +4,7 @@ project(WriteCompilerDetectionHeader)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
include(WriteCompilerDetectionHeader)
+include(CheckCXXSourceCompiles)
get_property(cxx_known_features GLOBAL PROPERTY CMAKE_CXX_KNOWN_FEATURES)
get_property(c_known_features GLOBAL PROPERTY CMAKE_C_KNOWN_FEATURES)
@@ -26,7 +27,6 @@ if (NOT CMAKE_CXX_COMPILE_FEATURES AND NOT CMAKE_C_COMPILE_FEATURES)
add_executable(WriteCompilerDetectionHeader "${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp")
if(UNIX OR NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
- include(CheckCXXSourceCompiles)
check_cxx_source_compiles("#include \"${CMAKE_CURRENT_BINARY_DIR}/test_compiler_detection.h\"\nint main() { return 0; }\n"
file_include_works
)
@@ -156,3 +156,31 @@ if (CMAKE_C_COMPILER_ID STREQUAL "GNU"
set_defines(WriteCompilerDetectionHeader_C11_multi "EXPECTED_COMPILER_C_FUNCTION_PROTOTYPES;EXPECTED_COMPILER_C_RESTRICT" "")
target_include_directories(WriteCompilerDetectionHeader_C11_multi PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/compiler_multi_files)
endif()
+
+# test for ALLOW_UNKNOWN_COMPILERS
+
+# use a compiler does not match the current one,
+# so one always hits the fallback code
+if (CMAKE_CXX_COMPILER_ID STREQUAL "SunPro")
+ set(OTHER_CXX "Intel")
+else()
+ set(OTHER_CXX "SunPro")
+endif()
+
+write_compiler_detection_header(
+ FILE "${CMAKE_CURRENT_BINARY_DIR}/test_compiler_detection_allow_unknown.h"
+ PREFIX TEST
+ COMPILERS ${OTHER_CXX}
+ FEATURES cxx_nullptr
+ ALLOW_UNKNOWN_COMPILERS
+)
+
+# intentionally abuse the TEST_NULLPR variable: this will only work
+# with the fallback code.
+check_cxx_source_compiles("#include \"${CMAKE_CURRENT_BINARY_DIR}/test_compiler_detection_allow_unknown.h\"
+int main() {\n int i = TEST_NULLPTR;\n return 0; }\n"
+ file_include_works_allow_unknown
+)
+if (NOT file_include_works_allow_unknown)
+ message(SEND_ERROR "Inclusion of ${CMAKE_CURRENT_BINARY_DIR}/test_compiler_detection_allow_unknown.h was expected to work, but did not.")
+endif()