Skip to content

Fix vkloadtests build with cmake 3.29+ #1010

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

Closed
wants to merge 3 commits into from
Closed
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
10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,9 @@ set(KTX_MAIN_SRC
)

if (KTX_FEATURE_ETC_UNPACK)
list(APPEND KTX_MAIN_SRC
external/etcdec/etcdec.cxx
)
list(APPEND KTX_MAIN_SRC
external/etcdec/etcdec.cxx
)
endif()

set(BASISU_ENCODER_CXX_SRC
Expand Down Expand Up @@ -480,12 +480,12 @@ if(KTX_FEATURE_GL_UPLOAD)
)
endif()

if(APPLE_MAC_OS OR LINUX OR WIN32)
if(APPLE OR LINUX OR WIN32)
# By wrapping in generator expression we force multi configuration
# generators (like Visual Studio, Xcode or Ninja multi-config) to
# take the exact path and not change it.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY $<1:${KTX_BUILD_DIR}/$<CONFIG>>)
if(APPLE_MAC_OS OR LINUX)
if(APPLE OR LINUX)
# Use 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
Expand Down
103 changes: 62 additions & 41 deletions cmake/modules/FindVulkan.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -233,23 +233,48 @@ if("FATAL_ERROR" IN_LIST Vulkan_FIND_COMPONENTS)
list(REMOVE_ITEM Vulkan_FIND_COMPONENTS "FATAL_ERROR")
endif()

# FindVulkan only works correctly with the default CMAKE_FIND_FRAMEWORK
# value: FIRST. If LAST it will find the macOS dylibs instead of the iOS
# frameworks when IOS is true. If ALWAYS it will fail to find the macOS
# dylibs. If NEVER it will fail to find the iOS frameworks. If frameworks
# are ever included in the SDK for macOS, the search mechanism will need
# revisiting.
if(DEFINED CMAKE_FIND_FRAMEWORK)
set(_Vulkan_saved_cmake_find_framework ${CMAKE_FIND_FRAMEWORK})
set(CMAKE_FIND_FRAMEWORK FIRST)
# FindVulkan only works correctly for iOS with CMAKE_FIND_FRAMEWORK set to
# FIRST or ALWAYS. If LAST or NEVER it will find the macOS dylibs instead
# of the iOS frameworks because the macOS lib directory has to be added to
# the search path so libraries for various tools can be found.
#
# For macOS there is a MoltenVK.xcframework which contains a static library.
# To find the MoltenVK.dylib, which is needed when building bundles we need
# to LAST or NEVER. LAST appears to be default value.
#
# If frameworks are ever included in the SDK for macOS, the search mechanism
# will need revisiting.
if(APPLE)
if(IOS)
if (NOT ${CMAKE_FIND_FRAMEWORK} STREQUAL "FIRST" AND NOT ${CMAKE_FIND_FRAMEWORK} STREQUAL "ALWAYS")
message(NOTICE "Temporarily setting CMAKE_FIND_FRAMEWORK to FIRST to find Vulkan iOS frameworks.")
set(_Vulkan_saved_cmake_find_framework ${CMAKE_FIND_FRAMEWORK})
set(CMAKE_FIND_FRAMEWORK FIRST)
endif()
else()
if (NOT ${CMAKE_FIND_FRAMEWORK} STREQUAL "LAST" AND NOT ${CMAKE_FIND_FRAMEWORK} STREQUAL "NEVER")
message(NOTICE "Temporarily setting CMAKE_FIND_FRAMEWORK to LAST to find Vulkan macOS dylibs.")
endif()
endif()
endif()

