Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS / macOS build fixes, iOS Simulator for x86_64 hosts, VS and Xcode build/run configs #1177

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ jobs:
- name: retrieve VulkanSDK
if: steps.VulkanSDK.outputs.cache-hit != 'true'
run: |
wget https://sdk.lunarg.com/sdk/download/1.3.280.0/mac/vulkansdk-macos-1.3.280.0.dmg
sudo hdiutil attach vulkansdk-macos-1.3.280.0.dmg
sudo /Volumes/vulkansdk-macos-1.3.280.0/InstallVulkan.app/Contents/MacOS/InstallVulkan --root ~/VulkanSDK --accept-licenses --default-answer --confirm-command install com.lunarg.vulkan.ios
sudo hdiutil detach /Volumes/vulkansdk-macos-1.3.280.0
wget https://sdk.lunarg.com/sdk/download/1.3.290.0/mac/vulkansdk-macos-1.3.290.0.dmg
sudo hdiutil attach vulkansdk-macos-1.3.290.0.dmg
sudo /Volumes/vulkansdk-macos-1.3.290.0/InstallVulkan.app/Contents/MacOS/InstallVulkan --root ~/VulkanSDK --accept-licenses --default-answer --confirm-command install com.lunarg.vulkan.ios
sudo hdiutil detach /Volumes/vulkansdk-macos-1.3.290.0

- name: build_ios
run: |
source ~/VulkanSDK/setup-env.sh
cmake -H"." -B"build/ios" -DVKB_BUILD_TESTS=ON -DVKB_BUILD_SAMPLES=ON -G Xcode -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_DEPLOYMENT_TARGET=13.0
source ~/VulkanSDK/iOS/setup-env.sh
cmake -H"." -B"build/ios" -DVKB_BUILD_TESTS=ON -DVKB_BUILD_SAMPLES=ON -G Xcode -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_DEPLOYMENT_TARGET=13.0 -DCMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED=NO
cmake --build "build/ios" --target vulkan_samples --config ${{ matrix.build_type }} -- -sdk iphoneos -allowProvisioningUpdates
72 changes: 52 additions & 20 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ project(vulkan_samples LANGUAGES C CXX)

if(IOS AND CMAKE_VERSION VERSION_LESS 3.20)
message(FATAL_ERROR "Configuring iOS apps requires a minimum CMake version of 3.20")
elseif(APPLE AND NOT IOS AND CMAKE_VERSION VERSION_LESS 3.17)
message(FATAL_ERROR "Configuring Xcode for macOS requires a minimum CMake version of 3.17")
endif()

add_subdirectory(plugins)
Expand Down Expand Up @@ -83,8 +85,10 @@ endif()

