summaryrefslogtreecommitdiff
path: root/Tests/TryCompile
diff options
context:
space:
mode:
authorAlexander Neundorf <neundorf@kde.org>2007-06-01 11:16:29 -0400
committerAlexander Neundorf <neundorf@kde.org>2007-06-01 11:16:29 -0400
commiteddf1cf39f50f9b06131ead26b5b84b8edfd60da (patch)
tree1cbc429b0f2006f19ee9c19773f841648405793d /Tests/TryCompile
parent26a5a295eb231dc9fae9ea90f6cf28d3b4eecaa2 (diff)
downloadcmake-eddf1cf39f50f9b06131ead26b5b84b8edfd60da.tar.gz
ENH: improve TRY_RUN() for crosscompiling: instead of just failing, it now
creates two cache variables, one for the RUN_RESULT, one for the RUN_OUTPUT (if required), which can be set or preset by the user. It has now also two new arguments: RUN_OUTPUT_VARIABLE and COMPILE_OUTPUT_VARIABLE (the old OUTPUT_VARIABLE merges both), so if only COMPILE_OUTPUT_VARIABLE is used the run time output of the TRY_RUN is unused and the user doesn't have to care about the output when crosscompiling. This is now used in FindThreads.cmake, CheckC/CXXSourceRuns.cmake and TestBigEndian.cmake, which used the output only for the logfile (compile output is still there). Test/TryCompile/ now also tests the behaviour of OUTPUT_VARIABLE, RUN_OUTPUT_VARIABLE and COMPILE_OUTPUT_VARIABLE. Alex
Diffstat (limited to 'Tests/TryCompile')
-rw-r--r--Tests/TryCompile/CMakeLists.txt29
-rw-r--r--Tests/TryCompile/exit_success.c3
-rw-r--r--Tests/TryCompile/exit_with_error.c3
3 files changed, 33 insertions, 2 deletions
diff --git a/Tests/TryCompile/CMakeLists.txt b/Tests/TryCompile/CMakeLists.txt
index 02359fe5e5..a39f7c902c 100644
--- a/Tests/TryCompile/CMakeLists.txt
+++ b/Tests/TryCompile/CMakeLists.txt
@@ -87,6 +87,8 @@ ADD_EXECUTABLE(TryCompile pass.c)
# now two tests for TRY_RUN
# try to run a file that should compile and run without error
+# also check that OUTPUT_VARIABLE contains both the compile output
+# and the run output
TRY_RUN(SHOULD_RUN SHOULD_COMPILE
${TryCompile_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
${TryCompile_SOURCE_DIR}/exit_success.c
@@ -97,16 +99,39 @@ 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")
+# check the compile output for the filename
+IF(NOT "${TRY_OUT}" MATCHES "exit_success")
+ MESSAGE(SEND_ERROR " TRY_OUT didn't contain \"exit_success\": \"${TRY_OUT}\"")
+ENDIF(NOT "${TRY_OUT}" MATCHES "exit_success")
+# check the run output
+IF(NOT "${TRY_OUT}" MATCHES "hello world")
+ MESSAGE(SEND_ERROR " TRY_OUT didn't contain \"hello world\": \"${TRY_OUT}\"")
+ENDIF(NOT "${TRY_OUT}" MATCHES "hello world")
+
# 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)
+ COMPILE_OUTPUT_VARIABLE COMPILE_OUTPUT
+ RUN_OUTPUT_VARIABLE RUN_OUTPUT)
+
IF(NOT SHOULD_COMPILE)
- MESSAGE(STATUS " exit_with_error failed compiling: ${TRY_OUT}")
+ MESSAGE(STATUS " exit_with_error failed compiling: ${COMPILE_OUTPUT}")
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")
+# check the compile output, it should contain the filename
+IF(NOT "${COMPILE_OUTPUT}" MATCHES "exit_with_error")
+ MESSAGE(SEND_ERROR " COMPILE_OUT didn't contain \"exit_with_error\": \"${COMPILE_OUTPUT}\"")
+ENDIF(NOT "${COMPILE_OUTPUT}" MATCHES "exit_with_error")
+#... but not the run time output
+IF("${COMPILE_OUTPUT}" MATCHES "hello world")
+ MESSAGE(SEND_ERROR " COMPILE_OUT contains the run output: \"${COMPILE_OUTPUT}\"")
+ENDIF("${COMPILE_OUTPUT}" MATCHES "hello world")
+# check the run output, it should stdout
+IF(NOT "${RUN_OUTPUT}" MATCHES "hello world")
+ MESSAGE(SEND_ERROR " RUN_OUTPUT didn't contain \"hello world\": \"${RUN_OUTPUT}\"")
+ENDIF(NOT "${RUN_OUTPUT}" MATCHES "hello world")
diff --git a/Tests/TryCompile/exit_success.c b/Tests/TryCompile/exit_success.c
index f8b643afbf..82f5b5f825 100644
--- a/Tests/TryCompile/exit_success.c
+++ b/Tests/TryCompile/exit_success.c
@@ -1,4 +1,7 @@
+#include <stdio.h>
+
int main()
{
+ printf("hello world\n");
return 0;
}
diff --git a/Tests/TryCompile/exit_with_error.c b/Tests/TryCompile/exit_with_error.c
index a9a283ddd1..f3c523d378 100644
--- a/Tests/TryCompile/exit_with_error.c
+++ b/Tests/TryCompile/exit_with_error.c
@@ -1,4 +1,7 @@
+#include <stdio.h>
+
int main()
{
+ printf("hello world\n");
return -1;
}