Commit 5e328c6d authored by Brad King's avatar Brad King Committed by Kitware Robot

Merge topic 'objc-trycompile' into release-3.16

7447aa4b ObjC: Add try_compile support
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !4006
parents 8bfd4447 7447aa4b
This diff is collapsed.
......@@ -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}})
......
^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\)$
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}")
^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\)$
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}")
......@@ -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)
......
int main()
{
return 0;
}
int main()
{
return 0;
}
......@@ -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()
#######################################################################
......
int main()
{
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment