-
Notifications
You must be signed in to change notification settings - Fork 119
/
CMakeLists.txt
135 lines (116 loc) · 4.17 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
cmake_minimum_required(VERSION 3.5...3.30)
project(volk VERSION
# VOLK_GENERATE_VERSION
301
# VOLK_GENERATE_VERSION
LANGUAGES C
)
# CMake 3.12 changes the default behaviour of option() to leave local variables
# unchanged if they exist (which we want), but we must work with older CMake versions.
if(NOT DEFINED VOLK_STATIC_DEFINES)
set(VOLK_STATIC_DEFINES "" CACHE STRING "Additional defines for building the volk static library, e.g. Vulkan platform defines")
endif()
if(NOT DEFINED VOLK_PULL_IN_VULKAN)
option(VOLK_PULL_IN_VULKAN "Vulkan as a transitive dependency" ON)
endif()
if(NOT DEFINED VOLK_INSTALL)
option(VOLK_INSTALL "Create installation targets" OFF)
endif()
if(NOT DEFINED VOLK_HEADERS_ONLY)
option(VOLK_HEADERS_ONLY "Add interface library only" OFF)
endif()
if(NOT DEFINED VULKAN_HEADERS_INSTALL_DIR)
set(VULKAN_HEADERS_INSTALL_DIR "" CACHE PATH "Where to get the Vulkan headers")
endif()
# -----------------------------------------------------
# Static library
if(NOT VOLK_HEADERS_ONLY OR VOLK_INSTALL)
add_library(volk STATIC volk.h volk.c)
add_library(volk::volk ALIAS volk)
target_include_directories(volk PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>
$<INSTALL_INTERFACE:include>
)
if(VOLK_STATIC_DEFINES)
target_compile_definitions(volk PUBLIC ${VOLK_STATIC_DEFINES})
endif()
if (NOT WIN32)
target_link_libraries(volk PUBLIC ${CMAKE_DL_LIBS})
endif()
endif()
# -----------------------------------------------------
# Interface library
add_library(volk_headers INTERFACE)
add_library(volk::volk_headers ALIAS volk_headers)
target_include_directories(volk_headers INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>
$<INSTALL_INTERFACE:include>
)
if (NOT WIN32)
target_link_libraries(volk_headers INTERFACE ${CMAKE_DL_LIBS})
endif()
# -----------------------------------------------------
# Vulkan transitive dependency
if(VOLK_PULL_IN_VULKAN)
# Try an explicit CMake variable first, then any Vulkan paths
# discovered by FindVulkan.cmake, then the $VULKAN_SDK environment
# variable if nothing else works.
if(VULKAN_HEADERS_INSTALL_DIR)
message("volk: using VULKAN_HEADERS_INSTALL_DIR option")
set(VOLK_INCLUDES "${VULKAN_HEADERS_INSTALL_DIR}/include")
else()
# If CMake has the FindVulkan module and it works, use it.
find_package(Vulkan QUIET)
if(Vulkan_INCLUDE_DIRS)
message("volk: using Vulkan_INCLUDE_DIRS from FindVulkan module")
set(VOLK_INCLUDES "${Vulkan_INCLUDE_DIRS}")
elseif(DEFINED ENV{VULKAN_SDK})
message("volk: using VULKAN_SDK environment variable")
set(VOLK_INCLUDES "$ENV{VULKAN_SDK}/include")
endif()
endif()
if(VOLK_INCLUDES)
if(TARGET volk)
target_include_directories(volk PUBLIC "${VOLK_INCLUDES}")
endif()
target_include_directories(volk_headers INTERFACE "${VOLK_INCLUDES}")
endif()
endif()
# -----------------------------------------------------
# Installation
if(VOLK_INSTALL)
include(GNUInstallDirs)
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/volk)
# Install files
install(FILES volk.h volk.c DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# Install library target and add it and any dependencies to export set.
install(TARGETS volk volk_headers
EXPORT volk-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
# Actually write exported config w/ imported targets
install(EXPORT volk-targets
FILE volkTargets.cmake
NAMESPACE volk::
DESTINATION ${INSTALL_CONFIGDIR}
)
# Create a ConfigVersion.cmake file:
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/volkConfigVersion.cmake
COMPATIBILITY AnyNewerVersion
)
# Configure config file
configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/cmake/volkConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/volkConfig.cmake
INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
)
# Install the fully generated config and configVersion files
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/volkConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/volkConfigVersion.cmake
DESTINATION ${INSTALL_CONFIGDIR}
)
endif()