# Create MSVC project
if(MSVC)
#Set the working directory to the source of the project so developer dont have to
# Set VS startup project, working directory to project root, and command line arguments to default sample
set_property(DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME})
set_property(TARGET ${PROJECT_NAME} PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
set_property(TARGET ${PROJECT_NAME} PROPERTY VS_DEBUGGER_COMMAND_ARGUMENTS "sample hello_triangle")

#Configure output paths
foreach(CONFIG_TYPE ${CMAKE_CONFIGURATION_TYPES})
Expand All @@ -99,28 +103,40 @@ endif()
# Enable building from XCode for IOS
if(IOS)
set(CMAKE_MACOSX_BUNDLE YES)
set(MACOSX_BUNDLE_GUI_IDENTIFIER com.khronos.vulkansamples)
if(NOT DEFINED MACOSX_BUNDLE_GUI_IDENTIFIER)
if(${CMAKE_OSX_SYSROOT} STREQUAL "iphoneos" AND DEFINED CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM)
message(FATAL_ERROR "Building for iOS device with a specified development team requires setting MACOSX_BUNDLE_GUI_IDENTIFIER")
else()
set(MACOSX_BUNDLE_GUI_IDENTIFIER com.khronos.vulkansamples)
endif()
endif()
if(NOT DEFINED CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM)
if(CMAKE_OSX_SYSROOT STREQUAL ios)
message(FATAL_ERROR "BUILDING for iOS device requires setting the CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM,
It is safe to build for iossimulator without code signing")
if(NOT DEFINED CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED)
if(${CMAKE_OSX_SYSROOT} STREQUAL "iphoneos")
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "YES")
else()
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO")
endif()
endif()
if(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED)
message(FATAL_ERROR "Building for iOS with code signing requires setting CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM; note it is safe to build for iOS Simulator without code signing")
else()
message("Building for ios simulator without a code signing identity; this is allowed, turning off code signing")
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO")
message(STATUS "Building for iOS device or iOS Simulator without a code signing identity; turning off code signing")
set_target_properties(${PROJECT_NAME} PROPERTIES
XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO"
XCODE_EMBED_FRAMEWORKS_CODE_SIGN_ON_COPY "NO"
)
endif ()
else()
message(STATUS "Building for iOS device or iOS Simulator with a code signing identity; turning on code signing")
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "YES")
set_target_properties(${PROJECT_NAME} PROPERTIES
XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "YES"
XCODE_EMBED_FRAMEWORKS_CODE_SIGN_ON_COPY "YES"
)
endif ()
find_package(Vulkan COMPONENTS MoltenVK REQUIRED)
if(${Vulkan_VERSION} VERSION_GREATER_EQUAL 1.3.278)
# No need to search for Vulkan package or MoltenVK library, Vulkan cache variables already defined on Apple platforms by global_options.cmake
if(Vulkan_LIBRARY AND ${Vulkan_VERSION} VERSION_GREATER_EQUAL 1.3.278)
target_sources(${PROJECT_NAME} PRIVATE
${Vulkan_Target_SDK}/iOS/share/vulkan
)
Expand All @@ -145,30 +161,46 @@ if(IOS)
MACOSX_PACKAGE_LOCATION Resources
)
set(FRAMEWORKS_TO_EMBED)
list(APPEND FRAMEWORKS_TO_EMBED "${Vulkan_MoltenVK_LIBRARY};${Vulkan_LIBRARIES};")
# trouble is can't turn this on/off if XCode decides to build debug and we're configured for release. Need to revist
#if(("${VKB_DEBUG}" STREQUAL "ON") OR ("${VKB_VALIDATION_LAYERS}" STREQUAL "ON"))
list(APPEND FRAMEWORKS_TO_EMBED "${Vulkan_Layer_VALIDATION}")
#endif ()
if(Vulkan_MoltenVK_LIBRARY)
list(APPEND FRAMEWORKS_TO_EMBED "${Vulkan_MoltenVK_LIBRARY};")
else()
message(FATAL_ERROR "Can't find MoltenVK library. Please install the Vulkan SDK or MoltenVK project and set VULKAN_SDK.")
endif()
if(Vulkan_LIBRARY)
list(APPEND FRAMEWORKS_TO_EMBED "${Vulkan_LIBRARY};")
endif()
if(Vulkan_Layer_VALIDATION)
# trouble is can't turn this on/off if XCode decides to build debug and we're configured for release. Need to revist
# note the Vulkan validation layer must be present and enabled even in release mode for the shader_debugprintf sample
#if(("${VKB_DEBUG}" STREQUAL "ON") OR ("${VKB_VALIDATION_LAYERS}" STREQUAL "ON"))
list(APPEND FRAMEWORKS_TO_EMBED "${Vulkan_Layer_VALIDATION}")
#endif()
endif()
set_target_properties(${PROJECT_NAME} PROPERTIES
MACOSX_BUNDLE_INFO_PLIST ${PROJECT_SOURCE_DIR}/ios/Info.plist
# These are already defined by the ios Info.plist file specified above
#MACOSX_BUNDLE_SHORT_VERSION_STRING 1.0.0
#MACOSX_BUNDLE_BUNDLE_VERSION 1.0.0
#MACOSX_BUNDLE_BUNDLE_NAME "vulkan samples"
)

