Browse Source

Merge topic 'package-dispatch-apple'

1dd4a9baff Tests: Cover generate_apple_platform_selection_file on all platforms
3148db4533 CMakePackageConfigHelpers: Fix Apple platform selection for tvOS

Acked-by: Kitware Robot <[email protected]>
Merge-request: !9077
Brad King 1 year ago
parent
commit
edb10c5325
28 changed files with 182 additions and 2 deletions
  1. 2 2
      Modules/Internal/PlatformSelectionFile.cmake.in
  2. 7 0
      Tests/RunCMake/CMakeLists.txt
  3. 3 0
      Tests/RunCMake/CMakePackage/CMakeLists.txt
  4. 86 0
      Tests/RunCMake/CMakePackage/RunCMakeTest.cmake
  5. 15 0
      Tests/RunCMake/CMakePackage/apple-common.cmake
  6. 22 0
      Tests/RunCMake/CMakePackage/apple-export-common.cmake
  7. 2 0
      Tests/RunCMake/CMakePackage/apple-export-ios-simulator.cmake
  8. 2 0
      Tests/RunCMake/CMakePackage/apple-export-ios.cmake
  9. 2 0
      Tests/RunCMake/CMakePackage/apple-export-macos.cmake
  10. 2 0
      Tests/RunCMake/CMakePackage/apple-export-tvos-simulator.cmake
  11. 2 0
      Tests/RunCMake/CMakePackage/apple-export-tvos.cmake
  12. 2 0
      Tests/RunCMake/CMakePackage/apple-export-visionos-simulator.cmake
  13. 2 0
      Tests/RunCMake/CMakePackage/apple-export-visionos.cmake
  14. 2 0
      Tests/RunCMake/CMakePackage/apple-export-watchos-simulator.cmake
  15. 2 0
      Tests/RunCMake/CMakePackage/apple-export-watchos.cmake
  16. 7 0
      Tests/RunCMake/CMakePackage/apple-import-common.cmake
  17. 1 0
      Tests/RunCMake/CMakePackage/apple-import-ios-simulator.cmake
  18. 1 0
      Tests/RunCMake/CMakePackage/apple-import-ios.cmake
  19. 1 0
      Tests/RunCMake/CMakePackage/apple-import-macos.cmake
  20. 1 0
      Tests/RunCMake/CMakePackage/apple-import-tvos-simulator.cmake
  21. 1 0
      Tests/RunCMake/CMakePackage/apple-import-tvos.cmake
  22. 1 0
      Tests/RunCMake/CMakePackage/apple-import-visionos-simulator.cmake
  23. 1 0
      Tests/RunCMake/CMakePackage/apple-import-visionos.cmake
  24. 1 0
      Tests/RunCMake/CMakePackage/apple-import-watchos-simulator.cmake
  25. 1 0
      Tests/RunCMake/CMakePackage/apple-import-watchos.cmake
  26. 3 0
      Tests/RunCMake/CMakePackage/include/mylib.h
  27. 6 0
      Tests/RunCMake/CMakePackage/src/myexe.c
  28. 4 0
      Tests/RunCMake/CMakePackage/src/mylib.c

+ 2 - 2
Modules/Internal/PlatformSelectionFile.cmake.in

@@ -5,9 +5,9 @@ if(_CMAKE_OSX_SYSROOT_LOWER MATCHES "(^|/)iphonesimulator")
   @_branch_IOS_SIMULATOR_CONFIG_FILE@
 elseif(_CMAKE_OSX_SYSROOT_LOWER MATCHES "(^|/)iphoneos")
   @_branch_IOS_CONFIG_FILE@
-elseif(_CMAKE_OSX_SYSROOT_LOWER MATCHES "(^|/)tvsimulator")
+elseif(_CMAKE_OSX_SYSROOT_LOWER MATCHES "(^|/)appletvsimulator")
   @_branch_TVOS_SIMULATOR_CONFIG_FILE@
-elseif(_CMAKE_OSX_SYSROOT_LOWER MATCHES "(^|/)tvos")
+elseif(_CMAKE_OSX_SYSROOT_LOWER MATCHES "(^|/)appletvos")
   @_branch_TVOS_CONFIG_FILE@
 elseif(_CMAKE_OSX_SYSROOT_LOWER MATCHES "(^|/)watchsimulator")
   @_branch_WATCHOS_SIMULATOR_CONFIG_FILE@

+ 7 - 0
Tests/RunCMake/CMakeLists.txt

@@ -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 - 0
Tests/RunCMake/CMakePackage/CMakeLists.txt

