11

I'm using cmake to generate a C++ Xcode project, but the debug information never gets generated. I have to manually select 'DWARF with dSym file' from the build setting every time I have generated the project with cmake.

Using 'SET (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")' makes no difference.

I'm also pretty sure it used to work correctly with XCode 6 (now using Xcode 7)

Arno Duvenhage
  • 1,910
  • 17
  • 36

1 Answers1

17

Solution

You can use CMAKE_XCODE_ATTRIBUTE_* variable.

To set DWARF you can use:

set(CMAKE_XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT "dwarf")

To set DWARF with dSYM File:

set(CMAKE_XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT "dwarf-with-dsym")

Hints

Name of the Xcode attribute and values can be found in "Quick Help" section (see square brackered [DEBUG_INFORMATION_FORMAT], [dwarf] and [dwarf-with-dsym]):

enter image description here

  • double thanks, I fixed some other naggling settings as well :-) – Arno Duvenhage Feb 05 '16 at 14:35
  • 3
    Note that using 'SET (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")' is still required together with setting CMAKE_XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT – Borys Verebskyi Apr 26 '18 at 11:29
  • 4
    Also note that best practices these days dictate to set properties directly on the target. In this case it would be done like so, without the CMAKE prefix: set_target_properties(${TARGETNAME} PROPERTIES XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT "dwarf-with-dsym") – qdin Jan 09 '19 at 14:16
  • this only works if Xcode generator is used, no? With Ninja + Clang it does not work for me – IceFire Jan 19 '23 at 20:25