if(IOS)
get_filename_component(Vulkan_Target_SDK "$ENV{VULKAN_SDK}/.." REALPATH)
list(APPEND CMAKE_FRAMEWORK_PATH "${Vulkan_Target_SDK}/iOS/lib")
set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)
set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
if(APPLE)
# Make robust against different ways VULKAN_SDK may be set.
get_filename_component(_Vulkan_SDK_dirname "$ENV{VULKAN_SDK}" NAME)
if(${_Vulkan_SDK_dirname} STREQUAL "macOS" OR ${_Vulkan_SDK_dirname} STREQUAL "iOS")
get_filename_component(Vulkan_SDK_Base "$ENV{VULKAN_SDK}/.." REALPATH)
else()
get_filename_component(Vulkan_SDK_Base "$ENV{VULKAN_SDK}" REALPATH)
endif()
set(_Vulkan_SDK ${Vulkan_SDK_Base}/macOS)
if(IOS)
list(APPEND CMAKE_FRAMEWORK_PATH "${Vulkan_SDK_Base}/iOS/lib")
set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)
set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
endif()
else()
set(_Vulkan_SDK "$ENV{VULKAN_SDK}")
endif()

# For backward compatibility as `FindVulkan` in previous CMake versions allow to retrieve `glslc`
Expand All @@ -264,55 +289,48 @@ endif()
if(WIN32)
set(_Vulkan_library_name vulkan-1)
set(_Vulkan_hint_include_search_paths
"$ENV{VULKAN_SDK}/include"
${_Vulkan_SDK}/include
)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(_Vulkan_hint_executable_search_paths
"$ENV{VULKAN_SDK}/bin"
${_Vulkan_SDK}/bin
)
set(_Vulkan_hint_library_search_paths
"$ENV{VULKAN_SDK}/lib"
"$ENV{VULKAN_SDK}/bin"
${_Vulkan_SDK}/lib
${_Vulkan_SDK}/bin
)
else()
set(_Vulkan_hint_executable_search_paths
"$ENV{VULKAN_SDK}/bin32"
"$ENV{VULKAN_SDK}/bin"
${_Vulkan_SDK}/bin32
${_Vulkan_SDK}/bin
)
set(_Vulkan_hint_library_search_paths
"$ENV{VULKAN_SDK}/lib32"
"$ENV{VULKAN_SDK}/bin32"
"$ENV{VULKAN_SDK}/lib"
"$ENV{VULKAN_SDK}/bin"
${_Vulkan_SDK}/lib32
${_Vulkan_SDK}/bin32
${_Vulkan_SDK}/lib
${_Vulkan_SDK}/bin
)
endif()
else()
set(_Vulkan_library_name vulkan)
set(_Vulkan_hint_include_search_paths
"$ENV{VULKAN_SDK}/include"
${_Vulkan_SDK}/include
)
set(_Vulkan_hint_executable_search_paths
"$ENV{VULKAN_SDK}/bin"
${_Vulkan_SDK}/bin
)
set(_Vulkan_hint_library_search_paths
"$ENV{VULKAN_SDK}/lib"
${_Vulkan_SDK}/lib
)
endif()
if(APPLE AND DEFINED Vulkan_Target_SDK)
list(APPEND _Vulkan_hint_include_search_paths
"${Vulkan_Target_SDK}/macOS/include"
)
if(APPLE AND IOS)
if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
list(APPEND _Vulkan_hint_library_search_paths
"${Vulkan_Target_SDK}/iOS/lib"
${Vulkan_SDK_Base}/iOS/lib
)
elseif(CMAKE_SYSTEM_NAME STREQUAL "tvOS")
list(APPEND _Vulkan_hint_library_search_paths
"${Vulkan_Target_SDK}/tvOS/lib"
)
else()
list(APPEND _Vulkan_hint_library_search_paths
"${Vulkan_Target_SDK}/lib"
${Vulkan_SDK_Base}/tvOS/lib
)
endif()
endif()
Expand All @@ -329,7 +347,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}")
mark_as_advanced(Vulkan_LIBRARY)

