# How to set \<build-tool-options\> via CMakeLists.txt?

**URL:** https://discourse.cmake.org/t/how-to-set-build-tool-options-via-cmakelists-txt/6925
**Category:** Usage
**Tags:** gen:ninja
**Created:** [November 22, 2022, 9:28am UTC](https://discourse.cmake.org/t/how-to-set-build-tool-options-via-cmakelists-txt/6925 "2022-11-22T09:28:49Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Kuxe](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kuxe/32/2939_2.png) [@Kuxe](https://discourse.cmake.org/u/Kuxe)
#### Post date: [November 22, 2022, 9:28am UTC](https://discourse.cmake.org/t/how-to-set-build-tool-options-via-cmakelists-txt/6925/1 "2022-11-22T09:28:50Z")

</div>

I’d like to have a CMake-option called `ENABLE_NINJA_EXPLAIN` that when enabled causes the build to be invoked like so:

```auto
ninja -d explain

```

Now, when invoking CMake from command-line, you can do:

```auto
cmake --build --preset <preset> [<options>] [-- <build-tool-options>]

```

This will pass `<build-tool-options>` to the underlying build tool. I’d like to set `<build-tool-options>` programmatically in `CMakeLists.txt`, such that `ninja` is given the `-d explain`-argument. **How can I do that?**

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 22, 2022, 1:31pm UTC](https://discourse.cmake.org/t/how-to-set-build-tool-options-via-cmakelists-txt/6925/2 "2022-11-22T13:31:10Z")

</div>

I don’t think there’s any mechanism `ninja` gives us to do this natively (i.e., in `build.ninja` itself). You might be able to set `CMAKE_MAKE_PROGRAM` to `ninja;-d;explain`, but some tools might not be expecting this extra output (Qt Creator comes to mind).

---

<div class="post-metadata">

### Author: ![Kuxe](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kuxe/32/2939_2.png) [@Kuxe](https://discourse.cmake.org/u/Kuxe)
#### Post date: [November 22, 2022, 2:25pm UTC](https://discourse.cmake.org/t/how-to-set-build-tool-options-via-cmakelists-txt/6925/3 "2022-11-22T14:25:09Z")

</div>

I don’t believe I need a mechanism from `ninja` to support this.

I tried setting `CMAKE_MAKE_PROGRAM` just like you said prior to creating this question, but then the following call happened at some point during CMake configuration: `ninja -d explain --version` which causes configuration to fail since it’s not a valid command.

I mean, if CMake is able to forward arguments to the underlying build-tool (be it `make` or `ninja` or something else) via command-line via the double-dash `--`, then I suppose CMake could do that very same thing via a cmake-variable instead? E.g

```auto
set(BUILD_TOOL_OPTIONS "-d explain")

```

where `${BUILD_TOOL_OPTIONS}` is used “as-if” I instead invoked: `cmake --build --preset my_preset -- -d explain]`. Does this make sense?

I haven’t found any variable that resembles `BUILD_TOOL_OPTIONS ` in [the official documentation](https://cmake.org/cmake/help/v3.24/manual/cmake-variables.7.html), hence my question 🙂 .

I take it no such variable exists?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 22, 2022, 2:30pm UTC](https://discourse.cmake.org/t/how-to-set-build-tool-options-via-cmakelists-txt/6925/4 "2022-11-22T14:30:39Z")

</div>

No, `cmake --build` reads the cache, but any local variable is gone by then. We’d need to add a new variable for such things. A [feature request](https://gitlab.kitware.com/cmake/cmake/-/issues) would be the next step I think.

---

<div class="post-metadata">

### Author: ![Kuxe](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kuxe/32/2939_2.png) [@Kuxe](https://discourse.cmake.org/u/Kuxe)
#### Post date: [November 30, 2022, 9:16pm UTC](https://discourse.cmake.org/t/how-to-set-build-tool-options-via-cmakelists-txt/6925/5 "2022-11-30T21:16:20Z")

</div>

I created [Feature Request: Set programmatically](https://gitlab.kitware.com/cmake/cmake/-/issues/24182) per Ben’s suggestion
