# \[macOS\] CMake refuses to do a debug build

**URL:** https://discourse.cmake.org/t/macos-cmake-refuses-to-do-a-debug-build/3807
**Category:** Usage
**Tags:** os:macos
**Created:** [July 21, 2021, 3:24pm UTC](https://discourse.cmake.org/t/macos-cmake-refuses-to-do-a-debug-build/3807 "2021-07-21T15:24:42Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Adam\_Sindelar](https://discourse.cmake.org/user_avatar/discourse.cmake.org/adam_sindelar/32/1654_2.png) [@Adam\_Sindelar](https://discourse.cmake.org/u/Adam_Sindelar)
#### Post date: [July 21, 2021, 3:24pm UTC](https://discourse.cmake.org/t/macos-cmake-refuses-to-do-a-debug-build/3807/1 "2021-07-21T15:24:42Z")

</div>

Hi there!

I’m trying to get cmake to pass -g2 to clang on macOS, and having tried everything in the man page and on Stack Overflow, I’m at a loss. Nothing I do seems to change its mind about whether its doing a Release or Debug build.

I’d really appreciate any pointers.

```auto
# How I'm setting up the build directory
adam@PrimeMover physics % cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug                                                                  
-- Failed to find LLVM FileCheck
-- git version: v0.0.0-dirty normalized to 0.0.0
-- Version: 1.5.4
-- Performing Test HAVE_THREAD_SAFETY_ATTRIBUTES -- failed to compile
-- Performing Test HAVE_STD_REGEX -- success
-- Performing Test HAVE_GNU_POSIX_REGEX -- failed to compile
-- Performing Test HAVE_POSIX_REGEX -- success
-- Performing Test HAVE_STEADY_CLOCK -- success
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/adam/SpacePhysics/physics/build

# How I'm running the build
cmake --build build --config Debug

# Another thing I've tried is putting this in CMakeLists.txt
set(CMAKE_BUILD_TYPE Debug)

```

None of the above seems to have any effect on the Makefiles cmake generates or what CXX\_DEFINES and CXX\_FLAGS are set during the build - all of them seem to be just whatever values clang has by default.

Any idea why this might be? I’m sure I’m missing something stupid.

---

<div class="post-metadata">

### Author: ![Adam\_Sindelar](https://discourse.cmake.org/user_avatar/discourse.cmake.org/adam_sindelar/32/1654_2.png) [@Adam\_Sindelar](https://discourse.cmake.org/u/Adam_Sindelar)
#### Post date: [July 21, 2021, 7:52pm UTC](https://discourse.cmake.org/t/macos-cmake-refuses-to-do-a-debug-build/3807/2 "2021-07-21T19:52:59Z")

</div>

By the way, I say I “just” want to pass -g2, but this is a bigger problem. cmake is also not, for example, declaring NDEBUG for release builds. It seems none of the configs have any effect on macOS build environments.

---

<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: [July 21, 2021, 9:57pm UTC](https://discourse.cmake.org/t/macos-cmake-refuses-to-do-a-debug-build/3807/3 "2021-07-21T21:57:31Z")

</div>

That sounds to me like the project might be overwriting variables like `CMAKE_CXX_FLAGS_DEBUG` and `CMAKE_CXX_FLAGS_RELEASE`. To be able to help any further, please reduce your project down to a minimal case that still reproduces your problem. More often than not, just trying to do that will uncover the problem.

---

<div class="post-metadata">

### Author: ![scivision](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@scivision](https://discourse.cmake.org/u/scivision)
#### Post date: [July 22, 2021, 5:54am UTC](https://discourse.cmake.org/t/macos-cmake-refuses-to-do-a-debug-build/3807/4 "2021-07-22T05:54:50Z")

</div>

I use CMake with many macOS users, and we use build types including Release, Debug, and RelWithDebInfo and haven’t had this kind of problem. We use clang, GCC, Intel compilers. Our project binary run times are often quite affected by the -O flags so I hear quickly if something isn’t working in that regard.

As Craig is saying, unfortunately some projects decide to get creative with forcing build settings. They might be including some file that force sets cache variable for CMAKE\_BUILD\_TYPE

---

<div class="post-metadata">

### Author: ![Adam\_Sindelar](https://discourse.cmake.org/user_avatar/discourse.cmake.org/adam_sindelar/32/1654_2.png) [@Adam\_Sindelar](https://discourse.cmake.org/u/Adam_Sindelar)
#### Post date: [July 22, 2021, 7:20pm UTC](https://discourse.cmake.org/t/macos-cmake-refuses-to-do-a-debug-build/3807/5 "2021-07-22T19:20:29Z")

</div>

You were right, a nested CMakeLists.txt was overriding the build type. Sorry for the noise.
