在ubuntu上的cmake项目中,我试图使用CPPClean为所有目标查找未使用/不必要的头。然而,我不知道如何将它集成到我的项目中。
CPPClean的用法是
cppclean --include-path=directory1 --include-path=directory2 <path>我想有一个目标,我可以建立,确实运行can在每一个目标,我标记。类似于:
add_library(foo_target
src/foo.cpp include/foo.hpp)
target_include_directories(foo_target PUBLIC include)
target_link_libraries(foo_target PUBLIC bar)
cppclean(foo_target) #this function adds the target to some kind of global list?然后,执行the的构建目标必须执行以下操作
对于所有被标记的目标:
的包含dir。
如果这是一种下降的方式,有什么想法吗?我将如何实现这最后一部分?特别是如何让一个目标执行(未知)数量的命令?
发布于 2021-12-14 14:22:45
如果这是一种下降的方式,
有什么想法吗?
好的。
我将如何实现最后一部分?
好吧,就像您指定的那样,您将在目标"main dir“上运行cppclean命令,其中包含以前点的dirs。
,尤其是如何让一个目标执行(未知)数量的命令?
“目标”代表要做的事情。foo_target构建了目标,它不会做任何其他事情。用add_custom_target()定义另一个目标。
function(cppclean name target)
# get all the include dirs of the target
get_target_properties....
# get all the include dirs of the libs that are linked to
recursively, get target_properties for each library target links to
See appriopriate stackoverflow thread.
# (which we can assume is installed on the system)
find_program(cppclean NAMES cppclean REQUIRED)
# run the cppclean commmand on the target main dir with the include dirs that we just determined
add_custom_target(${name}
COMMAND ${cppclean} args constructed from above
)
endfunction()在cmake中的应用
您还可以生成compile_commands.json,并从中提取每个可执行文件的包含路径。
https://stackoverflow.com/questions/70349679
复制相似问题