cmake: Put the manifest generation in a CMake module.

Will make it easier to modify/customize and
integrate the trampoline.
This commit is contained in:
Ryan Pavlik 2022-04-20 15:05:31 -05:00
parent e75fae4d80
commit c718d69dae
5 changed files with 207 additions and 2 deletions

View file

@ -1,6 +1,27 @@
# SPDX-FileCopyrightText: 2021, Collabora, Ltd.
# SPDX-FileCopyrightText: 2021-2022, Collabora, Ltd.
# SPDX-License-Identifier: CC0-1.0
with section("parse"):
# Specify structure for custom cmake functions
additional_commands = {
"generate_openxr_runtime_manifest_at_install": {
"kwargs": {
"DESTINATION": 1,
"MANIFEST_TEMPLATE": 1,
"OUT_FILENAME": 1,
"RELATIVE_RUNTIME_DIR": 1,
"RUNTIME_DIR_RELATIVE_TO_MANIFEST": 1,
"RUNTIME_TARGET": 1,
},
"pargs": {"flags": ["ABSOLUTE_RUNTIME_PATH"], "nargs": "*"},
},
"generate_openxr_runtime_manifest_buildtree": {
"kwargs": {"MANIFEST_TEMPLATE": 1, "OUT_FILE": 1, "RUNTIME_TARGET": 1},
"pargs": {"flags": [], "nargs": "*"},
},
}
with section("format"):
line_width = 100
tab_size = 8
@ -14,7 +35,7 @@ with section("format"):
max_pargs_hwrap = 4
max_rows_cmdline = 1
keyword_case = 'upper'
keyword_case = "upper"
# Do not reflow comments

View file

@ -0,0 +1,120 @@
# Copyright 2019-2022, Collabora, Ltd.
# SPDX-License-Identifier: BSL-1.0
#[[.rst:
GenerateOpenXRRuntimeManifest
---------------
The following functions are provided by this module:
- :command:`generate_openxr_runtime_manifest_buildtree`
- :command:`generate_openxr_runtime_manifest_at_install`
.. command:: generate_openxr_runtime_manifest_buildtree
Generates a runtime manifest suitable for use in the build tree,
with absolute paths, at configure time::
generate_openxr_runtime_manifest_buildtree(
RUNTIME_TARGET <target> # Name of your runtime target
OUT_FILE <outfile> # Name of the manifest file (with path) to generate
[MANIFEST_TEMPLATE <template>] # Optional: Specify an alternate template to use
)
.. command:: generate_openxr_runtime_manifest_at_install
Generates a runtime manifest at install time and installs it where desired::
generate_openxr_runtime_manifest_buildtree(
RUNTIME_TARGET <target> # Name of your runtime target
DESTINATION <dest> # The install-prefix-relative path to install the manifest to.
RELATIVE_RUNTIME_DIR <dir> # The install-prefix-relative path that the runtime library is installed to.
[ABSOLUTE_RUNTIME_PATH| # If present, path in generated manifest is absolute
RUNTIME_DIR_RELATIVE_TO_MANIFEST <dir>]
# If present (and ABSOLUTE_RUNTIME_PATH not present), specifies the
# runtime directory relative to the manifest directory in the installed layout
[OUT_FILENAME <outfilename> # Optional: Alternate name of the manifest file to generate
[MANIFEST_TEMPLATE <template>] # Optional: Specify an alternate template to use
)
#]]
get_filename_component(_OXR_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
set(_OXR_MANIFEST_SCRIPT
"${_OXR_CMAKE_DIR}/GenerateOpenXRRuntimeManifestInstall.cmake.in"
CACHE INTERNAL "" FORCE)
set(_OXR_MANIFEST_TEMPLATE
"${_OXR_CMAKE_DIR}/openxr_monado.in.json"
CACHE INTERNAL "" FORCE)
function(generate_openxr_runtime_manifest_buildtree)
set(options)
set(oneValueArgs RUNTIME_TARGET OUT_FILE MANIFEST_TEMPLATE)
set(multiValueArgs)
cmake_parse_arguments(_genmanifest "${options}" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN})
if(NOT _genmanifest_RUNTIME_TARGET)
message(FATAL_ERROR "Need RUNTIME_TARGET specified!")
endif()
if(NOT _genmanifest_OUT_FILE)
message(FATAL_ERROR "Need OUT_FILE specified!")
endif()
if(NOT _genmanifest_MANIFEST_TEMPLATE)
set(_genmanifest_MANIFEST_TEMPLATE "${_OXR_MANIFEST_TEMPLATE}")
endif()
# Set template values
# SHELL_PATH isn't perfect here, we actually always want backslashes on Windows,
# but it's the closest we have in generator expressions.
set(runtime_path $<SHELL_PATH:$<TARGET_FILE:${_genmanifest_RUNTIME_TARGET}>>)
# Need this step because file(GENERATE) only evaluates generator expressions, and not what configure_file does.
set(_intermediate
${CMAKE_CURRENT_BINARY_DIR}/intermediate_manifest_buildtree_${_genmanifest_RUNTIME_TARGET}.json
)
configure_file("${_genmanifest_MANIFEST_TEMPLATE}" "${_intermediate}" @ONLY)
file(
GENERATE
OUTPUT "${_genmanifest_OUT_FILE}"
INPUT "${_intermediate}")
endfunction()
function(generate_openxr_runtime_manifest_at_install)
set(options ABSOLUTE_RUNTIME_PATH)
set(oneValueArgs
RUNTIME_TARGET DESTINATION OUT_FILENAME
RUNTIME_DIR_RELATIVE_TO_MANIFEST RELATIVE_RUNTIME_DIR MANIFEST_TEMPLATE)
set(multiValueArgs)
cmake_parse_arguments(_genmanifest "${options}" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN})
if(NOT _genmanifest_RUNTIME_TARGET)
message(FATAL_ERROR "Need RUNTIME_TARGET specified!")
endif()
if(NOT _genmanifest_DESTINATION)
message(FATAL_ERROR "Need DESTINATION specified!")
endif()
if(NOT _genmanifest_RELATIVE_RUNTIME_DIR)
message(FATAL_ERROR "Need RELATIVE_RUNTIME_DIR specified!")
endif()
if(NOT _genmanifest_OUT_FILENAME)
set(_genmanifest_OUT_FILENAME "${_genmanifest_RUNTIME_TARGET}.json")
endif()
if(NOT _genmanifest_MANIFEST_TEMPLATE)
set(_genmanifest_MANIFEST_TEMPLATE "${_OXR_MANIFEST_TEMPLATE}")
endif()
set(_genmanifest_INTERMEDIATE_MANIFEST
"${CMAKE_CURRENT_BINARY_DIR}/${_genmanifest_OUT_FILENAME}")
# Template value
set(RUNTIME_FILENAME
${CMAKE_SHARED_MODULE_PREFIX}${_genmanifest_RUNTIME_TARGET}${CMAKE_SHARED_MODULE_SUFFIX}
)
set(_script
${CMAKE_CURRENT_BINARY_DIR}/make_manifest_${_genmanifest_RUNTIME_TARGET}.cmake
)
configure_file("${_OXR_MANIFEST_SCRIPT}" "${_script}" @ONLY)
install(SCRIPT "${_script}")
endfunction()

