summaryrefslogtreecommitdiff
path: root/Tests/TryCompile
diff options
context:
space:
mode:
authorAlexander Neundorf <neundorf@kde.org>2007-05-24 11:27:51 -0400
committerAlexander Neundorf <neundorf@kde.org>2007-05-24 11:27:51 -0400
commit7d7aba292c09170fc9f145d68644e1ff6d158eec (patch)
tree6b50a27fb13d788c4b977ea199c6311ceea04854 /Tests/TryCompile
parent8fb8a44f5f1de4c659cc4b4cfe060e91b1e48b9c (diff)
downloadcmake-7d7aba292c09170fc9f145d68644e1ff6d158eec.tar.gz
ENH: add two simple tests for TRY_RUN()
STYLE: create a new base class cmCoreTryCompile, from which cmTryCompileCommand and cmTryRunCommand are derived, so there are no public static functions with lots of arguments anymore Alex
Diffstat (limited to 'Tests/TryCompile')
-rw-r--r--Tests/TryCompile/CMakeLists.txt32
-rw-r--r--Tests/TryCompile/exit_success.c4
-rw-r--r--Tests/TryCompile/exit_with_error.c4
3 files changed, 38 insertions, 2 deletions
diff --git a/Tests/TryCompile/CMakeLists.txt b/Tests/TryCompile/CMakeLists.txt
index a9a08832bf..0de616f0a7 100644
--- a/Tests/TryCompile/CMakeLists.txt
+++ b/Tests/TryCompile/CMakeLists.txt
@@ -61,8 +61,7 @@ IF (CMAKE_ANSI_FOR_SCOPE)
MESSAGE("Compiler supports ansi for")
ELSE(CMAKE_ANSI_FOR_SCOPE)
MESSAGE("Compiler does not support ansi for scope")
-ENDIF(CMAKE_ANSI_FOR_SCOPE)
-
+ENDIF(CMAKE_ANSI_FOR_SCOPE)
MESSAGE("use the module now")
INCLUDE(${CMAKE_ROOT}/Modules/TestForANSIForScope.cmake)
@@ -73,3 +72,32 @@ ELSE(CMAKE_ANSI_FOR_SCOPE)
ENDIF(CMAKE_ANSI_FOR_SCOPE)
ADD_EXECUTABLE(TryCompile pass.c)
+
+######################################
+
+# now two tests for TRY_RUN
+
+# try to run a file that should compile and run without error
+TRY_RUN(SHOULD_RUN SHOULD_COMPILE
+ ${TryCompile_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
+ ${TryCompile_SOURCE_DIR}/exit_success.c
+ OUTPUT_VARIABLE TRY_OUT)
+IF(NOT SHOULD_COMPILE)
+ MESSAGE(SEND_ERROR "exit_success failed compiling: ${TRY_OUT}")
+ENDIF(NOT SHOULD_COMPILE)
+IF(NOT "${SHOULD_RUN}" STREQUAL "0")
+ MESSAGE(SEND_ERROR "exit_success failed running with exit code ${SHOULD_RUN}")
+ENDIF(NOT "${SHOULD_RUN}" STREQUAL "0")
+
+# try to run a file that should compile and run, but return an error
+TRY_RUN(SHOULD_EXIT_WITH_ERROR SHOULD_COMPILE
+ ${TryCompile_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
+ ${TryCompile_SOURCE_DIR}/exit_with_error.c
+ OUTPUT_VARIABLE TRY_OUT)
+IF(NOT SHOULD_COMPILE)
+ MESSAGE(STATUS " exit_with_error failed compiling: ${TRY_OUT}")
+ENDIF(NOT SHOULD_COMPILE)
+IF("${SHOULD_EXIT_WITH_ERROR}" STREQUAL "0")
+ MESSAGE(SEND_ERROR " exit_with_error passed with exit code ${SHOULD_EXIT_WITH_ERROR}")
+ENDIF("${SHOULD_EXIT_WITH_ERROR}" STREQUAL "0")
+
diff --git a/Tests/TryCompile/exit_success.c b/Tests/TryCompile/exit_success.c
new file mode 100644
index 0000000000..f8b643afbf
--- /dev/null
+++ b/Tests/TryCompile/exit_success.c
@@ -0,0 +1,4 @@
+int main()
+{
+ return 0;
+}
diff --git a/Tests/TryCompile/exit_with_error.c b/Tests/TryCompile/exit_with_error.c
new file mode 100644
index 0000000000..a9a283ddd1
--- /dev/null
+++ b/Tests/TryCompile/exit_with_error.c
@@ -0,0 +1,4 @@
+int main()
+{
+ return -1;
+}