0001-Support-installing-demos-support-out-of-tree-builds.patch 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. From edca667684764cfcc0460e448e834fadf623a887 Mon Sep 17 00:00:00 2001
  2. From: Jussi Kukkonen <jussi.kukkonen@intel.com>
  3. Date: Mon, 3 Jul 2017 14:49:18 +0300
  4. Subject: [PATCH] Support installing demos, support out-of-tree builds
  5. This is especially useful for cross-compile situation where testing
  6. happens on target.
  7. -DRESOURCE_INSTALL_DIR=<path> decides where data is installed (and
  8. where the binaries will load the data from): if it's left empty,
  9. then nothing will be installed and binaries will load the data from
  10. CMAKE_SOURCE_DIR.
  11. Binaries are now correctly built in CMAKE_BINARY_DIR.
  12. Upstream-Status: Submitted [https://github.com/SaschaWillems/Vulkan/pull/352]
  13. Signed-off-by: Jussi Kukkonen <jussi.kukkonen@intel.com>
  14. ---
  15. CMakeLists.txt | 15 ++++++++++++++-
  16. base/vulkanexamplebase.cpp | 2 +-
  17. 2 files changed, 15 insertions(+), 2 deletions(-)
  18. diff --git a/CMakeLists.txt b/CMakeLists.txt
  19. index b9886bc..4958fff 100644
  20. --- a/CMakeLists.txt
  21. +++ b/CMakeLists.txt
  22. @@ -16,6 +16,8 @@ include_directories(base)
  23. OPTION(USE_D2D_WSI "Build the project using Direct to Display swapchain" OFF)
  24. OPTION(USE_WAYLAND_WSI "Build the project using Wayland swapchain" OFF)
  25. +set(RESOURCE_INSTALL_DIR "" CACHE PATH "Path to install resources to (leave empty for running uninstalled)")
  26. +
  27. # Use FindVulkan module added with CMAKE 3.7
  28. if (NOT CMAKE_VERSION VERSION_LESS 3.7.0)
  29. message(STATUS "Using module to find Vulkan")
  30. @@ -108,6 +110,10 @@ function(buildExample EXAMPLE_NAME)
  31. add_executable(${EXAMPLE_NAME} ${MAIN_CPP} ${SOURCE} ${SHADERS})
  32. target_link_libraries(${EXAMPLE_NAME} ${Vulkan_LIBRARY} ${ASSIMP_LIBRARIES} ${WAYLAND_CLIENT_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
  33. endif(WIN32)
  34. +
  35. + if(RESOURCE_INSTALL_DIR)
  36. + install(TARGETS ${EXAMPLE_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
  37. + endif()
  38. endfunction(buildExample)
  39. # Build all examples
  40. @@ -117,6 +123,13 @@ function(buildExamples)
  41. endforeach(EXAMPLE)
  42. endfunction(buildExamples)
  43. +if(RESOURCE_INSTALL_DIR)
  44. + add_definitions(-DVK_EXAMPLE_DATA_DIR=\"${RESOURCE_INSTALL_DIR}/\")
  45. + install(DIRECTORY data/ DESTINATION ${RESOURCE_INSTALL_DIR}/)
  46. +else()
  47. + add_definitions(-DVK_EXAMPLE_DATA_DIR=\"${CMAKE_SOURCE_DIR}/data/\")
  48. +endif()
  49. +
  50. # Compiler specific stuff
  51. IF(MSVC)
  52. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
  53. @@ -128,7 +141,7 @@ ELSE(WIN32)
  54. link_libraries(${XCB_LIBRARIES} ${Vulkan_LIBRARY})
  55. ENDIF(WIN32)
  56. -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin/")
  57. +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/")
  58. set(EXAMPLES
  59. bloom
  60. diff --git a/base/vulkanexamplebase.cpp b/base/vulkanexamplebase.cpp
  61. index 647368a..a0f28a5 100644
  62. --- a/base/vulkanexamplebase.cpp
  63. +++ b/base/vulkanexamplebase.cpp
  64. @@ -84,7 +84,7 @@ const std::string VulkanExampleBase::getAssetPath()
  65. #if defined(__ANDROID__)
  66. return "";
  67. #else
  68. - return "./../data/";
  69. + return VK_EXAMPLE_DATA_DIR;
  70. #endif
  71. }
  72. #endif
  73. --
  74. 2.13.2