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

**URL:** https://discourse.cmake.org/t/how-to-refine-if-flag-set-flag-endif-code/3802
**Category:** Code
**Created:** [July 21, 2021, 9:31am UTC](https://discourse.cmake.org/t/how-to-refine-if-flag-set-flag-endif-code/3802 "2021-07-21T09:31:33Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![1113](https://discourse.cmake.org/user_avatar/discourse.cmake.org/1113/32/1653_2.png) [@1113](https://discourse.cmake.org/u/1113)
#### Post date: [July 21, 2021, 9:31am UTC](https://discourse.cmake.org/t/how-to-refine-if-flag-set-flag-endif-code/3802/1 "2021-07-21T09:31:33Z")

</div>

Hi

I want to move the code below into one line:

```auto
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

---

<div class="post-metadata">

### Author: ![rurabori](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rurabori/32/1651_2.png) [@rurabori](https://discourse.cmake.org/u/rurabori)
#### Post date: [July 21, 2021, 10:13am UTC](https://discourse.cmake.org/t/how-to-refine-if-flag-set-flag-endif-code/3802/2 "2021-07-21T10:13:39Z")

</div>

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

---

<div class="post-metadata">

### Author: ![1113](https://discourse.cmake.org/user_avatar/discourse.cmake.org/1113/32/1653_2.png) [@1113](https://discourse.cmake.org/u/1113)
#### Post date: [July 23, 2021, 2:22am UTC](https://discourse.cmake.org/t/how-to-refine-if-flag-set-flag-endif-code/3802/3 "2021-07-23T02:22:56Z")

</div>

Hi, Boris

It works, Thanks!!!

BR  
Jianliang Shen
