Updated to latest known good MoltenVK
[platform/upstream/Vulkan-Tools.git] / vulkaninfo / macOS / vulkaninfo.cmake
1 # ~~~
2 # Copyright (c) 2018-2019 Valve Corporation
3 # Copyright (c) 2018-2019 LunarG, Inc.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 # ~~~
17
18 # Vulkaninfo Application Bundle
19
20 # We already have a "vulkaninfo" target, so create a new target with a different name and use the OUTPUT_NAME property to rename the
21 # target to the desired name. The standalone binary is called "vulkaninfo" and the bundle is called "vulkaninfo.app". Note that the
22 # executable is a script that launches Terminal to see the output.
23 add_executable(vulkaninfo-bundle
24                MACOSX_BUNDLE
25                vulkaninfo.cpp
26                ${CMAKE_BINARY_DIR}/staging-json/MoltenVK_icd.json
27                ${CMAKE_CURRENT_SOURCE_DIR}/macOS/vulkaninfo.sh
28                ${CMAKE_CURRENT_SOURCE_DIR}/macOS/Resources/VulkanIcon.icns
29                ${CMAKE_CURRENT_SOURCE_DIR}/macOS/vulkaninfo/metal_view.mm
30                ${CMAKE_CURRENT_SOURCE_DIR}/macOS/vulkaninfo/metal_view.h)
31 set_target_properties(vulkaninfo-bundle
32                       PROPERTIES OUTPUT_NAME
33                                  vulkaninfo
34                                  MACOSX_BUNDLE_INFO_PLIST
35                                  ${CMAKE_CURRENT_SOURCE_DIR}/macOS/Info.plist)
36 # We do this so vulkaninfo is linked to an individual library and NOT a framework.
37 target_link_libraries(vulkaninfo-bundle ${Vulkan_LIBRARY} "-framework AppKit -framework QuartzCore" Vulkan::Headers)
38 target_include_directories(vulkaninfo-bundle PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/macOS/vulkaninfo ${CMAKE_CURRENT_SOURCE_DIR}/generated ${CMAKE_BINARY_DIR}/vulkaninfo)
39 add_dependencies(vulkaninfo-bundle MoltenVK_icd-staging-json)
40
41 set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/macOS/vulkaninfo.sh PROPERTIES MACOSX_PACKAGE_LOCATION "MacOS")
42 set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/macOS/Resources/VulkanIcon.icns
43                             PROPERTIES
44                             MACOSX_PACKAGE_LOCATION
45                             "Resources")
46 set_source_files_properties(${CMAKE_BINARY_DIR}/staging-json/MoltenVK_icd.json
47                             PROPERTIES
48                             MACOSX_PACKAGE_LOCATION
49                             "Resources/vulkan/icd.d")
50
51 # Xcode projects need some extra help with what would be install steps.
52 if(${CMAKE_GENERATOR} MATCHES "^Xcode.*")
53     add_custom_command(TARGET vulkaninfo-bundle POST_BUILD
54                        COMMAND ${CMAKE_COMMAND} -E copy "${MOLTENVK_DIR}/MoltenVK/dylib/macOS/libMoltenVK.dylib"
55                                ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/vulkaninfo.app/Contents/Frameworks/libMoltenVK.dylib
56                        DEPENDS vulkan)
57 else()
58     add_custom_command(TARGET vulkaninfo-bundle POST_BUILD
59                        COMMAND ${CMAKE_COMMAND} -E copy "${MOLTENVK_DIR}/MoltenVK/dylib/macOS/libMoltenVK.dylib"
60                                ${CMAKE_CURRENT_BINARY_DIR}/vulkaninfo.app/Contents/Frameworks/libMoltenVK.dylib
61                        DEPENDS vulkan)
62 endif()
63
64 # Keep RPATH so fixup_bundle can use it to find libraries
65 set_target_properties(vulkaninfo-bundle PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)
66 install(TARGETS vulkaninfo-bundle BUNDLE DESTINATION "vulkaninfo")
67 # Fix up the library search path in the executable to find (loader) libraries in the bundle. When fixup_bundle() is passed a bundle
68 # in the first argument, it looks at the Info.plist file to determine the BundleExecutable. In this case, the executable is a
69 # script, which can't be fixed up. Instead pass it the explicit name of the executable.
70 install(CODE "
71     include(BundleUtilities)
72     fixup_bundle(\${CMAKE_INSTALL_PREFIX}/vulkaninfo/vulkaninfo.app/Contents/MacOS/vulkaninfo \"\" \"${Vulkan_LIBRARY_DIR}\")
73     ")