diff options
author | Brad King <brad.king@kitware.com> | 2022-10-06 13:46:42 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2022-10-06 14:29:42 (GMT) |
commit | 90aa0bb30543cde2c3f58a090735904e17092c44 (patch) | |
tree | 8d19578f1df8747652e5ffcfe19ab57b7f5f5a1b /Tests/RunCMake | |
parent | 64ac01451dad389bb4ca00019a38fbb8bd68308e (diff) | |
download | CMake-90aa0bb30543cde2c3f58a090735904e17092c44.zip CMake-90aa0bb30543cde2c3f58a090735904e17092c44.tar.gz CMake-90aa0bb30543cde2c3f58a090735904e17092c44.tar.bz2 |
Tests: Move TryCompile check module cases to RunCMake.Check*
The latter already have similar checks for similar modules.
Diffstat (limited to 'Tests/RunCMake')
13 files changed, 226 insertions, 0 deletions
diff --git a/Tests/RunCMake/CheckCompilerFlag/CheckCCompilerFlag.cmake b/Tests/RunCMake/CheckCompilerFlag/CheckCCompilerFlag.cmake new file mode 100644 index 0000000..bfb6f72 --- /dev/null +++ b/Tests/RunCMake/CheckCompilerFlag/CheckCCompilerFlag.cmake @@ -0,0 +1,27 @@ + +enable_language (C) +include(CheckCCompilerFlag) + +set(C 1) # test that this is tolerated + +if(NOT CMAKE_C_COMPILER_ID STREQUAL "PathScale") + set(DD --) +endif() + +check_c_compiler_flag("${DD}-_this_is_not_a_flag_" C_BOGUS_FLAG) +if(C_BOGUS_FLAG) + message(SEND_ERROR "CHECK_C_COMPILER_FLAG() succeeded, but should have failed") +endif() +unset(C_BOGUS_FLAG CACHE) +if(DEFINED C_BOGUS_FLAG) + # Verify that CHECK_C_COMPILER_FLAG didn't construct a normal variable + message(SEND_ERROR "CHECK_C_COMPILER_FLAG shouldn't construct C_BOGUS_FLAG as a normal variable") +endif() + +if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "LCC") + unset(C_STRICT_PROTOTYPES CACHE) + CHECK_C_COMPILER_FLAG("-Werror;-Wstrict-prototypes" C_STRICT_PROTOTYPES) + if(NOT C_STRICT_PROTOTYPES) + message(SEND_ERROR "CHECK_C_COMPILER_FLAG failed -Werror -Wstrict-prototypes") + endif() +endif() diff --git a/Tests/RunCMake/CheckCompilerFlag/CheckCXXCompilerFlag.cmake b/Tests/RunCMake/CheckCompilerFlag/CheckCXXCompilerFlag.cmake new file mode 100644 index 0000000..eb20eb4 --- /dev/null +++ b/Tests/RunCMake/CheckCompilerFlag/CheckCXXCompilerFlag.cmake @@ -0,0 +1,19 @@ + +enable_language (CXX) +include(CheckCXXCompilerFlag) + +set(CXX 1) # test that this is tolerated + +if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "PathScale") + set(DD --) +endif() + +check_cxx_compiler_flag("${DD}-_this_is_not_a_flag_" CXX_BOGUS_FLAG) +if(CXX_BOGUS_FLAG) + message(SEND_ERROR "CHECK_CXX_COMPILER_FLAG() succeeded, but should have failed") +endif() +unset(CXX_BOGUS_FLAG CACHE) +if(DEFINED CXX_BOGUS_FLAG) + # Verify that CHECK_CXX_COMPILER_FLAG didn't construct a normal variable + message(SEND_ERROR "CHECK_CXX_COMPILER_FLAG shouldn't construct CXX_BOGUS_FLAG as a normal variable") +endif() diff --git a/Tests/RunCMake/CheckCompilerFlag/RunCMakeTest.cmake b/Tests/RunCMake/CheckCompilerFlag/RunCMakeTest.cmake index dce93a5..b0e025c 100644 --- a/Tests/RunCMake/CheckCompilerFlag/RunCMakeTest.cmake +++ b/Tests/RunCMake/CheckCompilerFlag/RunCMakeTest.cmake @@ -3,6 +3,8 @@ include(RunCMake) run_cmake(NotEnabledLanguage) run_cmake(NonExistentLanguage) +run_cmake(CheckCCompilerFlag) +run_cmake(CheckCXXCompilerFlag) run_cmake(CheckCompilerFlagC) run_cmake(CheckCompilerFlagCXX) diff --git a/Tests/RunCMake/CheckSourceCompiles/CheckCSourceCompiles.cmake b/Tests/RunCMake/CheckSourceCompiles/CheckCSourceCompiles.cmake new file mode 100644 index 0000000..7104650 --- /dev/null +++ b/Tests/RunCMake/CheckSourceCompiles/CheckCSourceCompiles.cmake @@ -0,0 +1,15 @@ + +enable_language (C) +include(CheckCSourceCompiles) + +set(C 1) # test that this is tolerated + +check_c_source_compiles("I don't build" SHOULD_FAIL) +if(SHOULD_FAIL) + message(SEND_ERROR "invalid C source didn't fail.") +endif() + +check_c_source_compiles("int main() {return 0;}" SHOULD_BUILD) +if(NOT SHOULD_BUILD) + message(SEND_ERROR "Test fail for valid C source.") +endif() diff --git a/Tests/RunCMake/CheckSourceCompiles/CheckCXXSourceCompiles.cmake b/Tests/RunCMake/CheckSourceCompiles/CheckCXXSourceCompiles.cmake new file mode 100644 index 0000000..7c9830a --- /dev/null +++ b/Tests/RunCMake/CheckSourceCompiles/CheckCXXSourceCompiles.cmake @@ -0,0 +1,28 @@ + +enable_language (CXX) +include(CheckCXXSourceCompiles) + +set(CXX 1) # test that this is tolerated + +check_cxx_source_compiles("I don't build" SHOULD_FAIL) +if(SHOULD_FAIL) + message(SEND_ERROR "invalid CXX source didn't fail.") +endif() + +check_cxx_source_compiles([=[ + #include <vector> + int main() { + return 0; + } +]=] + SHOULD_BUILD) +if(NOT SHOULD_BUILD) + message(SEND_ERROR "Test fail for valid CXX source.") +endif() + +CHECK_CXX_SOURCE_COMPILES("void l(char const (&x)[2]){}; int main() { l(\"\\\\n\"); return 0;}" + SHOULD_BUILD_COMPLEX) + +if(NOT SHOULD_BUILD_COMPLEX) + message(SEND_ERROR "Test fail for valid CXX complex source.") +endif() diff --git a/Tests/RunCMake/CheckSourceCompiles/CheckOBJCSourceCompiles.cmake b/Tests/RunCMake/CheckSourceCompiles/CheckOBJCSourceCompiles.cmake new file mode 100644 index 0000000..ac43a1e --- /dev/null +++ b/Tests/RunCMake/CheckSourceCompiles/CheckOBJCSourceCompiles.cmake @@ -0,0 +1,21 @@ +enable_language (OBJC) +include(CheckOBJCSourceCompiles) + +set(OBJC 1) # test that this is tolerated + +check_objc_source_compiles("I don't build in Objective-C" SHOULD_FAIL) +if(SHOULD_FAIL) + message(SEND_ERROR "invalid OBJC source didn't fail.") +endif() + +check_objc_source_compiles([[ + #import <Foundation/Foundation.h> + int main() { + NSObject *foo; + return 0; + } +]] SHOULD_BUILD) + +if(NOT SHOULD_BUILD) + message(SEND_ERROR "Test fail for valid OBJC source.") +endif() diff --git a/Tests/RunCMake/CheckSourceCompiles/CheckOBJCXXSourceCompiles.cmake b/Tests/RunCMake/CheckSourceCompiles/CheckOBJCXXSourceCompiles.cmake new file mode 100644 index 0000000..0088956 --- /dev/null +++ b/Tests/RunCMake/CheckSourceCompiles/CheckOBJCXXSourceCompiles.cmake @@ -0,0 +1,24 @@ +enable_language (OBJCXX) +include(CheckOBJCXXSourceCompiles) + +set(OBJCXX 1) # test that this is tolerated + +check_objcxx_source_compiles("I don't build in Objective-C++" SHOULD_FAIL) +if(SHOULD_FAIL) + message(SEND_ERROR "invalid OBJCXX source didn't fail.") +endif() + +check_objcxx_source_compiles([[ + #include <vector> + #import <Foundation/Foundation.h> + int main() { + std::vector<int> v; + NSObject *foo; + return 0; + } +]] SHOULD_BUILD) + + +if(NOT SHOULD_BUILD) + message(SEND_ERROR "Test fail for OBJCXX source.") +endif() diff --git a/Tests/RunCMake/CheckSourceCompiles/RunCMakeTest.cmake b/Tests/RunCMake/CheckSourceCompiles/RunCMakeTest.cmake index 64555d8..df77d3d 100644 --- a/Tests/RunCMake/CheckSourceCompiles/RunCMakeTest.cmake +++ b/Tests/RunCMake/CheckSourceCompiles/RunCMakeTest.cmake @@ -4,10 +4,14 @@ run_cmake(NotEnabledLanguage) run_cmake(NonExistentLanguage) run_cmake(UnknownArgument) +run_cmake(CheckCSourceCompiles) +run_cmake(CheckCXXSourceCompiles) run_cmake(CheckSourceCompilesC) run_cmake(CheckSourceCompilesCXX) if (APPLE) + run_cmake(CheckOBJCSourceCompiles) + run_cmake(CheckOBJCXXSourceCompiles) run_cmake(CheckSourceCompilesOBJC) run_cmake(CheckSourceCompilesOBJCXX) endif() diff --git a/Tests/RunCMake/CheckSourceRuns/CheckCSourceRuns.cmake b/Tests/RunCMake/CheckSourceRuns/CheckCSourceRuns.cmake new file mode 100644 index 0000000..c0f9463 --- /dev/null +++ b/Tests/RunCMake/CheckSourceRuns/CheckCSourceRuns.cmake @@ -0,0 +1,15 @@ + +enable_language (C) +include(CheckCSourceRuns) + +set(C 1) # test that this is tolerated + +check_c_source_runs("int main() {return 2;}" SHOULD_FAIL) +if(SHOULD_FAIL) + message(SEND_ERROR "check_c_source_runs succeeded, but should have failed.") +endif() + +check_c_source_runs("int main() {return 0;}" SHOULD_RUN) +if(NOT SHOULD_RUN) + message(SEND_ERROR "check_c_source_runs failed for valid C executable.") +endif() diff --git a/Tests/RunCMake/CheckSourceRuns/CheckCXXSourceRuns.cmake b/Tests/RunCMake/CheckSourceRuns/CheckCXXSourceRuns.cmake new file mode 100644 index 0000000..c4c9026 --- /dev/null +++ b/Tests/RunCMake/CheckSourceRuns/CheckCXXSourceRuns.cmake @@ -0,0 +1,22 @@ + +enable_language (CXX) +include(CheckCXXSourceRuns) + +set(CXX 1) # test that this is tolerated + +check_cxx_source_runs("int main() {return 2;}" SHOULD_FAIL) +if(SHOULD_FAIL) + message(SEND_ERROR "check_cxx_source_runs succeeded, but should have failed.") +endif() + +check_cxx_source_runs( +[=[ + #include <vector> + int main() { + return 0; + } +]=] + SHOULD_RUN) +if(NOT SHOULD_RUN) + message(SEND_ERROR "check_cxx_source_runs failed for valid C executable.") +endif() diff --git a/Tests/RunCMake/CheckSourceRuns/CheckOBJCSourceRuns.cmake b/Tests/RunCMake/CheckSourceRuns/CheckOBJCSourceRuns.cmake new file mode 100644 index 0000000..604b2a1 --- /dev/null +++ b/Tests/RunCMake/CheckSourceRuns/CheckOBJCSourceRuns.cmake @@ -0,0 +1,21 @@ +enable_language (OBJC) +include(CheckOBJCSourceRuns) + +set(OBJC 1) # test that this is tolerated + +check_objc_source_runs("int main() {return 2;}" SHOULD_FAIL) +if(SHOULD_FAIL) + message(SEND_ERROR "check_objc_source_runs succeeded, but should have failed.") +endif() + +check_objc_source_runs([[ + #import <Foundation/Foundation.h> + int main() { + NSObject *foo; + return 0; + } +]] SHOULD_BUILD) + +if(NOT SHOULD_BUILD) + message(SEND_ERROR "Test fail for valid OBJC source.") +endif() diff --git a/Tests/RunCMake/CheckSourceRuns/CheckOBJCXXSourceRuns.cmake b/Tests/RunCMake/CheckSourceRuns/CheckOBJCXXSourceRuns.cmake new file mode 100644 index 0000000..b220166 --- /dev/null +++ b/Tests/RunCMake/CheckSourceRuns/CheckOBJCXXSourceRuns.cmake @@ -0,0 +1,24 @@ +enable_language (OBJCXX) +include(CheckOBJCXXSourceRuns) + +set(OBJCXX 1) # test that this is tolerated + +check_objcxx_source_runs("int main() {return 2;}" SHOULD_FAIL) +if(SHOULD_FAIL) + message(SEND_ERROR "check_objcxx_source_runs succeeded, but should have failed.") +endif() + +check_objcxx_source_runs([[ + #include <vector> + #import <Foundation/Foundation.h> + int main() { + std::vector<int> v; + NSObject *foo; + return 0; + } +]] SHOULD_BUILD) + + +if(NOT SHOULD_BUILD) + message(SEND_ERROR "Test fail for OBJCXX source.") +endif() diff --git a/Tests/RunCMake/CheckSourceRuns/RunCMakeTest.cmake b/Tests/RunCMake/CheckSourceRuns/RunCMakeTest.cmake index ee5ab22..64cecfc 100644 --- a/Tests/RunCMake/CheckSourceRuns/RunCMakeTest.cmake +++ b/Tests/RunCMake/CheckSourceRuns/RunCMakeTest.cmake @@ -4,10 +4,14 @@ run_cmake(NotEnabledLanguage) run_cmake(NonExistentLanguage) run_cmake(UnknownArgument) +run_cmake(CheckCSourceRuns) +run_cmake(CheckCXXSourceRuns) run_cmake(CheckSourceRunsC) run_cmake(CheckSourceRunsCXX) if (APPLE) + run_cmake(CheckOBJCSourceRuns) + run_cmake(CheckOBJCXXSourceRuns) run_cmake(CheckSourceRunsOBJC) run_cmake(CheckSourceRunsOBJCXX) endif() |