# Saving Command Line Configuration

**URL:** https://discourse.cmake.org/t/saving-command-line-configuration/7981
**Category:** Usage
**Created:** [April 25, 2023, 2:00pm UTC](https://discourse.cmake.org/t/saving-command-line-configuration/7981 "2023-04-25T14:00:29Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![jamesETsmith](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jamesetsmith/32/3379_2.png) [@jamesETsmith](https://discourse.cmake.org/u/jamesETsmith)
#### Post date: [April 25, 2023, 2:00pm UTC](https://discourse.cmake.org/t/saving-command-line-configuration/7981/1 "2023-04-25T14:00:30Z")

</div>

# General

I’d like to save the command line arguments users pass at configure time into a source file that will be included with my project so that users can access that information at run time when benchmarking.

Is there an easy way to do this? I haven’t been able to find a way.

# Details

Ideally I could run something like:  
`cmake -B build -DOPTION1=VAL1 -DOPTION2=VAL2`

And I would store `-B build -DOPTION1=VAL1 -DOPTION2=VAL2` in source.

---

<div class="post-metadata">

### Author: ![benthevining](https://discourse.cmake.org/user_avatar/discourse.cmake.org/benthevining/32/1924_2.png) [@benthevining](https://discourse.cmake.org/u/benthevining)
#### Post date: [April 25, 2023, 5:34pm UTC](https://discourse.cmake.org/t/saving-command-line-configuration/7981/2 "2023-04-25T17:34:06Z")

</div>

As far as I know, getting the full command-line isn’t supported. But you can check the values of any variables, which should get you pretty close to what you want. I would probably have a template header with content such as:

```cpp
static const char* const OPTION_1 = "@OPTION_1@";

```

and then use `configure_file` to substitute in all the variable values in the template header.

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [April 26, 2023, 8:59am UTC](https://discourse.cmake.org/t/saving-command-line-configuration/7981/3 "2023-04-26T08:59:57Z")

</div>

You cannot know what command line arguments were passed, and in generally you shouldn’t try. CMake can be re-run for various scenarios, and in those cases, the command line arguments will be different to previous runs. CMake relies heavily on caching things between runs. Any information you need to access should come from the cache variables, not from trying to work out command line arguments.

---

<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: [April 26, 2023, 3:55pm UTC](https://discourse.cmake.org/t/saving-command-line-configuration/7981/4 "2023-04-26T15:55:33Z")

</div>

I believe that [this feature request](https://gitlab.kitware.com/cmake/cmake/-/issues/14756) is of interest here.