@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 3.28)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)

+ 86 - 0
Tests/RunCMake/CMakePackage/RunCMakeTest.cmake

@@ -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 - 0
Tests/RunCMake/CMakePackage/apple-common.cmake

@@ -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 - 0
Tests/RunCMake/CMakePackage/apple-export-common.cmake

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

+ 2 - 0
Tests/RunCMake/CMakePackage/apple-export-ios-simulator.cmake

@@ -0,0 +1,2 @@
+set(platform_name ios-simulator)
+include(apple-export-common.cmake)

+ 2 - 0
Tests/RunCMake/CMakePackage/apple-export-ios.cmake

@@ -0,0 +1,2 @@
+set(platform_name ios)
+include(apple-export-common.cmake)

+ 2 - 0
Tests/RunCMake/CMakePackage/apple-export-macos.cmake

@@ -0,0 +1,2 @@
+set(platform_name macos)
+include(apple-export-common.cmake)

+ 2 - 0
Tests/RunCMake/CMakePackage/apple-export-tvos-simulator.cmake

@@ -0,0 +1,2 @@
+set(platform_name tvos-simulator)
+include(apple-export-common.cmake)

+ 2 - 0
Tests/RunCMake/CMakePackage/apple-export-tvos.cmake

@@ -0,0 +1,2 @@
+set(platform_name tvos)
+include(apple-export-common.cmake)

+ 2 - 0
Tests/RunCMake/CMakePackage/apple-export-visionos-simulator.cmake

@@ -0,0 +1,2 @@
+set(platform_name visionos-simulator)
+include(apple-export-common.cmake)

+ 2 - 0
Tests/RunCMake/CMakePackage/apple-export-visionos.cmake

@@ -0,0 +1,2 @@
+set(platform_name visionos)
+include(apple-export-common.cmake)

+ 2 - 0
Tests/RunCMake/CMakePackage/apple-export-watchos-simulator.cmake

@@ -0,0 +1,2 @@
+set(platform_name watchos-simulator)
+include(apple-export-common.cmake)

+ 2 - 0
Tests/RunCMake/CMakePackage/apple-export-watchos.cmake

@@ -0,0 +1,2 @@
+set(platform_name watchos)
+include(apple-export-common.cmake)

+ 7 - 0
Tests/RunCMake/CMakePackage/apple-import-common.cmake

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

+ 1 - 0
Tests/RunCMake/CMakePackage/apple-import-ios-simulator.cmake

@@ -0,0 +1 @@
+include(apple-import-common.cmake)

+ 1 - 0
Tests/RunCMake/CMakePackage/apple-import-ios.cmake

@@ -0,0 +1 @@
+include(apple-import-common.cmake)

+ 1 - 0
Tests/RunCMake/CMakePackage/apple-import-macos.cmake

@@ -0,0 +1 @@
+include(apple-import-common.cmake)

+ 1 - 0
Tests/RunCMake/CMakePackage/apple-import-tvos-simulator.cmake

@@ -0,0 +1 @@
+include(apple-import-common.cmake)

+ 1 - 0
Tests/RunCMake/CMakePackage/apple-import-tvos.cmake

@@ -0,0 +1 @@
+include(apple-import-common.cmake)

+ 1 - 0
Tests/RunCMake/CMakePackage/apple-import-visionos-simulator.cmake

@@ -0,0 +1 @@
+include(apple-import-common.cmake)

+ 1 - 0
Tests/RunCMake/CMakePackage/apple-import-visionos.cmake

@@ -0,0 +1 @@
+include(apple-import-common.cmake)

+ 1 - 0
Tests/RunCMake/CMakePackage/apple-import-watchos-simulator.cmake

@@ -0,0 +1 @@
+include(apple-import-common.cmake)

+ 1 - 0
Tests/RunCMake/CMakePackage/apple-import-watchos.cmake

@@ -0,0 +1 @@
+include(apple-import-common.cmake)

+ 3 - 0
Tests/RunCMake/CMakePackage/include/mylib.h

@@ -0,0 +1,3 @@
+#pragma once
+
+extern int mylib(void);

+ 6 - 0
Tests/RunCMake/CMakePackage/src/myexe.c

@@ -0,0 +1,6 @@
+#include <mylib.h> /* include by angle-bracket to find installed copy */
+
+int main(void)
+{
+  return mylib();
+}

+ 4 - 0
Tests/RunCMake/CMakePackage/src/mylib.c

@@ -0,0 +1,4 @@
+int mylib(void)
+{
+  return 0;
+}