CMake和PC-Lint Plus-如何将CMake的包含目录列表传递给Lint? [英] CMake and PC-Lint Plus - how do I pass CMake's include directory list to Lint?

查看:580
本文介绍了CMake和PC-Lint Plus-如何将CMake的包含目录列表传递给Lint?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将PC-Lint Plus纳入我的cmake项目,主要是根据

I'm trying to incorporate PC-Lint Plus into my cmake project, mainly per PC-Lint needs a list of all include paths for the files to be scanned. How to get a list of all include paths recursively needed by a target in CMake?.

PC-Lint正在被调用,但由于并非所有包含都在PC-Lint调用中,因此最终死掉了.

PC-Lint is getting invoked, but ends up dying because not all the includes are in the PC-Lint invocation.

我将上面的链接转储到Lint.cmake中,并将其包含在我的顶级CMake文件中.在我的项目文件中,我添加了:

I dumped the above link into a Lint.cmake, and included that in my top level CMake file. In my project file, I added:

if(COMMAND add_pc_lint)
add_pc_lint(moded ${SRC_FILES})
endif(COMMAND add_pc_lint)

所以我希望这些行:

function(add_pc_lint target)
    get_directory_property(lint_include_directories INCLUDE_DIRECTORIES)
    # let's get those elephants across the alps
    # prepend each include directory with "-i"; also quotes the directory
    set(lint_include_directories_transformed)
    foreach(include_dir ${lint_include_directories})
        list(APPEND lint_include_directories_transformed -i"${include_dir}")
    endforeach(include_dir)

将包含目录列表从INCLUDE_DIRECTORIES中拉出.

to pull the include directory list out of INCLUDE_DIRECTORIES.

如果我添加:

message(STATUS "********************************************")
message(STATUS "Include directories - ${lint_include_directories}")
message(STATUS "********************************************")
message(STATUS "********************************************")
message(STATUS "INCLUDE_DIRECTORIES - ${INCLUDE_DIRECTORIES}")
message(STATUS "********************************************")

在直接位于foreach循环上方的

上,lint_include_directoriesINCLUDE_DIRECTORIES似乎都为空.

directly above the foreach loop, lint_include_directories and INCLUDE_DIRECTORIES both appear to be empty.

我该怎么做才能从CMake获取包含目录的完整列表(包括从target_link_librariestarget_include_directories)并提供给PC-Lint Plus?

What do I need to do to get the full list of include directories, including from target_link_libraries and target_include_directories, from CMake to give to PC-Lint Plus?

推荐答案

编辑:我已经更新了

EDIT: I have updated the CMake PC-Lint script to account for the issue described below in my response here.

PC-上的文档棉绒的使用似乎是针对旧的CMake,而不是基于目标的现代CMake. add_pc_lint函数从CMake目录属性中获取包含目录编译定义.如果您的项目有以下调用,则会填充这些目录属性:

The documentation on PC-Lint usage appears to be catered for old CMake, not the target-based modern CMake. The add_pc_lint function grabs the include directories and compile definitions from CMake directory properties. These directories properties will be populated if your project has calls such as:

  • include_directories()
  • add_definitions()
  • include_directories()
  • add_definitions()

没有这些命令(在现代CMake中实际上不应该使用),add_pc_lint函数可能无法找到您期望的所有包含目录和编译定义.

Without these commands (which really should not be used in modern CMake), the add_pc_lint function likely won't find all the include directories and compile definitions you expect.

在现代CMake中,当您使用诸如此类的命令时,包含目录编译定义会存储为 target 的属性. :

In modern CMake, the include directories and compile definitions are stored as properties of a target instead, when you use commands such as these:

  • target_include_directories()
  • target_compile_definitions()
  • target_include_directories()
  • target_compile_definitions()

在这种情况下,您必须修改add_pc_lint函数以从目标(而不是目录)获取属性.因此,从此更改add_pc_lint函数的顶部:

In this case, you have to modify the add_pc_lint function to grab the properties from the target, not the directory. So, change the top of the add_pc_lint function from this:

function(add_pc_lint target)
    get_directory_property(lint_include_directories INCLUDE_DIRECTORIES)
    get_directory_property(lint_defines COMPILE_DEFINITIONS)

对此:

function(add_pc_lint target)
    get_target_property(lint_include_directories ${target} INCLUDE_DIRECTORIES)
    get_target_property(lint_defines ${target} COMPILE_DEFINITIONS)

这篇关于CMake和PC-Lint Plus-如何将CMake的包含目录列表传递给Lint?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