Skip to content

Commit 5ba16a8

Browse files
Export OpenXRConfig.cmake during install
1 parent 3e40561 commit 5ba16a8

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

src/loader/CMakeLists.txt

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,48 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
238238
endif()
239239

240240
install(
241-
TARGETS openxr_loader
241+
TARGETS openxr_loader EXPORT openxr_loader_export
242242
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
243243
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
244244
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
245245
)
246+
# openxr-all-supported is a dependency of openxr_loader so it should be added to the export set
247+
install(TARGETS openxr-all-supported EXPORT openxr_loader_export)
248+
249+
export(
250+
EXPORT openxr_loader_export
251+
FILE ${CMAKE_CURRENT_BINARY_DIR}/OpenXRTargets.cmake
252+
NAMESPACE xr::
253+
)
254+
255+
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
256+
set(TARGET_DESTINATION cmake)
257+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
258+
set(TARGET_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/openxr/)
259+
endif()
260+
261+
install(
262+
EXPORT openxr_loader_export
263+
FILE OpenXRTargets.cmake
264+
NAMESPACE xr::
265+
DESTINATION ${TARGET_DESTINATION}
266+
)
267+
268+
include(CMakePackageConfigHelpers)
269+
set(INCLUDE_INSTALL_DIR include/)
270+
configure_package_config_file(
271+
OpenXRConfig.cmake.in
272+
${CMAKE_CURRENT_BINARY_DIR}/OpenXRConfig.cmake
273+
INSTALL_DESTINATION ${TARGET_DESTINATION}
274+
PATH_VARS INCLUDE_INSTALL_DIR
275+
)
276+
write_basic_package_version_file(
277+
${CMAKE_CURRENT_BINARY_DIR}/OpenXRConfigVersion.cmake
278+
VERSION "${MAJOR}.${MINOR}.${PATCH}"
279+
COMPATIBILITY SameMajorVersion
280+
)
281+
install(
282+
FILES ${CMAKE_CURRENT_BINARY_DIR}/OpenXRConfig.cmake
283+
${CMAKE_CURRENT_BINARY_DIR}/OpenXRConfigVersion.cmake
284+
DESTINATION ${TARGET_DESTINATION}
285+
)

src/loader/OpenXRConfig.cmake.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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(xr::openxr_loader INTERFACE ${OpenXR_INCLUDE_DIR})
8+
9+
check_required_components(OpenXR)

0 commit comments

Comments
 (0)