CMake删除include目录 [英] CMake remove include directory

查看:1240
本文介绍了CMake删除include目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法删除一旦找到包括目录在CMake。我发现了这里的类似问题。但答案对我来说没有多大意义。

Is there any way to remove once found include directory in CMake. I found similar question here. But answer does not make much sense for me.

我需要与上述消息的作者几乎完全相同。我有一个全局CMakeLists.txt文件,它找到所有必要的包含路径。但是在一个特定子模块的CMakeLists.txt文件中,我想隐藏或删除系统包含路径并提供替代包含路径。

I need almost exactly same as author of the above mentioned message. I have a global CMakeLists.txt file which finds all neccessary include paths. However in CMakeLists.txt file of a one particular submodule, I want to "hide" or "remove" system include path and provide alternative include path.

是的,一个解决方案可能只是简单地更改包括在提到的子模块,但此子模块是一个外部库从其他存储库,所以我不想更改其代码。

Yes, one solution could be just simply change includes in the mentioned submodule, but this submodule is an external library from other repository, so I do not want to change its code.

推荐答案

如果您能负担得起使用较新的CMake版本(2.8.11或更高版本),则优先 target_include_directories include_directories

If you can afford to use a newer CMake version (2.8.11 or higher), prefer target_include_directories over include_directories and most of your problems should disappear right away.

问题是旧的 include_directories 适用于目录属性,只有当硬盘上的文件的物理布局与不同子项目中的代码的逻辑组织完全匹配时才能实现。使用更复杂的代码库,这通常很难实现,并导致像你所描述的问题。新的 target_include_directories 取而代之工作在目标属性,意味着文件的包含目录的列表,而不是由它属于哪个子项目。这通常是考虑这种构建选项的更自然的方式。

The issue is that the old include_directories works on directory properties, which works out only if the physical layout of the files on the hard disk exactly matches the logical organisation of code in the different sub-projects. With more complex codebases, this is often difficult to achieve and leads to problems like the one you described. The new target_include_directories instead works on target properties, meaning that the list of include directories for a file is instead determined by which sub-project it belongs to. This is usually the more natural way to think about such build options.

如果你困在一个旧的CMake版本或者你必须使用 include_directories 因为其他原因(这可能是这种情况,如果问题是一个外部库,你不能更改),你可以尝试修补 include_directories设置的目录属性prop_dir / INCLUDE_DIRECTORIES.html#prop_dir / INCLUDE_DIRECTORIES.html#prop_dir%3aINCLUDE_DIRECTORIES =nofollow> INCLUDE_DIRECTORIES / code>命令,但要准备一些小小的:

If you are stuck with an older CMake version or you have to use include_directories for other reasons (which might be the case here, if the problem is an external library that you can not change), you can try tinkering with the INCLUDE_DIRECTORIES directory property that is being set by the include_directories command, but be prepared for some fiddling:

get_property(the_include_dirs DIRECTORY foo PROPERTY INCLUDE_DIRECTORIES)
string(REPLACE ${what_needs_to_go} "" new_include_dirs ${the_include_dirs})
set_property(DIRECTORY foo PROPERTY INCLUDE_DIRECTORIES ${new_include_dirs})

这篇关于CMake删除include目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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