Repository: conan-io/conan

Issue:
[question][bug] XcodeDeps with custom configuration does not behave as expected
### What is your question?

Hi,

I'm trying to understand the example from the [XcodeDeps tutorial with custom configurations](https://docs.conan.io/2/reference/tools/apple/xcodedeps.html#custom-configurations).

I've added the `conanfile.py` from the example and ran
```
> conan profile show
Host profile:
[settings]
arch=armv8
build_type=Release
compiler=apple-clang
compiler.cppstd=gnu20
compiler.libcxx=libc++
compiler.version=14
os=Macos

Build profile:
[settings]
arch=armv8
build_type=Release
compiler=apple-clang
compiler.cppstd=gnu20
compiler.libcxx=libc++
compiler.version=14
os=Macos

> conan install . --output-folder=build --build=missing -o 'shared=True'
```
 I was expecting that the config specifier in the resulting xcconfig files would now reflect the adapted configuration name, e.g. `ReleaseShared` - I thought that was the whole point.
But when I look inside the resulting `conan_zlib_zlib_release_arm64.xcconfig` then it's just `HEADER_SEARCH_PATHS_zlib_zlib[config=Release][arch=arm64][sdk=macosx*] ...`.

Is my understanding wrong?

We have several differently named Debug and Release configurations, e.g. "Release with asserts" and for that I need an xcconfig for all of them.

### Have you read the CONTRIBUTING guide?

- [X] I've read the CONTRIBUTING guide


Discussion:
If it was intended to work the way I would expect it to (and the docs suggest), then the problem might be this line:
https://github.com/conan-io/conan/blob/81b195262350a13525a44a0b079c9a4eab9fb1cd/conan/tools/apple/xcodedeps.py#L46

The first format argument should then be `self.configuration` instead of `(settings.get_safe("build_type")`. Otherwise the overwriting that's done in the docs has no effect:
```python
    def generate(self):
        xcode = XcodeDeps(self)
        # We assume that -o *:shared=True is used to install all shared deps too
        if self.options.shared:
            xcode.configuration = str(self.settings.build_type) + "Shared"
        xcode.generate()
```

Resolving patch:
diff --git a/conan/tools/apple/xcodedeps.py b/conan/tools/apple/xcodedeps.py
--- a/conan/tools/apple/xcodedeps.py
+++ b/conan/tools/apple/xcodedeps.py
@@ -24,10 +24,10 @@ def _format_name(name):
     return name.lower()
 
 
-def _xcconfig_settings_filename(settings):
+def _xcconfig_settings_filename(settings, configuration):
     arch = settings.get_safe("arch")
     architecture = _to_apple_arch(arch) or arch
-    props = [("configuration", settings.get_safe("build_type")),
+    props = [("configuration", configuration),
              ("architecture", architecture),
              ("sdk name", settings.get_safe("os.sdk")),
              ("sdk version", settings.get_safe("os.sdk_version"))]
@@ -35,7 +35,7 @@ def _xcconfig_settings_filename(settings):
     return _format_name(name)
 
 
-def _xcconfig_conditional(settings):
+def _xcconfig_conditional(settings, configuration):
     sdk_condition = "*"
     arch = settings.get_safe("arch")
     architecture = _to_apple_arch(arch) or arch
@@ -43,7 +43,7 @@ def _xcconfig_conditional(settings):
     if sdk:
         sdk_condition = "{}{}".format(sdk, settings.get_safe("os.sdk_version") or "*")
 
-    return "[config={}][arch={}][sdk={}]".format(settings.get_safe("build_type"), architecture, sdk_condition)
+    return "[config={}][arch={}][sdk={}]".format(configuration, architecture, sdk_condition)
 
 
 def _add_includes_to_file_or_create(filename, template, files_to_include):
@@ -149,7 +149,7 @@ def _merged_vars(name):
             'cxx_compiler_flags': " ".join('"{}"'.format(p.replace('"', '\\"')) for p in _merged_vars("cxxflags")),
             'linker_flags': " ".join('"{}"'.format(p.replace('"', '\\"')) for p in _merged_vars("sharedlinkflags")),
             'exe_flags': " ".join('"{}"'.format(p.replace('"', '\\"')) for p in _merged_vars("exelinkflags")),
-            'condition': _xcconfig_conditional(self._conanfile.settings)
+            'condition': _xcconfig_conditional(self._conanfile.settings, self.configuration)
         }
 
         if not require.headers:
@@ -231,7 +231,7 @@ def _global_xconfig_content(self):
     def get_content_for_component(self, require, pkg_name, component_name, package_folder, transitive_internal, transitive_external):
         result = {}
 
-        conf_name = _xcconfig_settings_filename(self._conanfile.settings)
+        conf_name = _xcconfig_settings_filename(self._conanfile.settings, self.configuration)
 
         props_name = "conan_{}_{}{}.xcconfig".format(pkg_name, component_name, conf_name)
         result[props_name] = self._conf_xconfig_file(require, pkg_name, component_name, package_folder, transitive_internal)
