How to get dSYM files when building a CMake project with the Ninja generator on macOS?

220 Views Asked by At

I noticed that if you build a CMake project on macOS using -GNinja, you will not get dSYM files on debug builds.

Are there any clever ways to get dSYM files when using the ninja generator?

You won't get them if you do set(CMAKE_XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT "dwarf-with-dsym") because that's XCode only.

One way around this I tried was to override cmake's add_library/ add_executable and insert a custom command to call dsymutil post build. However, this is undesirable, as it doesn't seem to work when your project uses IMPORTED libraries.

1

There are 1 best solutions below

0
On

This is an open issue on the CMake issue tracker since 2020. The issue description offers the following snippet, which may be an acceptable workaround until CMake natively supports dsymutil.

I'm not sure how this interacts with IMPORTED libraries.

find_program(DSYMUTIL_PROGRAM dsymutil)
if (DSYMUTIL_PROGRAM)
  foreach(lang C CXX)
    foreach(var LINK_EXECUTABLE CREATE_SHARED_LIBRARY)
      set(CMAKE_${lang}_${var} "${CMAKE_${lang}_${var}}" "${DSYMUTIL_PROGRAM} <TARGET>")
    endforeach()
  endforeach()
endif()