cmake: Clean up macOS install target
authorMike Schuchardt <mikes@lunarg.com>
Wed, 27 Jun 2018 21:58:49 +0000 (15:58 -0600)
committerMike Schuchardt <mikes@lunarg.com>
Tue, 10 Jul 2018 16:30:49 +0000 (10:30 -0600)
- 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
CMakeLists.txt
cube/CMakeLists.txt
cube/macOS/cube/cube.cmake
cube/macOS/cubepp/cubepp.cmake
vulkaninfo/CMakeLists.txt
vulkaninfo/macOS/vulkaninfo.cmake

index 70b8e07..0ca4cba 100644 (file)
--- 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=<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
 
index b625b80..a223974 100644 (file)
@@ -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")
index 7f3dc2d..3204214 100644 (file)
@@ -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()
index 948a465..69952ee 100644 (file)
@@ -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)
-# ~~~
index 31ff012..7e27e9c 100644 (file)
@@ -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)
-# ~~~
index 758a676..6bbfd9d 100644 (file)
@@ -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()
index 61d038f..d69610d 100644 (file)
@@ -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)
+)