diff --git a/conan/tools/apple/xcodetoolchain.py b/conan/tools/apple/xcodetoolchain.py
--- a/conan/tools/apple/xcodetoolchain.py
+++ b/conan/tools/apple/xcodetoolchain.py
@@ -64,21 +64,21 @@ def _cppstd(self):
 
     @property
     def _macosx_deployment_target(self):
-        return 'MACOSX_DEPLOYMENT_TARGET{}={}'.format(_xcconfig_conditional(self._conanfile.settings),
+        return 'MACOSX_DEPLOYMENT_TARGET{}={}'.format(_xcconfig_conditional(self._conanfile.settings, self.configuration),
                                                       self.os_version) if self.os_version else ""
 
     @property
     def _clang_cxx_library(self):
-        return 'CLANG_CXX_LIBRARY{}={}'.format(_xcconfig_conditional(self._conanfile.settings),
+        return 'CLANG_CXX_LIBRARY{}={}'.format(_xcconfig_conditional(self._conanfile.settings, self.configuration),
                                                self.libcxx) if self.libcxx else ""
 
     @property
     def _clang_cxx_language_standard(self):
-        return 'CLANG_CXX_LANGUAGE_STANDARD{}={}'.format(_xcconfig_conditional(self._conanfile.settings),
+        return 'CLANG_CXX_LANGUAGE_STANDARD{}={}'.format(_xcconfig_conditional(self._conanfile.settings, self.configuration),
                                                          self._cppstd) if self._cppstd else ""
     @property
     def _vars_xconfig_filename(self):
-        return "conantoolchain{}{}".format(_xcconfig_settings_filename(self._conanfile.settings),
+        return "conantoolchain{}{}".format(_xcconfig_settings_filename(self._conanfile.settings, self.configuration),
                                                                        self.extension)
 
     @property


Test patch:
diff --git a/conans/test/integration/toolchains/apple/test_xcodedeps.py b/conans/test/integration/toolchains/apple/test_xcodedeps.py
--- a/conans/test/integration/toolchains/apple/test_xcodedeps.py
+++ b/conans/test/integration/toolchains/apple/test_xcodedeps.py
@@ -89,6 +89,62 @@ def test_generator_files():
         check_contents(client, ["hello", "goodbye"], build_type, "x86_64", "12.1")
 
 
+@pytest.mark.skipif(platform.system() != "Darwin", reason="Only for MacOS")
+def test_generator_files_with_custom_config():
+    client = TestClient()
+
+    client.save({"hello.py": GenConanfile().with_settings("os", "arch", "compiler", "build_type")
+                                           .with_package_info(cpp_info={"libs": ["hello"]},
+                                                              env_info={})})
+    client.run("export hello.py --name=hello --version=0.1")
+
+    client.save({"goodbye.py": GenConanfile().with_settings("os", "arch", "compiler", "build_type")
+                                             .with_package_info(cpp_info={"libs": ["goodbye"]},
+                                                                env_info={})})
+    client.run("export goodbye.py --name=goodbye --version=0.1")
+
+    conanfile_py = textwrap.dedent("""
+        from conan import ConanFile
+        from conan.tools.apple import XcodeDeps
+        class LibConan(ConanFile):
+            settings = "os", "compiler", "build_type", "arch"
+            options = {"XcodeConfigName": [None, "ANY"]}
+            default_options = {"XcodeConfigName": None}
+            requires = "hello/0.1", "goodbye/0.1"
+            
+            def generate(self):
+                xcode = XcodeDeps(self)
+                if self.options.get_safe("XcodeConfigName"):
+                    xcode.configuration = str(self.options.get_safe("XcodeConfigName"))
+                xcode.generate()
+        """)
+
+    client.save({"conanfile.py": conanfile_py})
+    custom_config_name = "CustomConfig"
+
+    for use_custom_config in [True, False]:
+        for build_type in ["Release", "Debug"]:
+            cli_command = "install . -s build_type={} -s arch=x86_64 -s os.sdk_version=12.1  --build missing".format(build_type)
+            if use_custom_config:
+                cli_command += " -o XcodeConfigName={}".format(custom_config_name)
+                configuration_name = custom_config_name 
+            else:
+                configuration_name = build_type            
+
+            client.run(cli_command)
+
+            for config_file in expected_files(client.current_folder, configuration_name, "x86_64", "12.1"):
+                assert os.path.isfile(config_file)
+
+            conandeps = client.load("conandeps.xcconfig")
+            assert '#include "conan_hello.xcconfig"' in conandeps
+            assert '#include "conan_goodbye.xcconfig"' in conandeps
+
+            conan_config = client.load("conan_config.xcconfig")
+            assert '#include "conandeps.xcconfig"' in conan_config
+
+            check_contents(client, ["hello", "goodbye"],  configuration_name, "x86_64", "12.1",)
+
 @pytest.mark.skipif(platform.system() != "Darwin", reason="Only for MacOS")
 def test_xcodedeps_aggregate_components():
     client = TestClient()