# XCode config generator expression becomes NOCONFIG

**URL:** https://discourse.cmake.org/t/xcode-config-generator-expression-becomes-noconfig/4498
**Category:** Code
**Created:** [November 17, 2021, 7:59pm UTC](https://discourse.cmake.org/t/xcode-config-generator-expression-becomes-noconfig/4498 "2021-11-17T19:59:31Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Leon0402](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/l/ccd318/32.png) [@Leon0402](https://discourse.cmake.org/u/Leon0402)
#### Post date: [November 17, 2021, 7:59pm UTC](https://discourse.cmake.org/t/xcode-config-generator-expression-becomes-noconfig/4498/1 "2021-11-17T19:59:31Z")

</div>

I configure a file with generator expressions targeting single and multi configuration generators like so:

```cmake
configure_file(StartServer.cpp.in StartServer.cpp.in @ONLY) 
file(GENERATE
  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/StartServer_$<CONFIG>.cpp
  INPUT ${CMAKE_CURRENT_BINARY_DIR}/StartServer.cpp.in
)

```

then I add the generated file as a target source:

```auto
target_sources(StartServer
    PRIVATE
        ${CMAKE_CURRENT_BINARY_DIR}/StartServer_$<CONFIG>.cpp
)

```

This generates the various StartServer\_Debug.cpp, StartServer\_Release.cpp files and works on every generator (inluding multi config ones like Visual Studio) except XCode.

With XCode I get the error:

```auto
Cannot find source file:
    <...>/build-xcode-clang-debug/tests/e2e_tests/setup/StartServer_NOCONFIG.cpp

```

Why is `$<CONFIG>` expanded to NOCONFIG. I printed the generator expression to a file, it doesn’t have the value NOCONFIG.

What’s the proper way of doing this so it works for every available generator on every platform?

---

<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: [November 17, 2021, 8:07pm UTC](https://discourse.cmake.org/t/xcode-config-generator-expression-becomes-noconfig/4498/2 "2021-11-17T20:07:44Z")

</div>

I could be wrong, but I think the Xcode generator doesn’t support per-config source files. @brad.king would be able to confirm this.

---

<div class="post-metadata">

### Author: ![Leon0402](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/l/ccd318/32.png) [@Leon0402](https://discourse.cmake.org/u/Leon0402)
#### Post date: [November 17, 2021, 8:12pm UTC](https://discourse.cmake.org/t/xcode-config-generator-expression-becomes-noconfig/4498/3 "2021-11-17T20:12:57Z")

</div>

What can I then do to use generator expressions in source files for xcode?

---

<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: [November 18, 2021, 2:46pm UTC](https://discourse.cmake.org/t/xcode-config-generator-expression-becomes-noconfig/4498/4 "2021-11-18T14:46:09Z")

</div>

> What can I then do to use generator expressions in source files for xcode?

If they evaluate to per-config values, you can’t.

The Xcode generator does not support per-config sources. IIRC, Xcode does not provide a simple and robust way to express them.

In some cases one can work around this by using per-config `COMPILE_DEFINITIONS` along with a source that uses preprocessor conditions to `#include` the source of the matching configuration.

---

<div class="post-metadata">

### Author: ![Leon0402](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/l/ccd318/32.png) [@Leon0402](https://discourse.cmake.org/u/Leon0402)
#### Post date: [November 18, 2021, 3:14pm UTC](https://discourse.cmake.org/t/xcode-config-generator-expression-becomes-noconfig/4498/5 "2021-11-18T15:14:46Z")

</div>

> [@brad.king](#):
>
> In some cases one can work around this by using per-config `COMPILE_DEFINITIONS` along with a source that uses preprocessor conditions to `#include` the source of the matching configuration.

I want the value `$<TARGET_FILE:BeansServer>` to be available in my script. Currently I use configure\_file and generate for this.  
Can I pass this via `target_compile_definitions` as a macro instead?  
Will that work for Xcode and all other generators`

---

<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: [November 18, 2021, 3:31pm UTC](https://discourse.cmake.org/t/xcode-config-generator-expression-becomes-noconfig/4498/6 "2021-11-18T15:31:34Z")

</div>

Yes, `target_compile_definitions` should work.

The `COMPILE_DEFINITIONS` _source file property_ might also work too, but IIRC Xcode might have trouble with per-config per-source flags too.
