summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/CheckSourceRuns
diff options
context:
space:
mode:
authorRobert Maynard <robert.maynard@kitware.com>2020-09-14 17:26:43 (GMT)
committerRobert Maynard <robert.maynard@kitware.com>2020-09-23 16:28:37 (GMT)
commit357e2ef429b5245de4f2f5fc7ba7b8089d90bb1c (patch)
tree77b39aa9c625e80699a3998be433cde4f5dc9d88 /Tests/RunCMake/CheckSourceRuns
parent10ae907de07c26820a765c6a516d1f4baa46161d (diff)
downloadCMake-357e2ef429b5245de4f2f5fc7ba7b8089d90bb1c.zip
CMake-357e2ef429b5245de4f2f5fc7ba7b8089d90bb1c.tar.gz
CMake-357e2ef429b5245de4f2f5fc7ba7b8089d90bb1c.tar.bz2
CheckSoureRuns: Add a unified way to check if a source runs
Diffstat (limited to 'Tests/RunCMake/CheckSourceRuns')
-rw-r--r--Tests/RunCMake/CheckSourceRuns/CMakeLists.txt5
-rw-r--r--Tests/RunCMake/CheckSourceRuns/CheckCSourceRuns.cmake13
-rw-r--r--Tests/RunCMake/CheckSourceRuns/CheckCXXSourceRuns.cmake20
-rw-r--r--Tests/RunCMake/CheckSourceRuns/CheckFortranSourceRuns.cmake14
-rw-r--r--Tests/RunCMake/CheckSourceRuns/CheckOBJCSourceRuns.cmake14
-rw-r--r--Tests/RunCMake/CheckSourceRuns/CheckOBJCXXSourceRuns.cmake17
-rw-r--r--Tests/RunCMake/CheckSourceRuns/NonExistentLanguage-result.txt1
-rw-r--r--Tests/RunCMake/CheckSourceRuns/NonExistentLanguage-stderr.txt2
-rw-r--r--Tests/RunCMake/CheckSourceRuns/NonExistentLanguage.cmake3
-rw-r--r--Tests/RunCMake/CheckSourceRuns/NotEnabledLanguage-result.txt1
-rw-r--r--Tests/RunCMake/CheckSourceRuns/NotEnabledLanguage-stderr.txt2
-rw-r--r--Tests/RunCMake/CheckSourceRuns/NotEnabledLanguage.cmake3
-rw-r--r--Tests/RunCMake/CheckSourceRuns/RunCMakeTest.cmake16
13 files changed, 111 insertions, 0 deletions
diff --git a/Tests/RunCMake/CheckSourceRuns/CMakeLists.txt b/Tests/RunCMake/CheckSourceRuns/CMakeLists.txt
new file mode 100644
index 0000000..0421e28
--- /dev/null
+++ b/Tests/RunCMake/CheckSourceRuns/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/CheckSourceRuns/CheckCSourceRuns.cmake b/Tests/RunCMake/CheckSourceRuns/CheckCSourceRuns.cmake
new file mode 100644
index 0000000..3029ac2
--- /dev/null
+++ b/Tests/RunCMake/CheckSourceRuns/CheckCSourceRuns.cmake
@@ -0,0 +1,13 @@
+
+enable_language (C)
+include(CheckSourceRuns)
+
+check_source_runs(C "int main() {return 2;}" SHOULD_FAIL)
+if(SHOULD_FAIL)
+ message(SEND_ERROR "C check_source_runs succeeded, but should have failed.")
+endif()
+
+check_source_runs(C "int main() {return 0;}" SHOULD_RUN)
+if(NOT SHOULD_RUN)
+ message(SEND_ERROR "C check_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..d47ddda
--- /dev/null
+++ b/Tests/RunCMake/CheckSourceRuns/CheckCXXSourceRuns.cmake
@@ -0,0 +1,20 @@
+
+enable_language (CXX)
+include(CheckSourceRuns)
+
+check_source_runs(CXX "int main() {return 2;}" SHOULD_FAIL)
+if(SHOULD_FAIL)
+ message(SEND_ERROR "CXX check_source_runs succeeded, but should have failed.")
+endif()
+
+check_source_runs(CXX
+[=[
+ #include <vector>
+ int main() {
+ return 0;
+ }
+]=]
+ SHOULD_RUN)
+if(NOT SHOULD_RUN)
+ message(SEND_ERROR "CXX check_source_runs failed for valid C executable.")
+endif()
diff --git a/Tests/RunCMake/CheckSourceRuns/CheckFortranSourceRuns.cmake b/Tests/RunCMake/CheckSourceRuns/CheckFortranSourceRuns.cmake
new file mode 100644
index 0000000..2a1fdfe
--- /dev/null
+++ b/Tests/RunCMake/CheckSourceRuns/CheckFortranSourceRuns.cmake
@@ -0,0 +1,14 @@
+
+
+enable_language (Fortran)
+include(CheckSourceRuns)
+
+check_source_runs(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/CheckSourceRuns/CheckOBJCSourceRuns.cmake b/Tests/RunCMake/CheckSourceRuns/CheckOBJCSourceRuns.cmake
new file mode 100644
index 0000000..55f28f3
--- /dev/null
+++ b/Tests/RunCMake/CheckSourceRuns/CheckOBJCSourceRuns.cmake
@@ -0,0 +1,14 @@
+enable_language (OBJC)
+include(CheckSourceRuns)
+
+check_source_runs(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/CheckSourceRuns/CheckOBJCXXSourceRuns.cmake b/Tests/RunCMake/CheckSourceRuns/CheckOBJCXXSourceRuns.cmake
new file mode 100644
index 0000000..a218acd
--- /dev/null
+++ b/Tests/RunCMake/CheckSourceRuns/CheckOBJCXXSourceRuns.cmake
@@ -0,0 +1,17 @@
+enable_language (OBJCXX)
+include(CheckSourceRuns)
+
+check_source_runs(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/CheckSourceRuns/NonExistentLanguage-result.txt b/Tests/RunCMake/CheckSourceRuns/NonExistentLanguage-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/CheckSourceRuns/NonExistentLanguage-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CheckSourceRuns/NonExistentLanguage-stderr.txt b/Tests/RunCMake/CheckSourceRuns/NonExistentLanguage-stderr.txt
new file mode 100644
index 0000000..08ffc2d
--- /dev/null
+++ b/Tests/RunCMake/CheckSourceRuns/NonExistentLanguage-stderr.txt
@@ -0,0 +1,2 @@
+CMake Error at .*CheckSourceRuns\.cmake:[0-9]+ \(message\):
+ check_source_runs: FAKE_LANG: unknown language.
diff --git a/Tests/RunCMake/CheckSourceRuns/NonExistentLanguage.cmake b/Tests/RunCMake/CheckSourceRuns/NonExistentLanguage.cmake
new file mode 100644
index 0000000..8300740
--- /dev/null
+++ b/Tests/RunCMake/CheckSourceRuns/NonExistentLanguage.cmake
@@ -0,0 +1,3 @@
+
+include(CheckSourceRuns)
+check_source_runs(FAKE_LANG "int main() {return 0;}" SHOULD_BUILD)
diff --git a/Tests/RunCMake/CheckSourceRuns/NotEnabledLanguage-result.txt b/Tests/RunCMake/CheckSourceRuns/NotEnabledLanguage-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/CheckSourceRuns/NotEnabledLanguage-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CheckSourceRuns/NotEnabledLanguage-stderr.txt b/Tests/RunCMake/CheckSourceRuns/NotEnabledLanguage-stderr.txt
new file mode 100644
index 0000000..b590763
--- /dev/null
+++ b/Tests/RunCMake/CheckSourceRuns/NotEnabledLanguage-stderr.txt
@@ -0,0 +1,2 @@
+CMake Error at .*CheckSourceRuns\.cmake:[0-9]+ \(message\):
+ check_source_runs: C: needs to be enabled before use.
diff --git a/Tests/RunCMake/CheckSourceRuns/NotEnabledLanguage.cmake b/Tests/RunCMake/CheckSourceRuns/NotEnabledLanguage.cmake
new file mode 100644
index 0000000..e16cec2
--- /dev/null
+++ b/Tests/RunCMake/CheckSourceRuns/NotEnabledLanguage.cmake
@@ -0,0 +1,3 @@
+
+include(CheckSourceRuns)
+check_source_runs(C "int main() {return 0;}" SHOULD_BUILD)
diff --git a/Tests/RunCMake/CheckSourceRuns/RunCMakeTest.cmake b/Tests/RunCMake/CheckSourceRuns/RunCMakeTest.cmake
new file mode 100644
index 0000000..8bcde6a
--- /dev/null
+++ b/Tests/RunCMake/CheckSourceRuns/RunCMakeTest.cmake
@@ -0,0 +1,16 @@
+include(RunCMake)
+
+run_cmake(NotEnabledLanguage)
+run_cmake(NonExistentLanguage)
+
+run_cmake(CheckCSourceRuns)
+run_cmake(CheckCXXSourceRuns)
+
+if (APPLE)
+ run_cmake(CheckOBJCSourceRuns)
+ run_cmake(CheckOBJCXXSourceRuns)
+endif()
+
+if (CMAKE_Fortran_COMPILER_ID)
+ run_cmake(CheckFortranSourceRuns)
+endif()