CMakeDependentOption: Allow parentheses in the depends string
`if()` takes the condition as a list of arguments. Parentheses need to be separated as well. Fixes: #22303
This commit is contained in:
parent
0d3ddb1704
commit
0665d9092e
@ -42,7 +42,10 @@ macro(CMAKE_DEPENDENT_OPTION option doc default depends force)
|
||||
if(${option}_ISSET MATCHES "^${option}_ISSET$")
|
||||
set(${option}_AVAILABLE 1)
|
||||
foreach(d ${depends})
|
||||
string(REGEX REPLACE " +" ";" CMAKE_DEPENDENT_OPTION_DEP "${d}")
|
||||
string(REPLACE "(" " ( " _CMAKE_CDO_DEP "${d}")
|
||||
string(REPLACE ")" " ) " _CMAKE_CDO_DEP "${_CMAKE_CDO_DEP}")
|
||||
string(REGEX REPLACE " +" ";" CMAKE_DEPENDENT_OPTION_DEP "${_CMAKE_CDO_DEP}")
|
||||
unset(_CMAKE_CDO_DEP)
|
||||
if(${CMAKE_DEPENDENT_OPTION_DEP})
|
||||
else()
|
||||
set(${option}_AVAILABLE 0)
|
||||
|
@ -0,0 +1 @@
|
||||
-- USE_FOO='ON'
|
7
Tests/RunCMake/CMakeDependentOption/Parentheses.cmake
Normal file
7
Tests/RunCMake/CMakeDependentOption/Parentheses.cmake
Normal file
@ -0,0 +1,7 @@
|
||||
include(CMakeDependentOption)
|
||||
|
||||
set(A 1)
|
||||
set(B 1)
|
||||
set(C 0)
|
||||
cmake_dependent_option(USE_FOO "Use Foo" ON "A AND (B OR C)" OFF)
|
||||
message(STATUS "USE_FOO='${USE_FOO}'")
|
3
Tests/RunCMake/CMakeDependentOption/RunCMakeTest.cmake
Normal file
3
Tests/RunCMake/CMakeDependentOption/RunCMakeTest.cmake
Normal file
@ -0,0 +1,3 @@
|
||||
include(RunCMake)
|
||||
|
||||
run_cmake_script(Parentheses)
|
@ -233,6 +233,7 @@ add_RunCMake_test(BuildDepends
|
||||
if(UNIX AND "${CMAKE_GENERATOR}" MATCHES "Unix Makefiles|Ninja")
|
||||
add_RunCMake_test(Byproducts)
|
||||
endif()
|
||||
add_RunCMake_test(CMakeDependentOption)
|
||||
add_RunCMake_test(CMakeRoleGlobalProperty)
|
||||
add_RunCMake_test(CMakeRelease -DCMake_TEST_JQ=${CMake_TEST_JQ})
|
||||
if(UNIX AND "${CMAKE_GENERATOR}" MATCHES "Unix Makefiles|Ninja")
|
||||
|
Loading…
Reference in New Issue
Block a user