diff options
| author | Brad King <brad.king@kitware.com> | 2014-05-14 17:58:30 (GMT) |
|---|---|---|
| committer | CMake Topic Stage <kwrobot@kitware.com> | 2014-05-14 17:58:30 (GMT) |
| commit | 2e347eb1837d85c0323b51322f267e69a7bd680f (patch) | |
| tree | 82b82c16576477776c5cbe812a2f0f527d20af2e /Tests/Module/WriteCompilerDetectionHeader | |
| parent | 605eba8439fbad4baff7bee225674b207e9238b4 (diff) | |
| parent | 62a4a67dc54f3b796cd2735b230a863815d932b2 (diff) | |
| download | CMake-2e347eb1837d85c0323b51322f267e69a7bd680f.zip CMake-2e347eb1837d85c0323b51322f267e69a7bd680f.tar.gz CMake-2e347eb1837d85c0323b51322f267e69a7bd680f.tar.bz2 | |
Merge topic 'WriteCompilerDetectionHeader-module'
62a4a67d Add the WriteCompilerDetectionHeader module.
Diffstat (limited to 'Tests/Module/WriteCompilerDetectionHeader')
| -rw-r--r-- | Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt | 79 | ||||
| -rw-r--r-- | Tests/Module/WriteCompilerDetectionHeader/main.cpp | 19 |
2 files changed, 98 insertions, 0 deletions
diff --git a/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt b/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt new file mode 100644 index 0000000..6c5e0be --- /dev/null +++ b/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt @@ -0,0 +1,79 @@ +cmake_minimum_required(VERSION 3.0.0) +project(WriteCompilerDetectionHeader) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +include(WriteCompilerDetectionHeader) + +get_property(cxx_known_features GLOBAL PROPERTY CMAKE_CXX_KNOWN_FEATURES) + +write_compiler_detection_header( + FILE "${CMAKE_CURRENT_BINARY_DIR}/test_compiler_detection.h" + PREFIX TEST + COMPILERS GNU + VERSION 3.1 + PROLOG "// something" + EPILOG "// more" + FEATURES + ${cxx_known_features} +) + +if (NOT CMAKE_CXX_COMPILE_FEATURES) + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp" + "int main(int,char**) { return 0; }\n" + ) + add_executable(WriteCompilerDetectionHeader "${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp") + + include(CheckCXXSourceCompiles) + check_cxx_source_compiles("#include \"${CMAKE_CURRENT_BINARY_DIR}/test_compiler_detection.h\"\nint main() { return 0; }\n" + file_include_works + ) + if (file_include_works) + message(SEND_ERROR "Inclusion of ${CMAKE_CURRENT_BINARY_DIR}/test_compiler_detection.h was expected to cause an error, but did not.") + endif() + return() +endif() + +macro(set_defines target true_defs false_defs) + set(defines) + foreach(def ${true_defs}) + list(APPEND defines ${def}=1) + endforeach() + foreach(def ${false_defs}) + list(APPEND defines ${def}=0) + endforeach() + target_compile_definitions(${target} + PRIVATE + ${defines} + ) +endmacro() + +if (CMAKE_CXX_COMPILER_ID STREQUAL GNU) + # False for C++98 mode. + list(APPEND false_defs EXPECTED_COMPILER_CXX_DELEGATING_CONSTRUCTORS) + list(APPEND false_defs EXPECTED_COMPILER_CXX_VARIADIC_TEMPLATES) +endif() + +add_executable(WriteCompilerDetectionHeader main.cpp) +set_property(TARGET WriteCompilerDetectionHeader PROPERTY CXX_STANDARD 98) +set_defines(WriteCompilerDetectionHeader "${true_defs}" "${false_defs}") + +if(MSVC) + return() # MSVC has only one mode. +endif() + +# Since GNU 4.7 +if (";${CMAKE_CXX_COMPILE_FEATURES};" MATCHES ";cxx_delegating_constructors;") + list(APPEND true_defs EXPECTED_COMPILER_CXX_DELEGATING_CONSTRUCTORS) + list(REMOVE_ITEM false_defs EXPECTED_COMPILER_CXX_DELEGATING_CONSTRUCTORS) +endif() + +# Since GNU 4.4 +if (";${CMAKE_CXX_COMPILE_FEATURES};" MATCHES ";cxx_variadic_templates;") + list(APPEND true_defs EXPECTED_COMPILER_CXX_VARIADIC_TEMPLATES) + list(REMOVE_ITEM false_defs EXPECTED_COMPILER_CXX_VARIADIC_TEMPLATES) +endif() + +add_executable(WriteCompilerDetectionHeader_11 main.cpp) +set_property(TARGET WriteCompilerDetectionHeader_11 PROPERTY CXX_STANDARD 11) +set_defines(WriteCompilerDetectionHeader_11 "${true_defs}" "${false_defs}") diff --git a/Tests/Module/WriteCompilerDetectionHeader/main.cpp b/Tests/Module/WriteCompilerDetectionHeader/main.cpp new file mode 100644 index 0000000..8b4ea52 --- /dev/null +++ b/Tests/Module/WriteCompilerDetectionHeader/main.cpp @@ -0,0 +1,19 @@ + +#include "test_compiler_detection.h" + +#define JOIN_IMPL(A, B) A ## B +#define JOIN(A, B) JOIN_IMPL(A, B) +#define CHECK(FEATURE) (JOIN(TEST_COMPILER_, FEATURE) == JOIN(EXPECTED_COMPILER_, FEATURE)) + +#if !CHECK(CXX_DELEGATING_CONSTRUCTORS) +#error cxx_delegating_constructors expected availability did not match. +#endif + +#if !CHECK(CXX_VARIADIC_TEMPLATES) +#error cxx_variadic_templates expected availability did not match. +#endif + +int main() +{ + return 0; +} |
