Skip to content

Commit 40de3ed

Browse files
authored
Merge pull request #191 from matthieucoquet/cmake_export
Export of CMake config-file package during install
2 parents 0d5d0c2 + d2e2f74 commit 40de3ed

File tree

4 files changed

+57
-1
lines changed

4 files changed

+57
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
- issue.185.gh.OpenXR-SDK-Source
3+
---
4+
cmake: export OpenXRConfig.cmake during install. Two targets can be imported by another CMake application: OpenXR::openxr_loader and OpenXR::headers.

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ endif()
156156
if(BUILD_WITH_WAYLAND_HEADERS)
157157
target_compile_definitions(openxr-all-supported INTERFACE XR_USE_PLATFORM_WAYLAND)
158158
endif()
159+
# openxr-all-supported is a dependency of openxr_loader so it should be added to the export set
160+
install(TARGETS openxr-all-supported EXPORT openxr_loader_export)
159161

160162
# Find glslc shader compiler.
161163
# On Android, the NDK includes the binary, so no external dependency.

src/loader/CMakeLists.txt

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,46 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
239239
endif()
240240

241241
install(
242-
TARGETS openxr_loader
242+
TARGETS openxr_loader EXPORT openxr_loader_export
243243
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
244244
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
245245
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
246246
)
247+
248+
export(
249+
EXPORT openxr_loader_export
250+
FILE ${CMAKE_CURRENT_BINARY_DIR}/OpenXRTargets.cmake
251+
NAMESPACE OpenXR::
252+
)
253+
254+
if((CMAKE_SYSTEM_NAME STREQUAL "Windows") OR (CMAKE_SYSTEM_NAME STREQUAL "WindowsStore"))
255+
set(TARGET_DESTINATION cmake)
256+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
257+
set(TARGET_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/openxr/)
258+
endif()
259+
260+
install(
261+
EXPORT openxr_loader_export
262+
FILE OpenXRTargets.cmake
263+
NAMESPACE OpenXR::
264+
DESTINATION ${TARGET_DESTINATION}
265+
)
266+
267+
include(CMakePackageConfigHelpers)
268+
set(INCLUDE_INSTALL_DIR include/)
269+
configure_package_config_file(
270+
OpenXRConfig.cmake.in
271+
${CMAKE_CURRENT_BINARY_DIR}/OpenXRConfig.cmake
272+
INSTALL_DESTINATION ${TARGET_DESTINATION}
273+
PATH_VARS INCLUDE_INSTALL_DIR
274+
)
275+
write_basic_package_version_file(
276+
${CMAKE_CURRENT_BINARY_DIR}/OpenXRConfigVersion.cmake
277+
VERSION "${MAJOR}.${MINOR}.${PATCH}"
278+
COMPATIBILITY SameMajorVersion
279+
)
280+
install(
281+
FILES ${CMAKE_CURRENT_BINARY_DIR}/OpenXRConfig.cmake
282+
${CMAKE_CURRENT_BINARY_DIR}/OpenXRConfigVersion.cmake
283+
DESTINATION ${TARGET_DESTINATION}
284+
)

src/loader/OpenXRConfig.cmake.in

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
@PACKAGE_INIT@
3+
4+
# The header openxr.h is not added to the export target so we add the include directory here
5+
include("${CMAKE_CURRENT_LIST_DIR}/OpenXRTargets.cmake")
6+
set_and_check(OpenXR_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
7+
target_include_directories(OpenXR::openxr_loader INTERFACE ${OpenXR_INCLUDE_DIR})
8+
9+
add_library(OpenXR::headers INTERFACE IMPORTED)
10+
target_include_directories(OpenXR::headers SYSTEM INTERFACE ${OpenXR_INCLUDE_DIR})
11+
12+
check_required_components(OpenXR)

0 commit comments

Comments
 (0)