• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2015-2016 The Khronos Group Inc.
2#
3# Permission is hereby granted, free of charge, to any person obtaining a
4# copy of this software and/or associated documentation files (the
5# "Materials"), to deal in the Materials without restriction, including
6# without limitation the rights to use, copy, modify, merge, publish,
7# distribute, sublicense, and/or sell copies of the Materials, and to
8# permit persons to whom the Materials are furnished to do so, subject to
9# the following conditions:
10#
11# The above copyright notice and this permission notice shall be included
12# in all copies or substantial portions of the Materials.
13#
14# MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS
15# KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS
16# SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT
17#    https://www.khronos.org/registry/
18#
19# THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25# MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
26
27#
28# The SPIR-V headers from the SPIR-V Registry
29# https://www.khronos.org/registry/spir-v/
30#
31cmake_minimum_required(VERSION 3.0)
32project(SPIRV-Headers VERSION 1.5.5)
33
34# There are two ways to use this project.
35#
36# Using this source tree directly from a CMake-based project:
37#   1. Add an add_subdirectory directive to include this sub directory.
38#   2. Use ${SPIRV-Headers_SOURCE_DIR}/include} in a target_include_directories
39#      command.
40#
41# Installing the headers first, then using them with an implicit include
42# directory.  To install the headers:
43#   1. mkdir build ; cd build
44#   2. cmake ..
45#   3. cmake --build . --target install
46
47option(SPIRV_HEADERS_SKIP_EXAMPLES "Skip building examples"
48      ${SPIRV_HEADERS_SKIP_EXAMPLES})
49
50option(SPIRV_HEADERS_SKIP_INSTALL "Skip install"
51      ${SPIRV_HEADERS_SKIP_INSTALL})
52
53if(NOT ${SPIRV_HEADERS_SKIP_EXAMPLES})
54  set(SPIRV_HEADERS_ENABLE_EXAMPLES ON)
55endif()
56
57if(NOT ${SPIRV_HEADERS_SKIP_INSTALL})
58  set(SPIRV_HEADERS_ENABLE_INSTALL ON)
59  # legacy
60  add_custom_target(install-headers
61      COMMAND cmake -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/include/spirv
62          $ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/include/spirv)
63endif()
64
65if (SPIRV_HEADERS_ENABLE_EXAMPLES)
66  message(STATUS "Building SPIRV-Header examples")
67  add_subdirectory(example)
68endif()
69
70include(GNUInstallDirs)
71add_library(${PROJECT_NAME} INTERFACE)
72target_include_directories(${PROJECT_NAME} INTERFACE
73    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
74)
75
76# Installation
77
78if (SPIRV_HEADERS_ENABLE_INSTALL)
79    message(STATUS "Installing SPIRV-Header")
80
81    set(config_install_dir "${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_NAME}")
82
83    set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
84
85    set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
86    set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
87    set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
88    set(namespace "${PROJECT_NAME}::")
89
90    include(CMakePackageConfigHelpers)
91
92    if (NOT CMAKE_VERSION VERSION_LESS 3.14)
93        set(arch_independent_str ARCH_INDEPENDENT)
94    endif()
95    write_basic_package_version_file(
96        "${version_config}"
97        COMPATIBILITY SameMajorVersion
98        ${arch_independent_str}
99    )
100
101    configure_package_config_file(
102        "cmake/Config.cmake.in"
103        "${project_config}"
104        INSTALL_DESTINATION "${config_install_dir}"
105    )
106
107    install(
108        TARGETS ${PROJECT_NAME}
109        EXPORT "${TARGETS_EXPORT_NAME}"
110        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
111        ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
112        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
113        INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
114    )
115
116    install(
117        DIRECTORY include/spirv
118        DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
119    )
120
121    install(
122        FILES "${project_config}" "${version_config}"
123        DESTINATION "${config_install_dir}"
124    )
125
126    install(
127        EXPORT "${TARGETS_EXPORT_NAME}"
128        NAMESPACE "${namespace}"
129        DESTINATION "${config_install_dir}"
130    )
131
132    configure_file(${CMAKE_CURRENT_SOURCE_DIR}/SPIRV-Headers.pc.in ${CMAKE_BINARY_DIR}/SPIRV-Headers.pc @ONLY)
133    install(
134        FILES "${CMAKE_BINARY_DIR}/SPIRV-Headers.pc"
135        DESTINATION ${CMAKE_INSTALL_DATADIR}/pkgconfig
136    )
137endif()
138