summaryrefslogtreecommitdiffstats
path: root/Tests
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2020-10-06 12:18:39 (GMT)
committerKitware Robot <kwrobot@kitware.com>2020-10-06 12:18:46 (GMT)
commit990cf3c5d225cf0f18f1f8cad760f61614b5dade (patch)
treec7a545d72f26ac582f8204bf0eb2b8f76e6cbb04 /Tests
parent7ef9a91e188d0fe72f757a59547a97c7175fa674 (diff)
parent8ac97196591cc00c998afa2f90ba7861a315cc48 (diff)
downloadCMake-990cf3c5d225cf0f18f1f8cad760f61614b5dade.zip
CMake-990cf3c5d225cf0f18f1f8cad760f61614b5dade.tar.gz
CMake-990cf3c5d225cf0f18f1f8cad760f61614b5dade.tar.bz2
Merge topic 'add_checkcompilerflag_tests'
8ac9719659 CheckCompilerFlag: Add tests to verify module correctness Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !5328
Diffstat (limited to 'Tests')
-rw-r--r--Tests/RunCMake/CMakeLists.txt1
-rw-r--r--Tests/RunCMake/CheckCompilerFlag/CMakeLists.txt5
-rw-r--r--Tests/RunCMake/CheckCompilerFlag/CheckCCompilerFlag.cmake15
-rw-r--r--Tests/RunCMake/CheckCompilerFlag/CheckCXXCompilerFlag.cmake15
-rw-r--r--Tests/RunCMake/CheckCompilerFlag/CheckFortranCompilerFlag.cmake14
-rw-r--r--Tests/RunCMake/CheckCompilerFlag/CheckOBJCCompilerFlag.cmake12
-rw-r--r--Tests/RunCMake/CheckCompilerFlag/CheckOBJCXXCompilerFlag.cmake12
-rw-r--r--Tests/RunCMake/CheckCompilerFlag/NonExistentLanguage-result.txt1
-rw-r--r--Tests/RunCMake/CheckCompilerFlag/NonExistentLanguage-stderr.txt2
-rw-r--r--Tests/RunCMake/CheckCompilerFlag/NonExistentLanguage.cmake3
-rw-r--r--Tests/RunCMake/CheckCompilerFlag/NotEnabledLanguage-result.txt1
-rw-r--r--Tests/RunCMake/CheckCompilerFlag/NotEnabledLanguage-stderr.txt2
-rw-r--r--Tests/RunCMake/CheckCompilerFlag/NotEnabledLanguage.cmake3
-rw-r--r--Tests/RunCMake/CheckCompilerFlag/RunCMakeTest.cmake16
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()