LLVM works with CMake, so to enable debug mode on specific modules you either need to enable -g
flag on particular files or enable it on the whole build targets. Most likely you will need:
COMPILE_FLAGS
or COMPILE_DEFITIONS
target property (see Difference between COMPILE_FLAGS and COMPILE_OPTIONS) or COMPILE_FLAGS
source file property.
I have tried this quickly on one project, on both file- and target-levels and can confirm that it is doable.
Let's assume you have one file MySourceFile.cpp
and a build target MyTarget
. Below I am adding -hack-target
and -hack-file
to better see where this results in.
set(my_source_files
MySourceFile.cpp
)
add_library(MyTarget SHARED ${my_source_files} ...)
Adding -g flag on a target level:
get_target_property(my_target_compile_flags MyTarget COMPILE_FLAGS)
if (NOT my_target_compile_flags)
set(my_target_compile_flags "")
endif()
set_target_properties(MyTarget
PROPERTIES COMPILE_OPTIONS
"${my_target_compile_options} -g -hack-target")
Adding -g flag on a source file level:
get_source_file_property(my_source_file_compile_flags
MySource.cpp
COMPILE_FLAGS)
if (NOT my_source_file_compile_flags)
set(my_source_file_compile_flags "")
endif()
set_source_files_properties(MySource.cpp
PROPERTIES
COMPILE_FLAGS
"${my_source_file_compile_flags} -g -hack-file")
From the above lines the CMake helper functions can be made for your convenience of enabling -g
flag on the stuff you need easier.
I can speak of how this works on Ninja and Xcode:
Ninja
$ grep -ri "hack-" BuildNinja
BuildNinja//build.ninja: FLAGS = -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -fPIC -g -hack-target -std=c++11 -g -hack-file
Xcode
In Xcode -g
of a target level goes to "Generate Debug Symbols" property:

This is how flags look like:
Target one: 
File one: 