From abd1b02dfa6cffef8b6564011353849f20e7dfdc Mon Sep 17 00:00:00 2001 From: Juan Ramos Date: Mon, 29 Apr 2024 11:02:11 -0700 Subject: Tests/Architecture: Have test support Xcode 10+ --- Tests/Architecture/CMakeLists.txt | 36 +++++++++++++----------------------- Tests/CMakeLists.txt | 5 ++++- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/Tests/Architecture/CMakeLists.txt b/Tests/Architecture/CMakeLists.txt index 3d10ee0..8b3d0af 100644 --- a/Tests/Architecture/CMakeLists.txt +++ b/Tests/Architecture/CMakeLists.txt @@ -1,30 +1,21 @@ cmake_minimum_required(VERSION 3.5) project(Architecture C) -function(test_for_xcode4 result_var) - set(${result_var} 0 PARENT_SCOPE) - if(APPLE) - execute_process(COMMAND xcodebuild -version - OUTPUT_VARIABLE ov RESULT_VARIABLE rv - ) - if("${rv}" STREQUAL "0" AND ov MATCHES "^Xcode ([0-9]+)\\.") - if(NOT CMAKE_MATCH_1 VERSION_LESS 4) - set(${result_var} 1 PARENT_SCOPE) - endif() - endif() - endif() -endfunction() - -test_for_xcode4(is_xcode4) - -set(arch0 i386) -set(arch1 ppc) - -if(is_xcode4) - # Xcode 4, use modern architectures as defaults - # Arch 'ppc' no longer works: tools no longer available starting with Xcode 4 +if (CMake_TEST_XCODE_VERSION VERSION_GREATER_EQUAL 12) + # Since Xcode 12 we have two architectures again: arm64 and x86_64. + set(arch0 x86_64) + set(arch1 arm64) +elseif(CMake_TEST_XCODE_VERSION VERSION_GREATER_EQUAL 10) + # Xcode 10 / 11 do not have two supported architectures for the host. + message(STATUS "Skip test x86_64 only") + return() +elseif(CMake_TEST_XCODE_VERSION VERSION_GREATER_EQUAL 4) + # Xcode 4 no longer supports ppc, but does support x86_64. set(arch0 i386) set(arch1 x86_64) +else() + set(arch0 i386) + set(arch1 ppc) endif() add_library(foo foo.c) @@ -43,7 +34,6 @@ if(CMAKE_OSX_ARCHITECTURES) endif() endif() -message("is_xcode4='${is_xcode4}'") message("archs='${archs}'") message("arch0='${arch0}'") message("arch1='${arch1}'") diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 5d9d193..8f90551 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -578,10 +578,13 @@ if(BUILD_TESTING) if("${CMAKE_GENERATOR}" MATCHES "Make") ADD_TEST_MACRO(Policy0002 Policy0002) endif() - if(CTEST_TEST_OSX_ARCH) + if(CMake_TEST_XCODE_VERSION) + set(Architecture_BUILD_OPTIONS -DCMake_TEST_XCODE_VERSION=${CMake_TEST_XCODE_VERSION}) ADD_TEST_MACRO(Architecture Architecture) set_tests_properties(Architecture PROPERTIES PASS_REGULAR_EXPRESSION "(file is not of required architecture|does not match cputype|not the architecture being linked|but attempting to link with file built for)") + set_property(TEST Architecture APPEND PROPERTY + PASS_REGULAR_EXPRESSION "Skip test x86_64 only|found architecture '.*', required architecture '.*'") endif() list(APPEND TEST_BUILD_DIRS ${CMake_TEST_INSTALL_PREFIX}) -- cgit v0.12 From 40fa2c1c90abcfc74e9a2e55001b89c2fa45d6c5 Mon Sep 17 00:00:00 2001 From: Juan Ramos Date: Mon, 29 Apr 2024 11:05:38 -0700 Subject: Tests: Cleanup CMake_TEST_XCODE_VERSION code - Consolidate calls to xcodebuild -version - Handles cases where CMake_TEST_XCODE_VERSION is 0 to allow running tests with only command-line tools. --- Tests/BuildDepends/CMakeLists.txt | 4 ++++ Tests/BuildDepends/Project/CMakeLists.txt | 14 +------------- Tests/CMakeLists.txt | 13 +++++-------- 3 files changed, 10 insertions(+), 21 deletions(-) diff --git a/Tests/BuildDepends/CMakeLists.txt b/Tests/BuildDepends/CMakeLists.txt index 5ddae83..dbafc85 100644 --- a/Tests/BuildDepends/CMakeLists.txt +++ b/Tests/BuildDepends/CMakeLists.txt @@ -47,6 +47,10 @@ if(NOT CMAKE_GENERATOR MATCHES "Visual Studio ([^9]|9[0-9])") list(APPEND _cmake_options "-DTEST_MULTI3=1") endif() +if (APPLE) + list(APPEND _cmake_options "-DCMake_TEST_XCODE_VERSION=${CMake_TEST_XCODE_VERSION}") +endif() + file(MAKE_DIRECTORY ${BuildDepends_BINARY_DIR}/Project) message("Creating Project/foo.cxx") write_file(${BuildDepends_BINARY_DIR}/Project/foo.cxx diff --git a/Tests/BuildDepends/Project/CMakeLists.txt b/Tests/BuildDepends/Project/CMakeLists.txt index a320d53..2abda2e 100644 --- a/Tests/BuildDepends/Project/CMakeLists.txt +++ b/Tests/BuildDepends/Project/CMakeLists.txt @@ -1,19 +1,7 @@ cmake_minimum_required(VERSION 2.6) project(testRebuild) -if(APPLE) - set(CMake_TEST_XCODE_VERSION 0) - if(XCODE_VERSION) - set(CMake_TEST_XCODE_VERSION "${XCODE_VERSION}") - else() - execute_process( - COMMAND xcodebuild -version - OUTPUT_VARIABLE _version ERROR_VARIABLE _version_err - ) - if(_version MATCHES "^Xcode ([0-9]+(\\.[0-9]+)*)") - set(CMake_TEST_XCODE_VERSION "${CMAKE_MATCH_1}") - endif() - endif() +if(APPLE AND CMake_TEST_XCODE_VERSION) # only use multi-arch if the sysroot exists on this machine # Ninja needs -M which could not be used with multiple -arch flags if(EXISTS "${CMAKE_OSX_SYSROOT}" AND NOT "${CMAKE_GENERATOR}" MATCHES "Ninja") diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 8f90551..a75f6c2 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -299,25 +299,20 @@ if(BUILD_TESTING) "Should the tests that use '--build-target package' be run?" ON) mark_as_advanced(CTEST_TEST_CPACK) - set(CTEST_TEST_OSX_ARCH 0) set(CMake_TEST_XCODE_VERSION 0) if(APPLE) - set(CTEST_TEST_OSX_ARCH 1) if(XCODE_VERSION) set(CMake_TEST_XCODE_VERSION "${XCODE_VERSION}") else() execute_process( COMMAND xcodebuild -version - OUTPUT_VARIABLE _version ERROR_VARIABLE _version_err + OUTPUT_VARIABLE _version + RESULT_VARIABLE _failed ) - if(_version MATCHES "^Xcode ([0-9]+(\\.[0-9]+)*)") + if(NOT _failed AND _version MATCHES "^Xcode ([0-9]+(\\.[0-9]+)*)") set(CMake_TEST_XCODE_VERSION "${CMAKE_MATCH_1}") endif() endif() - if(NOT CMake_TEST_XCODE_VERSION VERSION_LESS 10) - # Since Xcode 10 we do not have two supported architectures for the host. - set(CTEST_TEST_OSX_ARCH 0) - endif() if(CMAKE_OSX_SYSROOT) execute_process( COMMAND xcodebuild -sdk ${CMAKE_OSX_SYSROOT} -version ProductName @@ -952,6 +947,8 @@ if(BUILD_TESTING) "${CMake_BINARY_DIR}/Tests/BuildDepends" ${build_generator_args} --build-project BuildDepends + --build-options + "-DCMake_TEST_XCODE_VERSION=${CMake_TEST_XCODE_VERSION}" ) list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/BuildDepends") -- cgit v0.12