Skip to content

Commit a7ee236

Browse files
authored
FindVulkan fixes. Bump CMake minimum version. (#1101)
* Bump cmake minimum version. Support pre-3.28 in FindVulkan. Fixes #1100. * Fix use of undefined variable and errant brace. * Set CMAKE_FIND_FRAMEWORK for correct operation. * Fix incorrect variable name and formatting. Only set CMAKE_FIND_FRAMEWORK when not previously defined. * Delete unnecessary unset. CMAKE_FIND_FRAMEWORK is not set if _Vulkan_saved_cmake_find_framework is unset. * Revert CMake version bumps. Instead: * Add fatal error in app/CMakeLists.txt when IOS and version < 3.20. * Change version <3.28 workaround in FindVulkan to work with CMake versions back to 3.16 and earlier.
1 parent 6d2ecf5 commit a7ee236

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

app/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ include(android_package)
2121
# create sample app project
2222
project(vulkan_samples LANGUAGES C CXX)
2323

24+
if(IOS AND CMAKE_VERSION VERSION_LESS 3.20)
25+
message(FATAL_ERROR "Configuring iOS apps requires a minimum CMake version of 3.20")
26+
endif()
27+
2428
add_subdirectory(plugins)
2529
add_subdirectory(apps)
2630

@@ -169,4 +173,4 @@ if(IOS)
169173
XCODE_ATTRIBUTE_DEAD_CODE_STRIPPING NO
170174
XCODE_SCHEME_ARGUMENTS "sample hello_triangle"
171175
)
172-
endif ()
176+
endif ()

bldsys/cmake/module/FindVulkan.cmake

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,17 @@ if("FATAL_ERROR" IN_LIST Vulkan_FIND_COMPONENTS)
233233
list(REMOVE_ITEM Vulkan_FIND_COMPONENTS "FATAL_ERROR")
234234
endif()
235235

236+
# FindVulkan only works correctly with the default CMAKE_FIND_FRAMEWORK
237+
# value: FIRST. If LAST it will find the macOS dylibs instead of the iOS
238+
# frameworks when IOS is true. If ALWAYS it will fail to find the macOS
239+
# dylibs. If NEVER it will fail to find the iOS frameworks. If frameworks
240+
# are ever included in the SDK for macOS, the search mechanism will need
241+
# revisiting.
242+
if(DEFINED CMAKE_FIND_FRAMEWORK)
243+
set(_Vulkan_saved_cmake_find_framework ${CMAKE_FIND_FRAMEWORK})
244+
set(CMAKE_FIND_FRAMEWORK FIRST)
245+
endif()
246+
236247
if(IOS)
237248
get_filename_component(Vulkan_Target_SDK "$ENV{VULKAN_SDK}/.." REALPATH)
238249
list(APPEND CMAKE_FRAMEWORK_PATH "${Vulkan_Target_SDK}/iOS/lib")
@@ -287,7 +298,7 @@ else()
287298
"$ENV{VULKAN_SDK}/lib"
288299
)
289300
endif()
290-
if(APPLE AND DEFINED ENV{VULKAN_SDK})
301+
if(APPLE AND DEFINED Vulkan_Target_SDK)
291302
list(APPEND _Vulkan_hint_include_search_paths
292303
"${Vulkan_Target_SDK}/macOS/include"
293304
)
@@ -301,7 +312,7 @@ if(APPLE AND DEFINED ENV{VULKAN_SDK})
301312
)
302313
else()
303314
list(APPEND _Vulkan_hint_library_search_paths
304-
"${Vulkan_Target_SDK}}/lib"
315+
"${Vulkan_Target_SDK}/lib"
305316
)
306317
endif()
307318
endif()
@@ -318,7 +329,7 @@ find_library(Vulkan_LIBRARY
318329
HINTS
319330
${_Vulkan_hint_library_search_paths}
320331
)
321-
message(STATUS vulkan_library ${Vulkan_LIBRARY} search paths ${_Vulkan_hint_library_search_paths})
332+
message(STATUS "vulkan_library ${Vulkan_LIBRARY} search paths ${_Vulkan_hint_library_search_paths}")
322333
mark_as_advanced(Vulkan_LIBRARY)
323334

324335
find_library(Vulkan_Layer_API_DUMP
@@ -522,6 +533,11 @@ if (dxc IN_LIST Vulkan_FIND_COMPONENTS)
522533
mark_as_advanced(Vulkan_dxc_EXECUTABLE)
523534
endif()
524535

536+
if(DEFINED _Vulkan_saved_cmake_find_framework)
537+
set(CMAKE_FIND_FRAMEWORK ${_Vulkan_saved_cmake_find_framework})
538+
unset(_Vulkan_saved_cmake_find_framework)
539+
endif()
540+
525541
if(Vulkan_GLSLC_EXECUTABLE)
526542
set(Vulkan_glslc_FOUND TRUE)
527543
else()
@@ -652,9 +668,18 @@ find_package_handle_standard_args(Vulkan
652668

653669
if(Vulkan_FOUND AND NOT TARGET Vulkan::Vulkan)
654670
add_library(Vulkan::Vulkan UNKNOWN IMPORTED)
671+
get_filename_component(_Vulkan_lib_extension ${Vulkan_LIBRARIES} LAST_EXT)
672+
if(_Vulkan_lib_extension STREQUAL ".framework" AND CMAKE_VERSION VERSION_LESS 3.28)
673+
set_target_properties(Vulkan::Vulkan PROPERTIES
674+
# Prior to 3.28 must reference library just inside the framework.
675+
IMPORTED_LOCATION "${Vulkan_LIBRARIES}/vulkan")
676+
else()
677+
set_target_properties(Vulkan::Vulkan PROPERTIES
678+
IMPORTED_LOCATION "${Vulkan_LIBRARIES}")
679+
endif()
655680
set_target_properties(Vulkan::Vulkan PROPERTIES
656-
IMPORTED_LOCATION "${Vulkan_LIBRARIES}"
657681
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
682+
unset(_Vulkan_lib_extension)
658683
endif()
659684

660685
if(Vulkan_FOUND AND NOT TARGET Vulkan::Headers)
@@ -934,4 +959,4 @@ unset(_Vulkan_hint_include_search_paths)
934959
unset(_Vulkan_hint_executable_search_paths)
935960
unset(_Vulkan_hint_library_search_paths)
936961

937-
cmake_policy(POP)
962+
cmake_policy(POP)

0 commit comments

Comments
 (0)