set_target_properties(${PROJECT_NAME} PROPERTIES
BUNDLE_IDENTIFIER com.khronos.vulkansamples
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER com.khronos.vulkansamples
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER ${MACOSX_BUNDLE_GUI_IDENTIFIER}
XCODE_ATTRIBUTE_CLANG_ENABLE_MODULES "YES"
XCODE_ATTRIBUTE_LD_RUNPATH_SEARCH_PATHS "@executable_path/Frameworks"
XCODE_ATTRIBUTE_CODE_SIGN_STYLE "Automatic" # already default value
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer"
MACOSX_BUNDLE_SHORT_VERSION_STRING 1.0.0
MACOSX_BUNDLE_BUNDLE_VERSION 1.0.0
MACOSX_BUNDLE_BUNDLE_NAME "vulkan samples"
XCODE_EMBED_FRAMEWORKS "${FRAMEWORKS_TO_EMBED}"
XCODE_EMBED_FRAMEWORKS_REMOVE_HEADERS_ON_COPY "YES"
XCODE_ATTRIBUTE_SKIP_INSTALL NO
XCODE_ATTRIBUTE_INSTALL_PATH "$(LOCAL_APPS_DIR)"
XCODE_ATTRIBUTE_DEAD_CODE_STRIPPING NO
XCODE_SCHEME_ARGUMENTS "sample hello_triangle"
)
endif ()
elseif(APPLE)
# Set Xcode working directory to project root, and command line arguments to default sample
set_target_properties(${PROJECT_NAME} PROPERTIES
XCODE_SCHEME_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
XCODE_SCHEME_ARGUMENTS "sample hello_triangle"
)
endif()
6 changes: 5 additions & 1 deletion app/ios/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@ limitations under the License.
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>com.khronos.vulkansamples</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleLongVersionString</key>
<string></string>
<key>CFBundleShortVersionString</key>
<string>1.0.0</string>
<key>CFBundleVersion</key>
<string>1.0.0</string>
<key>CFBundleName</key>
<string>vulkan samples</string>
<key>CFBundlePackageType</key>
Expand Down
72 changes: 69 additions & 3 deletions bldsys/cmake/global_options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,75 @@ endif()
if(APPLE)
cmake_minimum_required(VERSION 3.24)
set(VKB_ENABLE_PORTABILITY ON CACHE BOOL "Enable portability enumeration and subset features in the framework. This is required to be set when running on Apple platforms." FORCE)
if(IOS)
set(CMAKE_XCODE_GENERATE_SCHEME TRUE)
endif()

