···4242###
4343list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
4444list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/sanitizers")
4545-include(CMakeDependentOption)
4545+include(OptionWithDeps)
4646include(SPIR-V)
4747include(GNUInstallDirs)
4848if(NOT GIT_DESC)
···187187# This one is named differently because that's what CTest uses
188188option(BUILD_TESTING "Enable building of the test suite?" ON)
189189190190-# cmake-format: off
190190+if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
191191+ set(XRT_HAVE_LIBUDEV ON)
192192+ set(XRT_HAVE_INTERNAL_HID ON)
193193+else()
194194+ option_with_deps(
195195+ XRT_HAVE_LIBUDEV
196196+ "Enable libudev (used for device probing on Linux)"
197197+ ON
198198+ "UDEV_FOUND"
199199+ OFF
200200+ )
201201+endif()
191202203203+# cmake-format: off
192204option(XRT_FEATURE_COLOR_LOG "Enable logging in color on supported platforms" ON)
193193-cmake_dependent_option(XRT_HAVE_PERCETTO "Enable percetto support" ON "PERCETTO_FOUND" OFF)
194194-cmake_dependent_option(XRT_FEATURE_TRACING "Enable debug tracing on supported platforms" OFF "XRT_HAVE_PERCETTO" OFF)
205205+option_with_deps(CMAKE_INTERPROCEDURAL_OPTIMIZATION "Enable inter-procedural (link-time) optimization" DEFAULT OFF DEPENDS HAS_IPO)
195206196196-cmake_dependent_option(CMAKE_INTERPROCEDURAL_OPTIMIZATION "Enable inter-procedural (link-time) optimization" OFF "HAS_IPO" OFF)
197197-cmake_dependent_option(XRT_HAVE_WAYLAND "Enable Wayland support" ON "WAYLAND_FOUND AND WAYLAND_SCANNER_FOUND AND WAYLAND_PROTOCOLS_FOUND AND LIBDRM_FOUND" OFF)
198198-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)
199199-cmake_dependent_option(XRT_HAVE_XLIB "Enable xlib support" ON "X11_FOUND" OFF)
200200-cmake_dependent_option(XRT_HAVE_XRANDR "Enable xlib-xrandr support" ON "XRANDR_FOUND" OFF)
201201-cmake_dependent_option(XRT_HAVE_XCB "Enable xcb support" ON "XCB_FOUND" OFF)
207207+option_with_deps(XRT_HAVE_PERCETTO "Enable percetto support" DEPENDS PERCETTO_FOUND)
208208+option_with_deps(XRT_HAVE_WAYLAND "Enable Wayland support" DEPENDS WAYLAND_FOUND WAYLAND_SCANNER_FOUND WAYLAND_PROTOCOLS_FOUND LIBDRM_FOUND)
209209+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")
210210+option_with_deps(XRT_HAVE_XLIB "Enable xlib support" DEPENDS X11_FOUND)
211211+option_with_deps(XRT_HAVE_XRANDR "Enable xlib-xrandr support" DEPENDS XRANDR_FOUND)
212212+option_with_deps(XRT_HAVE_XCB "Enable xcb support" DEPENDS XCB_FOUND)
213213+option_with_deps(XRT_HAVE_VULKAN "Enable Vulkan Graphics API support (also needed for compositor)" DEPENDS VULKAN_FOUND)
214214+option_with_deps(XRT_HAVE_OPENGL "Enable OpenGL Graphics API support" DEPENDS OPENGL_WITHOUT_GLX_FOUND)
215215+option_with_deps(XRT_HAVE_OPENGL_GLX "Enable OpenGL Graphics API support on X11 (GLX)" DEPENDS XRT_HAVE_OPENGL OpenGL_GLX_FOUND)
216216+option_with_deps(XRT_HAVE_OPENGLES "Enable OpenGL-ES Graphics API support" DEPENDS OpenGLES_FOUND)
217217+option_with_deps(XRT_HAVE_EGL "Enable OpenGL(-ES) on EGL Graphics API support" DEPENDS EGL_FOUND "XRT_HAVE_OPENGL OR XRT_HAVE_OPENGLES")
218218+option_with_deps(XRT_HAVE_DBUS "Enable dbus support (for BLE support)" DEPENDS DBUS_FOUND)
219219+option_with_deps(XRT_HAVE_LIBBSD "Enable libbsd support" DEPENDS LIBBSD_FOUND)
220220+option_with_deps(XRT_FEATURE_TRACING "Enable debug tracing on supported platforms" DEFAULT OFF DEPENDS XRT_HAVE_PERCETTO)
221221+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")
222222+option_with_deps(XRT_FEATURE_OPENXR "Build OpenXR runtime target" DEPENDS XRT_FEATURE_COMPOSITOR_MAIN)
223223+option_with_deps(XRT_FEATURE_IPC "Enable the build of the IPC layer" DEPENDS "NOT WIN32")
224224+option_with_deps(XRT_FEATURE_SERVICE "Enable separate service module for OpenXR runtime" DEPENDS XRT_FEATURE_IPC XRT_FEATURE_OPENXR)
202225203203-cmake_dependent_option(XRT_HAVE_VULKAN "Enable Vulkan Graphics API support (also needed for compositor)" ON "VULKAN_FOUND" OFF)
204204-cmake_dependent_option(XRT_HAVE_OPENGL "Enable OpenGL Graphics API support" ON "OPENGL_WITHOUT_GLX_FOUND" OFF)
205205-cmake_dependent_option(XRT_HAVE_OPENGL_GLX "Enable OpenGL Graphics API support on X11 (GLX)" ON "XRT_HAVE_OPENGL; OpenGL_GLX_FOUND" OFF)
206206-cmake_dependent_option(XRT_HAVE_OPENGLES "Enable OpenGL-ES Graphics API support" ON "OpenGLES_FOUND" OFF)
207207-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)
226226+option_with_deps(XRT_HAVE_SYSTEMD "Enable systemd support (for socket activation of service)" DEPENDS Systemd_FOUND XRT_FEATURE_SERVICE)
227227+option_with_deps(XRT_INSTALL_SYSTEMD_UNIT_FILES "Install user unit files for systemd socket activation on installation" DEPENDS XRT_HAVE_SYSTEMD)
228228+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)
208229209209-cmake_dependent_option(XRT_HAVE_DBUS "Enable dbus support (for BLE support)" ON "DBUS_FOUND" OFF)
210210-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)
211211-cmake_dependent_option(XRT_HAVE_LIBBSD "Enable libbsd support" ON "LIBBSD_FOUND" OFF)
212212-cmake_dependent_option(XRT_FEATURE_OPENXR "Build OpenXR runtime target" ON "XRT_FEATURE_COMPOSITOR_MAIN" OFF)
213213-cmake_dependent_option(XRT_FEATURE_IPC "Enable the build of the IPC layer" ON "NOT WIN32" OFF)
214214-cmake_dependent_option(XRT_FEATURE_SERVICE "Enable separate service module for OpenXR runtime" ON "XRT_FEATURE_IPC AND XRT_FEATURE_OPENXR" OFF)
215215-cmake_dependent_option(XRT_HAVE_SYSTEMD "Enable systemd support (for socket activation of service)" ON "Systemd_FOUND AND XRT_FEATURE_SERVICE" OFF)
216216-cmake_dependent_option(XRT_INSTALL_SYSTEMD_UNIT_FILES "Install user unit files for systemd socket activation on installation" ON "XRT_HAVE_SYSTEMD" OFF)
217217-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)
218218-cmake_dependent_option(XRT_FEATURE_STEAMVR_PLUGIN "Build SteamVR plugin" ON "NOT ANDROID" OFF)
230230+option_with_deps(XRT_FEATURE_STEAMVR_PLUGIN "Build SteamVR plugin" DEPENDS "NOT ANDROID")
231231+option_with_deps(XRT_FEATURE_RENDERDOC "Enable RenderDoc API" DEPENDS "RT_LIBRARY OR WIN32")
232232+233233+234234+option_with_deps(XRT_HAVE_LIBUSB "Enable libusb (used for most drivers)" DEPENDS LIBUSB1_FOUND)
235235+option_with_deps(XRT_HAVE_HIDAPI "Enable libhidapi (used for PSVR)" DEPENDS HIDAPI_FOUND)
236236+option_with_deps(XRT_HAVE_JPEG "Enable jpeg code (used for some video drivers)" DEPENDS JPEG_FOUND)
237237+option_with_deps(XRT_HAVE_OPENCV "Enable OpenCV backend" DEPENDS OpenCV_FOUND)
238238+option_with_deps(XRT_HAVE_LIBUVC "Enable libuvc video driver" DEPENDS LIBUVC_FOUND XRT_HAVE_LIBUSB)
239239+option_with_deps(XRT_HAVE_FFMPEG "Enable ffmpeg testing video driver" DEPENDS FFMPEG_FOUND)
240240+option_with_deps(XRT_HAVE_SDL2 "Enable use of SDL2" DEPENDS SDL2_FOUND XRT_HAVE_OPENGL)
241241+option_with_deps(XRT_HAVE_SYSTEM_CJSON "Enable cJSON from system, instead of bundled source" DEPENDS CJSON_FOUND)
242242+option_with_deps(XRT_HAVE_GST "Enable gstreamer" DEPENDS GST_FOUND)
243243+option_with_deps(XRT_HAVE_REALSENSE "Enable RealSense support" DEPENDS realsense2_FOUND)
244244+option_with_deps(XRT_HAVE_ONNXRUNTIME "Enable ONNX runtime support" DEPENDS ONNXRUNTIME_FOUND)
245245+option_with_deps(XRT_HAVE_KIMERA_SLAM "Enable Kimera support" DEPENDS kimera_vio_FOUND)
246246+option_with_deps(XRT_HAVE_BASALT_SLAM "Enable Basalt support" DEPENDS basalt_FOUND)
247247+option_with_deps(XRT_HAVE_SLAM "Enable SLAM tracking support" DEPENDS SLAM XRT_HAVE_OPENCV)
248248+option_with_deps(XRT_BUILD_DRIVER_PSVR "Enable PSVR HMD driver" DEPENDS XRT_HAVE_HIDAPI)
249249+option_with_deps(XRT_BUILD_DRIVER_REALSENSE "Enable RealSense device driver" DEPENDS XRT_HAVE_REALSENSE)
250250+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)
251251+option_with_deps(XRT_BUILD_DRIVER_OHMD "Enable OpenHMD driver" DEPENDS OPENHMD_FOUND)
252252+option_with_deps(XRT_BUILD_DRIVER_HANDTRACKING "Enable Camera Hand Tracking driver" DEPENDS XRT_HAVE_ONNXRUNTIME XRT_HAVE_OPENCV XRT_HAVE_V4L2)
253253+option_with_deps(XRT_BUILD_DRIVER_DAYDREAM "Enable the Google Daydream View controller driver (BLE, via D-Bus)" DEPENDS XRT_HAVE_DBUS)
254254+option_with_deps(XRT_BUILD_DRIVER_ARDUINO "Enable Arduino input device with BLE via via D-Bus" DEPENDS XRT_HAVE_DBUS)
255255+option_with_deps(XRT_BUILD_DRIVER_ILLIXR "Enable ILLIXR driver" DEPENDS ILLIXR_PATH)
256256+option(XRT_BUILD_DRIVER_DUMMY "Enable dummy driver" ON)
257257+option_with_deps(XRT_BUILD_DRIVER_ULV2 "Enable Ultraleap v2 driver" DEPENDS LeapV2_FOUND)
258258+option_with_deps(XRT_BUILD_DRIVER_REMOTE "Enable remote debugging driver" DEPENDS "XRT_HAVE_LINUX OR ANDROID")
259259+option_with_deps(XRT_BUILD_DRIVER_WMR "Enable Windows Mixed Reality driver" DEPENDS "NOT WIN32")
260260+261261+option(XRT_BUILD_SAMPLES "Enable compiling sample code implementations that will not be linked into any final targets" ON)
262262+263263+option_with_deps(XRT_BUILD_DRIVER_HDK "Enable HDK driver" DEPENDS XRT_HAVE_INTERNAL_HID)
264264+option_with_deps(XRT_BUILD_DRIVER_PSMV "Enable Playstation Move driver" DEPENDS XRT_HAVE_INTERNAL_HID)
265265+option_with_deps(XRT_BUILD_DRIVER_HYDRA "Enable Hydra driver" DEPENDS XRT_HAVE_INTERNAL_HID)
266266+option_with_deps(XRT_BUILD_DRIVER_NS "Enable North Star driver" DEPENDS XRT_HAVE_INTERNAL_HID)
267267+option_with_deps(XRT_BUILD_DRIVER_VF "Build video frame driver (for video file support, uses gstreamer)" DEPENDS XRT_HAVE_GST)
268268+option_with_deps(XRT_BUILD_DRIVER_DEPTHAI "DepthAI" DEPENDS depthai_FOUND)
269269+option_with_deps(XRT_BUILD_DRIVER_SURVIVE "Enable libsurvive driver" DEPENDS SURVIVE_FOUND)
270270+option_with_deps(XRT_BUILD_DRIVER_ANDROID "Enable Android sensors driver" DEPENDS ANDROID)
271271+option_with_deps(XRT_BUILD_DRIVER_QWERTY "Enable Qwerty driver" DEPENDS XRT_HAVE_SDL2)
272272+option_with_deps(XRT_BUILD_DRIVER_EUROC "Enable EuRoC dataset driver for SLAM evaluation" DEPENDS XRT_HAVE_OPENCV)
273273+274274+# cmake-format: on
219275220276if(NOT DEFINED XRT_FEATURE_OPENXR_LAYER_DEPTH)
221277 set(XRT_FEATURE_OPENXR_LAYER_DEPTH ON)
···233289 set(XRT_FEATURE_OPENXR_LAYER_EQUIRECT1 ON)
234290endif()
235291236236-cmake_dependent_option(XRT_FEATURE_RENDERDOC "Enable RenderDoc API" OFF "RT_LIBRARY OR WIN32" OFF)
237237-238292# Most users won't touch these.
239293mark_as_advanced(XRT_FEATURE_COMPOSITOR_MAIN XRT_FEATURE_OPENXR)
240240-241241-242242-if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
243243- set(XRT_HAVE_LIBUDEV ON)
244244- set(XRT_HAVE_INTERNAL_HID ON)
245245-else()
246246- cmake_dependent_option(XRT_HAVE_LIBUDEV "Enable libudev (used for device probing on Linux)" ON "UDEV_FOUND" OFF)
247247-endif()
248248-249249-cmake_dependent_option(XRT_HAVE_LIBUSB "Enable libusb (used for most drivers)" ON "LIBUSB1_FOUND" OFF)
250250-cmake_dependent_option(XRT_HAVE_HIDAPI "Enable libhidapi (used for PSVR)" ON "HIDAPI_FOUND" OFF)
251251-cmake_dependent_option(XRT_HAVE_JPEG "Enable jpeg code (used for some video drivers)" ON "JPEG_FOUND" OFF)
252252-cmake_dependent_option(XRT_HAVE_OPENCV "Enable OpenCV backend" ON "OpenCV_FOUND" OFF)
253253-cmake_dependent_option(XRT_HAVE_LIBUVC "Enable libuvc video driver" ON "LIBUVC_FOUND AND XRT_HAVE_LIBUSB" OFF)
254254-cmake_dependent_option(XRT_HAVE_FFMPEG "Enable ffmpeg testing video driver" ON "FFMPEG_FOUND" OFF)
255255-cmake_dependent_option(XRT_HAVE_SDL2 "Enable use of SDL2" ON "SDL2_FOUND AND XRT_HAVE_OPENGL" OFF)
256256-cmake_dependent_option(XRT_HAVE_SYSTEM_CJSON "Enable cJSON from system, instead of bundled source" ON "CJSON_FOUND" OFF)
257257-cmake_dependent_option(XRT_HAVE_GST "Enable gstreamer" ON "GST_FOUND" OFF)
258258-cmake_dependent_option(XRT_HAVE_REALSENSE "Enable RealSense support" ON "realsense2_FOUND" OFF)
259259-cmake_dependent_option(XRT_HAVE_ONNXRUNTIME "Enable ONNX runtime support" ON "ONNXRUNTIME_FOUND" OFF)
260260-cmake_dependent_option(XRT_HAVE_KIMERA_SLAM "Enable Kimera support" ON "kimera_vio_FOUND" OFF)
261261-cmake_dependent_option(XRT_HAVE_BASALT_SLAM "Enable Basalt support" ON "basalt_FOUND" OFF)
262262-cmake_dependent_option(XRT_HAVE_SLAM "Enable SLAM tracking support" ON "SLAM;XRT_HAVE_OPENCV" OFF)
263263-cmake_dependent_option(XRT_BUILD_DRIVER_PSVR "Enable PSVR HMD driver" ON "XRT_HAVE_HIDAPI" OFF)
264264-cmake_dependent_option(XRT_BUILD_DRIVER_REALSENSE "Enable RealSense device driver" ON "XRT_HAVE_REALSENSE" OFF)
265265-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)
266266-cmake_dependent_option(XRT_BUILD_DRIVER_OHMD "Enable OpenHMD driver" ON "OPENHMD_FOUND" OFF)
267267-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)
268268-cmake_dependent_option(XRT_BUILD_DRIVER_DAYDREAM "Enable the Google Daydream View controller driver (BLE, via D-Bus)" ON "XRT_HAVE_DBUS" OFF)
269269-cmake_dependent_option(XRT_BUILD_DRIVER_ARDUINO "Enable Arduino input device with BLE via via D-Bus" ON "XRT_HAVE_DBUS" OFF)
270270-cmake_dependent_option(XRT_BUILD_DRIVER_ILLIXR "Enable ILLIXR driver" ON "ILLIXR_PATH" OFF)
271271-option(XRT_BUILD_DRIVER_DUMMY "Enable dummy driver" ON)
272272-cmake_dependent_option(XRT_BUILD_DRIVER_ULV2 "Enable Ultraleap v2 driver" ON "LeapV2_FOUND" OFF)
273273-cmake_dependent_option(XRT_BUILD_DRIVER_REMOTE "Enable remote debugging driver" ON "XRT_HAVE_LINUX OR ANDROID" OFF)
274274-cmake_dependent_option(XRT_BUILD_DRIVER_WMR "Enable Windows Mixed Reality driver" ON "NOT WIN32" OFF)
275275-276276-option(XRT_BUILD_SAMPLES "Enable compiling sample code implementations that will not be linked into any final targets" ON)
277277-278278-# These all use the Monado internal hid wrapper.
279279-cmake_dependent_option(XRT_BUILD_DRIVER_HDK "Enable HDK driver" ON "XRT_HAVE_INTERNAL_HID" OFF)
280280-cmake_dependent_option(XRT_BUILD_DRIVER_PSMV "Enable Playstation Move driver" ON "XRT_HAVE_INTERNAL_HID" OFF)
281281-cmake_dependent_option(XRT_BUILD_DRIVER_HYDRA "Enable Hydra driver" ON "XRT_HAVE_INTERNAL_HID" OFF)
282282-cmake_dependent_option(XRT_BUILD_DRIVER_NS "Enable North Star driver" ON "XRT_HAVE_INTERNAL_HID" OFF)
283283-cmake_dependent_option(XRT_BUILD_DRIVER_VF "Build video frame driver (for video file support, uses gstreamer)" ON "XRT_HAVE_GST" OFF)
284284-cmake_dependent_option(XRT_BUILD_DRIVER_DEPTHAI "DepthAI" ON "depthai_FOUND" OFF)
285285-286286-cmake_dependent_option(XRT_BUILD_DRIVER_SURVIVE "Enable libsurvive driver" ON "SURVIVE_FOUND" OFF)
287287-288288-cmake_dependent_option(XRT_BUILD_DRIVER_ANDROID "Enable Android sensors driver" ON "ANDROID" OFF)
289289-cmake_dependent_option(XRT_BUILD_DRIVER_QWERTY "Enable Qwerty driver" ON "XRT_HAVE_SDL2" OFF)
290290-cmake_dependent_option(XRT_BUILD_DRIVER_EUROC "Enable EuRoC dataset driver for SLAM evaluation" ON "XRT_HAVE_OPENCV" OFF)
291291-292292-# cmake-format: on
293293-294294# You can set this from a superproject to add a driver
295295# All drivers must be listed in here to be included in the generated header!
296296list(
+166
cmake/OptionWithDeps.cmake
···11+# Copyright 2022, Collabora, Ltd.
22+# Copyright 2000-2022 Kitware, Inc., Insight Software Consortium
33+#
44+# SPDX-License-Identifier: BSD-3-Clause
55+#
66+# CMake was initially developed by Kitware with the following sponsorship:
77+# * National Library of Medicine at the National Institutes of Health
88+# as part of the Insight Segmentation and Registration Toolkit (ITK).
99+#
1010+# * US National Labs (Los Alamos, Livermore, Sandia) ASC Parallel
1111+# Visualization Initiative.
1212+#
1313+# * National Alliance for Medical Image Computing (NAMIC) is funded by the
1414+# National Institutes of Health through the NIH Roadmap for Medical Research,
1515+# Grant U54 EB005149.
1616+#
1717+# * Kitware, Inc.
1818+#
1919+# (Based on CMakeDependentOption)
2020+2121+#[=======================================================================[.rst:
2222+OptionWithDeps
2323+--------------
2424+2525+Macro to provide an option dependent on other options.
2626+2727+This macro presents an option to the user only if a set of other
2828+conditions are true. If it is already specified by the user but the
2929+conditions are not true, it triggers an error.
3030+3131+This is based on cmake_dependent_options but meets common expectations better:
3232+if you explicitly try to enable something that is not available, you get an error
3333+instead of just having it silently disabled.
3434+3535+.. command:: option_with_deps
3636+3737+ .. code-block:: cmake
3838+3939+ option_with_deps(<option> "<help_text>" [DEFAULT <default>] DEPENDS [<depends>...])
4040+4141+ Describes a build option that has dependencies. If the option is requested,
4242+ but the depends are not satisfied, an error is issued. DEPENDS is a list of
4343+ conditions to check: all must be true to make the option available.
4444+ Otherwise, a local variable named ``<option>`` is set to ``OFF``.
4545+4646+ When ``<option>`` is available, the given ``<help_text>`` and initial
4747+ ``<default>`` are used. Otherwise, any value set by the user is preserved for
4848+ when ``<depends>`` is satisfied in the future.
4949+5050+ Note that the ``<option>`` variable only has a value which satisfies the
5151+ ``<depends>`` condition within the scope of the caller because it is a local
5252+ variable.
5353+5454+ Elements of ``<depends>`` cannot contain parentheses nor "AND" (each item is
5555+ implicitly "ANDed" together). Be sure to quote OR and NOT expressions, and avoid
5656+ complex expressions (such as with escaped quotes, etc) since they may fail,
5757+ especially before CMake 3.18.
5858+5959+Example invocation:
6060+6161+.. code-block:: cmake
6262+6363+ option_with_deps(USE_FOO "Use Foo" DEPENDS "USE_BAR" "NOT USE_ZOT")
6464+6565+If ``USE_BAR`` is true and ``USE_ZOT`` is false, this provides an option called
6666+``USE_FOO`` that defaults to ON. Otherwise, it sets ``USE_FOO`` to OFF and
6767+hides the option from the user. If the status of ``USE_BAR`` or ``USE_ZOT``
6868+ever changes, any value for the ``USE_FOO`` option is saved so that when the
6969+option is re-enabled it retains its old value.
7070+7171+#]=======================================================================]
7272+7373+function(option_with_deps option doc)
7474+ set(options)
7575+ set(oneValueArgs DEFAULT)
7676+ set(multiValueArgs DEPENDS)
7777+ cmake_parse_arguments(_option_deps "${options}" "${oneValueArgs}"
7878+ "${multiValueArgs}" ${ARGN})
7979+8080+ if(NOT DEFINED _option_deps_DEFAULT)
8181+ set(_option_deps_DEFAULT ON)
8282+ endif()
8383+8484+ # Check for invalid/bad depends args
8585+ foreach(d ${_option_deps_DEPENDS})
8686+ if("${d}" MATCHES "[(]")
8787+ message(
8888+ FATAL_ERROR "option_with_deps does not support parens in deps")
8989+ endif()
9090+ if("${d}" MATCHES "\\bAND\\b")
9191+ message(
9292+ FATAL_ERROR
9393+ "option_with_deps treats every deps item as being implicitly 'ANDed' together"
9494+ )
9595+ endif()
9696+ if("${d}" STREQUAL "OR")
9797+ message(FATAL_ERROR "option_with_deps needs OR expressions quoted")
9898+ endif()
9999+ if("${d}" STREQUAL "NOT")
100100+ message(FATAL_ERROR "option_with_deps needs NOT expressions quoted")
101101+ endif()
102102+ endforeach()
103103+104104+ # This is a case we removed from the original CMakeDependentOption module
105105+ if(NOT (${option}_ISSET MATCHES "^${option}_ISSET$"))
106106+ message(
107107+ FATAL_ERROR
108108+ "Probably too old of CMake version to cope with this module")
109109+ endif()
110110+111111+ # Check the actual deps, determine if the option is available
112112+ set(_avail ON)
113113+ foreach(d ${_option_deps_DEPENDS})
114114+ if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.18)
115115+ cmake_language(
116116+ EVAL
117117+ CODE
118118+ "
119119+ if(${d})
120120+ else()
121121+ set(_avail OFF)
122122+ set(_cond ${d})
123123+ endif()")
124124+ else()
125125+ # cmake_language(EVAL CODE was added in 3.18 so evaluate it the "old" way before then.
126126+ # turn spaces into semicolons so we have a list of arguments, signalling to CMAKE
127127+ # to interpret the "if()" differently
128128+ string(REGEX REPLACE " +" ";" CMAKE_DEPENDENT_OPTION_DEP "${d}")
129129+ if(${CMAKE_DEPENDENT_OPTION_DEP})
130130+131131+ else()
132132+ set(_avail OFF)
133133+ set(_cond ${d})
134134+ endif()
135135+ endif()
136136+ endforeach()
137137+138138+ # Error if option was requested but not available
139139+ if("${${option}}" AND NOT "${_avail}")
140140+ message(
141141+ FATAL_ERROR
142142+ "${option} specified but not available: failed check ${_cond}")
143143+ endif()
144144+145145+ # Handle remaining cases
146146+ set(_already_defined OFF)
147147+ if(DEFINED ${option})
148148+ set(_already_defined ON)
149149+ endif()
150150+ if(${_avail})
151151+ # Set a cache variable: the value here will not override an already-set value.
152152+ option(${option} "${doc}" "${_option_deps_DEFAULT}")
153153+154154+ if(NOT _already_defined)
155155+ # Needed to force this for some reason
156156+ set(${option}
157157+ "${${option}}"
158158+ CACHE BOOL "${doc}" FORCE)
159159+ endif()
160160+ else()
161161+ # Don't set a cache variable for something that's not available
162162+ set(${option}
163163+ OFF
164164+ PARENT_SCOPE)
165165+ endif()
166166+endfunction()
+13-8
doc/CMakeLists.txt
···11-# Copyright 2018-2020, Collabora, Ltd.
11+# Copyright 2018-2022, Collabora, Ltd.
22# SPDX-License-Identifier: BSL-1.0
3344# check if Doxygen is installed
55find_package(Doxygen)
6677-# cmake-format: off
88-99-cmake_dependent_option(BUILD_DOC "Build documentation" ON "DOXYGEN_FOUND" OFF)
1010-cmake_dependent_option(BUILD_DOC_WARN_UNDOCUMENTED "Warn on undocumented entities when building documentation" OFF "DOXYGEN_FOUND" OFF)
1111-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)
1212-1313-# cmake-format: on
77+option_with_deps(BUILD_DOC "Build documentation" DEPENDS DOXYGEN_FOUND)
88+option_with_deps(
99+ BUILD_DOC_WARN_UNDOCUMENTED "Warn on undocumented entities when building documentation"
1010+ DEFAULT OFF
1111+ DEPENDS DOXYGEN_FOUND
1212+ )
1313+option_with_deps(
1414+ BUILD_DOC_EXTRACT_ALL
1515+ "Extract all entities for documentation, not just documented ones (conflicts with BUILD_DOC_WARN_UNDOCUMENTED)"
1616+ DEFAULT OFF
1717+ DEPENDS DOXYGEN_FOUND "NOT BUILD_DOC_WARN_UNDOCUMENTED"
1818+ )
14191520if(BUILD_DOC)
1621 if(BUILD_DOC_WARN_UNDOCUMENTED)