mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-11 08:20:18 -06:00
Tests: Cover generate_apple_platform_selection_file on all platforms
The test added by commit 37bc3400cd (CMakePackageConfigHelpers: Add
generate_apple_platform_selection_file(), 2023-11-03) covers importing
only on macOS, and is specific to the xcframework test case. Add a
dedicated test for `generate_apple_platform_selection_file` that covers
export and import on all platforms.
This commit is contained in:
@@ -325,6 +325,13 @@ if(UNIX AND "${CMAKE_GENERATOR}" MATCHES "Unix Makefiles|Ninja")
|
||||
add_RunCMake_test(Byproducts)
|
||||
endif()
|
||||
add_RunCMake_test(CMakeDependentOption)
|
||||
if(APPLE # Remove these conditions when the test has non-Apple cases
|
||||
AND CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
|
||||
add_RunCMake_test(CMakePackage
|
||||
-DCMake_TEST_XCODE_VERSION=${CMake_TEST_XCODE_VERSION}
|
||||
-DCMAKE_C_COMPILER_ID=${CMAKE_C_COMPILER_ID}
|
||||
)
|
||||
endif()
|
||||
add_RunCMake_test(CMakeRoleGlobalProperty)
|
||||
add_RunCMake_test(CMakeRelease -DCMake_TEST_JQ=${CMake_TEST_JQ})
|
||||
if(CMAKE_GENERATOR MATCHES "Make|Ninja")
|
||||
|
||||
3
Tests/RunCMake/CMakePackage/CMakeLists.txt
Normal file
3
Tests/RunCMake/CMakePackage/CMakeLists.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
cmake_minimum_required(VERSION 3.28)
|
||||
project(${RunCMake_TEST} NONE)
|
||||
include(${RunCMake_TEST}.cmake)
|
||||
86
Tests/RunCMake/CMakePackage/RunCMakeTest.cmake
Normal file
86
Tests/RunCMake/CMakePackage/RunCMakeTest.cmake
Normal file
@@ -0,0 +1,86 @@
|
||||
include(RunCMake)
|
||||
|
||||
if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
|
||||
set(maybe_CMAKE_BUILD_TYPE -DCMAKE_BUILD_TYPE=Release)
|
||||
endif()
|
||||
|
||||
function(apple_export platform system_name archs sysroot)
|
||||
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/apple-export-${platform}-build)
|
||||
string(REPLACE ";" "\\;" archs "${archs}")
|
||||
run_cmake_with_options(apple-export-${platform}
|
||||
"-DCMAKE_SYSTEM_NAME=${system_name}"
|
||||
"-DCMAKE_OSX_ARCHITECTURES=${archs}"
|
||||
"-DCMAKE_OSX_SYSROOT=${sysroot}"
|
||||
"-DCMAKE_INSTALL_PREFIX=${apple_install}"
|
||||
${maybe_CMAKE_BUILD_TYPE}
|
||||
)
|
||||
set(RunCMake_TEST_NO_CLEAN 1)
|
||||
run_cmake_command(apple-export-${platform}-build ${CMAKE_COMMAND} --build . --config Release)
|
||||
run_cmake_command(apple-export-${platform}-install ${CMAKE_COMMAND} --install . --config Release)
|
||||
endfunction()
|
||||
|
||||
function(apple_import platform system_name archs sysroot)
|
||||
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/apple-import-${platform}-build)
|
||||
string(REPLACE ";" "\\;" archs "${archs}")
|
||||
run_cmake_with_options(apple-import-${platform}
|
||||
"-DCMAKE_SYSTEM_NAME=${system_name}"
|
||||
"-DCMAKE_OSX_ARCHITECTURES=${archs}"
|
||||
"-DCMAKE_OSX_SYSROOT=${sysroot}"
|
||||
"-DCMAKE_PREFIX_PATH=${apple_install}"
|
||||
${maybe_CMAKE_BUILD_TYPE}
|
||||
)
|
||||
set(RunCMake_TEST_NO_CLEAN 1)
|
||||
run_cmake_command(apple-import-${platform}-build ${CMAKE_COMMAND} --build . --config Release)
|
||||
endfunction()
|
||||
|
||||
if(APPLE AND CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
|
||||
set(apple_install ${RunCMake_BINARY_DIR}/apple-install)
|
||||
file(REMOVE_RECURSE "${apple_install}")
|
||||
|
||||
if(CMake_TEST_XCODE_VERSION VERSION_GREATER_EQUAL 12)
|
||||
set(macos_archs "x86_64;arm64")
|
||||
set(watch_sim_archs "x86_64")
|
||||
else()
|
||||
set(macos_archs "x86_64")
|
||||
set(watch_sim_archs "i386")
|
||||
endif()
|
||||
|
||||
if(CMake_TEST_XCODE_VERSION VERSION_GREATER_EQUAL 9)
|
||||
set(watch_archs "armv7k;arm64_32")
|
||||
else()
|
||||
set(watch_archs "armv7k")
|
||||
endif()
|
||||
|
||||
#FIXME(#25266): Xcode 15.0 does not have visionOS. Improve this condition.
|
||||
#if(CMake_TEST_XCODE_VERSION VERSION_GREATER_EQUAL 15)
|
||||
# set(enable_visionos 1)
|
||||
#endif()
|
||||
|
||||
apple_export(macos Darwin "${macos_archs}" macosx)
|
||||
apple_export(ios iOS "arm64" iphoneos)
|
||||
apple_export(tvos tvOS "arm64" appletvos)
|
||||
if(enable_visionos)
|
||||
apple_export(visionos visionOS "arm64" xros)
|
||||
endif()
|
||||
apple_export(watchos watchOS "${watch_archs}" watchos)
|
||||
apple_export(ios-simulator iOS "${macos_archs}" iphonesimulator)
|
||||
apple_export(tvos-simulator tvOS "${macos_archs}" appletvsimulator)
|
||||
if(enable_visionos)
|
||||
apple_export(visionos-simulator visionOS "${macos_archs}" xrsimulator)
|
||||
endif()
|
||||
apple_export(watchos-simulator watchOS "${watch_sim_archs}" watchsimulator)
|
||||
|
||||
apple_import(macos Darwin "${macos_archs}" macosx)
|
||||
apple_import(ios iOS "arm64" iphoneos)
|
||||
apple_import(tvos tvOS "arm64" appletvos)
|
||||
if(enable_visionos)
|
||||
apple_import(visionos visionOS "arm64" xros)
|
||||
endif()
|
||||
apple_import(watchos watchOS "${watch_archs}" watchos)
|
||||
apple_import(ios-simulator iOS "${macos_archs}" iphonesimulator)
|
||||
apple_import(tvos-simulator tvOS "${macos_archs}" appletvsimulator)
|
||||
if(enable_visionos)
|
||||
apple_import(visionos-simulator visionOS "${macos_archs}" xrsimulator)
|
||||
endif()
|
||||
apple_import(watchos-simulator watchOS "${watch_sim_archs}" watchsimulator)
|
||||
endif()
|
||||
15
Tests/RunCMake/CMakePackage/apple-common.cmake
Normal file
15
Tests/RunCMake/CMakePackage/apple-common.cmake
Normal file
@@ -0,0 +1,15 @@
|
||||
enable_language(C)
|
||||
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "^(iOS)$")
|
||||
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO")
|
||||
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO")
|
||||
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "")
|
||||
set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE "NO")
|
||||
endif()
|
||||
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "^(tvOS|watchOS|visionOS)$")
|
||||
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO")
|
||||
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO")
|
||||
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "")
|
||||
set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE "YES")
|
||||
endif()
|
||||
22
Tests/RunCMake/CMakePackage/apple-export-common.cmake
Normal file
22
Tests/RunCMake/CMakePackage/apple-export-common.cmake
Normal file
@@ -0,0 +1,22 @@
|
||||
include(apple-common.cmake)
|
||||
|
||||
add_library(mylib STATIC src/mylib.c)
|
||||
target_sources(mylib PUBLIC FILE_SET HEADERS BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include FILES include/mylib.h)
|
||||
install(TARGETS mylib EXPORT mylib-targets FILE_SET HEADERS ARCHIVE DESTINATION lib/${platform_name})
|
||||
|
||||
install(EXPORT mylib-targets DESTINATION lib/${platform_name}/cmake/mylib)
|
||||
|
||||
include(CMakePackageConfigHelpers)
|
||||
generate_apple_platform_selection_file(mylib-config-install.cmake
|
||||
INSTALL_DESTINATION lib/cmake/mylib
|
||||
MACOS_CONFIG_FILE lib/macos/cmake/mylib/mylib-targets.cmake
|
||||
IOS_CONFIG_FILE lib/ios/cmake/mylib/mylib-targets.cmake
|
||||
IOS_SIMULATOR_CONFIG_FILE lib/ios-simulator/cmake/mylib/mylib-targets.cmake
|
||||
TVOS_CONFIG_FILE lib/tvos/cmake/mylib/mylib-targets.cmake
|
||||
TVOS_SIMULATOR_CONFIG_FILE lib/tvos-simulator/cmake/mylib/mylib-targets.cmake
|
||||
VISIONOS_CONFIG_FILE lib/watchos/cmake/mylib/mylib-targets.cmake
|
||||
VISIONOS_SIMULATOR_CONFIG_FILE lib/watchos-simulator/cmake/mylib/mylib-targets.cmake
|
||||
WATCHOS_CONFIG_FILE lib/watchos/cmake/mylib/mylib-targets.cmake
|
||||
WATCHOS_SIMULATOR_CONFIG_FILE lib/watchos-simulator/cmake/mylib/mylib-targets.cmake
|
||||
)
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/mylib-config-install.cmake DESTINATION lib/cmake/mylib RENAME mylib-config.cmake)
|
||||
@@ -0,0 +1,2 @@
|
||||
set(platform_name ios-simulator)
|
||||
include(apple-export-common.cmake)
|
||||
2
Tests/RunCMake/CMakePackage/apple-export-ios.cmake
Normal file
2
Tests/RunCMake/CMakePackage/apple-export-ios.cmake
Normal file
@@ -0,0 +1,2 @@
|
||||
set(platform_name ios)
|
||||
include(apple-export-common.cmake)
|
||||
2
Tests/RunCMake/CMakePackage/apple-export-macos.cmake
Normal file
2
Tests/RunCMake/CMakePackage/apple-export-macos.cmake
Normal file
@@ -0,0 +1,2 @@
|
||||
set(platform_name macos)
|
||||
include(apple-export-common.cmake)
|
||||
@@ -0,0 +1,2 @@
|
||||
set(platform_name tvos-simulator)
|
||||
include(apple-export-common.cmake)
|
||||
2
Tests/RunCMake/CMakePackage/apple-export-tvos.cmake
Normal file
2
Tests/RunCMake/CMakePackage/apple-export-tvos.cmake
Normal file
@@ -0,0 +1,2 @@
|
||||
set(platform_name tvos)
|
||||
include(apple-export-common.cmake)
|
||||
@@ -0,0 +1,2 @@
|
||||
set(platform_name visionos-simulator)
|
||||
include(apple-export-common.cmake)
|
||||
2
Tests/RunCMake/CMakePackage/apple-export-visionos.cmake
Normal file
2
Tests/RunCMake/CMakePackage/apple-export-visionos.cmake
Normal file
@@ -0,0 +1,2 @@
|
||||
set(platform_name visionos)
|
||||
include(apple-export-common.cmake)
|
||||
@@ -0,0 +1,2 @@
|
||||
set(platform_name watchos-simulator)
|
||||
include(apple-export-common.cmake)
|
||||
2
Tests/RunCMake/CMakePackage/apple-export-watchos.cmake
Normal file
2
Tests/RunCMake/CMakePackage/apple-export-watchos.cmake
Normal file
@@ -0,0 +1,2 @@
|
||||
set(platform_name watchos)
|
||||
include(apple-export-common.cmake)
|
||||
7
Tests/RunCMake/CMakePackage/apple-import-common.cmake
Normal file
7
Tests/RunCMake/CMakePackage/apple-import-common.cmake
Normal file
@@ -0,0 +1,7 @@
|
||||
include(apple-common.cmake)
|
||||
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE NEVER)
|
||||
find_package(mylib CONFIG REQUIRED)
|
||||
|
||||
add_executable(myexe src/myexe.c)
|
||||
target_link_libraries(myexe PRIVATE mylib)
|
||||
@@ -0,0 +1 @@
|
||||
include(apple-import-common.cmake)
|
||||
1
Tests/RunCMake/CMakePackage/apple-import-ios.cmake
Normal file
1
Tests/RunCMake/CMakePackage/apple-import-ios.cmake
Normal file
@@ -0,0 +1 @@
|
||||
include(apple-import-common.cmake)
|
||||
1
Tests/RunCMake/CMakePackage/apple-import-macos.cmake
Normal file
1
Tests/RunCMake/CMakePackage/apple-import-macos.cmake
Normal file
@@ -0,0 +1 @@
|
||||
include(apple-import-common.cmake)
|
||||
@@ -0,0 +1 @@
|
||||
include(apple-import-common.cmake)
|
||||
1
Tests/RunCMake/CMakePackage/apple-import-tvos.cmake
Normal file
1
Tests/RunCMake/CMakePackage/apple-import-tvos.cmake
Normal file
@@ -0,0 +1 @@
|
||||
include(apple-import-common.cmake)
|
||||
@@ -0,0 +1 @@
|
||||
include(apple-import-common.cmake)
|
||||
1
Tests/RunCMake/CMakePackage/apple-import-visionos.cmake
Normal file
1
Tests/RunCMake/CMakePackage/apple-import-visionos.cmake
Normal file
@@ -0,0 +1 @@
|
||||
include(apple-import-common.cmake)
|
||||
@@ -0,0 +1 @@
|
||||
include(apple-import-common.cmake)
|
||||
1
Tests/RunCMake/CMakePackage/apple-import-watchos.cmake
Normal file
1
Tests/RunCMake/CMakePackage/apple-import-watchos.cmake
Normal file
@@ -0,0 +1 @@
|
||||
include(apple-import-common.cmake)
|
||||
3
Tests/RunCMake/CMakePackage/include/mylib.h
Normal file
3
Tests/RunCMake/CMakePackage/include/mylib.h
Normal file
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
extern int mylib(void);
|
||||
6
Tests/RunCMake/CMakePackage/src/myexe.c
Normal file
6
Tests/RunCMake/CMakePackage/src/myexe.c
Normal file
@@ -0,0 +1,6 @@
|
||||
#include <mylib.h> /* include by angle-bracket to find installed copy */
|
||||
|
||||
int main(void)
|
||||
{
|
||||
return mylib();
|
||||
}
|
||||
4
Tests/RunCMake/CMakePackage/src/mylib.c
Normal file
4
Tests/RunCMake/CMakePackage/src/mylib.c
Normal file
@@ -0,0 +1,4 @@
|
||||
int mylib(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user