cmake_dependent_option with complex conditionals

It seems that cmake_dependent_option does not work with complex conditionals. For example:

OPTION(OPT1 "Option 1" ON)
OPTION(OPT2 "Option 2" ON)
OPTION(OPT3 "Option 3" OFF)

# Complex condition in if statement
IF (OPT1 AND (OPT2 OR OPT3))
    MESSAGE("true")
ELSE()
    MESSAGE("false")
ENDIF()

# Same condition in CMAKE_DEPENDENT_OPTION doesn't work
CMAKE_DEPENDENT_OPTION(DEP_OPT "dependent option" OFF "OPT1 AND (OPT2 OR OPT3)" OFF)
MESSAGE("DEP OPT = ${DEP_OPT}")

The issue is the macro converts each space to a “;” before using the conditional. This step breaks up the complex conditional.
The documentation mentions that “Each element in the fourth parameter is evaluated as an if- condition”.
This implies that more complex conditionals (besides the implicit AND of the list) will not work?

Am I missing some way of constructing the depends argument?

Hmm. I think I would normally have used "OPT1;OPT2 OR OPT3" myself. Maybe it’s the parentheses which confuse things? Does "OPT1 AND ( OPT2 OR OPT3 )" work?

Removing the parenthesis, or adding spaces around the parenthesis works. So “OPT1 AND ( OPT2 OR OPT3 )” also works.

The key lines in the cmake_dependent_option macro are:
foreach(d ${depends})
string(REGEX REPLACE " +" “;” CMAKE_DEPENDENT_OPTION_DEP “${d}”)
if(${CMAKE_DEPENDENT_OPTION_DEP})

The REGEX effectively tokenizes the line based on spaces. So “OPT1 AND ( OPT2 OR OPT3 )” becomes “OPT1;AND;(;OPT2;OR;OPT3;)”, but the same expression without spaces “OPT1 AND (OPT2 OR OPT3)” becomes “OPT1;AND;(OPT2;OR;OPT3)”
My guess is the “if” statement expects input which is a list to be tokenized properly. In the second case, the parenthesis is not in a list element by itself, and so it is not recognized as a special token.

Right. I think that makes sense. The way conditional-taking commands work is a bit different, I think, in that they do tokenization on ( characters. They also “care” about quoting which most other commands just ignore. Maybe all commands do it, but that is likely done before any variable expansion.