find_package(Vulkan QUIET OPTIONAL_COMPONENTS MoltenVK)
if(USE_MoltenVK OR (IOS AND (NOT Vulkan_MoltenVK_FOUND OR (${CMAKE_OSX_SYSROOT} STREQUAL "iphonesimulator" AND ${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "x86_64"))))
# if using MoltenVK, or MoltenVK for iOS was not found, or using iOS Simulator on x86_64, look for MoltenVK in the Vulkan SDK and MoltenVK project locations
if(NOT Vulkan_MoltenVK_LIBRARY)
# since both are available in the Vulkan SDK and MoltenVK github project, make sure we look for MoltenVK framework on iOS and dylib on macOS
set(_saved_cmake_find_framework ${CMAKE_FIND_FRAMEWORK})
if(IOS)
set(CMAKE_FIND_FRAMEWORK ALWAYS)
else()
set(CMAKE_FIND_FRAMEWORK NEVER)
endif()
find_library(Vulkan_MoltenVK_LIBRARY NAMES MoltenVK HINTS "$ENV{VULKAN_SDK}/lib" "$ENV{VULKAN_SDK}/dynamic" "$ENV{VULKAN_SDK}/dylib/macOS")
set(CMAKE_FIND_FRAMEWORK ${_saved_cmake_find_framework})
unset(_saved_cmake_find_framework)
endif()

if(Vulkan_MoltenVK_LIBRARY)
get_filename_component(MoltenVK_LIBRARY_PATH ${Vulkan_MoltenVK_LIBRARY} DIRECTORY)

# For both iOS and macOS: set up global Vulkan Library defines so that MoltenVK is dynamically loaded versus the Vulkan loader
# on iOS we can control Vulkan library loading priority by selecting which libraries are embedded in the iOS application bundle
if(IOS)
add_compile_definitions(_HPP_VULKAN_LIBRARY="MoltenVK.framework/MoltenVK")
# unset FindVulkan.cmake cache variables so Vulkan loader, Validation Layer, and icd/layer json files are not embedded on iOS
unset(Vulkan_LIBRARY CACHE)
unset(Vulkan_Layer_VALIDATION CACHE)

# on macOS make sure that MoltenVK_LIBRARY_PATH points to the MoltenVK project installation and not to the Vulkan_LIBRARY location
# otherwise if DYLD_LIBRARY_PATH points to a common search path, Volk may dynamically load libvulkan.dylib versus libMoltenVK.dylib
elseif(NOT Vulkan_LIBRARY MATCHES "${MoltenVK_LIBRARY_PATH}")
add_compile_definitions(_HPP_VULKAN_LIBRARY="libMoltenVK.dylib")
add_compile_definitions(_GLFW_VULKAN_LIBRARY="libMoltenVK.dylib")
set(ENV{DYLD_LIBRARY_PATH} "${MoltenVK_LIBRARY_PATH}:$ENV{DYLD_LIBRARY_PATH}")
else()
message(FATAL_ERROR "Vulkan library found in MoltenVK search path. Please set VULKAN_SDK to the MoltenVK project install location.")
endif()
message(STATUS "Using MoltenVK: ${Vulkan_MoltenVK_LIBRARY}")
else()
message(FATAL_ERROR "Can't find MoltenVK library. Please install the Vulkan SDK or MoltenVK project and set VULKAN_SDK.")
endif()
elseif(IOS)
# if not using MoltenVK on iOS, set up global Vulkan Library define for iOS Vulkan loader
add_compile_definitions(_HPP_VULKAN_LIBRARY="vulkan.framework/vulkan")
endif()

if(CMAKE_GENERATOR MATCHES "Xcode")
set(CMAKE_XCODE_GENERATE_SCHEME ON)
set(CMAKE_XCODE_SCHEME_ENABLE_GPU_API_VALIDATION OFF)

if(NOT IOS)
# If the Vulkan library's or loader's environment variables are defined, make them available within Xcode schemes
if(DEFINED ENV{DYLD_LIBRARY_PATH})
set(CMAKE_XCODE_SCHEME_ENVIRONMENT "${CMAKE_XCODE_SCHEME_ENVIRONMENT};DYLD_LIBRARY_PATH=$ENV{DYLD_LIBRARY_PATH}")
endif()
if(DEFINED ENV{VK_ADD_LAYER_PATH})
set(CMAKE_XCODE_SCHEME_ENVIRONMENT "${CMAKE_XCODE_SCHEME_ENVIRONMENT};VK_ADD_LAYER_PATH=$ENV{VK_ADD_LAYER_PATH}")
endif()
if(DEFINED ENV{VK_ICD_FILENAMES})
set(CMAKE_XCODE_SCHEME_ENVIRONMENT "${CMAKE_XCODE_SCHEME_ENVIRONMENT};VK_ICD_FILENAMES=$ENV{VK_ICD_FILENAMES}")
endif()
if(DEFINED ENV{VK_DRIVER_FILES})
set(CMAKE_XCODE_SCHEME_ENVIRONMENT "${CMAKE_XCODE_SCHEME_ENVIRONMENT};VK_DRIVER_FILES=$ENV{VK_DRIVER_FILES}")
endif()

# Suppress regeneration for Xcode since environment variables will be lost if not set in Xcode locations/custom paths
set(CMAKE_SUPPRESS_REGENERATION ON)
endif()
endif()
endif()

set(VKB_WARNINGS_AS_ERRORS ON CACHE BOOL "Enable Warnings as Errors")
Expand Down
2 changes: 1 addition & 1 deletion bldsys/cmake/module/FindVulkan.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ find_library(Vulkan_LIBRARY
HINTS
${_Vulkan_hint_library_search_paths}
)
message(STATUS "vulkan_library ${Vulkan_LIBRARY} search paths ${_Vulkan_hint_library_search_paths}")
#message(STATUS "vulkan_library ${Vulkan_LIBRARY} search paths ${_Vulkan_hint_library_search_paths}")
SRSaunders marked this conversation as resolved.
Show resolved Hide resolved
mark_as_advanced(Vulkan_LIBRARY)

find_library(Vulkan_Layer_API_DUMP
Expand Down
Loading
Loading