# Xcode problem with files which has vary configuration

**URL:** https://discourse.cmake.org/t/xcode-problem-with-files-which-has-vary-configuration/11754
**Category:** Code
**Tags:** os:macos, gen:xcode
**Created:** [September 23, 2024, 5:51pm UTC](https://discourse.cmake.org/t/xcode-problem-with-files-which-has-vary-configuration/11754 "2024-09-23T17:51:00Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Gregor\_Smith](https://discourse.cmake.org/user_avatar/discourse.cmake.org/gregor_smith/32/4930_2.png) [@Gregor\_Smith](https://discourse.cmake.org/u/Gregor_Smith)
#### Post date: [September 23, 2024, 5:51pm UTC](https://discourse.cmake.org/t/xcode-problem-with-files-which-has-vary-configuration/11754/1 "2024-09-23T17:51:00Z")

</div>

Hi everyone  
Below I present a example source code that I hav borrow from other topic but it is a good example of my problem.  
I do not know if it is a cmake problem or what but I cannot belive that this simple approach to files chich has vary configuration doesn’t work in XCode.  
I have confirmed that this my source code works in MSVS so the question is why it doesn’t work in Xcode and what I should to do if I want to fix it and generate build tree for Xcode solution.

```auto
cmake_minimum_required(VERSION 3.30.3)
project(Sample)

file(WRITE main.cpp "int main() {}")
file(WRITE Release.cpp "")
file(WRITE Debug.cpp "")

add_executable(Sample
	main.cpp
	$<$<CONFIG:Debug>:Debug.cpp>
	$<$<CONFIG:Release>:Release.cpp>
)

```

When I am trying to generate build tree below command:

```auto
cmake -G "Xcode" -S . -B build

```

I get cmake error which look like this:

> 

 ![Screenshot 2024-09-23 at 19.48.03](https://discourse.cmake.org/uploads/default/original/2X/2/21cded6c9ebe7e93429a7fdafe4eaddab6ff6a56.png)

Please help!!

---

<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 23, 2024, 9:49pm UTC](https://discourse.cmake.org/t/xcode-problem-with-files-which-has-vary-configuration/11754/2 "2024-09-23T21:49:37Z")

</div>

The error message tells you exactly the situation. The Xcode generator doesn’t support what you’re trying to do. The restriction is specific to Xcode.

---

<div class="post-metadata">

### Author: ![Gregor\_Smith](https://discourse.cmake.org/user_avatar/discourse.cmake.org/gregor_smith/32/4930_2.png) [@Gregor\_Smith](https://discourse.cmake.org/u/Gregor_Smith)
#### Post date: [September 24, 2024, 9:25am UTC](https://discourse.cmake.org/t/xcode-problem-with-files-which-has-vary-configuration/11754/3 "2024-09-24T09:25:29Z")

</div>

Ok, so if this restriction is specific to Xcode, how can I generate an Xcode solution with the ‘multi-config’ approach? As far as I know, Xcode provides solutions that can have multiple configurations, and one is able to choose which flavor (release, debug, etc.) to build in the Xcode IDE. **Can you show me how to modify the above example code to achieve a multi-config Xcode solution?**

---

<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: [September 24, 2024, 12:00pm UTC](https://discourse.cmake.org/t/xcode-problem-with-files-which-has-vary-configuration/11754/4 "2024-09-24T12:00:27Z")

</div>

I would do this by adding both files always, and wrapping their entire contents in `#ifdef NDEBUG` or `#ifndef NDEBUG` as appropriate. You can of course use a different macro than `NDEBUG`, or even introduce your own just for this purpose. Then you can define the macro with a configuration-based genex.

---

<div class="post-metadata">

### Author: ![Gregor\_Smith](https://discourse.cmake.org/user_avatar/discourse.cmake.org/gregor_smith/32/4930_2.png) [@Gregor\_Smith](https://discourse.cmake.org/u/Gregor_Smith)
#### Post date: [September 24, 2024, 1:03pm UTC](https://discourse.cmake.org/t/xcode-problem-with-files-which-has-vary-configuration/11754/5 "2024-09-24T13:03:25Z")

</div>

As you might suspect, the code above is just an example; the problem concerns a much larger project consisting of many modules. Adding all the files and wrapping the code directly is probably not an option. Therefore, my question is whether this is indeed specific to Xcode, or perhaps it’s a lack of proper implementation in CMake. Xcode supports multi-config solutions, so the inability to generate such solutions in CMake or the need for a workaround suggests that the issue lies with CMake, not Xcode.

---

<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: [September 24, 2024, 1:04pm UTC](https://discourse.cmake.org/t/xcode-problem-with-files-which-has-vary-configuration/11754/6 "2024-09-24T13:04:26Z")

</div>

The problem is not multi-config solutions per se, but having the set of source files of a target differ between configs. Does vanilla XCode support that?
