From 7a45c4e6159c0815e4663a529a1e718136a16e39 Mon Sep 17 00:00:00 2001 From: Andreas Atteneder Date: Wed, 27 Mar 2024 22:55:25 +0100 Subject: [PATCH] feat: Support for Apple tvOS and Apple visionOS. (#885) With this patch it's possible to compile against tvOS and visionOS SDKs. Similar to iOS: - `ktx`/`ktx_read` default to library type `STATIC` - Tools and test targets are disabled - Bit-code embedding can be enabled via `KTX_EMBED_BITCODE` Differences to iOS: - It's possible to build a dynamic/shared library framework (via `KTX_FEATURE_STATIC_LIBRARY=OFF`). --- CMakeLists.txt | 55 +++++++++++++++++++--------------- tests/CMakeLists.txt | 2 +- tests/loadtests/CMakeLists.txt | 2 +- 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d15bc4dcf..07e30d63b8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,7 +37,15 @@ include(cmake/cputypetest.cmake) # OPTIONS -if( IOS OR EMSCRIPTEN ) +if(IOS OR CMAKE_SYSTEM_NAME STREQUAL "tvOS" OR CMAKE_SYSTEM_NAME STREQUAL "visionOS") + set( APPLE_LOCKED_OS ON ) +endif() + +if(APPLE AND CMAKE_SYSTEM_NAME STREQUAL "Darwin") + set( APPLE_MAC_OS ON ) +endif() + +if(APPLE_LOCKED_OS OR EMSCRIPTEN) set( LIB_TYPE_DEFAULT ON ) else() set( LIB_TYPE_DEFAULT OFF ) @@ -46,7 +54,7 @@ endif() CMAKE_DEPENDENT_OPTION( KTX_FEATURE_TOOLS "Create KTX tools" ON - "NOT IOS;NOT ANDROID;NOT EMSCRIPTEN" + "NOT APPLE_LOCKED_OS;NOT ANDROID;NOT EMSCRIPTEN" OFF ) option( KTX_FEATURE_DOC "Create KTX documentation." OFF ) @@ -109,7 +117,7 @@ endif() CMAKE_DEPENDENT_OPTION( KTX_EMBED_BITCODE "Embed bitcode in binaries." OFF - "APPLE AND IOS" + "APPLE AND APPLE_LOCKED_OS" OFF ) @@ -128,15 +136,13 @@ set( KTX_FEATURE_LOADTEST_APPS set_property( CACHE KTX_FEATURE_LOADTEST_APPS PROPERTY STRINGS OFF OpenGL Vulkan OpenGL+Vulkan ) -if(WIN32 OR APPLE) - if(NOT IOS) - CMAKE_DEPENDENT_OPTION( KTX_LOADTEST_APPS_USE_LOCAL_DEPENDENCIES - "Look for locally installed dependencies. Fail build if not found. When OFF use binaries from the KTX-Software repo, if available for the target processor. Useful when building for Windows arm64 using vcpkg packages." - OFF - KTX_FEATURE_LOADTEST_APPS - OFF - ) - endif() +if(WIN32 OR APPLE_MAC_OS) + CMAKE_DEPENDENT_OPTION( KTX_LOADTEST_APPS_USE_LOCAL_DEPENDENCIES + "Look for locally installed dependencies. Fail build if not found. When OFF use binaries from the KTX-Software repo, if available for the target processor. Useful when building for Windows arm64 using vcpkg packages." + OFF + KTX_FEATURE_LOADTEST_APPS + OFF + ) else() set( KTX_LOADTEST_APPS_USE_LOCAL_DEPENDENCIES ON ) endif() @@ -155,16 +161,19 @@ if(APPLE) set(XCODE_DEVELOPMENT_TEAM "" CACHE STRING "Xcode development team ID") set(PRODUCTBUILD_IDENTITY_NAME "" CACHE STRING "productbuild identity name") set(PRODUCTBUILD_KEYCHAIN_PATH "" CACHE FILEPATH "pkgbuild keychain file") - if(IOS) + if(APPLE_LOCKED_OS) set(XCODE_PROVISIONING_PROFILE_SPECIFIER "" CACHE STRING "Xcode provisioning profile specifier") set(MOLTENVK_SDK "$ENV{VULKAN_SDK}/../MoltenVK" CACHE STRING "MoltenVK directory inside the Vulkan SDK") endif() # Deployment - set(CMAKE_OSX_DEPLOYMENT_TARGET "10.11" CACHE STRING "macOS Deployment Target") - if(IOS) - set(CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET "11.0" CACHE STRING "iOS Deployment Target") + if(APPLE_MAC_OS) + set(CMAKE_OSX_DEPLOYMENT_TARGET "10.11" CACHE STRING "macOS Deployment Target") + elseif(IOS OR CMAKE_SYSTEM_NAME STREQUAL "tvOS") + set(CMAKE_OSX_DEPLOYMENT_TARGET "11.0" CACHE STRING "iOS/tvOS Deployment Target") set(CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH NO) + elseif(CMAKE_SYSTEM_NAME STREQUAL "visionOS") + set(CMAKE_OSX_DEPLOYMENT_TARGET "1.0" CACHE STRING "visionOS Deployment Target") endif() endif() @@ -456,14 +465,12 @@ if(WIN32) # generators (like Visual Studio) to take the exact path and not # change it. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY $<1:${KTX_BUILD_DIR}/$>) -elseif(APPLE OR LINUX) - if(NOT IOS) +elseif(APPLE_MAC_OS OR LINUX) # Set a common RUNTIME_OUTPUT_DIR and LIBRARY_OUTPUT_DIR for all targets, # so that INSTALL RPATH is functional in build directory as well. # BUILD_WITH_INSTALL_RPATH is necessary for working code signing. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY $<1:${KTX_BUILD_DIR}/$>) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY $<1:${KTX_BUILD_DIR}/$>) - endif() endif() set(KTX_BASISU_INCLUDE_DIRS @@ -500,7 +507,7 @@ macro(common_libktx_settings target enable_write library_type) CXX_STANDARD_REQUIRED YES ) - if(IOS) + if(APPLE_LOCKED_OS) set_target_properties(${target} PROPERTIES FRAMEWORK TRUE ) @@ -1157,7 +1164,7 @@ endif() # Use of this to install KHR/khr_df.h is due to CMake's failure to # preserve the include source folder hierarchy. # See https://gitlab.kitware.com/cmake/cmake/-/issues/16739. -if (IOS) +if (APPLE_LOCKED_OS) set_source_files_properties( include/KHR/khr_df.h PROPERTIES MACOSX_PACKAGE_LOCATION Headers/KHR @@ -1234,8 +1241,8 @@ elseif( CMAKE_SYSTEM_PROCESSOR ) else() set(processor_name ${CMAKE_SYSTEM_PROCESSOR}) endif() -elseif( IOS ) - # CMAKE_SYSTEM_PROCESSOR not set when building for iOS. +elseif( APPLE_LOCKED_OS ) + # CMAKE_SYSTEM_PROCESSOR not set when building for iOS/tvOS/visionOS. set(processor_name "arm64") endif() string(TOLOWER "${processor_name}" processor_name) @@ -1243,7 +1250,7 @@ string(TOLOWER "${processor_name}" processor_name) set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${KTX_VERSION_FULL}-${CMAKE_SYSTEM_NAME}-${processor_name}") if(APPLE) - if(NOT IOS) + if(APPLE_MAC_OS) install(FILES tools/package/mac/ktx-uninstall DESTINATION ${CMAKE_INSTALL_BINDIR} PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e02a2b7aa0..1d4c2d690e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -20,7 +20,7 @@ if(KTX_FEATURE_LOADTEST_APPS) endif() # gtest based unit-tests -if(KTX_FEATURE_TESTS AND NOT IOS AND NOT ANDROID AND NOT EMSCRIPTEN) +if(KTX_FEATURE_TESTS AND NOT APPLE_LOCKED_OS AND NOT ANDROID AND NOT EMSCRIPTEN) include(tests.cmake) endif() diff --git a/tests/loadtests/CMakeLists.txt b/tests/loadtests/CMakeLists.txt index f175166394..8a54d2cb7b 100644 --- a/tests/loadtests/CMakeLists.txt +++ b/tests/loadtests/CMakeLists.txt @@ -8,7 +8,7 @@ if(WIN32) ) endif() -if(NOT IOS) +if(NOT APPLE_LOCKED_OS) set( fp_pref ${CMAKE_FIND_PACKAGE_PREFER_CONFIG} ) # Prefer CONFIG for vcpkg set( CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE )