mkdir build
cd build
- cmake -DCMAKE_BUILD_TYPE=Debug -DVULKAN_LOADER_INSTALL_DIR=/absolute_path_to/Vulkan-Loader_install_dir -DMOLTENVK_REPO_ROOT=/absolute_path_to/MoltenVK ..
+ cmake -DCMAKE_BUILD_TYPE=Debug \
+ -DVULKAN_LOADER_INSTALL_DIR=/absolute_path_to/Vulkan-Loader_install_dir \
+ -DMOLTENVK_REPO_ROOT=/absolute_path_to/MoltenVK \
+ -DCMAKE_INSTALL_PREFIX=install ..
make
To speed up the build on a multi-core machine, use the `-j` option for `make`
make install
-This step "cleans up" the `RPATH` to remove any external references and
-performs other bundle fix-ups. After running `make install`, re-run the
-`otool` command again and note:
+This step copies the bundled applications to the location specified by
+CMAKE_INSTALL_PREFIX and "cleans up" the `RPATH` to remove any external
+references and performs other bundle fix-ups. After running `make install`,
+run the `otool` command again from the `build/install` directory and note:
- `LC_LOAD_DYLIB` is now `@executable_path/../MacOS/libvulkan.1.dylib`
- `LC_RPATH` is no longer present
The "bundle fix-up" operation also puts a copy of the Vulkan loader into the
bundle, making the bundle completely self-contained and self-referencing.
-Note that the "install" target has a very different meaning compared to the
-Linux "make install" target. The Linux "install" copies the targets to system
-directories. In MacOS, "install" means fixing up application bundles. In both
-cases, the "install" target operations clean up the `RPATH`.
-
##### The Non-bundled vulkaninfo Application
There is also a non-bundled version of the `vulkaninfo` application that you
vulkaninfo/vulkaninfo
-If you run this before you run "make install", vulkaninfo's RPATH is already
+If you run this from the build directory, vulkaninfo's RPATH is already
set to point to the Vulkan loader in the build tree, so it has no trouble
finding it. But the loader will not find the MoltenVK driver and you'll see a
message about an incompatible driver. To remedy this:
- VK_ICD_FILENAMES=<path-to>/MoltenVK/Package/Latest/MoltenVK/macOS/MoltenVK_icd.json demos/vulkaninfo
+ VK_ICD_FILENAMES=<path-to>/MoltenVK/Package/Latest/MoltenVK/macOS/MoltenVK_icd.json vulkaninfo/vulkaninfo
-If you run `vulkaninfo` after doing a "make install", the `RPATH` in the
-`vulkaninfo` application got removed and the OS needs extra help to locate the
-Vulkan loader:
+If you run `vulkaninfo` from the install directory, the `RPATH` in the
+`vulkaninfo` application got removed and the OS needs extra help to locate
+the Vulkan loader:
- DYLD_LIBRARY_PATH=<path-to>/Vulkan-Loader/loader VK_ICD_FILENAMES=<path-to>/MoltenVK/Package/Latest/MoltenVK/macOS/MoltenVK_icd.json demos/vulkaninfo
+ DYLD_LIBRARY_PATH=<path-to>/Vulkan-Loader/loader VK_ICD_FILENAMES=<path-to>/MoltenVK/Package/Latest/MoltenVK/macOS/MoltenVK_icd.json vulkaninfo/vulkaninfo
#### Building with the Xcode Generator
if(APPLE)
# CMake versions 3 or later need CMAKE_MACOSX_RPATH defined. This avoids the CMP0042 policy message.
set(CMAKE_MACOSX_RPATH 1)
- # The "install" target for MacOS fixes up bundles in place.
- set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR})
endif()
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
endif()
if(APPLE)
- set_target_properties(cube PROPERTIES INSTALL_RPATH "@loader_path/../lib")
- install(TARGETS cube DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
+ # Keep RPATH so fixup_bundle can use it to find libraries
+ set_target_properties(cube PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)
+ install(TARGETS cube BUNDLE DESTINATION "cube")
+ # Fix up the library references to be self-contained within the bundle.
+ install(
+ CODE
+ "
+ include(BundleUtilities)
+ fixup_bundle(\${CMAKE_INSTALL_PREFIX}/cube/cube.app \"\" \"\")
+ "
+ )
else()
install(TARGETS cube RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
endif()
if(APPLE)
- set_target_properties(cubepp PROPERTIES INSTALL_RPATH "@loader_path/../lib")
- install(TARGETS cubepp DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
+ # Keep RPATH so fixup_bundle can use it to find libraries
+ set_target_properties(cubepp PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)
+ install(TARGETS cubepp BUNDLE DESTINATION "cube")
+ # Fix up the library references to be self-contained within the bundle.
+ install(
+ CODE
+ "
+ include(BundleUtilities)
+ fixup_bundle(\${CMAKE_INSTALL_PREFIX}/cube/cubepp.app \"\" \"\")
+ "
+ )
else()
install(TARGETS cubepp RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
${CMAKE_CURRENT_BINARY_DIR}/cube.app/Contents/Frameworks/libMoltenVK.dylib
DEPENDS vulkan)
endif()
-
-# Fix up the library search path in the executable to find (loader) libraries in the bundle.
-install(CODE "
- include(BundleUtilities)
- fixup_bundle(${CMAKE_INSTALL_PREFIX}/cube/cube.app \"\" \"\")
- "
- COMPONENT Runtime)
-
-# ~~~
-# Not sure this is needed. When activated, it makes a symlink from
-# libvulkan.dylib to libvulkan.1.dylib (which in turn symlinks to libvulkan.1.0.xx.dylib.)
-# install(FILES
-# "${CMAKE_BINARY_DIR}/loader/libvulkan.dylib"
-# DESTINATION "demos/cube.app/Contents/MacOS"
-# COMPONENT Runtime)
-# ~~~
MACOSX_PACKAGE_LOCATION
"Resources/vulkan/icd.d")
-# Direct the MoltenVK library to the right place.
-install(FILES "${MOLTENVK_DIR}/MoltenVK/macOS/libMoltenVK.dylib" DESTINATION "demos/cubepp.app/Contents/Frameworks"
- COMPONENT Runtime)
-
# Copy the MoltenVK lib into the bundle.
if(${CMAKE_GENERATOR} MATCHES "^Xcode.*")
add_custom_command(TARGET cubepp POST_BUILD
${CMAKE_CURRENT_BINARY_DIR}/cubepp.app/Contents/Frameworks/libMoltenVK.dylib
DEPENDS vulkan)
endif()
-
-# Fix up the library search path in the executable to find (loader) libraries in the bundle.
-install(CODE "
- include(BundleUtilities)
- fixup_bundle(${CMAKE_INSTALL_PREFIX}/cube/cubepp.app \"\" \"\")
- "
- COMPONENT Runtime)
-
-# ~~~
-# Not sure this is needed. When activated, it makes a symlink from
-# libvulkan.dylib to libvulkan.1.dylib (which in turn symlinks to libvulkan.1.0.xx.dylib.)
-# install(FILES
-# "${CMAKE_BINARY_DIR}/loader/libvulkan.dylib"
-# DESTINATION "demos/cubepp.app/Contents/MacOS"
-# COMPONENT Runtime)
-# ~~~
endif()
if(APPLE)
- set_target_properties(vulkaninfo PROPERTIES INSTALL_RPATH "@loader_path/../lib")
- install(TARGETS vulkaninfo DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
+ install(TARGETS vulkaninfo RUNTIME DESTINATION "vulkaninfo")
else()
install(TARGETS vulkaninfo RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
MACOSX_PACKAGE_LOCATION
"Resources/vulkan/icd.d")
-# Direct the MoltenVK library to the right place.
-install(FILES "${MOLTENVK_DIR}/MoltenVK/macOS/libMoltenVK.dylib" DESTINATION "demos/vulkaninfo.app/Contents/Frameworks"
- COMPONENT Runtime)
# Xcode projects need some extra help with what would be install steps.
if(${CMAKE_GENERATOR} MATCHES "^Xcode.*")
add_custom_command(TARGET vulkaninfo-bundle POST_BUILD
DEPENDS vulkan)
endif()
-# Fix up the library search path in the executable to find (loader) libraries in the bundle. When fixup_bundle() is passed a bundle
-# in the first argument, it looks at the Info.plist file to determine the BundleExecutable. In this case, the executable is a
-# script, which can't be fixed up. Instead pass it the explicit name of the executable.
+# Keep RPATH so fixup_bundle can use it to find libraries
+set_target_properties(vulkaninfo-bundle PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)
+install(TARGETS vulkaninfo-bundle BUNDLE DESTINATION "vulkaninfo")
+# Fix up the library search path in the executable to find (loader) libraries
+# in the bundle. When fixup_bundle() is passed a bundle in the first argument,
+# it looks at the Info.plist file to determine the BundleExecutable. In this
+# case, the executable is a script, which can't be fixed up. Instead pass it
+# the explicit name of the executable.
install(
CODE
"
include(BundleUtilities)
- fixup_bundle(${CMAKE_INSTALL_PREFIX}/vulkaninfo/vulkaninfo.app/Contents/MacOS/vulkaninfo \"\" \"\")
+ fixup_bundle(\${CMAKE_INSTALL_PREFIX}/vulkaninfo/vulkaninfo.app/Contents/MacOS/vulkaninfo \"\" \"\")
"
- COMPONENT Runtime)
+)