···42###
43list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
44list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/sanitizers")
45-include(CMakeDependentOption)
46include(SPIR-V)
47include(GNUInstallDirs)
48if(NOT GIT_DESC)
···187# This one is named differently because that's what CTest uses
188option(BUILD_TESTING "Enable building of the test suite?" ON)
189190-# cmake-format: off
000000000001910192option(XRT_FEATURE_COLOR_LOG "Enable logging in color on supported platforms" ON)
193-cmake_dependent_option(XRT_HAVE_PERCETTO "Enable percetto support" ON "PERCETTO_FOUND" OFF)
194-cmake_dependent_option(XRT_FEATURE_TRACING "Enable debug tracing on supported platforms" OFF "XRT_HAVE_PERCETTO" OFF)
195196-cmake_dependent_option(CMAKE_INTERPROCEDURAL_OPTIMIZATION "Enable inter-procedural (link-time) optimization" OFF "HAS_IPO" OFF)
197-cmake_dependent_option(XRT_HAVE_WAYLAND "Enable Wayland support" ON "WAYLAND_FOUND AND WAYLAND_SCANNER_FOUND AND WAYLAND_PROTOCOLS_FOUND AND LIBDRM_FOUND" OFF)
198-cmake_dependent_option(XRT_HAVE_WAYLAND_DIRECT "Enable Wayland direct support" ON "XRT_HAVE_WAYLAND AND LIBDRM_FOUND AND WAYLAND_PROTOCOLS_VERSION VERSION_GREATER_EQUAL 1.22" OFF)
199-cmake_dependent_option(XRT_HAVE_XLIB "Enable xlib support" ON "X11_FOUND" OFF)
200-cmake_dependent_option(XRT_HAVE_XRANDR "Enable xlib-xrandr support" ON "XRANDR_FOUND" OFF)
201-cmake_dependent_option(XRT_HAVE_XCB "Enable xcb support" ON "XCB_FOUND" OFF)
000000000000202203-cmake_dependent_option(XRT_HAVE_VULKAN "Enable Vulkan Graphics API support (also needed for compositor)" ON "VULKAN_FOUND" OFF)
204-cmake_dependent_option(XRT_HAVE_OPENGL "Enable OpenGL Graphics API support" ON "OPENGL_WITHOUT_GLX_FOUND" OFF)
205-cmake_dependent_option(XRT_HAVE_OPENGL_GLX "Enable OpenGL Graphics API support on X11 (GLX)" ON "XRT_HAVE_OPENGL; OpenGL_GLX_FOUND" OFF)
206-cmake_dependent_option(XRT_HAVE_OPENGLES "Enable OpenGL-ES Graphics API support" ON "OpenGLES_FOUND" OFF)
207-cmake_dependent_option(XRT_HAVE_EGL "Enable OpenGL(-ES) on EGL Graphics API support" ON "EGL_FOUND; XRT_HAVE_OPENGL OR XRT_HAVE_OPENGLES" OFF)
208209-cmake_dependent_option(XRT_HAVE_DBUS "Enable dbus support (for BLE support)" ON "DBUS_FOUND" OFF)
210-cmake_dependent_option(XRT_FEATURE_COMPOSITOR_MAIN "Build main compositor host functionality" ON "XRT_HAVE_VULKAN; XRT_HAVE_WAYLAND OR XRT_HAVE_XCB OR ANDROID OR WIN32" OFF)
211-cmake_dependent_option(XRT_HAVE_LIBBSD "Enable libbsd support" ON "LIBBSD_FOUND" OFF)
212-cmake_dependent_option(XRT_FEATURE_OPENXR "Build OpenXR runtime target" ON "XRT_FEATURE_COMPOSITOR_MAIN" OFF)
213-cmake_dependent_option(XRT_FEATURE_IPC "Enable the build of the IPC layer" ON "NOT WIN32" OFF)
214-cmake_dependent_option(XRT_FEATURE_SERVICE "Enable separate service module for OpenXR runtime" ON "XRT_FEATURE_IPC AND XRT_FEATURE_OPENXR" OFF)
215-cmake_dependent_option(XRT_HAVE_SYSTEMD "Enable systemd support (for socket activation of service)" ON "Systemd_FOUND AND XRT_FEATURE_SERVICE" OFF)
216-cmake_dependent_option(XRT_INSTALL_SYSTEMD_UNIT_FILES "Install user unit files for systemd socket activation on installation" ON "XRT_HAVE_SYSTEMD" OFF)
217-cmake_dependent_option(XRT_INSTALL_ABSOLUTE_SYSTEMD_UNIT_FILES "Use an absolute path to monado-system in installed user unit files for systemd socket activation" ON "XRT_INSTALL_SYSTEMD_UNIT_FILES" OFF)
218-cmake_dependent_option(XRT_FEATURE_STEAMVR_PLUGIN "Build SteamVR plugin" ON "NOT ANDROID" OFF)
00000000000000000000000000000000000219220if(NOT DEFINED XRT_FEATURE_OPENXR_LAYER_DEPTH)
221 set(XRT_FEATURE_OPENXR_LAYER_DEPTH ON)
···233 set(XRT_FEATURE_OPENXR_LAYER_EQUIRECT1 ON)
234endif()
235236-cmake_dependent_option(XRT_FEATURE_RENDERDOC "Enable RenderDoc API" OFF "RT_LIBRARY OR WIN32" OFF)
237-238# Most users won't touch these.
239mark_as_advanced(XRT_FEATURE_COMPOSITOR_MAIN XRT_FEATURE_OPENXR)
240-241-242-if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
243- set(XRT_HAVE_LIBUDEV ON)
244- set(XRT_HAVE_INTERNAL_HID ON)
245-else()
246- cmake_dependent_option(XRT_HAVE_LIBUDEV "Enable libudev (used for device probing on Linux)" ON "UDEV_FOUND" OFF)
247-endif()
248-249-cmake_dependent_option(XRT_HAVE_LIBUSB "Enable libusb (used for most drivers)" ON "LIBUSB1_FOUND" OFF)
250-cmake_dependent_option(XRT_HAVE_HIDAPI "Enable libhidapi (used for PSVR)" ON "HIDAPI_FOUND" OFF)
251-cmake_dependent_option(XRT_HAVE_JPEG "Enable jpeg code (used for some video drivers)" ON "JPEG_FOUND" OFF)
252-cmake_dependent_option(XRT_HAVE_OPENCV "Enable OpenCV backend" ON "OpenCV_FOUND" OFF)
253-cmake_dependent_option(XRT_HAVE_LIBUVC "Enable libuvc video driver" ON "LIBUVC_FOUND AND XRT_HAVE_LIBUSB" OFF)
254-cmake_dependent_option(XRT_HAVE_FFMPEG "Enable ffmpeg testing video driver" ON "FFMPEG_FOUND" OFF)
255-cmake_dependent_option(XRT_HAVE_SDL2 "Enable use of SDL2" ON "SDL2_FOUND AND XRT_HAVE_OPENGL" OFF)
256-cmake_dependent_option(XRT_HAVE_SYSTEM_CJSON "Enable cJSON from system, instead of bundled source" ON "CJSON_FOUND" OFF)
257-cmake_dependent_option(XRT_HAVE_GST "Enable gstreamer" ON "GST_FOUND" OFF)
258-cmake_dependent_option(XRT_HAVE_REALSENSE "Enable RealSense support" ON "realsense2_FOUND" OFF)
259-cmake_dependent_option(XRT_HAVE_ONNXRUNTIME "Enable ONNX runtime support" ON "ONNXRUNTIME_FOUND" OFF)
260-cmake_dependent_option(XRT_HAVE_KIMERA_SLAM "Enable Kimera support" ON "kimera_vio_FOUND" OFF)
261-cmake_dependent_option(XRT_HAVE_BASALT_SLAM "Enable Basalt support" ON "basalt_FOUND" OFF)
262-cmake_dependent_option(XRT_HAVE_SLAM "Enable SLAM tracking support" ON "SLAM;XRT_HAVE_OPENCV" OFF)
263-cmake_dependent_option(XRT_BUILD_DRIVER_PSVR "Enable PSVR HMD driver" ON "XRT_HAVE_HIDAPI" OFF)
264-cmake_dependent_option(XRT_BUILD_DRIVER_REALSENSE "Enable RealSense device driver" ON "XRT_HAVE_REALSENSE" OFF)
265-cmake_dependent_option(XRT_BUILD_DRIVER_VIVE "Enable driver for HTC Vive, Vive Pro, Valve Index, and their controllers" ON "ZLIB_FOUND AND XRT_HAVE_LINUX" OFF)
266-cmake_dependent_option(XRT_BUILD_DRIVER_OHMD "Enable OpenHMD driver" ON "OPENHMD_FOUND" OFF)
267-cmake_dependent_option(XRT_BUILD_DRIVER_HANDTRACKING "Enable Camera Hand Tracking driver" ON "XRT_HAVE_ONNXRUNTIME AND XRT_HAVE_OPENCV AND XRT_HAVE_V4L2" OFF)
268-cmake_dependent_option(XRT_BUILD_DRIVER_DAYDREAM "Enable the Google Daydream View controller driver (BLE, via D-Bus)" ON "XRT_HAVE_DBUS" OFF)
269-cmake_dependent_option(XRT_BUILD_DRIVER_ARDUINO "Enable Arduino input device with BLE via via D-Bus" ON "XRT_HAVE_DBUS" OFF)
270-cmake_dependent_option(XRT_BUILD_DRIVER_ILLIXR "Enable ILLIXR driver" ON "ILLIXR_PATH" OFF)
271-option(XRT_BUILD_DRIVER_DUMMY "Enable dummy driver" ON)
272-cmake_dependent_option(XRT_BUILD_DRIVER_ULV2 "Enable Ultraleap v2 driver" ON "LeapV2_FOUND" OFF)
273-cmake_dependent_option(XRT_BUILD_DRIVER_REMOTE "Enable remote debugging driver" ON "XRT_HAVE_LINUX OR ANDROID" OFF)
274-cmake_dependent_option(XRT_BUILD_DRIVER_WMR "Enable Windows Mixed Reality driver" ON "NOT WIN32" OFF)
275-276-option(XRT_BUILD_SAMPLES "Enable compiling sample code implementations that will not be linked into any final targets" ON)
277-278-# These all use the Monado internal hid wrapper.
279-cmake_dependent_option(XRT_BUILD_DRIVER_HDK "Enable HDK driver" ON "XRT_HAVE_INTERNAL_HID" OFF)
280-cmake_dependent_option(XRT_BUILD_DRIVER_PSMV "Enable Playstation Move driver" ON "XRT_HAVE_INTERNAL_HID" OFF)
281-cmake_dependent_option(XRT_BUILD_DRIVER_HYDRA "Enable Hydra driver" ON "XRT_HAVE_INTERNAL_HID" OFF)
282-cmake_dependent_option(XRT_BUILD_DRIVER_NS "Enable North Star driver" ON "XRT_HAVE_INTERNAL_HID" OFF)
283-cmake_dependent_option(XRT_BUILD_DRIVER_VF "Build video frame driver (for video file support, uses gstreamer)" ON "XRT_HAVE_GST" OFF)
284-cmake_dependent_option(XRT_BUILD_DRIVER_DEPTHAI "DepthAI" ON "depthai_FOUND" OFF)
285-286-cmake_dependent_option(XRT_BUILD_DRIVER_SURVIVE "Enable libsurvive driver" ON "SURVIVE_FOUND" OFF)
287-288-cmake_dependent_option(XRT_BUILD_DRIVER_ANDROID "Enable Android sensors driver" ON "ANDROID" OFF)
289-cmake_dependent_option(XRT_BUILD_DRIVER_QWERTY "Enable Qwerty driver" ON "XRT_HAVE_SDL2" OFF)
290-cmake_dependent_option(XRT_BUILD_DRIVER_EUROC "Enable EuRoC dataset driver for SLAM evaluation" ON "XRT_HAVE_OPENCV" OFF)
291-292-# cmake-format: on
293-294# You can set this from a superproject to add a driver
295# All drivers must be listed in here to be included in the generated header!
296list(
···42###
43list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
44list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/sanitizers")
45+include(OptionWithDeps)
46include(SPIR-V)
47include(GNUInstallDirs)
48if(NOT GIT_DESC)
···187# This one is named differently because that's what CTest uses
188option(BUILD_TESTING "Enable building of the test suite?" ON)
189190+if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
191+ set(XRT_HAVE_LIBUDEV ON)
192+ set(XRT_HAVE_INTERNAL_HID ON)
193+else()
194+ option_with_deps(
195+ XRT_HAVE_LIBUDEV
196+ "Enable libudev (used for device probing on Linux)"
197+ ON
198+ "UDEV_FOUND"
199+ OFF
200+ )
201+endif()
202203+# cmake-format: off
204option(XRT_FEATURE_COLOR_LOG "Enable logging in color on supported platforms" ON)
205+option_with_deps(CMAKE_INTERPROCEDURAL_OPTIMIZATION "Enable inter-procedural (link-time) optimization" DEFAULT OFF DEPENDS HAS_IPO)
0206207+option_with_deps(XRT_HAVE_PERCETTO "Enable percetto support" DEPENDS PERCETTO_FOUND)
208+option_with_deps(XRT_HAVE_WAYLAND "Enable Wayland support" DEPENDS WAYLAND_FOUND WAYLAND_SCANNER_FOUND WAYLAND_PROTOCOLS_FOUND LIBDRM_FOUND)
209+option_with_deps(XRT_HAVE_WAYLAND_DIRECT "Enable Wayland direct support" DEPENDS XRT_HAVE_WAYLAND LIBDRM_FOUND "WAYLAND_PROTOCOLS_VERSION VERSION_GREATER_EQUAL 1.22")
210+option_with_deps(XRT_HAVE_XLIB "Enable xlib support" DEPENDS X11_FOUND)
211+option_with_deps(XRT_HAVE_XRANDR "Enable xlib-xrandr support" DEPENDS XRANDR_FOUND)
212+option_with_deps(XRT_HAVE_XCB "Enable xcb support" DEPENDS XCB_FOUND)
213+option_with_deps(XRT_HAVE_VULKAN "Enable Vulkan Graphics API support (also needed for compositor)" DEPENDS VULKAN_FOUND)
214+option_with_deps(XRT_HAVE_OPENGL "Enable OpenGL Graphics API support" DEPENDS OPENGL_WITHOUT_GLX_FOUND)
215+option_with_deps(XRT_HAVE_OPENGL_GLX "Enable OpenGL Graphics API support on X11 (GLX)" DEPENDS XRT_HAVE_OPENGL OpenGL_GLX_FOUND)
216+option_with_deps(XRT_HAVE_OPENGLES "Enable OpenGL-ES Graphics API support" DEPENDS OpenGLES_FOUND)
217+option_with_deps(XRT_HAVE_EGL "Enable OpenGL(-ES) on EGL Graphics API support" DEPENDS EGL_FOUND "XRT_HAVE_OPENGL OR XRT_HAVE_OPENGLES")
218+option_with_deps(XRT_HAVE_DBUS "Enable dbus support (for BLE support)" DEPENDS DBUS_FOUND)
219+option_with_deps(XRT_HAVE_LIBBSD "Enable libbsd support" DEPENDS LIBBSD_FOUND)
220+option_with_deps(XRT_FEATURE_TRACING "Enable debug tracing on supported platforms" DEFAULT OFF DEPENDS XRT_HAVE_PERCETTO)
221+option_with_deps(XRT_FEATURE_COMPOSITOR_MAIN "Build main compositor host functionality" DEPENDS XRT_HAVE_VULKAN "XRT_HAVE_WAYLAND OR XRT_HAVE_XCB OR ANDROID OR WIN32")
222+option_with_deps(XRT_FEATURE_OPENXR "Build OpenXR runtime target" DEPENDS XRT_FEATURE_COMPOSITOR_MAIN)
223+option_with_deps(XRT_FEATURE_IPC "Enable the build of the IPC layer" DEPENDS "NOT WIN32")
224+option_with_deps(XRT_FEATURE_SERVICE "Enable separate service module for OpenXR runtime" DEPENDS XRT_FEATURE_IPC XRT_FEATURE_OPENXR)
225226+option_with_deps(XRT_HAVE_SYSTEMD "Enable systemd support (for socket activation of service)" DEPENDS Systemd_FOUND XRT_FEATURE_SERVICE)
227+option_with_deps(XRT_INSTALL_SYSTEMD_UNIT_FILES "Install user unit files for systemd socket activation on installation" DEPENDS XRT_HAVE_SYSTEMD)
228+option_with_deps(XRT_INSTALL_ABSOLUTE_SYSTEMD_UNIT_FILES "Use an absolute path to monado-system in installed user unit files for systemd socket activation" DEPENDS XRT_INSTALL_SYSTEMD_UNIT_FILES)
00229230+option_with_deps(XRT_FEATURE_STEAMVR_PLUGIN "Build SteamVR plugin" DEPENDS "NOT ANDROID")
231+option_with_deps(XRT_FEATURE_RENDERDOC "Enable RenderDoc API" DEPENDS "RT_LIBRARY OR WIN32")
232+233+234+option_with_deps(XRT_HAVE_LIBUSB "Enable libusb (used for most drivers)" DEPENDS LIBUSB1_FOUND)
235+option_with_deps(XRT_HAVE_HIDAPI "Enable libhidapi (used for PSVR)" DEPENDS HIDAPI_FOUND)
236+option_with_deps(XRT_HAVE_JPEG "Enable jpeg code (used for some video drivers)" DEPENDS JPEG_FOUND)
237+option_with_deps(XRT_HAVE_OPENCV "Enable OpenCV backend" DEPENDS OpenCV_FOUND)
238+option_with_deps(XRT_HAVE_LIBUVC "Enable libuvc video driver" DEPENDS LIBUVC_FOUND XRT_HAVE_LIBUSB)
239+option_with_deps(XRT_HAVE_FFMPEG "Enable ffmpeg testing video driver" DEPENDS FFMPEG_FOUND)
240+option_with_deps(XRT_HAVE_SDL2 "Enable use of SDL2" DEPENDS SDL2_FOUND XRT_HAVE_OPENGL)
241+option_with_deps(XRT_HAVE_SYSTEM_CJSON "Enable cJSON from system, instead of bundled source" DEPENDS CJSON_FOUND)
242+option_with_deps(XRT_HAVE_GST "Enable gstreamer" DEPENDS GST_FOUND)
243+option_with_deps(XRT_HAVE_REALSENSE "Enable RealSense support" DEPENDS realsense2_FOUND)
244+option_with_deps(XRT_HAVE_ONNXRUNTIME "Enable ONNX runtime support" DEPENDS ONNXRUNTIME_FOUND)
245+option_with_deps(XRT_HAVE_KIMERA_SLAM "Enable Kimera support" DEPENDS kimera_vio_FOUND)
246+option_with_deps(XRT_HAVE_BASALT_SLAM "Enable Basalt support" DEPENDS basalt_FOUND)
247+option_with_deps(XRT_HAVE_SLAM "Enable SLAM tracking support" DEPENDS SLAM XRT_HAVE_OPENCV)
248+option_with_deps(XRT_BUILD_DRIVER_PSVR "Enable PSVR HMD driver" DEPENDS XRT_HAVE_HIDAPI)
249+option_with_deps(XRT_BUILD_DRIVER_REALSENSE "Enable RealSense device driver" DEPENDS XRT_HAVE_REALSENSE)
250+option_with_deps(XRT_BUILD_DRIVER_VIVE "Enable driver for HTC Vive, Vive Pro, Valve Index, and their controllers" DEPENDS ZLIB_FOUND XRT_HAVE_LINUX)
251+option_with_deps(XRT_BUILD_DRIVER_OHMD "Enable OpenHMD driver" DEPENDS OPENHMD_FOUND)
252+option_with_deps(XRT_BUILD_DRIVER_HANDTRACKING "Enable Camera Hand Tracking driver" DEPENDS XRT_HAVE_ONNXRUNTIME XRT_HAVE_OPENCV XRT_HAVE_V4L2)
253+option_with_deps(XRT_BUILD_DRIVER_DAYDREAM "Enable the Google Daydream View controller driver (BLE, via D-Bus)" DEPENDS XRT_HAVE_DBUS)
254+option_with_deps(XRT_BUILD_DRIVER_ARDUINO "Enable Arduino input device with BLE via via D-Bus" DEPENDS XRT_HAVE_DBUS)
255+option_with_deps(XRT_BUILD_DRIVER_ILLIXR "Enable ILLIXR driver" DEPENDS ILLIXR_PATH)
256+option(XRT_BUILD_DRIVER_DUMMY "Enable dummy driver" ON)
257+option_with_deps(XRT_BUILD_DRIVER_ULV2 "Enable Ultraleap v2 driver" DEPENDS LeapV2_FOUND)
258+option_with_deps(XRT_BUILD_DRIVER_REMOTE "Enable remote debugging driver" DEPENDS "XRT_HAVE_LINUX OR ANDROID")
259+option_with_deps(XRT_BUILD_DRIVER_WMR "Enable Windows Mixed Reality driver" DEPENDS "NOT WIN32")
260+261+option(XRT_BUILD_SAMPLES "Enable compiling sample code implementations that will not be linked into any final targets" ON)
262+263+option_with_deps(XRT_BUILD_DRIVER_HDK "Enable HDK driver" DEPENDS XRT_HAVE_INTERNAL_HID)
264+option_with_deps(XRT_BUILD_DRIVER_PSMV "Enable Playstation Move driver" DEPENDS XRT_HAVE_INTERNAL_HID)
265+option_with_deps(XRT_BUILD_DRIVER_HYDRA "Enable Hydra driver" DEPENDS XRT_HAVE_INTERNAL_HID)
266+option_with_deps(XRT_BUILD_DRIVER_NS "Enable North Star driver" DEPENDS XRT_HAVE_INTERNAL_HID)
267+option_with_deps(XRT_BUILD_DRIVER_VF "Build video frame driver (for video file support, uses gstreamer)" DEPENDS XRT_HAVE_GST)
268+option_with_deps(XRT_BUILD_DRIVER_DEPTHAI "DepthAI" DEPENDS depthai_FOUND)
269+option_with_deps(XRT_BUILD_DRIVER_SURVIVE "Enable libsurvive driver" DEPENDS SURVIVE_FOUND)
270+option_with_deps(XRT_BUILD_DRIVER_ANDROID "Enable Android sensors driver" DEPENDS ANDROID)
271+option_with_deps(XRT_BUILD_DRIVER_QWERTY "Enable Qwerty driver" DEPENDS XRT_HAVE_SDL2)
272+option_with_deps(XRT_BUILD_DRIVER_EUROC "Enable EuRoC dataset driver for SLAM evaluation" DEPENDS XRT_HAVE_OPENCV)
273+274+# cmake-format: on
275276if(NOT DEFINED XRT_FEATURE_OPENXR_LAYER_DEPTH)
277 set(XRT_FEATURE_OPENXR_LAYER_DEPTH ON)
···289 set(XRT_FEATURE_OPENXR_LAYER_EQUIRECT1 ON)
290endif()
29100292# Most users won't touch these.
293mark_as_advanced(XRT_FEATURE_COMPOSITOR_MAIN XRT_FEATURE_OPENXR)
000000000000000000000000000000000000000000000000000000294# You can set this from a superproject to add a driver
295# All drivers must be listed in here to be included in the generated header!
296list(
···1+# Copyright 2022, Collabora, Ltd.
2+# Copyright 2000-2022 Kitware, Inc., Insight Software Consortium
3+#
4+# SPDX-License-Identifier: BSD-3-Clause
5+#
6+# CMake was initially developed by Kitware with the following sponsorship:
7+# * National Library of Medicine at the National Institutes of Health
8+# as part of the Insight Segmentation and Registration Toolkit (ITK).
9+#
10+# * US National Labs (Los Alamos, Livermore, Sandia) ASC Parallel
11+# Visualization Initiative.
12+#
13+# * National Alliance for Medical Image Computing (NAMIC) is funded by the
14+# National Institutes of Health through the NIH Roadmap for Medical Research,
15+# Grant U54 EB005149.
16+#
17+# * Kitware, Inc.
18+#
19+# (Based on CMakeDependentOption)
20+21+#[=======================================================================[.rst:
22+OptionWithDeps
23+--------------
24+25+Macro to provide an option dependent on other options.
26+27+This macro presents an option to the user only if a set of other
28+conditions are true. If it is already specified by the user but the
29+conditions are not true, it triggers an error.
30+31+This is based on cmake_dependent_options but meets common expectations better:
32+if you explicitly try to enable something that is not available, you get an error
33+instead of just having it silently disabled.
34+35+.. command:: option_with_deps
36+37+ .. code-block:: cmake
38+39+ option_with_deps(<option> "<help_text>" [DEFAULT <default>] DEPENDS [<depends>...])
40+41+ Describes a build option that has dependencies. If the option is requested,
42+ but the depends are not satisfied, an error is issued. DEPENDS is a list of
43+ conditions to check: all must be true to make the option available.
44+ Otherwise, a local variable named ``<option>`` is set to ``OFF``.
45+46+ When ``<option>`` is available, the given ``<help_text>`` and initial
47+ ``<default>`` are used. Otherwise, any value set by the user is preserved for
48+ when ``<depends>`` is satisfied in the future.
49+50+ Note that the ``<option>`` variable only has a value which satisfies the
51+ ``<depends>`` condition within the scope of the caller because it is a local
52+ variable.
53+54+ Elements of ``<depends>`` cannot contain parentheses nor "AND" (each item is
55+ implicitly "ANDed" together). Be sure to quote OR and NOT expressions, and avoid
56+ complex expressions (such as with escaped quotes, etc) since they may fail,
57+ especially before CMake 3.18.
58+59+Example invocation:
60+61+.. code-block:: cmake
62+63+ option_with_deps(USE_FOO "Use Foo" DEPENDS "USE_BAR" "NOT USE_ZOT")
64+65+If ``USE_BAR`` is true and ``USE_ZOT`` is false, this provides an option called
66+``USE_FOO`` that defaults to ON. Otherwise, it sets ``USE_FOO`` to OFF and
67+hides the option from the user. If the status of ``USE_BAR`` or ``USE_ZOT``
68+ever changes, any value for the ``USE_FOO`` option is saved so that when the
69+option is re-enabled it retains its old value.
70+71+#]=======================================================================]
72+73+function(option_with_deps option doc)
74+ set(options)
75+ set(oneValueArgs DEFAULT)
76+ set(multiValueArgs DEPENDS)
77+ cmake_parse_arguments(_option_deps "${options}" "${oneValueArgs}"
78+ "${multiValueArgs}" ${ARGN})
79+80+ if(NOT DEFINED _option_deps_DEFAULT)
81+ set(_option_deps_DEFAULT ON)
82+ endif()
83+84+ # Check for invalid/bad depends args
85+ foreach(d ${_option_deps_DEPENDS})
86+ if("${d}" MATCHES "[(]")
87+ message(
88+ FATAL_ERROR "option_with_deps does not support parens in deps")
89+ endif()
90+ if("${d}" MATCHES "\\bAND\\b")
91+ message(
92+ FATAL_ERROR
93+ "option_with_deps treats every deps item as being implicitly 'ANDed' together"
94+ )
95+ endif()
96+ if("${d}" STREQUAL "OR")
97+ message(FATAL_ERROR "option_with_deps needs OR expressions quoted")
98+ endif()
99+ if("${d}" STREQUAL "NOT")
100+ message(FATAL_ERROR "option_with_deps needs NOT expressions quoted")
101+ endif()
102+ endforeach()
103+104+ # This is a case we removed from the original CMakeDependentOption module
105+ if(NOT (${option}_ISSET MATCHES "^${option}_ISSET$"))
106+ message(
107+ FATAL_ERROR
108+ "Probably too old of CMake version to cope with this module")
109+ endif()
110+111+ # Check the actual deps, determine if the option is available
112+ set(_avail ON)
113+ foreach(d ${_option_deps_DEPENDS})
114+ if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.18)
115+ cmake_language(
116+ EVAL
117+ CODE
118+ "
119+ if(${d})
120+ else()
121+ set(_avail OFF)
122+ set(_cond ${d})
123+ endif()")
124+ else()
125+ # cmake_language(EVAL CODE was added in 3.18 so evaluate it the "old" way before then.
126+ # turn spaces into semicolons so we have a list of arguments, signalling to CMAKE
127+ # to interpret the "if()" differently
128+ string(REGEX REPLACE " +" ";" CMAKE_DEPENDENT_OPTION_DEP "${d}")
129+ if(${CMAKE_DEPENDENT_OPTION_DEP})
130+131+ else()
132+ set(_avail OFF)
133+ set(_cond ${d})
134+ endif()
135+ endif()
136+ endforeach()
137+138+ # Error if option was requested but not available
139+ if("${${option}}" AND NOT "${_avail}")
140+ message(
141+ FATAL_ERROR
142+ "${option} specified but not available: failed check ${_cond}")
143+ endif()
144+145+ # Handle remaining cases
146+ set(_already_defined OFF)
147+ if(DEFINED ${option})
148+ set(_already_defined ON)
149+ endif()
150+ if(${_avail})
151+ # Set a cache variable: the value here will not override an already-set value.
152+ option(${option} "${doc}" "${_option_deps_DEFAULT}")
153+154+ if(NOT _already_defined)
155+ # Needed to force this for some reason
156+ set(${option}
157+ "${${option}}"
158+ CACHE BOOL "${doc}" FORCE)
159+ endif()
160+ else()
161+ # Don't set a cache variable for something that's not available
162+ set(${option}
163+ OFF
164+ PARENT_SCOPE)
165+ endif()
166+endfunction()
+13-8
doc/CMakeLists.txt
···1-# Copyright 2018-2020, Collabora, Ltd.
2# SPDX-License-Identifier: BSL-1.0
34# check if Doxygen is installed
5find_package(Doxygen)
67-# cmake-format: off
8-9-cmake_dependent_option(BUILD_DOC "Build documentation" ON "DOXYGEN_FOUND" OFF)
10-cmake_dependent_option(BUILD_DOC_WARN_UNDOCUMENTED "Warn on undocumented entities when building documentation" OFF "DOXYGEN_FOUND" OFF)
11-cmake_dependent_option(BUILD_DOC_EXTRACT_ALL "Extract all entities for documentation, not just documented ones (conflicts with BUILD_DOC_WARN_UNDOCUMENTED)" ON "DOXYGEN_FOUND AND NOT BUILD_DOC_WARN_UNDOCUMENTED" OFF)
12-13-# cmake-format: on
000001415if(BUILD_DOC)
16 if(BUILD_DOC_WARN_UNDOCUMENTED)
···1+# Copyright 2018-2022, Collabora, Ltd.
2# SPDX-License-Identifier: BSL-1.0
34# check if Doxygen is installed
5find_package(Doxygen)
67+option_with_deps(BUILD_DOC "Build documentation" DEPENDS DOXYGEN_FOUND)
8+option_with_deps(
9+ BUILD_DOC_WARN_UNDOCUMENTED "Warn on undocumented entities when building documentation"
10+ DEFAULT OFF
11+ DEPENDS DOXYGEN_FOUND
12+ )
13+option_with_deps(
14+ BUILD_DOC_EXTRACT_ALL
15+ "Extract all entities for documentation, not just documented ones (conflicts with BUILD_DOC_WARN_UNDOCUMENTED)"
16+ DEFAULT OFF
17+ DEPENDS DOXYGEN_FOUND "NOT BUILD_DOC_WARN_UNDOCUMENTED"
18+ )
1920if(BUILD_DOC)
21 if(BUILD_DOC_WARN_UNDOCUMENTED)