diff options
author | Robert Maynard <robert.maynard@kitware.com> | 2020-09-14 17:17:42 (GMT) |
---|---|---|
committer | Robert Maynard <robert.maynard@kitware.com> | 2020-09-23 16:28:37 (GMT) |
commit | 10ae907de07c26820a765c6a516d1f4baa46161d (patch) | |
tree | 51550bfe24aa14db9bec91efc1e45a1d841fb939 /Tests/RunCMake | |
parent | f5c928f73cdb35b4cc0ea052f663071ec590624e (diff) | |
download | CMake-10ae907de07c26820a765c6a516d1f4baa46161d.zip CMake-10ae907de07c26820a765c6a516d1f4baa46161d.tar.gz CMake-10ae907de07c26820a765c6a516d1f4baa46161d.tar.bz2 |
CheckSoureCompiles: Add a unified way to check if a source compiles
Diffstat (limited to 'Tests/RunCMake')
14 files changed, 119 insertions, 0 deletions
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index ff0ae62..a8b76b4 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -534,6 +534,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(CheckSourceCompiles) add_RunCMake_test(CheckModules) add_RunCMake_test(CheckIPOSupported) if (CMAKE_SYSTEM_NAME MATCHES "(Linux|Darwin)" @@ -542,6 +543,7 @@ if (CMAKE_SYSTEM_NAME MATCHES "(Linux|Darwin)" -DCMAKE_Fortran_COMPILER_ID=${CMAKE_Fortran_COMPILER_ID}) endif() + add_RunCMake_test(CommandLine -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME} -DCYGWIN=${CYGWIN} -DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}) add_RunCMake_test(CommandLineTar) diff --git a/Tests/RunCMake/CheckSourceCompiles/CMakeLists.txt b/Tests/RunCMake/CheckSourceCompiles/CMakeLists.txt new file mode 100644 index 0000000..0421e28 --- /dev/null +++ b/Tests/RunCMake/CheckSourceCompiles/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/CheckSourceCompiles/CheckCSourceCompiles.cmake b/Tests/RunCMake/CheckSourceCompiles/CheckCSourceCompiles.cmake new file mode 100644 index 0000000..cf46189 --- /dev/null +++ b/Tests/RunCMake/CheckSourceCompiles/CheckCSourceCompiles.cmake @@ -0,0 +1,13 @@ + +enable_language (C) +include(CheckSourceCompiles) + +check_source_compiles(C "I don't build" SHOULD_FAIL) +if(SHOULD_FAIL) + message(SEND_ERROR "invalid C source didn't fail.") +endif() + +check_source_compiles(C "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..ec01d42 --- /dev/null +++ b/Tests/RunCMake/CheckSourceCompiles/CheckCXXSourceCompiles.cmake @@ -0,0 +1,26 @@ + +enable_language (CXX) +include(CheckSourceCompiles) + +check_source_compiles(CXX "I don't build" SHOULD_FAIL) +if(SHOULD_FAIL) + message(SEND_ERROR "invalid CXX source didn't fail.") +endif() + +check_source_compiles(CXX [=[ + #include <vector> + int main() { + return 0; + } +]=] + SHOULD_BUILD) +if(NOT SHOULD_BUILD) + message(SEND_ERROR "Test fail for valid CXX source.") +endif() + +check_source_compiles(CXX "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/CheckFortranSourceCompiles.cmake b/Tests/RunCMake/CheckSourceCompiles/CheckFortranSourceCompiles.cmake new file mode 100644 index 0000000..1d4e16d --- /dev/null +++ b/Tests/RunCMake/CheckSourceCompiles/CheckFortranSourceCompiles.cmake @@ -0,0 +1,14 @@ + + +enable_language (Fortran) +include(CheckSourceCompiles) + +check_source_compiles(Fortran [=[ + PROGRAM TEST_HAVE_PRINT + PRINT *, 'Hello' + END +]=] SHOULD_BUILD) + +if(NOT SHOULD_BUILD) + message(SEND_ERROR "Test fail for valid Fortran source.") +endif() diff --git a/Tests/RunCMake/CheckSourceCompiles/CheckOBJCSourceCompiles.cmake b/Tests/RunCMake/CheckSourceCompiles/CheckOBJCSourceCompiles.cmake new file mode 100644 index 0000000..2f53cfc4 --- /dev/null +++ b/Tests/RunCMake/CheckSourceCompiles/CheckOBJCSourceCompiles.cmake @@ -0,0 +1,14 @@ +enable_language (OBJC) +include(CheckSourceCompiles) + +check_source_compiles(OBJC [[ + #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..805d513 --- /dev/null +++ b/Tests/RunCMake/CheckSourceCompiles/CheckOBJCXXSourceCompiles.cmake @@ -0,0 +1,17 @@ +enable_language (OBJCXX) +include(CheckSourceCompiles) + +check_source_compiles(OBJCXX [[ + #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/NonExistentLanguage-result.txt b/Tests/RunCMake/CheckSourceCompiles/NonExistentLanguage-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CheckSourceCompiles/NonExistentLanguage-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CheckSourceCompiles/NonExistentLanguage-stderr.txt b/Tests/RunCMake/CheckSourceCompiles/NonExistentLanguage-stderr.txt new file mode 100644 index 0000000..bf2ea82 --- /dev/null +++ b/Tests/RunCMake/CheckSourceCompiles/NonExistentLanguage-stderr.txt @@ -0,0 +1,2 @@ +CMake Error at .*CheckSourceCompiles\.cmake:[0-9]+ \(message\): + check_source_compiles: FAKE_LANG: unknown language. diff --git a/Tests/RunCMake/CheckSourceCompiles/NonExistentLanguage.cmake b/Tests/RunCMake/CheckSourceCompiles/NonExistentLanguage.cmake new file mode 100644 index 0000000..fc7de06 --- /dev/null +++ b/Tests/RunCMake/CheckSourceCompiles/NonExistentLanguage.cmake @@ -0,0 +1,3 @@ + +include(CheckSourceCompiles) +check_source_compiles(FAKE_LANG "int main() {return 0;}" SHOULD_BUILD) diff --git a/Tests/RunCMake/CheckSourceCompiles/NotEnabledLanguage-result.txt b/Tests/RunCMake/CheckSourceCompiles/NotEnabledLanguage-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CheckSourceCompiles/NotEnabledLanguage-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CheckSourceCompiles/NotEnabledLanguage-stderr.txt b/Tests/RunCMake/CheckSourceCompiles/NotEnabledLanguage-stderr.txt new file mode 100644 index 0000000..ebc983a --- /dev/null +++ b/Tests/RunCMake/CheckSourceCompiles/NotEnabledLanguage-stderr.txt @@ -0,0 +1,2 @@ +CMake Error at .*CheckSourceCompiles\.cmake:[0-9]+ \(message\): + check_source_compiles: C: needs to be enabled before use. diff --git a/Tests/RunCMake/CheckSourceCompiles/NotEnabledLanguage.cmake b/Tests/RunCMake/CheckSourceCompiles/NotEnabledLanguage.cmake new file mode 100644 index 0000000..dec0db3 --- /dev/null +++ b/Tests/RunCMake/CheckSourceCompiles/NotEnabledLanguage.cmake @@ -0,0 +1,3 @@ + +include(CheckSourceCompiles) +check_source_compiles(C "int main() {return 0;}" SHOULD_BUILD) diff --git a/Tests/RunCMake/CheckSourceCompiles/RunCMakeTest.cmake b/Tests/RunCMake/CheckSourceCompiles/RunCMakeTest.cmake new file mode 100644 index 0000000..bf32828 --- /dev/null +++ b/Tests/RunCMake/CheckSourceCompiles/RunCMakeTest.cmake @@ -0,0 +1,16 @@ +include(RunCMake) + +run_cmake(NotEnabledLanguage) +run_cmake(NonExistentLanguage) + +run_cmake(CheckCSourceCompiles) +run_cmake(CheckCXXSourceCompiles) + +if (APPLE) + run_cmake(CheckOBJCSourceCompiles) + run_cmake(CheckOBJCXXSourceCompiles) +endif() + +if (CMAKE_Fortran_COMPILER_ID) + run_cmake(CheckFortranSourceCompiles) +endif() |