build: gh52-CMake changes to enable make install on Linux
authorKarl Schultz <karl@lunarg.com>
Fri, 30 Sep 2016 19:32:16 +0000 (13:32 -0600)
committerKarl Schultz <karl@lunarg.com>
Mon, 3 Oct 2016 14:35:01 +0000 (08:35 -0600)
See BUILD.md for details.

Change-Id: Ide1f635a57b57af384d9d1baac20c2256629f812

BUILD.md
demos/CMakeLists.txt
layers/CMakeLists.txt
loader/CMakeLists.txt
tests/layers/CMakeLists.txt

index 09982e9..3097efe 100644 (file)
--- a/BUILD.md
+++ b/BUILD.md
@@ -58,6 +58,44 @@ The `LoaderAndLayerInterface` document in the `loader` folder in this repository
 describes both how ICDs and layers should be properly
 packaged, and how developers can point to ICDs and layers within their builds.
 
+### Linux Install to System Directories
+
+Installing the files resulting from your build to the systems directories is optional since
+environment variables can usually be used instead to locate the binaries.
+There are also risks with interfering with binaries installed by packages.
+If you are certain that you would like to install your binaries to system directories,
+you can proceed with these instructions.
+
+Assuming that you've built the code as described above and the current directory is still `dbuild`,
+you can execute:
+
+```
+sudo make install
+```
+
+This command installs files to:
+
+* `/usr/local/lib`:  Vulkan loader and layers shared objects
+* `/usr/local/bin`:  vulkaninfo application
+* `/etc/vulkan/explicit_layer.d`:  Layer JSON files
+
+You may need to run `ldconfig` in order to refresh the system loader search cache on some Linux systems.
+
+The list of installed files appears in the build directory in a file named `install_manifest.txt`.
+You can easily remove the installed files with:
+
+```
+cat install_manifest.txt | sudo xargs rm
+```
+
+See the CMake documentation for details on using `DESTDIR` and `CMAKE_INSTALL_PREFIX` to customize
+your installation location.
+
+Note that some executables in this repository (e.g., `cube`) use the "rpath" linker directive
+to load the Vulkan loader from the build directory, `dbuild` in this example.
+This means that even after installing the loader to the system directories, these executables
+still use the loader from the build directory.
+
 ## Validation Test
 
 The test executables can be found in the dbuild/tests directory. 
index ccfd84b..cdfb9e6 100644 (file)
@@ -114,3 +114,7 @@ endif()
 if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL ${CMAKE_HOST_SYSTEM_PROCESSOR})
     add_subdirectory(smoke)
 endif()
+
+if(UNIX)
+    install(TARGETS vulkaninfo DESTINATION bin)
+endif()
index 13f9e69..de0dc94 100644 (file)
@@ -67,6 +67,21 @@ else()
     endif()
 endif()
 
+# Add targets for JSON file install on Linux.
+# Need to remove the "./" from the library path before installing to /etc.
+if(UNIX)
+    foreach (config_file ${LAYER_JSON_FILES})
+        add_custom_target(${config_file}-staging-json ALL
+            COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/staging-json
+            COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/linux/${config_file}.json ${CMAKE_CURRENT_BINARY_DIR}/staging-json
+            COMMAND sed -i -e "/\"library_path\":/s$./libVkLayer$libVkLayer$" ${CMAKE_CURRENT_BINARY_DIR}/staging-json/${config_file}.json
+            VERBATIM
+            DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/linux/${config_file}.json
+            )
+        install(FILES ${CMAKE_CURRENT_BINARY_DIR}/staging-json/${config_file}.json DESTINATION /etc/vulkan/explicit_layer.d)
+    endforeach(config_file)
+endif()
+
 if (WIN32)
     macro(add_vk_layer target)
     add_custom_command(OUTPUT VkLayer_${target}.def
@@ -83,7 +98,7 @@ else()
     target_link_Libraries(VkLayer_${target} VkLayer_utils)
     add_dependencies(VkLayer_${target} generate_dispatch_table_helper generate_vk_layer_helpers generate_enum_string_helper VkLayer_utils)
     set_target_properties(VkLayer_${target} PROPERTIES LINK_FLAGS "-Wl,-Bsymbolic")
-    install(TARGETS VkLayer_${target} DESTINATION ${PROJECT_BINARY_DIR}/install_staging)
+    install(TARGETS VkLayer_${target} DESTINATION lib)
     endmacro()
 endif()
 
@@ -176,7 +191,7 @@ if (WIN32)
     add_library(VkLayer_utils STATIC vk_layer_config.cpp vk_layer_extension_utils.cpp vk_layer_utils.cpp)
 else()
     add_library(VkLayer_utils SHARED vk_layer_config.cpp vk_layer_extension_utils.cpp vk_layer_utils.cpp)
-    install(TARGETS VkLayer_utils DESTINATION ${PROJECT_BINARY_DIR}/install_staging)
+    install(TARGETS VkLayer_utils DESTINATION lib)
 endif()
 
 add_vk_layer(core_validation core_validation.cpp vk_layer_table.cpp vk_safe_struct.cpp descriptor_sets.cpp)
index 061fb72..742dec4 100644 (file)
@@ -85,4 +85,5 @@ else()
     add_library(vulkan SHARED ${LOADER_SRCS})
     set_target_properties(vulkan PROPERTIES SOVERSION "1" VERSION "1.0.28")
     target_link_libraries(vulkan -ldl -lpthread -lm)
+    install(TARGETS vulkan LIBRARY DESTINATION lib)
 endif()
index c675f1e..786ef14 100644 (file)
@@ -50,7 +50,6 @@ else()
     add_library(VkLayer_${target} SHARED ${ARGN})
     add_dependencies(VkLayer_${target} generate_tests_dispatch_table_helper VkLayer_utils)
     set_target_properties(VkLayer_${target} PROPERTIES LINK_FLAGS "-Wl,-Bsymbolic")
-    install(TARGETS VkLayer_${target} DESTINATION ${PROJECT_BINARY_DIR}/install_staging)
     endmacro()
 endif()