在CMake中列出include_directories [英] Listing include_directories in CMake

查看:1149
本文介绍了在CMake中列出include_directories的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个cmake build,其中我正在寻找一堆依赖,即我有很多实例:

I have a cmake build in which I'm searching for a bunch of dependencies, i.e. I have many instances of:

FIND_PACKAGE(SomePackage)
if(SOMEPACKAGE_FOUND)
  include_directories(${SOMEPACKAGE_INCLUDE_DIR})
  link_libraries(${SOMEPACKAGE_LIBRARIES})
endif(SOMEPACKAGE_FOUND)

现在,我想添加一个自定义命令来构建一个预编译头文件,但是为了做到这一点,我需要知道所有的路径通过我的 include_directories 调用添加。如何获得这些目录的列表(最好使用正确的-I / path / to /目录格式),以便我可以将它们添加到我的自定义命令?

Now, I want to add a custom command to build a precompiled header file, but to do this I need to know all of the paths added by my include_directories calls. How can I get a list of these directories (preferably with the proper -I/path/to/directory format) so that I can add them to my custom command?

推荐答案

您可以使用get_property命令检索目录属性的值
INCLUDE_DIRECTORIES

You can use the get_property command to retrieve the value of the directory property INCLUDE_DIRECTORIES

像这样:

get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
foreach(dir ${dirs})
  message(STATUS "dir='${dir}'")
endforeach()

此目录属性的值仅跟踪之前在相同CMakeLists文件中发生的include_directories命令,或者跟踪在父CMakeLists文件中从先前出现的继承的include_directories命令。如果你的find_package和include_directories命令分散在许多子目录中,这将是一个具有挑战性的问题。

The value of this directory property only tracks the include_directories commands that have occurred previously in the same CMakeLists file, or that have been inherited from previous occurrences in a parent CMakeLists file. If your find_package and include_directories commands are scattered about throughout many subdirectories, this becomes a challenging issue.

如果你达到这一点,你可以考虑覆盖include_directories命令自己的函数或宏,并跟踪传递给它自己的值。

If you get to that point, you may consider overriding the include_directories command with your own function or macro and track the values passed to it yourself. Or, simply accumulate them in a global property or an internal cache variable alongside each call to include_directories.

请参阅这里的文档:

http://cmake.org/cmake/help/v2.8.8 /cmake.html#command:get_property

http://cmake.org/cmake/help/v2.8.8/cmake.html#prop_dir:INCLUDE_DIRECTORIES

这篇关于在CMake中列出include_directories的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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