diff options
author | Brad King <brad.king@kitware.com> | 2022-11-01 13:00:36 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2022-11-01 13:01:01 (GMT) |
commit | ea0d24c70121909e333120f39b15be58120dd73a (patch) | |
tree | 740120c662be0406fa15bffc417d3986ede129fe /Tests | |
parent | df54f1ddf897db17af847ed39a989222261f262a (diff) | |
parent | bb2370842f5d3919db1b755f94288dfffe28d39f (diff) | |
download | CMake-ea0d24c70121909e333120f39b15be58120dd73a.zip CMake-ea0d24c70121909e333120f39b15be58120dd73a.tar.gz CMake-ea0d24c70121909e333120f39b15be58120dd73a.tar.bz2 |
Merge topic 'test-objc'
bb2370842f Tests: Simplify RunCMake.try_compile compiler inspection
1abcb094a7 Tests: Fix logic to enable RunCMake.try_compile OBJC/OBJCXX cases
b641a80d55 Tests: Factor out a CMake_TEST_OBJC variable for OBJC/OBJCXX test conditions
Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !7855
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/CMakeLists.txt | 14 | ||||
-rw-r--r-- | Tests/RunCMake/CMakeLists.txt | 63 | ||||
-rw-r--r-- | Tests/RunCMake/try_compile/Inspect.cmake | 27 | ||||
-rw-r--r-- | Tests/RunCMake/try_compile/RunCMakeTest.cmake | 21 |
4 files changed, 57 insertions, 68 deletions
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 850e743..112455b 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -349,6 +349,12 @@ if(BUILD_TESTING) endif() endif() + if(NOT DEFINED CMake_TEST_OBJC) + if(APPLE AND CMAKE_C_COMPILER_ID MATCHES "Clang|GNU") + set(CMake_TEST_OBJC 1) + endif() + endif() + # Use 1500 or CTEST_TEST_TIMEOUT for long test timeout value, # whichever is greater. set(CMAKE_LONG_TEST_TIMEOUT 1500) @@ -438,6 +444,11 @@ if(BUILD_TESTING) endif() endif() + if(CMake_TEST_OBJC) + add_subdirectory(ObjC) + add_subdirectory(ObjCXX) + endif() + if(${CMAKE_GENERATOR} MATCHES "Visual Studio ([^9]|[9][0-9])") ADD_TEST_MACRO(CSharpOnly CSharpOnly) if(NOT CMAKE_VS_PLATFORM_NAME STREQUAL "ARM64") @@ -2506,9 +2517,6 @@ if(BUILD_TESTING) -Dgen=${CMAKE_GENERATOR} -P ${CMake_SOURCE_DIR}/Tests/CFBundleTest/VerifyResult.cmake) list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/CFBundleTest") - - add_subdirectory(ObjC) - add_subdirectory(ObjCXX) endif() endif() diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 280a21a..6bf8f3f 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -299,8 +299,8 @@ if(UNIX AND "${CMAKE_GENERATOR}" MATCHES "Unix Makefiles|Ninja") add_RunCMake_test(CompilerChange) endif() add_RunCMake_test(CompilerNotFound) -if (APPLE AND CMAKE_C_COMPILER_ID MATCHES "Clang|GNU") - list(APPEND CompilerTest_ARGS -DCMake_TEST_OBJC=1) +if(DEFINED CMake_TEST_OBJC) + list(APPEND CompilerTest_ARGS -DCMake_TEST_OBJC=${CMake_TEST_OBJC}) endif() if(CMAKE_Fortran_COMPILER) list(APPEND CompilerTest_ARGS -DCMake_TEST_Fortran=1) @@ -502,64 +502,15 @@ if(APPLE) endif() function(add_RunCMake_test_try_compile) - if(CMAKE_VERSION VERSION_LESS 3.9.20170907 AND "x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xMSVC") - # Older CMake versions do not know about MSVC language standards. - # Approximate our logic from MSVC-CXX.cmake. - if ((NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.0.24215.1 AND - CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.10) OR - NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.10.25017) - set(CMAKE_CXX_STANDARD_DEFAULT 14) - elseif (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16.0) - set(CMAKE_CXX_STANDARD_DEFAULT "") - else() - unset(CMAKE_CXX_STANDARD_DEFAULT) - endif() - endif() - if(CMAKE_VERSION VERSION_LESS 3.18.20200813 AND "x${CMAKE_C_COMPILER_ID}" STREQUAL "xMSVC") - # Older CMake versions do not know about MSVC language standards. - # Approximate our logic from MSVC-C.cmake. - if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 19.27) - set(CMAKE_C_STANDARD_DEFAULT 99) - else() - set(CMAKE_C_STANDARD_DEFAULT "") - endif() - endif() - if(CMAKE_VERSION VERSION_LESS 3.20.20210225 AND "x${CMAKE_C_COMPILER_ID}" STREQUAL "xClang") - # Older CMake versions do not know about Clang MSVC compatibility mode - # standards. Approximate the logic from Clang-C.cmake. - if(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 11.0) - set(CMAKE_C_STANDARD_DEFAULT 17) - elseif(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 3.5.2) - set(CMAKE_C_STANDARD_DEFAULT 11) - endif() - endif() - if(CMAKE_VERSION VERSION_LESS 3.20.6 AND "x${CMAKE_C_COMPILER_ID}" STREQUAL "xIntelLLVM" AND "x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC") - # Older CMake versions accidentally set the default standards to empty when - # IntelLLVM targets the MSVC ABI, thus not activating standard selection. - # Approximate the logic from IntelLLVM-{C,CXX}.cmake. - if(DEFINED CMAKE_C_STANDARD_DEFAULT AND "${CMAKE_C_STANDARD_DEFAULT}" STREQUAL "") - set(CMAKE_C_STANDARD_DEFAULT 17) - endif() - if(DEFINED CMAKE_CXX_STANDARD_DEFAULT AND "${CMAKE_CXX_STANDARD_DEFAULT}" STREQUAL "") - set(CMAKE_CXX_STANDARD_DEFAULT 14) - endif() - endif() foreach( var IN ITEMS CMAKE_SYSTEM_NAME - CMAKE_C_COMPILER_ID - CMAKE_C_COMPILER_VERSION - CMAKE_C_STANDARD_DEFAULT - CMAKE_CXX_COMPILER_ID - CMAKE_CXX_COMPILER_VERSION - CMAKE_CXX_STANDARD_DEFAULT CMake_TEST_CUDA CMake_TEST_ISPC CMake_TEST_HIP + CMake_TEST_OBJC CMake_TEST_FILESYSTEM_1S - CMAKE_OBJC_STANDARD_DEFAULT - CMAKE_OBJCXX_STANDARD_DEFAULT ) if(DEFINED ${var}) list(APPEND try_compile_ARGS -D${var}=${${var}}) @@ -897,13 +848,13 @@ if("${CMAKE_GENERATOR}" MATCHES "Make|Ninja") if(DEFINED CMake_TEST_ISPC) list(APPEND CompilerLauncher_ARGS -DCMake_TEST_ISPC=${CMake_TEST_ISPC}) endif() + if(DEFINED CMake_TEST_OBJC) + list(APPEND CompilerLauncher_ARGS -DCMake_TEST_OBJC=${CMake_TEST_OBJC}) + list(APPEND LinkerLauncher_ARGS -DCMake_TEST_OBJC=${CMake_TEST_OBJC}) + endif() if(CMAKE_Fortran_COMPILER) list(APPEND CompilerLauncher_ARGS -DCMake_TEST_Fortran=1) endif() - if (APPLE AND CMAKE_C_COMPILER_ID MATCHES "Clang|GNU") - list(APPEND CompilerLauncher_ARGS -DCMake_TEST_OBJC=1) - list(APPEND LinkerLauncher_ARGS -DCMake_TEST_OBJC=1) - endif() add_RunCMake_test(CompilerLauncher) set_property(TEST RunCMake.CompilerLauncher APPEND PROPERTY LABELS "CUDA;HIP;ISPC") diff --git a/Tests/RunCMake/try_compile/Inspect.cmake b/Tests/RunCMake/try_compile/Inspect.cmake index added41..2977d02 100644 --- a/Tests/RunCMake/try_compile/Inspect.cmake +++ b/Tests/RunCMake/try_compile/Inspect.cmake @@ -1,4 +1,25 @@ +enable_language(C) enable_language(CXX) -file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/info.cmake" " -set(CMAKE_CXX_EXTENSIONS_DEFAULT \"${CMAKE_CXX_EXTENSIONS_DEFAULT}\") -") +if(CMake_TEST_OBJC) + enable_language(OBJC) + enable_language(OBJCXX) +endif() + +set(info "") +foreach(var + CMAKE_C_COMPILER_ID + CMAKE_C_COMPILER_VERSION + CMAKE_C_STANDARD_DEFAULT + CMAKE_CXX_COMPILER_ID + CMAKE_CXX_COMPILER_VERSION + CMAKE_CXX_STANDARD_DEFAULT + CMAKE_CXX_EXTENSIONS_DEFAULT + CMAKE_OBJC_STANDARD_DEFAULT + CMAKE_OBJCXX_STANDARD_DEFAULT + ) + if(DEFINED ${var}) + string(APPEND info "set(${var} \"${${var}}\")\n") + endif() +endforeach() + +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/info.cmake" "${info}") diff --git a/Tests/RunCMake/try_compile/RunCMakeTest.cmake b/Tests/RunCMake/try_compile/RunCMakeTest.cmake index 7245471..ad1cc29 100644 --- a/Tests/RunCMake/try_compile/RunCMakeTest.cmake +++ b/Tests/RunCMake/try_compile/RunCMakeTest.cmake @@ -1,5 +1,20 @@ include(RunCMake) +# Detect information from the toolchain: +# - CMAKE_C_COMPILER_ID +# - CMAKE_C_COMPILER_VERSION +# - CMAKE_C_STANDARD_DEFAULT +# - CMAKE_CXX_COMPILER_ID +# - CMAKE_CXX_COMPILER_VERSION +# - CMAKE_CXX_STANDARD_DEFAULT +# - CMAKE_CXX_EXTENSIONS_DEFAULT +# - CMAKE_OBJC_STANDARD_DEFAULT +# - CMAKE_OBJCXX_STANDARD_DEFAULT +run_cmake_with_options(Inspect + -DCMake_TEST_OBJC=${CMake_TEST_OBJC} + ) +include("${RunCMake_BINARY_DIR}/Inspect-build/info.cmake") + run_cmake(NoArgs) run_cmake(OneArg) run_cmake(TwoArgs) @@ -88,12 +103,6 @@ if(RunCMake_GENERATOR MATCHES "Make|Ninja") unset(RunCMake_TEST_NO_CLEAN) endif() -# Lookup CMAKE_CXX_EXTENSIONS_DEFAULT. -# FIXME: Someday we could move this to the top of the file and use it in -# place of some of the values passed by 'Tests/RunCMake/CMakeLists.txt'. -run_cmake(Inspect) -include("${RunCMake_BINARY_DIR}/Inspect-build/info.cmake") - # FIXME: Support more compilers and default standard levels. if (DEFINED CMAKE_CXX_STANDARD_DEFAULT AND DEFINED CMAKE_CXX_EXTENSIONS_DEFAULT AND ( |