diff options
author | Brad King <brad.king@kitware.com> | 2016-02-19 18:23:48 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-02-19 19:07:38 (GMT) |
commit | 7f1bd9fe6910f7633d98dec018cc01331a46b87e (patch) | |
tree | d7f1e58c327d7aecd6ce861b6cd6b3c65c8bff71 /Tests | |
parent | 509b1f08ea3ee1d8063efc81fee851ee075b3c97 (diff) | |
download | CMake-7f1bd9fe6910f7633d98dec018cc01331a46b87e.zip CMake-7f1bd9fe6910f7633d98dec018cc01331a46b87e.tar.gz CMake-7f1bd9fe6910f7633d98dec018cc01331a46b87e.tar.bz2 |
try_compile: Add option to control type of target
Create a `CMAKE_TRY_COMPILE_TARGET_TYPE` option to specify use
of `add_library(... STATIC ...)` for the generated test project.
This will be useful for cross-compiling toolchains that cannot
link a binary without custom flags or scripts.
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/RunCMake/try_compile/RunCMakeTest.cmake | 4 | ||||
-rw-r--r-- | Tests/RunCMake/try_compile/TargetTypeExe.cmake | 14 | ||||
-rw-r--r-- | Tests/RunCMake/try_compile/TargetTypeInvalid-result.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/try_compile/TargetTypeInvalid-stderr.txt | 5 | ||||
-rw-r--r-- | Tests/RunCMake/try_compile/TargetTypeInvalid.cmake | 2 | ||||
-rw-r--r-- | Tests/RunCMake/try_compile/TargetTypeStatic.cmake | 14 | ||||
-rw-r--r-- | Tests/RunCMake/try_compile/other.c | 1 |
7 files changed, 41 insertions, 0 deletions
diff --git a/Tests/RunCMake/try_compile/RunCMakeTest.cmake b/Tests/RunCMake/try_compile/RunCMakeTest.cmake index 6cdbafa..43ce998 100644 --- a/Tests/RunCMake/try_compile/RunCMakeTest.cmake +++ b/Tests/RunCMake/try_compile/RunCMakeTest.cmake @@ -16,6 +16,10 @@ run_cmake(BadSources2) run_cmake(NonSourceCopyFile) run_cmake(NonSourceCompileDefinitions) +run_cmake(TargetTypeExe) +run_cmake(TargetTypeInvalid) +run_cmake(TargetTypeStatic) + run_cmake(CMP0056) if(RunCMake_GENERATOR MATCHES "Make|Ninja") diff --git a/Tests/RunCMake/try_compile/TargetTypeExe.cmake b/Tests/RunCMake/try_compile/TargetTypeExe.cmake new file mode 100644 index 0000000..9b6e727 --- /dev/null +++ b/Tests/RunCMake/try_compile/TargetTypeExe.cmake @@ -0,0 +1,14 @@ +enable_language(C) +set(CMAKE_TRY_COMPILE_TARGET_TYPE EXECUTABLE) +try_compile(result ${CMAKE_CURRENT_BINARY_DIR} + SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src.c + OUTPUT_VARIABLE out + COPY_FILE ${CMAKE_CURRENT_BINARY_DIR}/copy + COPY_FILE_ERROR copy_err + ) +if(NOT result) + message(FATAL_ERROR "try_compile failed:\n${out}") +endif() +if(copy_err) + message(FATAL_ERROR "try_compile COPY_FILE failed:\n${copy_err}") +endif() diff --git a/Tests/RunCMake/try_compile/TargetTypeInvalid-result.txt b/Tests/RunCMake/try_compile/TargetTypeInvalid-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/try_compile/TargetTypeInvalid-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/try_compile/TargetTypeInvalid-stderr.txt b/Tests/RunCMake/try_compile/TargetTypeInvalid-stderr.txt new file mode 100644 index 0000000..08b281a --- /dev/null +++ b/Tests/RunCMake/try_compile/TargetTypeInvalid-stderr.txt @@ -0,0 +1,5 @@ +^CMake Error at TargetTypeInvalid.cmake:2 \(try_compile\): + Invalid value 'INVALID' for CMAKE_TRY_COMPILE_TARGET_TYPE. Only + 'EXECUTABLE' and 'STATIC_LIBRARY' are allowed. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/try_compile/TargetTypeInvalid.cmake b/Tests/RunCMake/try_compile/TargetTypeInvalid.cmake new file mode 100644 index 0000000..0bbc4ac --- /dev/null +++ b/Tests/RunCMake/try_compile/TargetTypeInvalid.cmake @@ -0,0 +1,2 @@ +set(CMAKE_TRY_COMPILE_TARGET_TYPE INVALID) +try_compile(result ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src.c) diff --git a/Tests/RunCMake/try_compile/TargetTypeStatic.cmake b/Tests/RunCMake/try_compile/TargetTypeStatic.cmake new file mode 100644 index 0000000..006b8b8 --- /dev/null +++ b/Tests/RunCMake/try_compile/TargetTypeStatic.cmake @@ -0,0 +1,14 @@ +enable_language(C) +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) +try_compile(result ${CMAKE_CURRENT_BINARY_DIR} + SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/other.c + OUTPUT_VARIABLE out + COPY_FILE ${CMAKE_CURRENT_BINARY_DIR}/copy + COPY_FILE_ERROR copy_err + ) +if(NOT result) + message(FATAL_ERROR "try_compile failed:\n${out}") +endif() +if(copy_err) + message(FATAL_ERROR "try_compile COPY_FILE failed:\n${copy_err}") +endif() diff --git a/Tests/RunCMake/try_compile/other.c b/Tests/RunCMake/try_compile/other.c new file mode 100644 index 0000000..6c24f10 --- /dev/null +++ b/Tests/RunCMake/try_compile/other.c @@ -0,0 +1 @@ +int other(void) { return 0; } |