How to refine "if(flag) set(flag) endif()" code

Hi

I want to move the code below into one line:

if(NOT CONFIG_A)
        set(CONFIG_B OFF CACHE BOOL "test")
endif()

As I researched the document, I can use set $<NOT:$<CONFIG_A>>, how to embed it into the code? Like set(CONFIG_B $<NOT:$<CONFIG_A>> CACHE BOOL "test"), but it cannot work. I want this is CACHE set not FORCE set. Any suggestion is welcome.

BR
Jianliang Shen

Hi, seems like you’re looking for https://cmake.org/cmake/help/latest/module/CMakeDependentOption.html

Hi, Boris

It works, Thanks!!!

BR
Jianliang Shen

1 Like