Skip to content

Commit

Permalink
build: Enable install targets on Windows
Browse files Browse the repository at this point in the history
Note: cube is not yet being installed.
  • Loading branch information
karl-lunarg committed May 28, 2018
1 parent 5e1623c commit c3b64a7
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 32 deletions.
23 changes: 13 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ if (NOT CMAKE_VERSION VERSION_LESS 3.7.0)
find_package(Vulkan)
endif()

include(GNUInstallDirs)
# Set a better default install location for Windows only if the user did not provide one.
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND WIN32)
set (CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "default install path" FORCE )
endif()

if(APPLE)
# CMake versions 3 or later need CMAKE_MACOSX_RPATH defined.
# This avoids the CMP0042 policy message.
Expand Down Expand Up @@ -95,17 +101,14 @@ option(BUILD_ICD "Build icd" ON)
# Require the user to ask that it be installed if they really want it.
option(INSTALL_ICD "Install icd" OFF)

if(UNIX)
include(GNUInstallDirs)
# uninstall target
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
# uninstall target
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)

add_custom_target(uninstall-Vulkan-Tools
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
endif()
add_custom_target(uninstall-Vulkan-Tools
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)

if(APPLE)
include(mac_common.cmake)
Expand Down
44 changes: 30 additions & 14 deletions icd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ else()
message(FATAL_ERROR "Unsupported Platform!")
endif()

# Copy or link the JSON files to the binary directory for ease of use in the build tree.
set(ICD_JSON_FILES VkICD_mock_icd)

if (WIN32)
# extra setup for out-of-tree builds
if (NOT (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR))
if (CMAKE_GENERATOR MATCHES "^Visual Studio.*")
foreach (config_file ${ICD_JSON_FILES})
Expand Down Expand Up @@ -131,14 +132,19 @@ if (WIN32)
add_library(VkICD_${target} SHARED ${ARGN} VkICD_${target}.def)
add_dependencies(VkICD_${target} icd_generate_helper_files generate_icd_files)
#target_link_Libraries(VkICD_${target} VkICD_utils)
if(INSTALL_ICD)
install(TARGETS VkICD_${target} DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
endmacro()
elseif(APPLE)
macro(add_vk_icd target)
add_library(VkICD_${target} SHARED ${ARGN})
#target_link_Libraries(VkICD_${target} VkICD_utils)
add_dependencies(VkICD_${target} icd_generate_helper_files generate_icd_files)
set_target_properties(VkICD_${target} PROPERTIES LINK_FLAGS "-Wl")
install(TARGETS VkICD_${target} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
if(INSTALL_ICD)
install(TARGETS VkICD_${target} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
endif()
endmacro()
else()
macro(add_vk_icd target)
Expand All @@ -148,18 +154,6 @@ else()
set_target_properties(VkICD_${target} PROPERTIES LINK_FLAGS "-Wl,-export-dynamic,-Bsymbolic,--exclude-libs,ALL")
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND INSTALL_ICD)
install(TARGETS VkICD_${target} DESTINATION ${CMAKE_INSTALL_LIBDIR})
# Add targets for JSON file install on Linux.
# Need to remove the "./" from the library path before installing to system directories.
foreach (config_file ${ICD_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$./libVkICD$libVkICD$" ${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 ${CMAKE_INSTALL_DATAROOTDIR}/vulkan/icd.d)
endforeach(config_file)
endif()
endmacro()
endif()
Expand Down Expand Up @@ -193,3 +187,25 @@ run_vk_xml_generate(mock_icd_generator.py mock_icd.cpp)

add_vk_icd(mock_icd mock_icd.cpp mock_icd.h)

# JSON file(s) install targets.
# For Linux, need to remove the "./" from the library path before installing to system directories.
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND INSTALL_ICD)
foreach (config_file ${ICD_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$./libVkICD$libVkICD$" ${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 ${CMAKE_INSTALL_DATAROOTDIR}/vulkan/icd.d)
endforeach(config_file)
endif()

# Windows uses the JSON file as-is.
if(WIN32 AND INSTALL_ICD)
foreach (config_file ${ICD_JSON_FILES})
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/windows/${config_file}.json DESTINATION ${CMAKE_INSTALL_LIBDIR})
endforeach(config_file)
endif()

14 changes: 6 additions & 8 deletions vulkaninfo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,6 @@ if(LOADER_REPO_ROOT)
endif()
endif()

if(APPLE)
set_target_properties(vulkaninfo PROPERTIES
INSTALL_RPATH "@loader_path/../lib"
)
install(TARGETS vulkaninfo DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
endif()

# Create vulkaninfo application bundle for MacOS
if(APPLE)
include(${CMAKE_CURRENT_SOURCE_DIR}/macOS/vulkaninfo.cmake)
Expand All @@ -80,7 +73,12 @@ elseif(APPLE)
add_definitions(-DVK_USE_PLATFORM_MACOS_MVK)
endif()

if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
if(APPLE)
set_target_properties(vulkaninfo PROPERTIES
INSTALL_RPATH "@loader_path/../lib"
)
install(TARGETS vulkaninfo DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
else()
install(TARGETS vulkaninfo RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()

0 comments on commit c3b64a7

Please sign in to comment.