diff options
author | Robert Maynard <robert.maynard@kitware.com> | 2020-10-05 18:13:53 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2020-10-06 11:07:02 (GMT) |
commit | 8ac97196591cc00c998afa2f90ba7861a315cc48 (patch) | |
tree | 4654e68158fec77d2c77a6454b25085f8cd3fd1b /Tests | |
parent | b1898bf97570b2887f7398105231ff72adb1564d (diff) | |
download | CMake-8ac97196591cc00c998afa2f90ba7861a315cc48.zip CMake-8ac97196591cc00c998afa2f90ba7861a315cc48.tar.gz CMake-8ac97196591cc00c998afa2f90ba7861a315cc48.tar.bz2 |
CheckCompilerFlag: Add tests to verify module correctness
Diffstat (limited to 'Tests')
14 files changed, 102 insertions, 0 deletions
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index c70eb75..9d5c8fb 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -538,6 +538,7 @@ add_RunCMake_test(target_compile_features) add_RunCMake_test(target_compile_options -DCMAKE_C_COMPILER_ID=${CMAKE_C_COMPILER_ID}) add_RunCMake_test(target_include_directories) add_RunCMake_test(target_sources) +add_RunCMake_test(CheckCompilerFlag) add_RunCMake_test(CheckSourceCompiles) add_RunCMake_test(CheckSourceRuns) add_RunCMake_test(CheckModules) diff --git a/Tests/RunCMake/CheckCompilerFlag/CMakeLists.txt b/Tests/RunCMake/CheckCompilerFlag/CMakeLists.txt new file mode 100644 index 0000000..0421e28 --- /dev/null +++ b/Tests/RunCMake/CheckCompilerFlag/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.13) + +project(${RunCMake_TEST} LANGUAGES NONE) + +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/CheckCompilerFlag/CheckCCompilerFlag.cmake b/Tests/RunCMake/CheckCompilerFlag/CheckCCompilerFlag.cmake new file mode 100644 index 0000000..d268ed2 --- /dev/null +++ b/Tests/RunCMake/CheckCompilerFlag/CheckCCompilerFlag.cmake @@ -0,0 +1,15 @@ + +enable_language (C) +include(CheckCompilerFlag) + +check_compiler_flag(C "-_this_is_not_a_flag_" SHOULD_FAIL) +if(SHOULD_FAIL) + message(SEND_ERROR "invalid C compile flag didn't fail.") +endif() + +if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang" AND NOT "x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC") + check_compiler_flag(C "-x c" SHOULD_WORK) + if(NOT SHOULD_WORK) + message(SEND_ERROR "${CMAKE_C_COMPILER_ID} compiler flag '-x c' check failed") + endif() +endif() diff --git a/Tests/RunCMake/CheckCompilerFlag/CheckCXXCompilerFlag.cmake b/Tests/RunCMake/CheckCompilerFlag/CheckCXXCompilerFlag.cmake new file mode 100644 index 0000000..bbc104e --- /dev/null +++ b/Tests/RunCMake/CheckCompilerFlag/CheckCXXCompilerFlag.cmake @@ -0,0 +1,15 @@ + +enable_language (CXX) +include(CheckCompilerFlag) + +check_compiler_flag(CXX "-_this_is_not_a_flag_" SHOULD_FAIL) +if(SHOULD_FAIL) + message(SEND_ERROR "invalid CXX compile flag didn't fail.") +endif() + +if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" AND NOT "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC") + check_compiler_flag(CXX "-x c++" SHOULD_WORK) + if(NOT SHOULD_WORK) + message(SEND_ERROR "${CMAKE_CXX_COMPILER_ID} compiler flag '-x c++' check failed") + endif() +endif() diff --git a/Tests/RunCMake/CheckCompilerFlag/CheckFortranCompilerFlag.cmake b/Tests/RunCMake/CheckCompilerFlag/CheckFortranCompilerFlag.cmake new file mode 100644 index 0000000..220ee29 --- /dev/null +++ b/Tests/RunCMake/CheckCompilerFlag/CheckFortranCompilerFlag.cmake @@ -0,0 +1,14 @@ +enable_language (Fortran) +include(CheckCompilerFlag) + +check_compiler_flag(Fortran "-_this_is_not_a_flag_" SHOULD_FAIL) +if(SHOULD_FAIL) + message(SEND_ERROR "invalid Fortran compile flag didn't fail.") +endif() + +if(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") + check_compiler_flag(Fortran "-Wall" SHOULD_WORK) + if(NOT SHOULD_WORK) + message(SEND_ERROR "${CMAKE_Fortran_COMPILER_ID} compiler flag '-Wall' check failed") + endif() +endif() diff --git a/Tests/RunCMake/CheckCompilerFlag/CheckOBJCCompilerFlag.cmake b/Tests/RunCMake/CheckCompilerFlag/CheckOBJCCompilerFlag.cmake new file mode 100644 index 0000000..e9344ca --- /dev/null +++ b/Tests/RunCMake/CheckCompilerFlag/CheckOBJCCompilerFlag.cmake @@ -0,0 +1,12 @@ +enable_language (OBJC) +include(CheckCompilerFlag) + +check_compiler_flag(OBJC "-_this_is_not_a_flag_" SHOULD_FAIL) +if(SHOULD_FAIL) + message(SEND_ERROR "invalid OBJC compile flag didn't fail.") +endif() + +check_compiler_flag(OBJC "-Wall" SHOULD_WORK) +if(NOT SHOULD_WORK) + message(SEND_ERROR "${CMAKE_OBJC_COMPILER_ID} compiler flag '-Wall' check failed") +endif() diff --git a/Tests/RunCMake/CheckCompilerFlag/CheckOBJCXXCompilerFlag.cmake b/Tests/RunCMake/CheckCompilerFlag/CheckOBJCXXCompilerFlag.cmake new file mode 100644 index 0000000..503a1de --- /dev/null +++ b/Tests/RunCMake/CheckCompilerFlag/CheckOBJCXXCompilerFlag.cmake @@ -0,0 +1,12 @@ +enable_language (OBJCXX) +include(CheckCompilerFlag) + +check_compiler_flag(OBJCXX "-_this_is_not_a_flag_" SHOULD_FAIL) +if(SHOULD_FAIL) + message(SEND_ERROR "invalid OBJCXX compile flag didn't fail.") +endif() + +check_compiler_flag(OBJCXX "-Wall" SHOULD_WORK) +if(NOT SHOULD_WORK) + message(SEND_ERROR "${CMAKE_OBJCXX_COMPILER_ID} compiler flag '-Wall' check failed") +endif() diff --git a/Tests/RunCMake/CheckCompilerFlag/NonExistentLanguage-result.txt b/Tests/RunCMake/CheckCompilerFlag/NonExistentLanguage-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CheckCompilerFlag/NonExistentLanguage-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CheckCompilerFlag/NonExistentLanguage-stderr.txt b/Tests/RunCMake/CheckCompilerFlag/NonExistentLanguage-stderr.txt new file mode 100644 index 0000000..89d0565 --- /dev/null +++ b/Tests/RunCMake/CheckCompilerFlag/NonExistentLanguage-stderr.txt @@ -0,0 +1,2 @@ +CMake Error at .*CheckCompilerFlag\.cmake:[0-9]+ \(message\): + check_compiler_flag: FAKE_LANG: unknown language. diff --git a/Tests/RunCMake/CheckCompilerFlag/NonExistentLanguage.cmake b/Tests/RunCMake/CheckCompilerFlag/NonExistentLanguage.cmake new file mode 100644 index 0000000..0741953 --- /dev/null +++ b/Tests/RunCMake/CheckCompilerFlag/NonExistentLanguage.cmake @@ -0,0 +1,3 @@ + +include(CheckCompilerFlag) +check_compiler_flag(FAKE_LANG "int main() {return 0;}" SHOULD_BUILD) diff --git a/Tests/RunCMake/CheckCompilerFlag/NotEnabledLanguage-result.txt b/Tests/RunCMake/CheckCompilerFlag/NotEnabledLanguage-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CheckCompilerFlag/NotEnabledLanguage-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CheckCompilerFlag/NotEnabledLanguage-stderr.txt b/Tests/RunCMake/CheckCompilerFlag/NotEnabledLanguage-stderr.txt new file mode 100644 index 0000000..23dd4a1 --- /dev/null +++ b/Tests/RunCMake/CheckCompilerFlag/NotEnabledLanguage-stderr.txt @@ -0,0 +1,2 @@ +CMake Error at .*CheckCompilerFlag\.cmake:[0-9]+ \(message\): + check_compiler_flag: C: needs to be enabled before use. diff --git a/Tests/RunCMake/CheckCompilerFlag/NotEnabledLanguage.cmake b/Tests/RunCMake/CheckCompilerFlag/NotEnabledLanguage.cmake new file mode 100644 index 0000000..14769a2 --- /dev/null +++ b/Tests/RunCMake/CheckCompilerFlag/NotEnabledLanguage.cmake @@ -0,0 +1,3 @@ + +include(CheckCompilerFlag) +check_compiler_flag(C "int main() {return 0;}" SHOULD_BUILD) diff --git a/Tests/RunCMake/CheckCompilerFlag/RunCMakeTest.cmake b/Tests/RunCMake/CheckCompilerFlag/RunCMakeTest.cmake new file mode 100644 index 0000000..d56b8a9 --- /dev/null +++ b/Tests/RunCMake/CheckCompilerFlag/RunCMakeTest.cmake @@ -0,0 +1,16 @@ +include(RunCMake) + +run_cmake(NotEnabledLanguage) +run_cmake(NonExistentLanguage) + +run_cmake(CheckCCompilerFlag) +run_cmake(CheckCXXCompilerFlag) + +if (APPLE) + run_cmake(CheckOBJCCompilerFlag) + run_cmake(CheckOBJCXXCompilerFlag) +endif() + +if (CMAKE_Fortran_COMPILER_ID) + run_cmake(CheckFortranCompilerFlag) +endif() |