Imported Upstream version 3.25.0
[platform/upstream/cmake.git] / Modules / FindVulkan.cmake
1 # Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
3
4 #[=======================================================================[.rst:
5 FindVulkan
6 ----------
7
8 .. versionadded:: 3.7
9
10 Find Vulkan, which is a low-overhead, cross-platform 3D graphics
11 and computing API.
12
13 Optional COMPONENTS
14 ^^^^^^^^^^^^^^^^^^^
15
16 .. versionadded:: 3.24
17
18 This module respects several optional COMPONENTS.
19 There are corresponding imported targets for each of these.
20
21 ``glslc``
22   The SPIR-V compiler.
23
24 ``glslangValidator``
25   The ``glslangValidator`` tool.
26
27 ``glslang``
28   The SPIR-V generator library.
29
30 ``shaderc_combined``
31   The static library for Vulkan shader compilation.
32
33 ``SPIRV-Tools``
34   Tools to process SPIR-V modules.
35
36 ``MoltenVK``
37   On macOS, an additional component ``MoltenVK`` is available.
38
39 ``dxc``
40   .. versionadded:: 3.25
41
42   The DirectX Shader Compiler.
43
44 The ``glslc`` and ``glslangValidator`` components are provided even
45 if not explicitly requested (for backward compatibility).
46
47 IMPORTED Targets
48 ^^^^^^^^^^^^^^^^
49
50 This module defines :prop_tgt:`IMPORTED` targets if Vulkan has been found:
51
52 ``Vulkan::Vulkan``
53   The main Vulkan library.
54
55 ``Vulkan::glslc``
56   .. versionadded:: 3.19
57
58   The GLSLC SPIR-V compiler, if it has been found.
59
60 ``Vulkan::Headers``
61   .. versionadded:: 3.21
62
63   Provides just Vulkan headers include paths, if found.  No library is
64   included in this target.  This can be useful for applications that
65   load Vulkan library dynamically.
66
67 ``Vulkan::glslangValidator``
68   .. versionadded:: 3.21
69
70   The glslangValidator tool, if found.  It is used to compile GLSL and
71   HLSL shaders into SPIR-V.
72
73 ``Vulkan::glslang``
74   .. versionadded:: 3.24
75
76   Defined if SDK has the Khronos-reference front-end shader parser and SPIR-V
77   generator library (glslang).
78
79 ``Vulkan::shaderc_combined``
80   .. versionadded:: 3.24
81
82   Defined if SDK has the Google static library for Vulkan shader compilation
83   (shaderc_combined).
84
85 ``Vulkan::SPIRV-Tools``
86   .. versionadded:: 3.24
87
88   Defined if SDK has the Khronos library to process SPIR-V modules
89   (SPIRV-Tools).
90
91 ``Vulkan::MoltenVK``
92   .. versionadded:: 3.24
93
94   Defined if SDK has the Khronos library which implement a subset of Vulkan API
95   over Apple Metal graphics framework. (MoltenVK).
96
97 ``Vulkan::volk``
98   .. versionadded:: 3.25
99
100   Defined if SDK has the Vulkan meta-loader (volk).
101
102 ``Vulkan::dxc_lib``
103   .. versionadded:: 3.25
104
105   Defined if SDK has the DirectX shader compiler library.
106
107 ``Vulkan::dxc_exe``
108   .. versionadded:: 3.25
109
110   Defined if SDK has the DirectX shader compiler CLI tool.
111
112 Result Variables
113 ^^^^^^^^^^^^^^^^
114
115 This module defines the following variables:
116
117 ``Vulkan_FOUND``
118   set to true if Vulkan was found
119 ``Vulkan_INCLUDE_DIRS``
120   include directories for Vulkan
121 ``Vulkan_LIBRARIES``
122   link against this library to use Vulkan
123 ``Vulkan_VERSION``
124   .. versionadded:: 3.23
125
126   value from ``vulkan/vulkan_core.h``
127 ``Vulkan_glslc_FOUND``
128   .. versionadded:: 3.24
129
130   True, if the SDK has the glslc executable.
131 ``Vulkan_glslangValidator_FOUND``
132   .. versionadded:: 3.24
133
134   True, if the SDK has the glslangValidator executable.
135 ``Vulkan_glslang_FOUND``
136   .. versionadded:: 3.24
137
138   True, if the SDK has the glslang library.
139 ``Vulkan_shaderc_combined_FOUND``
140   .. versionadded:: 3.24
141
142   True, if the SDK has the shaderc_combined library.
143 ``Vulkan_SPIRV-Tools_FOUND``
144   .. versionadded:: 3.24
145
146   True, if the SDK has the SPIRV-Tools library.
147 ``Vulkan_MoltenVK_FOUND``
148   .. versionadded:: 3.24
149
150   True, if the SDK has the MoltenVK library.
151 ``Vulkan_volk_FOUND``
152   .. versionadded:: 3.25
153
154   True, if the SDK has the volk library.
155
156 ``Vulkan_dxc_lib_FOUND``
157   .. versionadded:: 3.25
158
159   True, if the SDK has the DirectX shader compiler library.
160
161 ``Vulkan_dxc_exe_FOUND``
162   .. versionadded:: 3.25
163
164   True, if the SDK has the DirectX shader compiler CLI tool.
165
166
167 The module will also defines these cache variables:
168
169 ``Vulkan_INCLUDE_DIR``
170   the Vulkan include directory
171 ``Vulkan_LIBRARY``
172   the path to the Vulkan library
173 ``Vulkan_GLSLC_EXECUTABLE``
174   the path to the GLSL SPIR-V compiler
175 ``Vulkan_GLSLANG_VALIDATOR_EXECUTABLE``
176   the path to the glslangValidator tool
177 ``Vulkan_glslang_LIBRARY``
178   .. versionadded:: 3.24
179
180   Path to the glslang library.
181 ``Vulkan_shaderc_combined_LIBRARY``
182   .. versionadded:: 3.24
183
184   Path to the shaderc_combined library.
185 ``Vulkan_SPIRV-Tools_LIBRARY``
186   .. versionadded:: 3.24
187
188   Path to the SPIRV-Tools library.
189 ``Vulkan_MoltenVK_LIBRARY``
190   .. versionadded:: 3.24
191
192   Path to the MoltenVK library.
193
194 ``Vulkan_volk_LIBRARY``
195   .. versionadded:: 3.25
196
197   Path to the volk library.
198
199 ``Vulkan_dxc_LIBRARY``
200   .. versionadded:: 3.25
201
202   Path to the DirectX shader compiler library.
203
204 ``Vulkan_dxc_EXECUTABLE``
205   .. versionadded:: 3.25
206
207   Path to the DirectX shader compiler CLI tool.
208
209 Hints
210 ^^^^^
211
212 .. versionadded:: 3.18
213
214 The ``VULKAN_SDK`` environment variable optionally specifies the
215 location of the Vulkan SDK root directory for the given
216 architecture. It is typically set by sourcing the toplevel
217 ``setup-env.sh`` script of the Vulkan SDK directory into the shell
218 environment.
219
220 #]=======================================================================]
221
222 cmake_policy(PUSH)
223 cmake_policy(SET CMP0057 NEW)
224
225 # Provide compatibility with a common invalid component request that
226 # was silently ignored prior to CMake 3.24.
227 if("FATAL_ERROR" IN_LIST Vulkan_FIND_COMPONENTS)
228   message(AUTHOR_WARNING
229     "Ignoring unknown component 'FATAL_ERROR'.\n"
230     "The find_package() command documents no such argument."
231     )
232   list(REMOVE_ITEM Vulkan_FIND_COMPONENTS "FATAL_ERROR")
233 endif()
234
235 # For backward compatibility as `FindVulkan` in previous CMake versions allow to retrieve `glslc`
236 # and `glslangValidator` without requesting the corresponding component.
237 if(NOT glslc IN_LIST Vulkan_FIND_COMPONENTS)
238   list(APPEND Vulkan_FIND_COMPONENTS glslc)
239 endif()
240 if(NOT glslangValidator IN_LIST Vulkan_FIND_COMPONENTS)
241   list(APPEND Vulkan_FIND_COMPONENTS glslangValidator)
242 endif()
243
244 if(WIN32)
245   set(_Vulkan_library_name vulkan-1)
246   set(_Vulkan_hint_include_search_paths
247     "$ENV{VULKAN_SDK}/Include"
248   )
249   if(CMAKE_SIZEOF_VOID_P EQUAL 8)
250     set(_Vulkan_hint_executable_search_paths
251       "$ENV{VULKAN_SDK}/Bin"
252     )
253     set(_Vulkan_hint_library_search_paths
254       "$ENV{VULKAN_SDK}/Lib"
255       "$ENV{VULKAN_SDK}/Bin"
256     )
257   else()
258     set(_Vulkan_hint_executable_search_paths
259       "$ENV{VULKAN_SDK}/Bin32"
260     )
261     set(_Vulkan_hint_library_search_paths
262       "$ENV{VULKAN_SDK}/Lib32"
263       "$ENV{VULKAN_SDK}/Bin32"
264     )
265   endif()
266 else()
267   set(_Vulkan_library_name vulkan)
268   set(_Vulkan_hint_include_search_paths
269     "$ENV{VULKAN_SDK}/include"
270   )
271   set(_Vulkan_hint_executable_search_paths
272     "$ENV{VULKAN_SDK}/bin"
273   )
274   set(_Vulkan_hint_library_search_paths
275     "$ENV{VULKAN_SDK}/lib"
276   )
277 endif()
278 if(APPLE AND DEFINED ENV{VULKAN_SDK})
279   cmake_path(SET _MoltenVK_path NORMALIZE "$ENV{VULKAN_SDK}/../MoltenVK")
280   if(EXISTS "${_MoltenVK_path}")
281     list(APPEND _Vulkan_hint_include_search_paths
282       "${_MoltenVK_path}/include"
283     )
284     if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
285       list(APPEND _Vulkan_hint_library_search_paths
286         "${_MoltenVK_path}/dylib/iOS"
287       )
288     elseif(CMAKE_SYSTEM_NAME STREQUAL "tvOS")
289       list(APPEND _Vulkan_hint_library_search_paths
290         "${_MoltenVK_path}/dylib/tvOS"
291       )
292     else()
293       list(APPEND _Vulkan_hint_library_search_paths
294         "${_MoltenVK_path}/dylib/macOS"
295       )
296     endif()
297   endif()
298   unset(_MoltenVK_path)
299 endif()
300
301 find_path(Vulkan_INCLUDE_DIR
302   NAMES vulkan/vulkan.h
303   HINTS
304     ${_Vulkan_hint_include_search_paths}
305   )
306 mark_as_advanced(Vulkan_INCLUDE_DIR)
307
308 find_library(Vulkan_LIBRARY
309   NAMES ${_Vulkan_library_name}
310   HINTS
311     ${_Vulkan_hint_library_search_paths}
312   )
313 mark_as_advanced(Vulkan_LIBRARY)
314
315 if(glslc IN_LIST Vulkan_FIND_COMPONENTS)
316   find_program(Vulkan_GLSLC_EXECUTABLE
317     NAMES glslc
318     HINTS
319       ${_Vulkan_hint_executable_search_paths}
320     )
321   mark_as_advanced(Vulkan_GLSLC_EXECUTABLE)
322 endif()
323 if(glslangValidator IN_LIST Vulkan_FIND_COMPONENTS)
324   find_program(Vulkan_GLSLANG_VALIDATOR_EXECUTABLE
325     NAMES glslangValidator
326     HINTS
327       ${_Vulkan_hint_executable_search_paths}
328     )
329   mark_as_advanced(Vulkan_GLSLANG_VALIDATOR_EXECUTABLE)
330 endif()
331 if(glslang IN_LIST Vulkan_FIND_COMPONENTS)
332   find_library(Vulkan_glslang-spirv_LIBRARY
333     NAMES SPIRV
334     HINTS
335       ${_Vulkan_hint_library_search_paths}
336     )
337   mark_as_advanced(Vulkan_glslang-spirv_LIBRARY)
338
339   find_library(Vulkan_glslang-spirv_DEBUG_LIBRARY
340     NAMES SPIRVd
341     HINTS
342       ${_Vulkan_hint_library_search_paths}
343     )
344   mark_as_advanced(Vulkan_glslang-spirv_DEBUG_LIBRARY)
345
346   find_library(Vulkan_glslang-oglcompiler_LIBRARY
347     NAMES OGLCompiler
348     HINTS
349       ${_Vulkan_hint_library_search_paths}
350     )
351   mark_as_advanced(Vulkan_glslang-oglcompiler_LIBRARY)
352
353   find_library(Vulkan_glslang-oglcompiler_DEBUG_LIBRARY
354     NAMES OGLCompilerd
355     HINTS
356       ${_Vulkan_hint_library_search_paths}
357     )
358   mark_as_advanced(Vulkan_glslang-oglcompiler_DEBUG_LIBRARY)
359
360   find_library(Vulkan_glslang-osdependent_LIBRARY
361     NAMES OSDependent
362     HINTS
363       ${_Vulkan_hint_library_search_paths}
364     )
365   mark_as_advanced(Vulkan_glslang-osdependent_LIBRARY)
366
367   find_library(Vulkan_glslang-osdependent_DEBUG_LIBRARY
368     NAMES OSDependentd
369     HINTS
370       ${_Vulkan_hint_library_search_paths}
371     )
372   mark_as_advanced(Vulkan_glslang-osdependent_DEBUG_LIBRARY)
373
374   find_library(Vulkan_glslang-machineindependent_LIBRARY
375     NAMES MachineIndependent
376     HINTS
377       ${_Vulkan_hint_library_search_paths}
378     )
379   mark_as_advanced(Vulkan_glslang-machineindependent_LIBRARY)
380
381   find_library(Vulkan_glslang-machineindependent_DEBUG_LIBRARY
382     NAMES MachineIndependentd
383     HINTS
384       ${_Vulkan_hint_library_search_paths}
385     )
386   mark_as_advanced(Vulkan_glslang-machineindependent_DEBUG_LIBRARY)
387
388   find_library(Vulkan_glslang-genericcodegen_LIBRARY
389     NAMES GenericCodeGen
390     HINTS
391       ${_Vulkan_hint_library_search_paths}
392     )
393   mark_as_advanced(Vulkan_glslang-genericcodegen_LIBRARY)
394
395   find_library(Vulkan_glslang-genericcodegen_DEBUG_LIBRARY
396     NAMES GenericCodeGend
397     HINTS
398       ${_Vulkan_hint_library_search_paths}
399     )
400   mark_as_advanced(Vulkan_glslang-genericcodegen_DEBUG_LIBRARY)
401
402   find_library(Vulkan_glslang_LIBRARY
403     NAMES glslang
404     HINTS
405       ${_Vulkan_hint_library_search_paths}
406     )
407   mark_as_advanced(Vulkan_glslang_LIBRARY)
408
409   find_library(Vulkan_glslang_DEBUG_LIBRARY
410     NAMES glslangd
411     HINTS
412       ${_Vulkan_hint_library_search_paths}
413     )
414   mark_as_advanced(Vulkan_glslang_DEBUG_LIBRARY)
415 endif()
416 if(shaderc_combined IN_LIST Vulkan_FIND_COMPONENTS)
417   find_library(Vulkan_shaderc_combined_LIBRARY
418     NAMES shaderc_combined
419     HINTS
420     ${_Vulkan_hint_library_search_paths})
421   mark_as_advanced(Vulkan_shaderc_combined_LIBRARY)
422
423   find_library(Vulkan_shaderc_combined_DEBUG_LIBRARY
424     NAMES shaderc_combinedd
425     HINTS
426     ${_Vulkan_hint_library_search_paths})
427   mark_as_advanced(Vulkan_shaderc_combined_DEBUG_LIBRARY)
428 endif()
429 if(SPIRV-Tools IN_LIST Vulkan_FIND_COMPONENTS)
430   find_library(Vulkan_SPIRV-Tools_LIBRARY
431     NAMES SPIRV-Tools
432     HINTS
433       ${_Vulkan_hint_library_search_paths})
434   mark_as_advanced(Vulkan_SPIRV-Tools_LIBRARY)
435
436   find_library(Vulkan_SPIRV-Tools_DEBUG_LIBRARY
437     NAMES SPIRV-Toolsd
438     HINTS
439       ${_Vulkan_hint_library_search_paths})
440   mark_as_advanced(Vulkan_SPIRV-Tools_DEBUG_LIBRARY)
441 endif()
442 if(MoltenVK IN_LIST Vulkan_FIND_COMPONENTS)
443   find_library(Vulkan_MoltenVK_LIBRARY
444     NAMES MoltenVK
445     HINTS
446       ${_Vulkan_hint_library_search_paths})
447   mark_as_advanced(Vulkan_MoltenVK_LIBRARY)
448
449   find_path(Vulkan_MoltenVK_INCLUDE_DIR
450     NAMES MoltenVK/mvk_vulkan.h
451     HINTS
452       ${_Vulkan_hint_include_search_paths}
453     )
454   mark_as_advanced(Vulkan_MoltenVK_INCLUDE_DIR)
455 endif()
456 if(volk IN_LIST Vulkan_FIND_COMPONENTS)
457   find_library(Vulkan_volk_LIBRARY
458           NAMES volk
459           HINTS
460             ${_Vulkan_hint_library_search_paths})
461   mark_as_advanced(Vulkan_Volk_LIBRARY)
462 endif()
463
464 if (dxc IN_LIST Vulkan_FIND_COMPONENTS)
465   find_library(Vulkan_dxc_LIBRARY
466           NAMES dxcompiler
467           HINTS
468             ${_Vulkan_hint_library_search_paths})
469   mark_as_advanced(Vulkan_dxc_LIBRARY)
470
471   find_program(Vulkan_dxc_EXECUTABLE
472           NAMES dxc
473           HINTS
474             ${_Vulkan_hint_executable_search_paths})
475   mark_as_advanced(Vulkan_dxc_EXECUTABLE)
476 endif()
477
478 if(Vulkan_GLSLC_EXECUTABLE)
479   set(Vulkan_glslc_FOUND TRUE)
480 else()
481   set(Vulkan_glslc_FOUND FALSE)
482 endif()
483
484 if(Vulkan_GLSLANG_VALIDATOR_EXECUTABLE)
485   set(Vulkan_glslangValidator_FOUND TRUE)
486 else()
487   set(Vulkan_glslangValidator_FOUND FALSE)
488 endif()
489
490 if (Vulkan_dxc_EXECUTABLE)
491   set(Vulkan_dxc_exe_FOUND TRUE)
492 else()
493   set(Vulkan_dxc_exe_FOUND FALSE)
494 endif()
495
496 function(_Vulkan_set_library_component_found component)
497   cmake_parse_arguments(PARSE_ARGV 1 _ARG
498     "NO_WARNING"
499     ""
500     "DEPENDENT_COMPONENTS")
501
502   set(all_dependent_component_found TRUE)
503   foreach(dependent_component IN LISTS _ARG_DEPENDENT_COMPONENTS)
504     if(NOT Vulkan_${dependent_component}_FOUND)
505       set(all_dependent_component_found FALSE)
506       break()
507     endif()
508   endforeach()
509
510   if(all_dependent_component_found AND (Vulkan_${component}_LIBRARY OR Vulkan_${component}_DEBUG_LIBRARY))
511     set(Vulkan_${component}_FOUND TRUE PARENT_SCOPE)
512
513     # For Windows Vulkan SDK, third party tools binaries are provided with different MSVC ABI:
514     #   - Release binaries uses a runtime library
515     #   - Debug binaries uses a debug runtime library
516     # This lead to incompatibilities in linking for some configuration types due to CMake-default or project-configured selected MSVC ABI.
517     if(WIN32 AND NOT _ARG_NO_WARNING)
518       if(NOT Vulkan_${component}_LIBRARY)
519         message(WARNING
520 "Library ${component} for Release configuration is missing, imported target Vulkan::${component} may not be able to link when targeting this build configuration due to incompatible MSVC ABI.")
521       endif()
522       if(NOT Vulkan_${component}_DEBUG_LIBRARY)
523         message(WARNING
524 "Library ${component} for Debug configuration is missing, imported target Vulkan::${component} may not be able to link when targeting this build configuration due to incompatible MSVC ABI. Consider re-installing the Vulkan SDK and request debug libraries to fix this warning.")
525       endif()
526     endif()
527   else()
528     set(Vulkan_${component}_FOUND FALSE PARENT_SCOPE)
529   endif()
530 endfunction()
531
532 _Vulkan_set_library_component_found(glslang-spirv NO_WARNING)
533 _Vulkan_set_library_component_found(glslang-oglcompiler NO_WARNING)
534 _Vulkan_set_library_component_found(glslang-osdependent NO_WARNING)
535 _Vulkan_set_library_component_found(glslang-machineindependent NO_WARNING)
536 _Vulkan_set_library_component_found(glslang-genericcodegen NO_WARNING)
537 _Vulkan_set_library_component_found(glslang
538   DEPENDENT_COMPONENTS
539     glslang-spirv
540     glslang-oglcompiler
541     glslang-osdependent
542     glslang-machineindependent
543     glslang-genericcodegen)
544 _Vulkan_set_library_component_found(shaderc_combined)
545 _Vulkan_set_library_component_found(SPIRV-Tools)
546 _Vulkan_set_library_component_found(volk)
547 _Vulkan_set_library_component_found(dxc)
548
549 if(Vulkan_MoltenVK_INCLUDE_DIR AND Vulkan_MoltenVK_LIBRARY)
550   set(Vulkan_MoltenVK_FOUND TRUE)
551 else()
552   set(Vulkan_MoltenVK_FOUND FALSE)
553 endif()
554
555 set(Vulkan_LIBRARIES ${Vulkan_LIBRARY})
556 set(Vulkan_INCLUDE_DIRS ${Vulkan_INCLUDE_DIR})
557
558 # detect version e.g 1.2.189
559 set(Vulkan_VERSION "")
560 if(Vulkan_INCLUDE_DIR)
561   set(VULKAN_CORE_H ${Vulkan_INCLUDE_DIR}/vulkan/vulkan_core.h)
562   if(EXISTS ${VULKAN_CORE_H})
563     file(STRINGS  ${VULKAN_CORE_H} VulkanHeaderVersionLine REGEX "^#define VK_HEADER_VERSION ")
564     string(REGEX MATCHALL "[0-9]+" VulkanHeaderVersion "${VulkanHeaderVersionLine}")
565     file(STRINGS  ${VULKAN_CORE_H} VulkanHeaderVersionLine2 REGEX "^#define VK_HEADER_VERSION_COMPLETE ")
566     string(REGEX MATCHALL "[0-9]+" VulkanHeaderVersion2 "${VulkanHeaderVersionLine2}")
567     list(LENGTH VulkanHeaderVersion2 _len)
568     #  versions >= 1.2.175 have an additional numbers in front of e.g. '0, 1, 2' instead of '1, 2'
569     if(_len EQUAL 3)
570         list(REMOVE_AT VulkanHeaderVersion2 0)
571     endif()
572     list(APPEND VulkanHeaderVersion2 ${VulkanHeaderVersion})
573     list(JOIN VulkanHeaderVersion2 "." Vulkan_VERSION)
574   endif()
575 endif()
576
577 if(Vulkan_MoltenVK_FOUND)
578   set(Vulkan_MoltenVK_VERSION "")
579   if(Vulkan_MoltenVK_INCLUDE_DIR)
580     set(VK_MVK_MOLTENVK_H ${Vulkan_MoltenVK_INCLUDE_DIR}/MoltenVK/vk_mvk_moltenvk.h)
581     if(EXISTS ${VK_MVK_MOLTENVK_H})
582       file(STRINGS  ${VK_MVK_MOLTENVK_H} _Vulkan_MoltenVK_VERSION_MAJOR REGEX "^#define MVK_VERSION_MAJOR ")
583       string(REGEX MATCHALL "[0-9]+" _Vulkan_MoltenVK_VERSION_MAJOR "${_Vulkan_MoltenVK_VERSION_MAJOR}")
584       file(STRINGS  ${VK_MVK_MOLTENVK_H} _Vulkan_MoltenVK_VERSION_MINOR REGEX "^#define MVK_VERSION_MINOR ")
585       string(REGEX MATCHALL "[0-9]+" _Vulkan_MoltenVK_VERSION_MINOR "${_Vulkan_MoltenVK_VERSION_MINOR}")
586       file(STRINGS  ${VK_MVK_MOLTENVK_H} _Vulkan_MoltenVK_VERSION_PATCH REGEX "^#define MVK_VERSION_PATCH ")
587       string(REGEX MATCHALL "[0-9]+" _Vulkan_MoltenVK_VERSION_PATCH "${_Vulkan_MoltenVK_VERSION_PATCH}")
588       set(Vulkan_MoltenVK_VERSION "${_Vulkan_MoltenVK_VERSION_MAJOR}.${_Vulkan_MoltenVK_VERSION_MINOR}.${_Vulkan_MoltenVK_VERSION_PATCH}")
589       unset(_Vulkan_MoltenVK_VERSION_MAJOR)
590       unset(_Vulkan_MoltenVK_VERSION_MINOR)
591       unset(_Vulkan_MoltenVK_VERSION_PATCH)
592     endif()
593   endif()
594 endif()
595
596 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
597 find_package_handle_standard_args(Vulkan
598   REQUIRED_VARS
599     Vulkan_LIBRARY
600     Vulkan_INCLUDE_DIR
601   VERSION_VAR
602     Vulkan_VERSION
603   HANDLE_COMPONENTS
604 )
605
606 if(Vulkan_FOUND AND NOT TARGET Vulkan::Vulkan)
607   add_library(Vulkan::Vulkan UNKNOWN IMPORTED)
608   set_target_properties(Vulkan::Vulkan PROPERTIES
609     IMPORTED_LOCATION "${Vulkan_LIBRARIES}"
610     INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
611 endif()
612
613 if(Vulkan_FOUND AND NOT TARGET Vulkan::Headers)
614   add_library(Vulkan::Headers INTERFACE IMPORTED)
615   set_target_properties(Vulkan::Headers PROPERTIES
616     INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
617 endif()
618
619 if(Vulkan_FOUND AND Vulkan_GLSLC_EXECUTABLE AND NOT TARGET Vulkan::glslc)
620   add_executable(Vulkan::glslc IMPORTED)
621   set_property(TARGET Vulkan::glslc PROPERTY IMPORTED_LOCATION "${Vulkan_GLSLC_EXECUTABLE}")
622 endif()
623
624 if(Vulkan_FOUND AND Vulkan_GLSLANG_VALIDATOR_EXECUTABLE AND NOT TARGET Vulkan::glslangValidator)
625   add_executable(Vulkan::glslangValidator IMPORTED)
626   set_property(TARGET Vulkan::glslangValidator PROPERTY IMPORTED_LOCATION "${Vulkan_GLSLANG_VALIDATOR_EXECUTABLE}")
627 endif()
628
629 if(Vulkan_FOUND)
630   if((Vulkan_glslang-spirv_LIBRARY OR Vulkan_glslang-spirv_DEBUG_LIBRARY) AND NOT TARGET Vulkan::glslang-spirv)
631     add_library(Vulkan::glslang-spirv STATIC IMPORTED)
632     set_property(TARGET Vulkan::glslang-spirv
633       PROPERTY
634         INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
635     if(Vulkan_glslang-spirv_LIBRARY)
636       set_property(TARGET Vulkan::glslang-spirv APPEND
637         PROPERTY
638           IMPORTED_CONFIGURATIONS Release)
639       set_property(TARGET Vulkan::glslang-spirv
640         PROPERTY
641           IMPORTED_LOCATION_RELEASE "${Vulkan_glslang-spirv_LIBRARY}")
642     endif()
643     if(Vulkan_glslang-spirv_DEBUG_LIBRARY)
644       set_property(TARGET Vulkan::glslang-spirv APPEND
645         PROPERTY
646           IMPORTED_CONFIGURATIONS Debug)
647       set_property(TARGET Vulkan::glslang-spirv
648         PROPERTY
649           IMPORTED_LOCATION_DEBUG "${Vulkan_glslang-spirv_DEBUG_LIBRARY}")
650     endif()
651   endif()
652
653   if((Vulkan_glslang-oglcompiler_LIBRARY OR Vulkan_glslang-oglcompiler_DEBUG_LIBRARY) AND NOT TARGET Vulkan::glslang-oglcompiler)
654     add_library(Vulkan::glslang-oglcompiler STATIC IMPORTED)
655     set_property(TARGET Vulkan::glslang-oglcompiler
656       PROPERTY
657         INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
658     if(Vulkan_glslang-oglcompiler_LIBRARY)
659       set_property(TARGET Vulkan::glslang-oglcompiler APPEND
660         PROPERTY
661           IMPORTED_CONFIGURATIONS Release)
662       set_property(TARGET Vulkan::glslang-oglcompiler
663         PROPERTY
664           IMPORTED_LOCATION_RELEASE "${Vulkan_glslang-oglcompiler_LIBRARY}")
665     endif()
666     if(Vulkan_glslang-oglcompiler_DEBUG_LIBRARY)
667       set_property(TARGET Vulkan::glslang-oglcompiler APPEND
668         PROPERTY
669           IMPORTED_CONFIGURATIONS Debug)
670       set_property(TARGET Vulkan::glslang-oglcompiler
671         PROPERTY
672           IMPORTED_LOCATION_DEBUG "${Vulkan_glslang-oglcompiler_DEBUG_LIBRARY}")
673     endif()
674   endif()
675
676   if((Vulkan_glslang-osdependent_LIBRARY OR Vulkan_glslang-osdependent_DEBUG_LIBRARY) AND NOT TARGET Vulkan::glslang-osdependent)
677     add_library(Vulkan::glslang-osdependent STATIC IMPORTED)
678     set_property(TARGET Vulkan::glslang-osdependent
679       PROPERTY
680         INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
681     if(Vulkan_glslang-osdependent_LIBRARY)
682       set_property(TARGET Vulkan::glslang-osdependent APPEND
683         PROPERTY
684           IMPORTED_CONFIGURATIONS Release)
685       set_property(TARGET Vulkan::glslang-osdependent
686         PROPERTY
687           IMPORTED_LOCATION_RELEASE "${Vulkan_glslang-osdependent_LIBRARY}")
688     endif()
689     if(Vulkan_glslang-osdependent_DEBUG_LIBRARY)
690       set_property(TARGET Vulkan::glslang-osdependent APPEND
691         PROPERTY
692           IMPORTED_CONFIGURATIONS Debug)
693       set_property(TARGET Vulkan::glslang-osdependent
694         PROPERTY
695           IMPORTED_LOCATION_DEBUG "${Vulkan_glslang-osdependent_DEBUG_LIBRARY}")
696     endif()
697   endif()
698
699   if((Vulkan_glslang-machineindependent_LIBRARY OR Vulkan_glslang-machineindependent_DEBUG_LIBRARY) AND NOT TARGET Vulkan::glslang-machineindependent)
700     add_library(Vulkan::glslang-machineindependent STATIC IMPORTED)
701     set_property(TARGET Vulkan::glslang-machineindependent
702       PROPERTY
703         INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
704     if(Vulkan_glslang-machineindependent_LIBRARY)
705       set_property(TARGET Vulkan::glslang-machineindependent APPEND
706         PROPERTY
707           IMPORTED_CONFIGURATIONS Release)
708       set_property(TARGET Vulkan::glslang-machineindependent
709         PROPERTY
710           IMPORTED_LOCATION_RELEASE "${Vulkan_glslang-machineindependent_LIBRARY}")
711     endif()
712     if(Vulkan_glslang-machineindependent_DEBUG_LIBRARY)
713       set_property(TARGET Vulkan::glslang-machineindependent APPEND
714         PROPERTY
715           IMPORTED_CONFIGURATIONS Debug)
716       set_property(TARGET Vulkan::glslang-machineindependent
717         PROPERTY
718           IMPORTED_LOCATION_DEBUG "${Vulkan_glslang-machineindependent_DEBUG_LIBRARY}")
719     endif()
720   endif()
721
722   if((Vulkan_glslang-genericcodegen_LIBRARY OR Vulkan_glslang-genericcodegen_DEBUG_LIBRARY) AND NOT TARGET Vulkan::glslang-genericcodegen)
723     add_library(Vulkan::glslang-genericcodegen STATIC IMPORTED)
724     set_property(TARGET Vulkan::glslang-genericcodegen
725       PROPERTY
726         INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
727     if(Vulkan_glslang-genericcodegen_LIBRARY)
728       set_property(TARGET Vulkan::glslang-genericcodegen APPEND
729         PROPERTY
730           IMPORTED_CONFIGURATIONS Release)
731       set_property(TARGET Vulkan::glslang-genericcodegen
732         PROPERTY
733           IMPORTED_LOCATION_RELEASE "${Vulkan_glslang-genericcodegen_LIBRARY}")
734     endif()
735     if(Vulkan_glslang-genericcodegen_DEBUG_LIBRARY)
736       set_property(TARGET Vulkan::glslang-genericcodegen APPEND
737         PROPERTY
738           IMPORTED_CONFIGURATIONS Debug)
739       set_property(TARGET Vulkan::glslang-genericcodegen
740         PROPERTY
741           IMPORTED_LOCATION_DEBUG "${Vulkan_glslang-genericcodegen_DEBUG_LIBRARY}")
742     endif()
743   endif()
744
745   if((Vulkan_glslang_LIBRARY OR Vulkan_glslang_DEBUG_LIBRARY)
746       AND TARGET Vulkan::glslang-spirv
747       AND TARGET Vulkan::glslang-oglcompiler
748       AND TARGET Vulkan::glslang-osdependent
749       AND TARGET Vulkan::glslang-machineindependent
750       AND TARGET Vulkan::glslang-genericcodegen
751       AND NOT TARGET Vulkan::glslang)
752     add_library(Vulkan::glslang STATIC IMPORTED)
753     set_property(TARGET Vulkan::glslang
754       PROPERTY
755         INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
756     if(Vulkan_glslang_LIBRARY)
757       set_property(TARGET Vulkan::glslang APPEND
758         PROPERTY
759           IMPORTED_CONFIGURATIONS Release)
760       set_property(TARGET Vulkan::glslang
761         PROPERTY
762           IMPORTED_LOCATION_RELEASE "${Vulkan_glslang_LIBRARY}")
763     endif()
764     if(Vulkan_glslang_DEBUG_LIBRARY)
765       set_property(TARGET Vulkan::glslang APPEND
766         PROPERTY
767           IMPORTED_CONFIGURATIONS Debug)
768       set_property(TARGET Vulkan::glslang
769         PROPERTY
770           IMPORTED_LOCATION_DEBUG "${Vulkan_glslang_DEBUG_LIBRARY}")
771     endif()
772     target_link_libraries(Vulkan::glslang
773       INTERFACE
774         Vulkan::glslang-spirv
775         Vulkan::glslang-oglcompiler
776         Vulkan::glslang-osdependent
777         Vulkan::glslang-machineindependent
778         Vulkan::glslang-genericcodegen
779     )
780   endif()
781
782   if((Vulkan_shaderc_combined_LIBRARY OR Vulkan_shaderc_combined_DEBUG_LIBRARY) AND NOT TARGET Vulkan::shaderc_combined)
783     add_library(Vulkan::shaderc_combined STATIC IMPORTED)
784     set_property(TARGET Vulkan::shaderc_combined
785       PROPERTY
786         INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
787     if(Vulkan_shaderc_combined_LIBRARY)
788       set_property(TARGET Vulkan::shaderc_combined APPEND
789         PROPERTY
790           IMPORTED_CONFIGURATIONS Release)
791       set_property(TARGET Vulkan::shaderc_combined
792         PROPERTY
793           IMPORTED_LOCATION_RELEASE "${Vulkan_shaderc_combined_LIBRARY}")
794     endif()
795     if(Vulkan_shaderc_combined_DEBUG_LIBRARY)
796       set_property(TARGET Vulkan::shaderc_combined APPEND
797         PROPERTY
798           IMPORTED_CONFIGURATIONS Debug)
799       set_property(TARGET Vulkan::shaderc_combined
800         PROPERTY
801           IMPORTED_LOCATION_DEBUG "${Vulkan_shaderc_combined_DEBUG_LIBRARY}")
802     endif()
803
804     if(UNIX)
805       find_package(Threads REQUIRED)
806       target_link_libraries(Vulkan::shaderc_combined
807         INTERFACE
808           Threads::Threads)
809     endif()
810   endif()
811
812   if((Vulkan_SPIRV-Tools_LIBRARY OR Vulkan_SPIRV-Tools_DEBUG_LIBRARY) AND NOT TARGET Vulkan::SPIRV-Tools)
813     add_library(Vulkan::SPIRV-Tools STATIC IMPORTED)
814     set_property(TARGET Vulkan::SPIRV-Tools
815       PROPERTY
816         INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
817     if(Vulkan_SPIRV-Tools_LIBRARY)
818       set_property(TARGET Vulkan::SPIRV-Tools APPEND
819         PROPERTY
820           IMPORTED_CONFIGURATIONS Release)
821       set_property(TARGET Vulkan::SPIRV-Tools
822         PROPERTY
823           IMPORTED_LOCATION_RELEASE "${Vulkan_SPIRV-Tools_LIBRARY}")
824     endif()
825     if(Vulkan_SPIRV-Tools_DEBUG_LIBRARY)
826       set_property(TARGET Vulkan::SPIRV-Tools APPEND
827         PROPERTY
828           IMPORTED_CONFIGURATIONS Debug)
829       set_property(TARGET Vulkan::SPIRV-Tools
830         PROPERTY
831           IMPORTED_LOCATION_DEBUG "${Vulkan_SPIRV-Tools_DEBUG_LIBRARY}")
832     endif()
833   endif()
834
835   if(Vulkan_volk_LIBRARY AND NOT TARGET Vulkan::volk)
836     add_library(Vulkan::volk STATIC IMPORTED)
837     set_property(TARGET Vulkan::volk
838             PROPERTY
839               INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
840     set_property(TARGET Vulkan::volk APPEND
841             PROPERTY
842               IMPORTED_CONFIGURATIONS Release)
843     set_property(TARGET Vulkan::volk APPEND
844             PROPERTY
845               IMPORTED_LOCATION_RELEASE "${Vulkan_volk_LIBRARY}")
846
847     if (NOT WIN32)
848       set_property(TARGET Vulkan::volk APPEND
849               PROPERTY
850                 IMPORTED_LINK_INTERFACE_LIBRARIES dl)
851     endif()
852   endif()
853
854   if (Vulkan_dxc_LIBRARY AND NOT TARGET Vulkan::dxc_lib)
855     add_library(Vulkan::dxc_lib STATIC IMPORTED)
856     set_property(TARGET Vulkan::dxc_lib
857       PROPERTY
858         INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}")
859     set_property(TARGET Vulkan::dxc_lib APPEND
860       PROPERTY
861         IMPORTED_CONFIGURATIONS Release)
862     set_property(TARGET Vulkan::dxc_lib APPEND
863       PROPERTY
864         IMPORTED_LOCATION_RELEASE "${Vulkan_dxc_LIBRARY}")
865   endif()
866
867   if(Vulkan_dxc_EXECUTABLE AND NOT TARGET Vulkan::dxc_exe)
868     add_executable(Vulkan::dxc_exe IMPORTED)
869     set_property(TARGET Vulkan::dxc_exe PROPERTY IMPORTED_LOCATION "${Vulkan_dxc_EXECUTABLE}")
870   endif()
871
872 endif()
873
874 if(Vulkan_MoltenVK_FOUND)
875   if(Vulkan_MoltenVK_LIBRARY AND NOT TARGET Vulkan::MoltenVK)
876     add_library(Vulkan::MoltenVK SHARED IMPORTED)
877     set_target_properties(Vulkan::MoltenVK
878       PROPERTIES
879         INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_MoltenVK_INCLUDE_DIR}"
880         IMPORTED_LOCATION "${Vulkan_MoltenVK_LIBRARY}"
881     )
882   endif()
883 endif()
884
885 unset(_Vulkan_library_name)
886 unset(_Vulkan_hint_include_search_paths)
887 unset(_Vulkan_hint_executable_search_paths)
888 unset(_Vulkan_hint_library_search_paths)
889
890 cmake_policy(POP)