# Adding default build configuration for scheme in XCode

**URL:** https://discourse.cmake.org/t/adding-default-build-configuration-for-scheme-in-xcode/2129
**Category:** Development
**Created:** [November 5, 2020, 3:44pm UTC](https://discourse.cmake.org/t/adding-default-build-configuration-for-scheme-in-xcode/2129 "2020-11-05T15:44:07Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![zhang\_kai](https://discourse.cmake.org/user_avatar/discourse.cmake.org/zhang_kai/32/929_2.png) [@zhang\_kai](https://discourse.cmake.org/u/zhang_kai)
#### Post date: [November 5, 2020, 3:44pm UTC](https://discourse.cmake.org/t/adding-default-build-configuration-for-scheme-in-xcode/2129/1 "2020-11-05T15:44:07Z")

</div>

For now, the default build configuration in the XCode scheme is hardcoded in `cmXCodeScheme.cxx`. For example, the build configuration for launch action(the “RUN” command in XCode) is “Debug”.

Sometimes, it’s not what the users wanted. For the project that I’m working on, I want the default build configuration for “RUN” is “RelWithDebInfo”. Since our project is a huge one, sometimes it took a long time for me to build then realized that I did not choose the right build configuration.

I think we can add a new `XCODE_SCHEME_DEFAULT_RUN_CONFIG` property for users to set the default build configuration to what they want. I have created a branch to do some tests and it’s working well for me. If this is a meaningful addition to CMake, I would be more than happy to submit a merge request.

---

<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: [November 5, 2020, 6:07pm UTC](https://discourse.cmake.org/t/adding-default-build-configuration-for-scheme-in-xcode/2129/2 "2020-11-05T18:07:07Z")

</div>

The feature seems reasonable to me.

Cc: @gjasny @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: [November 5, 2020, 7:53pm UTC](https://discourse.cmake.org/t/adding-default-build-configuration-for-scheme-in-xcode/2129/3 "2020-11-05T19:53:37Z")

</div>

The `CMAKE_DEFAULT_BUILD_TYPE` variable added in CMake 3.17 is somewhat related. It is only for the Ninja Multi-config generator at the moment though.

---

<div class="post-metadata">

### Author: ![jamiepond](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jamiepond/32/2451_2.png) [@jamiepond](https://discourse.cmake.org/u/jamiepond)
#### Post date: [May 24, 2022, 6:36pm UTC](https://discourse.cmake.org/t/adding-default-build-configuration-for-scheme-in-xcode/2129/4 "2022-05-24T18:36:01Z")

</div>

Are there any updates to this? Or any workarounds to try? Thanks so much 🙂

---

<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: [May 24, 2022, 10:06pm UTC](https://discourse.cmake.org/t/adding-default-build-configuration-for-scheme-in-xcode/2129/5 "2022-05-24T22:06:17Z")

</div>

I’m not aware of anyone working on changes related to this topic.

---

<div class="post-metadata">

### Author: ![zhang\_kai](https://discourse.cmake.org/user_avatar/discourse.cmake.org/zhang_kai/32/929_2.png) [@zhang\_kai](https://discourse.cmake.org/u/zhang_kai)
#### Post date: [May 28, 2022, 3:19am UTC](https://discourse.cmake.org/t/adding-default-build-configuration-for-scheme-in-xcode/2129/6 "2022-05-28T03:19:01Z")

</div>

Hi, sorry for not following this. After I post this, our team made a decision and switched to another build system. But I have a working draft. The code is actually very simple.

I added a new `XCODE_SCHEME_DEFAULT_RUN_CONFIG` and in Source/cmXCodeScheme.cxx, instead of `WriteLaunchAction(xout, FindConfiguration("Debug"), container);` I use:

```auto
std::string launchConfiguration = this->Target->GetTarget()->GetSafeProperty(
   "XCODE_SCHEME_DEFAULT_RUN_CONFIG");
 if (launchConfiguration.empty())
 {
   launchConfiguration = "Debug";
 }
 WriteLaunchAction(xout, FindConfiguration(launchConfiguration), container);

```

You can give it a try.

---

<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: [May 30, 2022, 12:43pm UTC](https://discourse.cmake.org/t/adding-default-build-configuration-for-scheme-in-xcode/2129/7 "2022-05-30T12:43:59Z")

</div>

An MR with these changes (and doc additions) would be greatly appreciated 🙂 .

---

<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: [May 30, 2022, 9:20pm UTC](https://discourse.cmake.org/t/adding-default-build-configuration-for-scheme-in-xcode/2129/8 "2022-05-30T21:20:52Z")

</div>

Rather than adding a new property or variable, I do think it would be better to use the existing `CMAKE_DEFAULT_BUILD_TYPE` variable for this. If that variable isn’t set, we could use the first config listed in `CMAKE_CONFIGURATION_TYPES` as a fallback. I think that would still give us the same behavior as now if `CMAKE_DEFAULT_BUILD_TYPE` isn’t set and `CMAKE_CONFIGURATION_TYPES` is left at its default value. We should avoid adding a new Xcode-specific variable when a more general, suitable variable already exists.

---

<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: [May 30, 2022, 9:22pm UTC](https://discourse.cmake.org/t/adding-default-build-configuration-for-scheme-in-xcode/2129/9 "2022-05-30T21:22:37Z")

</div>

CC: @kyle.edwards for awareness (proposing to expand the generators that `CMAKE_DEFAULT_BUILD_TYPE` applies to).
