I want to debug a single file in the source code of LLVM. Because building the whole project with debug info will waste a great amount of space. LLVM uses CMake as its build system. How can I add debuginfo to a single file?
Asked
Active
Viewed 171 times
2
-
I would suppose that combination of [get_source_file_property](https://cmake.org/cmake/help/v3.0/command/get_source_file_property.html) and [set_source_files_properties](https://cmake.org/cmake/help/v3.0/command/set_source_files_properties.html) patching [COMPILE_FLAGS](https://cmake.org/cmake/help/v3.0/prop_sf/COMPILE_FLAGS.html) could do the job. – Stanislav Pankevich Feb 24 '17 at 15:41
1 Answers
1
Here is a cross-platform version of "setting a debuginfo flags on a single file":
cmake_minimum_required(VERSION 2.8)
project(DebugInfoForSingleFile)
separate_arguments(_flags_release UNIX_COMMAND "${CMAKE_CXX_FLAGS_RELEASE}")
separate_arguments(_flags_with_dbg_info UNIX_COMMAND "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
list(REMOVE_ITEM _flags_with_dbg_info ${_flags_release})
string(REPLACE ";" " " _flags_with_dbg_info "${_flags_with_dbg_info}")
file(WRITE main.cpp "int main() { return 0; }")
add_executable(${PROJECT_NAME} main.cpp)
set_source_files_properties(main.cpp PROPERTIES COMPILE_FLAGS "${_flags_with_dbg_info}")
Please note that CMake normally also reduces the optimization level together with activating debug info.
Reference