From b7c389c9d3efe5cea722eb7395fb70529dd27566 Mon Sep 17 00:00:00 2001 From: Mike Schuchardt Date: Wed, 27 Jun 2018 15:58:49 -0600 Subject: cmake: Clean up macOS install target - Stop hardcoding CMAKE_INSTALL_PREFIX to CMAKE_BINARY_DIR so install products are in a predictable location - Use install/fixup_bundle to create stand-alone app bundles for cube, cubepp, vulkaninfo-bundle at CMAKE_INSTALL_PREFIX - Set INSTALL_RPATH_USE_LINK_PATH for bundle targets so fixup_bundle can find libraries when run from the install tree - Remove rpath from install copy of vulkaninfo - Remove extraneous copy of libMoltenVK.dylib from CMAKE_INSTALL_PREFIX/demos - Update BUILD.md --- BUILD.md | 29 ++++++++++++++--------------- CMakeLists.txt | 2 -- cube/CMakeLists.txt | 26 ++++++++++++++++++++++---- cube/macOS/cube/cube.cmake | 16 ---------------- cube/macOS/cubepp/cubepp.cmake | 20 -------------------- vulkaninfo/CMakeLists.txt | 3 +-- vulkaninfo/macOS/vulkaninfo.cmake | 18 ++++++++++-------- 7 files changed, 47 insertions(+), 67 deletions(-) diff --git a/BUILD.md b/BUILD.md index 70b8e073..0ca4cba5 100644 --- a/BUILD.md +++ b/BUILD.md @@ -697,7 +697,10 @@ build is: 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` @@ -738,9 +741,10 @@ To address this problem, run: 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 @@ -748,11 +752,6 @@ performs other bundle fix-ups. After running `make install`, re-run the 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 @@ -760,18 +759,18 @@ can run from the command line: 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=/MoltenVK/Package/Latest/MoltenVK/macOS/MoltenVK_icd.json demos/vulkaninfo + VK_ICD_FILENAMES=/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=/Vulkan-Loader/loader VK_ICD_FILENAMES=/MoltenVK/Package/Latest/MoltenVK/macOS/MoltenVK_icd.json demos/vulkaninfo + DYLD_LIBRARY_PATH=/Vulkan-Loader/loader VK_ICD_FILENAMES=/MoltenVK/Package/Latest/MoltenVK/macOS/MoltenVK_icd.json vulkaninfo/vulkaninfo #### Building with the Xcode Generator diff --git a/CMakeLists.txt b/CMakeLists.txt index b625b807..a2239747 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,8 +93,6 @@ endif() 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") diff --git a/cube/CMakeLists.txt b/cube/CMakeLists.txt index 7f3dc2d8..3204214f 100644 --- a/cube/CMakeLists.txt +++ b/cube/CMakeLists.txt @@ -200,8 +200,17 @@ else() 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() @@ -230,8 +239,17 @@ else() 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() diff --git a/cube/macOS/cube/cube.cmake b/cube/macOS/cube/cube.cmake index 948a4650..69952eeb 100644 --- a/cube/macOS/cube/cube.cmake +++ b/cube/macOS/cube/cube.cmake @@ -78,19 +78,3 @@ else() ${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) -# ~~~ diff --git a/cube/macOS/cubepp/cubepp.cmake b/cube/macOS/cubepp/cubepp.cmake index 31ff0125..7e27e9c6 100644 --- a/cube/macOS/cubepp/cubepp.cmake +++ b/cube/macOS/cubepp/cubepp.cmake @@ -67,10 +67,6 @@ set_source_files_properties("${CMAKE_BINARY_DIR}/staging-json/MoltenVK_icd.json" 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 @@ -83,19 +79,3 @@ else() ${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) -# ~~~ diff --git a/vulkaninfo/CMakeLists.txt b/vulkaninfo/CMakeLists.txt index 758a6762..6bbfd9d1 100644 --- a/vulkaninfo/CMakeLists.txt +++ b/vulkaninfo/CMakeLists.txt @@ -97,8 +97,7 @@ elseif(APPLE) 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() diff --git a/vulkaninfo/macOS/vulkaninfo.cmake b/vulkaninfo/macOS/vulkaninfo.cmake index 61d038f7..d69610d8 100644 --- a/vulkaninfo/macOS/vulkaninfo.cmake +++ b/vulkaninfo/macOS/vulkaninfo.cmake @@ -44,9 +44,6 @@ set_source_files_properties(${CMAKE_BINARY_DIR}/staging-json/MoltenVK_icd.json 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 @@ -60,13 +57,18 @@ else() 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) +) -- cgit v1.2.3