View file

@ -0,0 +1,56 @@
# Copyright 2019-2022, Collabora, Ltd.
# Copyright 2019, Benjamin Saunders <ben.e.saunders@gmail.com>
# SPDX-License-Identifier: BSL-1.0
# Get input from main CMake script
set(MANIFEST_TEMPLATE @_genmanifest_MANIFEST_TEMPLATE@)
set(DESTINATION @_genmanifest_DESTINATION@)
set(OUT_FILENAME @_genmanifest_OUT_FILENAME@)
set(RUNTIME_TARGET @_genmanifest_RUNTIME_TARGET@)
set(INTERMEDIATE_MANIFEST @_genmanifest_INTERMEDIATE_MANIFEST@)
# Runtime install dir relative to install prefix
set(RELATIVE_RUNTIME_DIR @_genmanifest_RELATIVE_RUNTIME_DIR@)
# Runtime so/dll filename
set(RUNTIME_FILENAME @RUNTIME_FILENAME@)
# The relative path from the manifest dir to the runtime. Optional.
set(RUNTIME_DIR_RELATIVE_TO_MANIFEST
@_genmanifest_RUNTIME_DIR_RELATIVE_TO_MANIFEST@)
# Config option
set(ABSOLUTE_RUNTIME_PATH @_genmanifest_ABSOLUTE_RUNTIME_PATH@)
if(ABSOLUTE_RUNTIME_PATH)
# Absolute path to runtime
message(STATUS "Installing OpenXR runtime manifest with absolute path to runtime")
set(RUNTIME_PATH ${RELATIVE_RUNTIME_DIR}/${RUNTIME_FILENAME})
if(NOT IS_ABSOLUTE ${RELATIVE_RUNTIME_DIR})
set(RUNTIME_PATH ${CMAKE_INSTALL_PREFIX}/${RUNTIME_PATH})
endif()
elseif(RUNTIME_DIR_RELATIVE_TO_MANIFEST)
# Relative path to runtime.
message(STATUS "Installing OpenXR runtime manifest with JSON-relative path to runtime")
set(RUNTIME_PATH ${RUNTIME_DIR_RELATIVE_TO_MANIFEST}/${RUNTIME_FILENAME})
else()
# Unqualified runtime filename: requires it exist on the system shared library search path.
message(STATUS "Installing OpenXR runtime manifest with unqualified runtime filename (uses system search path)")
set(RUNTIME_PATH ${RUNTIME_FILENAME})
endif()
if(WIN32)
string(REPLACE "/" [[\\]] RUNTIME_PATH ${RUNTIME_PATH})
endif()
set(runtime_path ${RUNTIME_PATH})
if("x${CMAKE_INSTALL_COMPONENT}x" STREQUAL "xUnspecifiedx"
OR NOT CMAKE_INSTALL_COMPONENT)
# Create manifest
configure_file("${MANIFEST_TEMPLATE}" "${INTERMEDIATE_MANIFEST}")
# Install it
file(
INSTALL
DESTINATION "${CMAKE_INSTALL_PREFIX}/${DESTINATION}"
TYPE FILE FILES "${INTERMEDIATE_MANIFEST}")
endif()

View file

@ -0,0 +1,6 @@
{
"file_format_version": "1.0.0",
"runtime": {
"library_path": "@runtime_path@"
}
}

View file

@ -0,0 +1,2 @@
Copyright 2018-2020, Collabora, Ltd.
SPDX-License-Identifier: BSL-1.0