CMake with XCode target, generate debug symbols setting ignored for Release config
Asked Answered
H

2

7

I am trying to generate a dSYM file for my Release configuration. In my CMake config, I have:

if (CMAKE_GENERATOR STREQUAL "Xcode")
  # generate debug symbols in a .dsym file for release mode
  set(CMAKE_XCODE_ATTRIBUTE_GCC_GENERATE_DEBUGGING_SYMBOLS[variant=Release] 
      "YES")
  set(CMAKE_XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT[variant=Release] 
      "dwarf-with-dsym")
  # strip symbols from final executable
  set(CMAKE_XCODE_ATTRIBUTE_DEPLOYMENT_POSTPROCESSING[variant=Release] 
      "YES")
endif()

The debug information format and deployment postprocessing are both picked up for the Release configuration. However, Generate Debug Symbols in the XCode interface / GCC_GENERATE_DEBUGGING_SYMBOLS in the xxx.xcodeproj/project.pbxproj file are set toNO for the Release configuration.

Generate debug symbols off in Release

Removing the [variant=Release] restriction has no effect on the Release config. If I manually turn on the setting in Release, I am getting the desired outcome. How can I get CMake to create the Xcode project with this setting on for the Release config?

I do not want to use RelWithDebInfo because it has a lower optimization setting (-O2 instead of -O3). I want the .dSYM file for debugging crashes from the field.

Hui answered 6/4, 2018 at 14:37 Comment(0)
S
3

You'll have to resort to modifiying the CMAKE_CXX_FLAGS although I would recommend using target_compile_options with generator expressions:

target_compile_options(your_exe PRIVATE
    $<$<CXX_COMPILER_ID:Clang>:-g>
    )
Starveling answered 8/4, 2018 at 3:30 Comment(3)
This did the trick, although my case is for common configuration so I used add_compile_options with appropriate generator expressions.Hui
I have tried including this snippet (substituting with my target of course) and also adding in the OP snippet, but in both cases Generate Debug Symbols for Release remains No. You mention modifying CMAKE_CXX_FLAGS. Is that necessary as well as the target_compile_options?Indoors
@PaulMasri-Stone sorry, I can't say. I have not worked directly with CMake for quite a while now. The CMake Discourse might be of help if you post your question there: discourse.cmake.orgStarveling
M
0

Use a post build script using add_custom_command that runs xcrun dsymutil $<TARGET_FILE:your_target> -o $<TARGET_DIR:your_target>/blah.dSYM.

This has a downside that this script will always be run even if nothing changes in the code. Using it as a step of Xcode build process could eliminate that redundant run. Benefit is that all generators can use it.

Muckraker answered 29/4, 2021 at 19:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.