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.
This commit is contained in:
Juan Ramos
2024-04-29 11:05:38 -07:00
parent abd1b02dfa
commit 40fa2c1c90
3 changed files with 10 additions and 21 deletions

View File

@@ -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

View File

@@ -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")

View File

@@ -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")