Building Release on macOS with separate debug symbols file

I’m trying to figure out how to build Release config that also include debug symbols in a separate file on macOS. How is that controlled via CMake?

There’s an issue tracking this request.

1 Like

What can one do with current CMake?

I tried to set these flags manually:

function(SetBuildDefaultSettings)
  if(WIN32)
    SetBuildDefaultSettingsWin32()
  endif()
endfunction()

function(SetBuildDefaultSettingsWin32)
  # CMake's Release configuration for Windows isn't ideal.
  # Ref: https://gitlab.kitware.com/cmake/cmake/-/issues/20812

  # Default optimizations,
  # disable assert,
  # generate PDB,
  # enable function-level linking.
  set(CMAKE_CXX_FLAGS_RELEASE "/O2 /DNDEBUG /Zi /Gy")

  # Generate PDB,
  # disable incremental linking,
  # remove unreferenced sections,
  # merge identical sections.
  set(LINKER_RELEASE_OPTIONS "/DEBUG /INCREMENTAL:NO /OPT:REF /OPT:ICF")
  set(CMAKE_EXE_LINKER_FLAGS_RELEASE ${LINKER_RELEASE_OPTIONS})
  set(CMAKE_MODULE_LINKER_FLAGS_RELEASE ${LINKER_RELEASE_OPTIONS})
  set(CMAKE_SHARED_LINKER_FLAGS_RELEASE ${LINKER_RELEASE_OPTIONS})
endfunction()

I have tried setting early in the root CMakeLists.txt file, and after project, but it appear that the variables is overridden…?

Functions make variable scopes, so the value is updated in the function and then dropped when the function returns.

Aaah! Duh!

Ok, I removed the functions and used only include and now I see the values change.

When should this be set though? Before or after project()? And if I want to use this with vcpkg, how would I ensure vcpkg also use the same settings?

I’ve not used build chain files before, but is this something that is appropriate (ideal?) for that?

I think the value only “really” matters at the end of the directory scope (which is what targets get when they query for it).