2017-02-24 64 views
1

我想在LLVM的源代码中调试单个文件。因为用调试信息构建整个项目会浪费大量空间。 LLVM使用CMake作为其构建系统。如何将debuginfo添加到单个文件?使用CMake将DebugInfo添加到单个文件中

+0

我想的[get_source_file_property]该组合(https://cmake.org/cmake/help/v3.0/command/get_source_file_property.html )和[set_source_files_properties](https://cmake.org/cmake/help/v3.0/command/set_source_files_properties.html)修补[COMPILE_FLAGS](https://cmake.org/cmake/help/v3.0/prop_sf /COMPILE_FLAGS.html)可以完成这项工作。 –

回答

0

这里是“对单个文件设置debuginfo软标志”跨平台版本:

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}") 

请注意,通常的CMake也激活调试信息一起降低了优化级别。

参考

相关问题