Skip to content
Snippets Groups Projects
Commit 67db40f2 authored by Simon Praetorius's avatar Simon Praetorius
Browse files

Merge branch 'cherry-pick-1511' into 'releases/2.10'

Backport: Replace the FATAL_ERROR in dune_policy(SET) by an author warning

See merge request !1518
parents 339499ee 40a0db57
No related branches found
No related tags found
1 merge request!1518Backport: Replace the FATAL_ERROR in dune_policy(SET) by an author warning
Pipeline #77343 failed
......@@ -16,7 +16,7 @@ influenced by the global cmake variable ``DUNE_POLICY_DEFAULT``.
.. code-block:: cmake
dune_policy(GET <policy> <var>)
dune_policy(SET <policy> <value>)
dune_policy(SET <policy> <value> [QUIET])
dune_policy(LIST)
.. cmake:command:: dune_define_policy
......@@ -41,41 +41,28 @@ Global options
``DUNE_POLICY_DISABLE_WARNING`` (default=FALSE)
If set to `TRUE`, warnings about unset dune policies are deactivated.
``DUNE_POLICY_IGNORE_UNDEFINED`` (default=FALSE)
Ignore undefined dune policies in GET and SET operations.
This option is useful if you want to set a policy in a module that
should be compatible with a range of upstream dune modules where
possibly not all policies are already defined. If this option is set to
`FALSE`, an error message is shown if you try to set or get an undefined
policy.
#]=======================================================================]
include_guard(GLOBAL)
set(DUNE_POLICY_DEFAULT "OLD" CACHE STRING "Default value for an unset dune policy.")
set_property(CACHE DUNE_POLICY_DEFAULT PROPERTY STRINGS "OLD" "NEW")
option(DUNE_POLICY_DISABLE_WARNING "Do not show warnings about unset dune policies." FALSE)
option(DUNE_POLICY_IGNORE_UNDEFINED "Ignore undefined dune policies in GET and SET operations." FALSE)
# print a help message with the signature of the dune_policy function
function(dune_policy_help _errorlevel _msg)
message(${_errorlevel} "${_msg}"
"The function `dune_policy` has the following signatures:"
" dune_policy(GET <policy> <var>): extract the value of the given <policy> in the variable <var>."
" dune_policy(SET <policy> <value>): change the given <policy> to <value>."
" dune_policy(LIST): list all registered policies with their values."
" dune_policy(HELP): show this help message.")
message(${_errorlevel} "${_msg}\n"
"The function `dune_policy` has the following signatures:\n"
" dune_policy(GET <policy> <var>): extract the value of the given <policy> in the variable <var>.\n"
" dune_policy(SET <policy> <value> [QUIET]): change the given <policy> to <value>.\n"
" dune_policy(LIST): list all registered policies with their values.\n"
" dune_policy(HELP): show this help message.\n")
endfunction(dune_policy_help)
# get the value of a _policy, or the DUNE_POLICY_DEFAULT, or NEW if the policy's dune version is reached
function(dune_get_policy _policy _var)
get_property(_policy_defined GLOBAL PROPERTY DUNE_POLICY_${_policy} DEFINED)
if(NOT _policy_defined)
if(DUNE_POLICY_IGNORE_UNDEFINED)
return()
else()
dune_policy_help(FATAL_ERROR "Undefined policy ${_policy}.")
endif()
dune_policy_help(FATAL_ERROR "Undefined policy ${_policy}.")
endif()
get_property(_policy_set GLOBAL PROPERTY DUNE_POLICY_${_policy} SET)
if(NOT _policy_set)
......@@ -100,15 +87,18 @@ function(dune_get_policy _policy _var)
set(${_var} ${_policy_value} PARENT_SCOPE)
endfunction(dune_get_policy)
# set a given _policy to the _value
# set a given _policy to the _value. If QUIET is passed as additional argument, ignore undefined policies.
function(dune_set_policy _policy _value)
set(_quiet FALSE)
if(ARGC GREATER 2 AND "${ARGV2}" STREQUAL "QUIET")
set(_quiet TRUE)
endif()
get_property(_policy_defined GLOBAL PROPERTY DUNE_POLICY_${_policy} DEFINED)
if(NOT _policy_defined)
if(DUNE_POLICY_IGNORE_UNDEFINED)
return()
else()
dune_policy_help(FATAL_ERROR "Undefined policy ${_policy}.")
if(NOT _quiet)
dune_policy_help(AUTHOR_WARNING "Undefined policy ${_policy} (ignored).")
endif()
return()
endif()
set_property(GLOBAL PROPERTY DUNE_POLICY_${_policy} ${_value})
endfunction(dune_set_policy)
......@@ -116,16 +106,16 @@ endfunction(dune_set_policy)
# generic policy method to get, set, or list policies
function(dune_policy _method)
if(_method STREQUAL "GET")
if(ARGV2 LESS 3)
if(ARGC LESS 3)
dune_policy_help(FATAL_ERROR "Not enough arguments passed to dune_policy(GET...)")
endif()
dune_get_policy(${ARGV1} _var)
set(${ARGV2} ${_var} PARENT_SCOPE)
elseif(_method STREQUAL "SET")
if(ARGV2 LESS 3)
if(ARGC LESS 3)
dune_policy_help(FATAL_ERROR "Not enough arguments passed to dune_policy(SET...)")
endif()
dune_set_policy(${ARGV1} ${ARGV2})
dune_set_policy(${ARGN})
elseif(_method STREQUAL "LIST")
get_property(_policies GLOBAL PROPERTY DUNE_POLICIES)
foreach(_policy ${policies})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment