# Generator Expression using Custom Configuration Name

**URL:** https://discourse.cmake.org/t/generator-expression-using-custom-configuration-name/9042
**Category:** Usage
**Tags:** os:windows, gen:vs
**Created:** [September 21, 2023, 6:17pm UTC](https://discourse.cmake.org/t/generator-expression-using-custom-configuration-name/9042 "2023-09-21T18:17:27Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![pcd3897](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/58956e/32.png) [@pcd3897](https://discourse.cmake.org/u/pcd3897)
#### Post date: [September 21, 2023, 6:17pm UTC](https://discourse.cmake.org/t/generator-expression-using-custom-configuration-name/9042/1 "2023-09-21T18:17:27Z")

</div>

I am working with the Visual Studio Generator. I created custom configuration types using `-DCMAKE_CONFIGURATION_TYPES="Custom-1;Custom-2"` when calling CMAKE. My CMAKELISTS.txt uses the config type like this:

`set(Var1 $<$<CONFIG:Custom-1>:Custom1Var><$<$<CONFIG:Custom-2>:Custom2Var>)`

However, when I generate, I get errors saying

`Error Evaluating generator Expression: $<CONFIG:Custom-1>.`

I have checked that the CMAKE\_CONFIGURATION\_TYPES variable is set correctly. I am using CMAKE 3.15.7.

What am I doing incorrectly?

Thanks!

---

<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: [September 21, 2023, 10:23pm UTC](https://discourse.cmake.org/t/generator-expression-using-custom-configuration-name/9042/2 "2023-09-21T22:23:06Z")

</div>

Do you still get the error if you replace the hyphens (`-`) with underscores (`_`) in your configuration names?

---

<div class="post-metadata">

### Author: ![pcd3897](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/58956e/32.png) [@pcd3897](https://discourse.cmake.org/u/pcd3897)
#### Post date: [September 21, 2023, 10:24pm UTC](https://discourse.cmake.org/t/generator-expression-using-custom-configuration-name/9042/3 "2023-09-21T22:24:11Z")

</div>

I do not get the error.

---

<div class="post-metadata">

### Author: ![pcd3897](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/58956e/32.png) [@pcd3897](https://discourse.cmake.org/u/pcd3897)
#### Post date: [September 22, 2023, 2:02pm UTC](https://discourse.cmake.org/t/generator-expression-using-custom-configuration-name/9042/4 "2023-09-22T14:02:51Z")

</div>

However, I would like it to be a hyphen, is this not do-able?

---

<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: [September 24, 2023, 12:46am UTC](https://discourse.cmake.org/t/generator-expression-using-custom-configuration-name/9042/5 "2023-09-24T00:46:59Z")

</div>

Apparently not. I’m not aware of `-` being special in generator expressions… There may, however, be old assumptions/enforcements around configuration names lingering around (e.g., it is called `RelWithDebInfo` because old(?) Visual Studio would do “substr” matches instead of `==` matches and requesting `Release` could find any of `Release`, `ReleaseMinimumSize`, or `ReleaseWithDebug` depending on ordering).

@brad.king?

---

<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: [September 24, 2023, 3:45am UTC](https://discourse.cmake.org/t/generator-expression-using-custom-configuration-name/9042/6 "2023-09-24T03:45:35Z")

</div>

The expression in the description is malformed, but I suspect that is just a typo in transcribing from your real project. You have a stray `<` in the middle. It should be:

```cmake
set(Var1 $<$<CONFIG:Custom-1>:Custom1Var>$<$<CONFIG:Custom-2>:Custom2Var>)

```

I think the regular expression on [this line](https://gitlab.kitware.com/cmake/cmake/-/blob/v3.27.6/Source/cmGeneratorExpressionNode.cxx?ref_type=tags#L2129) is the reason hyphens in configuration names are not supported in generator expressions. Adding a hyphen to that regular expression allows your example to work (after fixing the malformed part mentioned above). I don’t know if that’s a safe change in general or whether other places also don’t support a hyphen in a config name. It probably needs a deeper analysis than I have the time to available to dedicate right now. Hopefully this gives enough clues to someone else who might be able to do a deeper analysis.

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [September 25, 2023, 1:52pm UTC](https://discourse.cmake.org/t/generator-expression-using-custom-configuration-name/9042/7 "2023-09-25T13:52:48Z")

</div>

In general we expect configuration names to be valid C identifiers. This minimizes the chance that some tool or file format doesn’t handle them correctly.
