diff options
author | Brad King <brad.king@kitware.com> | 2016-12-07 14:22:22 (GMT) |
---|---|---|
committer | CMake Topic Stage <kwrobot@kitware.com> | 2016-12-07 14:22:22 (GMT) |
commit | a0d64ecf8b9eac29cbfeb7461cf3bcb1688f7aa7 (patch) | |
tree | 99011b6e805e6032e1679d0fa98ecd5f8e846458 /Tests | |
parent | 0478314e13e6d04a0100cc3be4ab84540a8beaa5 (diff) | |
parent | f72ba42b7c643b1b217d1b8f6684cec3289e7201 (diff) | |
download | CMake-a0d64ecf8b9eac29cbfeb7461cf3bcb1688f7aa7.zip CMake-a0d64ecf8b9eac29cbfeb7461cf3bcb1688f7aa7.tar.gz CMake-a0d64ecf8b9eac29cbfeb7461cf3bcb1688f7aa7.tar.bz2 |
Merge topic 'try_compile-lang-std'
f72ba42b try_compile: Add policy CMP0067 to honor language standards
45aa03b9 try_compile: Add options to specify language standards
3bb2051e try_compile: Stop processing when test build system fails to generate
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/RunCMake/CMakeLists.txt | 12 | ||||
-rw-r--r-- | Tests/RunCMake/try_compile/CMP0067-stderr.txt | 25 | ||||
-rw-r--r-- | Tests/RunCMake/try_compile/CMP0067.cmake | 40 | ||||
-rw-r--r-- | Tests/RunCMake/try_compile/CStandard-result.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/try_compile/CStandard-stderr.txt | 7 | ||||
-rw-r--r-- | Tests/RunCMake/try_compile/CStandard.cmake | 7 | ||||
-rw-r--r-- | Tests/RunCMake/try_compile/CStandardGNU.c | 10 | ||||
-rw-r--r-- | Tests/RunCMake/try_compile/CStandardGNU.cmake | 23 | ||||
-rw-r--r-- | Tests/RunCMake/try_compile/CStandardNoDefault.cmake | 9 | ||||
-rw-r--r-- | Tests/RunCMake/try_compile/CxxStandard-result.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/try_compile/CxxStandard-stderr.txt | 7 | ||||
-rw-r--r-- | Tests/RunCMake/try_compile/CxxStandard.cmake | 7 | ||||
-rw-r--r-- | Tests/RunCMake/try_compile/CxxStandardGNU.cmake | 23 | ||||
-rw-r--r-- | Tests/RunCMake/try_compile/CxxStandardGNU.cxx | 11 | ||||
-rw-r--r-- | Tests/RunCMake/try_compile/CxxStandardNoDefault.cmake | 9 | ||||
-rw-r--r-- | Tests/RunCMake/try_compile/RunCMakeTest.cmake | 18 | ||||
-rw-r--r-- | Tests/RunCMake/try_compile/src.cxx | 4 |
17 files changed, 214 insertions, 0 deletions
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index c02b917..1b88d46 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -215,6 +215,18 @@ add_RunCMake_test(project -DCMake_TEST_RESOURCES=${CMake_TEST_RESOURCES}) add_RunCMake_test(return) add_RunCMake_test(set_property) add_RunCMake_test(string) +foreach(var + CMAKE_C_COMPILER_ID + CMAKE_C_COMPILER_VERSION + CMAKE_C_STANDARD_DEFAULT + CMAKE_CXX_COMPILER_ID + CMAKE_CXX_COMPILER_VERSION + CMAKE_CXX_STANDARD_DEFAULT + ) + if(DEFINED ${var}) + list(APPEND try_compile_ARGS -D${var}=${${var}}) + endif() +endforeach() add_RunCMake_test(try_compile) add_RunCMake_test(try_run) add_RunCMake_test(set) diff --git a/Tests/RunCMake/try_compile/CMP0067-stderr.txt b/Tests/RunCMake/try_compile/CMP0067-stderr.txt new file mode 100644 index 0000000..e2677ed --- /dev/null +++ b/Tests/RunCMake/try_compile/CMP0067-stderr.txt @@ -0,0 +1,25 @@ +before try_compile with CMP0067 WARN-enabled but no variables +after try_compile with CMP0067 WARN-enabled but no variables +before try_compile with CMP0067 WARN-default +after try_compile with CMP0067 WARN-default +before try_compile with CMP0067 WARN-enabled +CMake Warning \(dev\) at CMP0067.cmake:[0-9]+ \(try_compile\): + Policy CMP0067 is not set: Honor language standard in try_compile\(\) + source-file signature. Run "cmake --help-policy CMP0067" for policy + details. Use the cmake_policy command to set the policy and suppress this + warning. + + For compatibility with older versions of CMake, try_compile is not honoring + language standard variables in the test project: + + CMAKE_C_STANDARD + +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\) +This warning is for project developers. Use -Wno-dev to suppress it. + +after try_compile with CMP0067 WARN-enabled +before try_compile with CMP0067 OLD +after try_compile with CMP0067 OLD +before try_compile with CMP0067 NEW +after try_compile with CMP0067 NEW diff --git a/Tests/RunCMake/try_compile/CMP0067.cmake b/Tests/RunCMake/try_compile/CMP0067.cmake new file mode 100644 index 0000000..dd05d96 --- /dev/null +++ b/Tests/RunCMake/try_compile/CMP0067.cmake @@ -0,0 +1,40 @@ +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") diff --git a/Tests/RunCMake/try_compile/CStandard-result.txt b/Tests/RunCMake/try_compile/CStandard-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/try_compile/CStandard-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/try_compile/CStandard-stderr.txt b/Tests/RunCMake/try_compile/CStandard-stderr.txt new file mode 100644 index 0000000..209afcc --- /dev/null +++ b/Tests/RunCMake/try_compile/CStandard-stderr.txt @@ -0,0 +1,7 @@ +^CMake Error at .*/Tests/RunCMake/try_compile/CStandard-build/CMakeFiles/CMakeTmp/CMakeLists.txt:[0-9]+ \(add_executable\): + C_STANDARD is set to invalid value '3' ++ +CMake Error at CStandard.cmake:[0-9]+ \(try_compile\): + Failed to generate test project build system. +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/try_compile/CStandard.cmake b/Tests/RunCMake/try_compile/CStandard.cmake new file mode 100644 index 0000000..2849ed4 --- /dev/null +++ b/Tests/RunCMake/try_compile/CStandard.cmake @@ -0,0 +1,7 @@ +enable_language(C) +try_compile(result ${CMAKE_CURRENT_BINARY_DIR} + SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src.c + C_STANDARD 3 + OUTPUT_VARIABLE out + ) +message("try_compile output:\n${out}") diff --git a/Tests/RunCMake/try_compile/CStandardGNU.c b/Tests/RunCMake/try_compile/CStandardGNU.c new file mode 100644 index 0000000..ac26c15 --- /dev/null +++ b/Tests/RunCMake/try_compile/CStandardGNU.c @@ -0,0 +1,10 @@ +#if __STDC_VERSION__ != 199901L +#error "Not GNU C 99 mode!" +#endif +#ifndef __STRICT_ANSI__ +#error "Not GNU C strict ANSI!" +#endif +int main(void) +{ + return 0; +} diff --git a/Tests/RunCMake/try_compile/CStandardGNU.cmake b/Tests/RunCMake/try_compile/CStandardGNU.cmake new file mode 100644 index 0000000..79ae874 --- /dev/null +++ b/Tests/RunCMake/try_compile/CStandardGNU.cmake @@ -0,0 +1,23 @@ +enable_language(C) +try_compile(result ${CMAKE_CURRENT_BINARY_DIR} + SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/CStandardGNU.c + C_STANDARD 99 + C_STANDARD_REQUIRED 1 + C_EXTENSIONS 0 + OUTPUT_VARIABLE out + ) +if(NOT result) + message(FATAL_ERROR "try_compile failed:\n${out}") +endif() + +cmake_policy(SET CMP0067 NEW) +set(CMAKE_C_STANDARD 99) +set(CMAKE_C_STANDARD_REQUIRED 1) +set(CMAKE_C_EXTENSIONS 0) +try_compile(result ${CMAKE_CURRENT_BINARY_DIR} + SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/CStandardGNU.c + OUTPUT_VARIABLE out + ) +if(NOT result) + message(FATAL_ERROR "try_compile failed:\n${out}") +endif() diff --git a/Tests/RunCMake/try_compile/CStandardNoDefault.cmake b/Tests/RunCMake/try_compile/CStandardNoDefault.cmake new file mode 100644 index 0000000..97e72ea --- /dev/null +++ b/Tests/RunCMake/try_compile/CStandardNoDefault.cmake @@ -0,0 +1,9 @@ +enable_language(C) +try_compile(result ${CMAKE_CURRENT_BINARY_DIR} + SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src.c + C_STANDARD 3 # bogus, but not used + OUTPUT_VARIABLE out + ) +if(NOT result) + message(FATAL_ERROR "try_compile failed:\n${out}") +endif() diff --git a/Tests/RunCMake/try_compile/CxxStandard-result.txt b/Tests/RunCMake/try_compile/CxxStandard-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/try_compile/CxxStandard-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/try_compile/CxxStandard-stderr.txt b/Tests/RunCMake/try_compile/CxxStandard-stderr.txt new file mode 100644 index 0000000..ec7245f --- /dev/null +++ b/Tests/RunCMake/try_compile/CxxStandard-stderr.txt @@ -0,0 +1,7 @@ +^CMake Error at .*/Tests/RunCMake/try_compile/CxxStandard-build/CMakeFiles/CMakeTmp/CMakeLists.txt:[0-9]+ \(add_executable\): + CXX_STANDARD is set to invalid value '3' ++ +CMake Error at CxxStandard.cmake:[0-9]+ \(try_compile\): + Failed to generate test project build system. +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/try_compile/CxxStandard.cmake b/Tests/RunCMake/try_compile/CxxStandard.cmake new file mode 100644 index 0000000..bcb49b9 --- /dev/null +++ b/Tests/RunCMake/try_compile/CxxStandard.cmake @@ -0,0 +1,7 @@ +enable_language(CXX) +try_compile(result ${CMAKE_CURRENT_BINARY_DIR} + SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src.cxx + CXX_STANDARD 3 + OUTPUT_VARIABLE out + ) +message("try_compile output:\n${out}") diff --git a/Tests/RunCMake/try_compile/CxxStandardGNU.cmake b/Tests/RunCMake/try_compile/CxxStandardGNU.cmake new file mode 100644 index 0000000..e714fe4 --- /dev/null +++ b/Tests/RunCMake/try_compile/CxxStandardGNU.cmake @@ -0,0 +1,23 @@ +enable_language(CXX) +try_compile(result ${CMAKE_CURRENT_BINARY_DIR} + SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/CxxStandardGNU.cxx + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED 1 + CXX_EXTENSIONS 0 + OUTPUT_VARIABLE out + ) +if(NOT result) + message(FATAL_ERROR "try_compile failed:\n${out}") +endif() + +cmake_policy(SET CMP0067 NEW) +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED 1) +set(CMAKE_CXX_EXTENSIONS 0) +try_compile(result ${CMAKE_CURRENT_BINARY_DIR} + SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/CxxStandardGNU.cxx + OUTPUT_VARIABLE out + ) +if(NOT result) + message(FATAL_ERROR "try_compile failed:\n${out}") +endif() diff --git a/Tests/RunCMake/try_compile/CxxStandardGNU.cxx b/Tests/RunCMake/try_compile/CxxStandardGNU.cxx new file mode 100644 index 0000000..7990a78 --- /dev/null +++ b/Tests/RunCMake/try_compile/CxxStandardGNU.cxx @@ -0,0 +1,11 @@ +#if __cplusplus != 201103L && \ + !(__cplusplus < 201103L && defined(__GXX_EXPERIMENTAL_CXX0X__)) +#error "Not GNU C++ 11 mode!" +#endif +#ifndef __STRICT_ANSI__ +#error "Not GNU C++ strict ANSI!" +#endif +int main() +{ + return 0; +} diff --git a/Tests/RunCMake/try_compile/CxxStandardNoDefault.cmake b/Tests/RunCMake/try_compile/CxxStandardNoDefault.cmake new file mode 100644 index 0000000..35caa9d --- /dev/null +++ b/Tests/RunCMake/try_compile/CxxStandardNoDefault.cmake @@ -0,0 +1,9 @@ +enable_language(CXX) +try_compile(result ${CMAKE_CURRENT_BINARY_DIR} + SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src.cxx + CXX_STANDARD 3 # bogus, but not used + OUTPUT_VARIABLE out + ) +if(NOT result) + message(FATAL_ERROR "try_compile failed:\n${out}") +endif() diff --git a/Tests/RunCMake/try_compile/RunCMakeTest.cmake b/Tests/RunCMake/try_compile/RunCMakeTest.cmake index 4934bcd..d1b0217 100644 --- a/Tests/RunCMake/try_compile/RunCMakeTest.cmake +++ b/Tests/RunCMake/try_compile/RunCMakeTest.cmake @@ -25,8 +25,26 @@ run_cmake(TargetTypeExe) run_cmake(TargetTypeInvalid) run_cmake(TargetTypeStatic) +if(CMAKE_C_STANDARD_DEFAULT) + run_cmake(CStandard) +elseif(DEFINED CMAKE_C_STANDARD_DEFAULT) + run_cmake(CStandardNoDefault) +endif() +if(CMAKE_CXX_STANDARD_DEFAULT) + run_cmake(CxxStandard) +elseif(DEFINED CMAKE_CXX_STANDARD_DEFAULT) + run_cmake(CxxStandardNoDefault) +endif() +if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.4) + run_cmake(CStandardGNU) +endif() +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.4) + run_cmake(CxxStandardGNU) +endif() + run_cmake(CMP0056) run_cmake(CMP0066) +run_cmake(CMP0067) if(RunCMake_GENERATOR MATCHES "Make|Ninja") # Use a single build tree for a few tests without cleaning. diff --git a/Tests/RunCMake/try_compile/src.cxx b/Tests/RunCMake/try_compile/src.cxx new file mode 100644 index 0000000..f8b643a --- /dev/null +++ b/Tests/RunCMake/try_compile/src.cxx @@ -0,0 +1,4 @@ +int main() +{ + return 0; +} |