diff options
author | Cristian Adam <cristian.adam@gmail.com> | 2019-11-06 23:55:48 +0100 |
---|---|---|
committer | Cristian Adam <cristian.adam@gmail.com> | 2019-11-09 11:25:32 +0100 |
commit | 7447aa4b340420b0d55bc17bdd9ca1422b1806cf (patch) | |
tree | fb6c81fc7dea4897f7b954edb6fd0c5b9af47e25 /Tests | |
parent | ef86e8991b6b9b2d4b25f98a95ba950f9ba19485 (diff) | |
download | cmake-7447aa4b340420b0d55bc17bdd9ca1422b1806cf.tar.gz |
ObjC: Add try_compile support
Fixes: #19920
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/RunCMake/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Tests/RunCMake/try_compile/ObjCStandard-result.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/try_compile/ObjCStandard-stderr.txt | 7 | ||||
-rw-r--r-- | Tests/RunCMake/try_compile/ObjCStandard.cmake | 7 | ||||
-rw-r--r-- | Tests/RunCMake/try_compile/ObjCxxStandard-result.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/try_compile/ObjCxxStandard-stderr.txt | 7 | ||||
-rw-r--r-- | Tests/RunCMake/try_compile/ObjCxxStandard.cmake | 7 | ||||
-rw-r--r-- | Tests/RunCMake/try_compile/RunCMakeTest.cmake | 6 | ||||
-rw-r--r-- | Tests/RunCMake/try_compile/src.m | 4 | ||||
-rw-r--r-- | Tests/RunCMake/try_compile/src.mm | 4 | ||||
-rw-r--r-- | Tests/TryCompile/CMakeLists.txt | 19 | ||||
-rw-r--r-- | Tests/TryCompile/fail.m | 1 | ||||
-rw-r--r-- | Tests/TryCompile/pass.m | 4 |
13 files changed, 70 insertions, 0 deletions
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 0925c0e5a0..19a23e062c 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -313,6 +313,8 @@ function(add_RunCMake_test_try_compile) CMAKE_CXX_COMPILER_VERSION CMAKE_CXX_STANDARD_DEFAULT CMake_TEST_CUDA + CMAKE_OBJC_STANDARD_DEFAULT + CMAKE_OBJCXX_STANDARD_DEFAULT ) if(DEFINED ${var}) list(APPEND try_compile_ARGS -D${var}=${${var}}) diff --git a/Tests/RunCMake/try_compile/ObjCStandard-result.txt b/Tests/RunCMake/try_compile/ObjCStandard-result.txt new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/Tests/RunCMake/try_compile/ObjCStandard-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/try_compile/ObjCStandard-stderr.txt b/Tests/RunCMake/try_compile/ObjCStandard-stderr.txt new file mode 100644 index 0000000000..f1b4df9e02 --- /dev/null +++ b/Tests/RunCMake/try_compile/ObjCStandard-stderr.txt @@ -0,0 +1,7 @@ +^CMake Error at .*/Tests/RunCMake/try_compile/ObjCStandard-build/CMakeFiles/CMakeTmp/CMakeLists.txt:[0-9]+ \(add_executable\): + OBJC_STANDARD is set to invalid value '3' ++ +CMake Error at ObjCStandard.cmake:[0-9]+ \(try_compile\): + Failed to generate test project build system. +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/try_compile/ObjCStandard.cmake b/Tests/RunCMake/try_compile/ObjCStandard.cmake new file mode 100644 index 0000000000..b2066f9575 --- /dev/null +++ b/Tests/RunCMake/try_compile/ObjCStandard.cmake @@ -0,0 +1,7 @@ +enable_language(OBJC) +try_compile(result ${CMAKE_CURRENT_BINARY_DIR} + SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src.m + OBJC_STANDARD 3 + OUTPUT_VARIABLE out + ) +message("try_compile output:\n${out}") diff --git a/Tests/RunCMake/try_compile/ObjCxxStandard-result.txt b/Tests/RunCMake/try_compile/ObjCxxStandard-result.txt new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/Tests/RunCMake/try_compile/ObjCxxStandard-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/try_compile/ObjCxxStandard-stderr.txt b/Tests/RunCMake/try_compile/ObjCxxStandard-stderr.txt new file mode 100644 index 0000000000..a2f91b48f4 --- /dev/null +++ b/Tests/RunCMake/try_compile/ObjCxxStandard-stderr.txt @@ -0,0 +1,7 @@ +^CMake Error at .*/Tests/RunCMake/try_compile/ObjCxxStandard-build/CMakeFiles/CMakeTmp/CMakeLists.txt:[0-9]+ \(add_executable\): + OBJCXX_STANDARD is set to invalid value '3' ++ +CMake Error at ObjCxxStandard.cmake:[0-9]+ \(try_compile\): + Failed to generate test project build system. +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/try_compile/ObjCxxStandard.cmake b/Tests/RunCMake/try_compile/ObjCxxStandard.cmake new file mode 100644 index 0000000000..1221805c0d --- /dev/null +++ b/Tests/RunCMake/try_compile/ObjCxxStandard.cmake @@ -0,0 +1,7 @@ +enable_language(OBJCXX) +try_compile(result ${CMAKE_CURRENT_BINARY_DIR} + SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src.mm + OBJCXX_STANDARD 3 + OUTPUT_VARIABLE out + ) +message("try_compile output:\n${out}") diff --git a/Tests/RunCMake/try_compile/RunCMakeTest.cmake b/Tests/RunCMake/try_compile/RunCMakeTest.cmake index 77fb7a0f35..91f014e4d2 100644 --- a/Tests/RunCMake/try_compile/RunCMakeTest.cmake +++ b/Tests/RunCMake/try_compile/RunCMakeTest.cmake @@ -37,11 +37,17 @@ if(CMAKE_C_STANDARD_DEFAULT) elseif(DEFINED CMAKE_C_STANDARD_DEFAULT) run_cmake(CStandardNoDefault) endif() +if(CMAKE_OBJC_STANDARD_DEFAULT) + run_cmake(ObjCStandard) +endif() if(CMAKE_CXX_STANDARD_DEFAULT) run_cmake(CxxStandard) elseif(DEFINED CMAKE_CXX_STANDARD_DEFAULT) run_cmake(CxxStandardNoDefault) endif() +if(CMAKE_OBJCXX_STANDARD_DEFAULT) + run_cmake(ObjCxxStandard) +endif() if(CMake_TEST_CUDA) if(CMAKE_HOST_WIN32) run_cmake(CudaStandardNoDefault) diff --git a/Tests/RunCMake/try_compile/src.m b/Tests/RunCMake/try_compile/src.m new file mode 100644 index 0000000000..f8b643afbf --- /dev/null +++ b/Tests/RunCMake/try_compile/src.m @@ -0,0 +1,4 @@ +int main() +{ + return 0; +} diff --git a/Tests/RunCMake/try_compile/src.mm b/Tests/RunCMake/try_compile/src.mm new file mode 100644 index 0000000000..f8b643afbf --- /dev/null +++ b/Tests/RunCMake/try_compile/src.mm @@ -0,0 +1,4 @@ +int main() +{ + return 0; +} diff --git a/Tests/TryCompile/CMakeLists.txt b/Tests/TryCompile/CMakeLists.txt index 498e5562db..9ec9b70fdd 100644 --- a/Tests/TryCompile/CMakeLists.txt +++ b/Tests/TryCompile/CMakeLists.txt @@ -365,6 +365,25 @@ if (APPLE) TEST_ASSERT(SIMPLE_OBJCXX_RUN_SHOULD_WORK "CHECK_OBJCXX_SOURCE_RUNS() failed, but should have succeeded") TEST_FAIL(OBJCXX_RUN_SHOULD_FAIL "CHECK_OBJCXX_SOURCE_RUNS() succeeds, but should have failed") TEST_ASSERT(OBJCXX_RUN_SHOULD_WORK "CHECK_OBJCXX_SOURCE_RUNS() failed, but should have succeeded") + + # try to compile a file that should compile + try_compile(SHOULD_PASS + ${TryCompile_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp + ${TryCompile_SOURCE_DIR}/pass.m + OUTPUT_VARIABLE TRY_OUT) + if(NOT SHOULD_PASS) + message(SEND_ERROR "should pass failed ${TRY_OUT}") + endif() + + # try to compile a file that should not compile + try_compile(SHOULD_FAIL + ${TryCompile_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp + ${TryCompile_SOURCE_DIR}/fail.m + OUTPUT_VARIABLE TRY_OUT) + if(SHOULD_FAIL) + message(SEND_ERROR "Should fail passed ${TRY_OUT}") + endif() + endif() ####################################################################### diff --git a/Tests/TryCompile/fail.m b/Tests/TryCompile/fail.m new file mode 100644 index 0000000000..b915ebe4cb --- /dev/null +++ b/Tests/TryCompile/fail.m @@ -0,0 +1 @@ +asdflkjasdlj diff --git a/Tests/TryCompile/pass.m b/Tests/TryCompile/pass.m new file mode 100644 index 0000000000..f8b643afbf --- /dev/null +++ b/Tests/TryCompile/pass.m @@ -0,0 +1,4 @@ +int main() +{ + return 0; +} |