Xcode problem with files which has vary configuration

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.

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:

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

I get cmake error which look like this:

Please help!!

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.

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?

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.

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.

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?