summaryrefslogtreecommitdiffstats
path: root/Tests/TryCompile/CMakeLists.txt
diff options
context:
space:
mode:
Diffstat (limited to 'Tests/TryCompile/CMakeLists.txt')
-rw-r--r--Tests/TryCompile/CMakeLists.txt42
1 files changed, 42 insertions, 0 deletions
diff --git a/Tests/TryCompile/CMakeLists.txt b/Tests/TryCompile/CMakeLists.txt
index 8ebb00a..9560190 100644
--- a/Tests/TryCompile/CMakeLists.txt
+++ b/Tests/TryCompile/CMakeLists.txt
@@ -64,6 +64,48 @@ set(try_compile_compile_output_var COMPILE_OUT)
set(try_compile_run_output_var RUN_OUTPUT)
include(old_and_new_signature_tests.cmake)
+# try to compile an empty source specified directly
+try_compile(SHOULD_FAIL_DUE_TO_EMPTY_SOURCE
+ SOURCE_FROM_ARG empty.c "")
+if(SHOULD_FAIL_DUE_TO_EMPTY_SOURCE)
+ message(SEND_ERROR "Trying to compile an empty source succeeded?")
+endif()
+
+try_compile(SHOULD_FAIL_DUE_TO_EMPTY_SOURCE
+ SOURCE_FROM_VAR empty.c NAME_OF_A_VAR_THAT_IS_NOT_SET)
+if(SHOULD_FAIL_DUE_TO_EMPTY_SOURCE)
+ message(SEND_ERROR "Trying to compile an empty source succeeded?")
+endif()
+
+# try to run a source specified directly
+set(TRY_RUN_MAIN_CODE
+ "extern int answer(); \n"
+ "int main() { return answer(); }\n")
+set(TRY_RUN_EXT_CODE
+ "int answer() { return 42; }\n")
+
+try_run(SHOULD_EXIT_WITH_ERROR SHOULD_COMPILE
+ SOURCE_FROM_ARG main.c "${TRY_RUN_MAIN_CODE}"
+ SOURCE_FROM_ARG answer.c "${TRY_RUN_EXT_CODE}"
+ COMPILE_OUTPUT_VARIABLE COMPILE_OUTPUT)
+if(NOT SHOULD_COMPILE)
+ message(SEND_ERROR " SOURCE_FROM_ARG failed compiling: ${COMPILE_OUTPUT}")
+endif()
+if(NOT SHOULD_EXIT_WITH_ERROR EQUAL 42)
+ message(SEND_ERROR " SOURCE_FROM_ARG gave unexpected run result: ${SHOULD_EXIT_WITH_ERROR}")
+endif()
+
+try_run(SHOULD_EXIT_WITH_ERROR SHOULD_COMPILE
+ SOURCE_FROM_VAR main.c TRY_RUN_MAIN_CODE
+ SOURCE_FROM_VAR answer.c TRY_RUN_EXT_CODE
+ COMPILE_OUTPUT_VARIABLE COMPILE_OUTPUT)
+if(NOT SHOULD_COMPILE)
+ message(SEND_ERROR " SOURCE_FROM_VAR failed compiling: ${COMPILE_OUTPUT}")
+endif()
+if(NOT SHOULD_EXIT_WITH_ERROR EQUAL 42)
+ message(SEND_ERROR " SOURCE_FROM_VAR gave unexpected run result: ${SHOULD_EXIT_WITH_ERROR}")
+endif()
+
# try to compile a project (old signature)
message("Testing try_compile project mode (old signature)")
try_compile(TEST_INNER