# Option and configure\_file: How to be consistent?

**URL:** https://discourse.cmake.org/t/option-and-configure-file-how-to-be-consistent/3028
**Category:** Code
**Created:** [March 26, 2021, 1:21pm UTC](https://discourse.cmake.org/t/option-and-configure-file-how-to-be-consistent/3028 "2021-03-26T13:21:08Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![mathomp4](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mathomp4/32/176_2.png) [@mathomp4](https://discourse.cmake.org/u/mathomp4)
#### Post date: [March 26, 2021, 1:21pm UTC](https://discourse.cmake.org/t/option-and-configure-file-how-to-be-consistent/3028/1 "2021-03-26T13:21:08Z")

</div>

Once again, I bare my CMake ignorance to the forum! In this case, it’s to do with `option()`. Namely, in some code I have, I added:

```cmake
option(HYDROSTATIC "Build FV dynamics as hydrostatic" ON)
if (HYDROSTATIC)
  ...build as hydro...
else()
  ...build as non-hydro...
endif ()

```

And it works. Indeed, I can use `-DHYDROSTATIC=NO` or `-DHYDROSTATIC=0` and it seems to be the same as `-DHYDROSTATIC=OFF`. I think this comes from CMake thinking of `NO` and `OFF` as equivalent to `false` and `0`?

But here’s the fun thing. Later on, I want to use a `configure_file()` call to edit a shell script to change based on the value of `HYDROSTATIC`. I tried a little script:

```bash
echo "HYDROSTATIC = @HYDROSTATIC@"

```

and then did a:

```cmake
configure_file(test.bash test.bash @ONLY)

```

and if I do CMake with `-DHYDROSTATIC=OFF` I see:

```bash
echo "HYDROSTATIC = OFF"

```

and if I use `-DHYDROSTATIC=NO`, you get:

```bash
echo "HYDROSTATIC = NO"

```

So, in the “real” script, I’d like to have a simple if-test:

```bash
if [["$HYDROSTATIC" == "OFF"]]
then
...

```

rather than needing to test for every value of “false”:

```bash
if [["$HYDROSTATIC" == "OFF" || "$HYDROSTATIC" == "NO" || "$HYDROSTATIC" == "0"]]
then
...

```

Is there some clever way of using, maybe, generator expressions that I could use so that no matter what synonym of true/false is used at CMake time, the build system can supply a single value to my `configure_file()`'d script?

---

<div class="post-metadata">

### Author: ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)
#### Post date: [March 26, 2021, 1:38pm UTC](https://discourse.cmake.org/t/option-and-configure-file-how-to-be-consistent/3028/2 "2021-03-26T13:38:11Z")

</div>

You can introduce your own variable with a known set of values:

```auto
if(HYDROSTATIC)
  set(CFG_HYDROSTATIC ON)
else()
  set(CFG_HYDROSTATIC OFF)
endif()

```

and then use `CFG_HYDROSTATIC` in your `configure_file()` call.

Generator expressions cannot help with `configure_file()`, because they are evaluated and generate time, not configure time. If you were using `file(GENEREATE)` instead, you could use them:

```auto
$<BOOL:${HYDROSTATIC}>

```

will expand to either `0` or `1` based on CMake’s interpretation of the truthness of `${HYDROSTATIC}`. But since it’s a configure-time decision, I would go with the fixed-value variable.

---

<div class="post-metadata">

### Author: ![mathomp4](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mathomp4/32/176_2.png) [@mathomp4](https://discourse.cmake.org/u/mathomp4)
#### Post date: [March 26, 2021, 3:00pm UTC](https://discourse.cmake.org/t/option-and-configure-file-how-to-be-consistent/3028/3 "2021-03-26T15:00:26Z")

</div>

@Angew That was sort of what I was thinking of doing, but I was just hoping/wondering if there was some cool CMake-y way to do it I didn’t know about. I’m always surprised by some of the cool things CMake can do!

Thanks!