find_library(Vulkan_Layer_API_DUMP
Expand Down Expand Up @@ -491,9 +509,9 @@ if(MoltenVK IN_LIST Vulkan_FIND_COMPONENTS)
# CMake has a bug in 3.28 that doesn't handle xcframeworks. Do it by hand for now.
if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
if(CMAKE_VERSION VERSION_LESS 3.29)
set( _Vulkan_hint_library_search_paths ${Vulkan_Target_SDK}/ios/lib/MoltenVK.xcframework/ios-arm64)
set( _Vulkan_hint_library_search_paths ${Vulkan_SDK_Base}/ios/lib/MoltenVK.xcframework/ios-arm64)
else ()
set( _Vulkan_hint_library_search_paths ${Vulkan_Target_SDK}/ios/lib/)
set( _Vulkan_hint_library_search_paths ${Vulkan_SDK_Base}/ios/lib/)
endif ()
endif ()
find_library(Vulkan_MoltenVK_LIBRARY
Expand All @@ -502,6 +520,7 @@ if(MoltenVK IN_LIST Vulkan_FIND_COMPONENTS)
HINTS
${_Vulkan_hint_library_search_paths}
)
message(STATUS "MoltenVK_LIBRARY ${Vulkan_MoltenVK_LIBRARY} search paths ${_Vulkan_hint_library_search_paths}")
mark_as_advanced(Vulkan_MoltenVK_LIBRARY)

find_path(Vulkan_MoltenVK_INCLUDE_DIR
Expand Down Expand Up @@ -955,6 +974,8 @@ if(Vulkan_MoltenVK_FOUND)
endif()

unset(_Vulkan_library_name)
unset(_Vulkan_SDK)
unset(_Vulkan_SDK_dirname)
unset(_Vulkan_hint_include_search_paths)
unset(_Vulkan_hint_executable_search_paths)
unset(_Vulkan_hint_library_search_paths)
Expand Down
9 changes: 4 additions & 5 deletions tests/loadtests/vkloadtests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
# Find Vulkan package
if(APPLE)
# N.B. FindVulkan needs the VULKAN_SDK environment variable set to find
# the iOS frameworks and to set Vulkan_Target_SDK, used later in this
# the iOS frameworks and to set Vulkan_SDK_Base, used later in this
# file. Therefore ensure to make that env. var. available to CMake and
# Xcode. Special care is needed to ensure it is available to the CMake
# and Xcode GUIs.
# set(CMAKE_FIND_DEBUG_MODE TRUE)
find_package( Vulkan REQUIRED COMPONENTS MoltenVK )
# set(CMAKE_FIND_DEBUG_MODE FALSE)

# Derive some other useful variables from those provided by find_package
if(APPLE_LOCKED_OS)
set( Vulkan_SHARE_VULKAN ${Vulkan_Target_SDK}/${CMAKE_SYSTEM_NAME}/share/vulkan )
set( Vulkan_SHARE_VULKAN ${Vulkan_SDK_Base}/${CMAKE_SYSTEM_NAME}/share/vulkan )
else()
# Vulkan_LIBRARIES points to "libvulkan.dylib".
# Find the name of the actual dylib which includes the version no.
Expand Down Expand Up @@ -310,7 +309,7 @@ if(APPLE)
XCODE_EMBED_FRAMEWORKS_CODE_SIGN_ON_COPY "YES"
XCODE_EMBED_FRAMEWORKS_REMOVE_HEADERS_ON_COPY "YES"
# Set RPATH to find frameworks
INSTALL_RPATH "@executable_path/Frameworks"
INSTALL_RPATH @executable_path/Frameworks
)
else()
# Why is XCODE_EMBED_FRAMEWORKS_CODE_SIGN_ON_COPY not set here?
Expand All @@ -321,7 +320,7 @@ if(APPLE)
set_target_properties( vkloadtests PROPERTIES
XCODE_EMBED_FRAMEWORKS "${Vulkan_LIBRARY_REAL_PATH_NAME};${Vulkan_MoltenVK_LIBRARY};${Vulkan_Layer_VALIDATION}"
# Set RPATH to find frameworks and dylibs
INSTALL_RPATH "@executable_path/../Frameworks"
INSTALL_RPATH @executable_path/../Frameworks
)
if(BUILD_SHARED_LIBS)
# XCODE_EMBED_FRAMEWORKS does not appear to support generator
Expand Down