2023-11-10 11:31:01 +00:00
|
|
|
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
# file Copyright.txt or https://cmake.org/licensing for details.
|
|
|
|
|
|
|
|
#[=======================================================================[.rst:
|
|
|
|
DependentOption
|
|
|
|
--------------------
|
|
|
|
Roughly based on CMakeDependentOption:
|
|
|
|
https://github.com/Kitware/CMake/blob/master/Modules/CMakeDependentOption.cmake
|
|
|
|
|
|
|
|
Modified to so it produces warnings instead of hiding an option completely and
|
|
|
|
sets a default value.
|
2023-11-10 20:25:45 +00:00
|
|
|
Difference is that `depends` argument is ALWAYS a semicolon separated list of
|
|
|
|
<expr> tokens.
|
2023-11-10 11:31:01 +00:00
|
|
|
|
|
|
|
Argument meaning and order are the same, and there's an additional (warn)
|
|
|
|
argument which is the message printed if the end-user enabled a feature which
|
|
|
|
isn't "possible".
|
2023-11-10 20:25:45 +00:00
|
|
|
|
|
|
|
Actual checks are deferred until RUN_DEPENDENCY_CHECKS() is called in order to
|
|
|
|
allow out of order declaration of dependencies and dependecy graph cycles.
|
|
|
|
As the checks can affect each other they're run in a loop until the graph settles.
|
2023-11-10 11:31:01 +00:00
|
|
|
#]=======================================================================]
|
|
|
|
|
2023-11-10 20:25:45 +00:00
|
|
|
set(__DEPENDENT_OPTIONS_CHANGE_HAPPENED true)
|
|
|
|
set(__DEPENDENT_OPTIONS_LATER_INVOKED_CODE "")
|
|
|
|
|
2023-11-10 11:31:01 +00:00
|
|
|
macro(DEPENDENT_OPTION option doc default depends else warn)
|
2023-11-10 20:25:45 +00:00
|
|
|
option(${option} "${doc}" "${default}")
|
|
|
|
|
|
|
|
string(APPEND __DEPENDENT_OPTIONS_LATER_INVOKED_CODE "
|
|
|
|
set(${option}_POSSIBLE 1)
|
|
|
|
string(REGEX MATCHALL \"[^;]+\" __${option}_TOKENS \"${depends}\")
|
|
|
|
foreach(it \${__${option}_TOKENS})
|
|
|
|
cmake_language(EVAL CODE \"
|
|
|
|
if (\${it})
|
2023-11-10 11:31:01 +00:00
|
|
|
else()
|
|
|
|
set(${option}_POSSIBLE 0)
|
2023-11-10 20:25:45 +00:00
|
|
|
endif()\")
|
|
|
|
endforeach()
|
|
|
|
unset(__${option}_TOKENS)
|
|
|
|
if(NOT ${option}_POSSIBLE)
|
|
|
|
if(NOT \"\${${option}}\" STREQUAL \"${else}\")
|
|
|
|
message(NOTICE \"${warn}; setting to '${else}'.\")
|
|
|
|
set(${option} ${else} CACHE BOOL \"${doc}\" FORCE)
|
|
|
|
set(__DEPENDENT_OPTIONS_CHANGE_HAPPENED true)
|
|
|
|
endif()
|
2023-11-10 11:31:01 +00:00
|
|
|
endif()
|
2023-11-10 20:25:45 +00:00
|
|
|
unset(${option}_POSSIBLE)")
|
2023-11-10 11:31:01 +00:00
|
|
|
endmacro()
|
2023-11-10 20:25:45 +00:00
|
|
|
|
|
|
|
macro(RUN_DEPENDENCY_CHECKS)
|
2023-11-10 23:45:11 +00:00
|
|
|
# controls max allowed dependency chain to avoid infinite loops during
|
|
|
|
# configure phase
|
|
|
|
set(__DEPENDENT_OPTIONS_LOOP_COUNTER 10)
|
|
|
|
|
2023-11-10 20:25:45 +00:00
|
|
|
while(__DEPENDENT_OPTIONS_CHANGE_HAPPENED)
|
2023-11-10 23:45:11 +00:00
|
|
|
MATH(EXPR __DEPENDENT_OPTIONS_LOOP_COUNTER "${__DEPENDENT_OPTIONS_LOOP_COUNTER}-1")
|
2023-11-10 20:25:45 +00:00
|
|
|
set(__DEPENDENT_OPTIONS_CHANGE_HAPPENED false)
|
|
|
|
cmake_language(EVAL CODE "${__DEPENDENT_OPTIONS_LATER_INVOKED_CODE}")
|
2023-11-10 23:45:11 +00:00
|
|
|
if(__DEPENDENT_OPTIONS_LOOP_COUNTER LESS_EQUAL "0")
|
|
|
|
break()
|
|
|
|
endif()
|
2023-11-10 20:25:45 +00:00
|
|
|
endwhile()
|
2023-11-10 23:45:11 +00:00
|
|
|
unset(__DEPENDENT_OPTIONS_LOOP_COUNTER)
|
2023-11-10 20:25:45 +00:00
|
|
|
set(__DEPENDENT_OPTIONS_CHANGE_HAPPENED true)
|
|
|
|
set(__DEPENDENT_OPTIONS_LATER_INVOKED_CODE "")
|
2023-11-10 23:45:11 +00:00
|
|
|
endmacro()
|