对于cmake“include”命令,文件和模块有什么区别? [英] For the cmake "include" command, what is the difference between a file and a module?

查看:155
本文介绍了对于cmake“include”命令,文件和模块有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用一些我不想构建的库作为使用它们的每个项目的一部分。一个很容易理解的例子是LLVM,它有78个静态库。即使有cmake代码在每个cmakefile中查找和导入这些代码也是过多的。

I use some libraries that I don't want built as part of every project that uses them. A very understandable example is LLVM, which has 78 static libraries. Even having the cmake code to find and import these in every cmakefile is excessive.

显而易见的解决方案似乎是使用include命令, cmake脚本的大块写入* .cmake文件,并设置一个CMAKE_MODULE_PATH环境变量。

The obvious solution seems to be to use the "include" command, and to factor out relevant chunks of cmake script into *.cmake files, and set up a CMAKE_MODULE_PATH environment variable.

除了它只是plain不起作用。 Cmake没有找到我在include命令中指定的文件。

Except it just plain doesn't work. Cmake doesn't find the file I specify in the include command.

在偶然的时候,我甚至尝试在环境变量中指定路径几种方式 - 反斜杠,一次使用正斜杠... - 每次重新启动命令提示符并检查环境变量是否存在和正确。

On the off-chance, I even tried specifying the path in the environment variable several ways - once with backslashes, once with forward slashes... - and I restarted the command prompt each time and checked that the environment variable was present and correct.

在cmake手册中某种意味着文件不同于模块 - 只有模块获得自动添加扩展和搜索路径处理。但是没有什么区别的解释。我猜想缺少的扩展可能就足够了(就像标准模块一样),但显然不是这样。

In the cmake manual, it kind of implies that a "file" is different from a "module" - only a module gets the automatic add-the-extension-and-search-the-path treatment. But there is no explanation of what the difference is. I guessed that the missing extension might be enough (as with standard modules) but clearly it isn't.

搜索模块的手册没有什么帮助这个词似乎是重载的。例如,一个模块也是一个使用LoadLibrary / dl_open加载的动态库。

Searching the manual for "module" isn't much help as the word seems to be overloaded. For example, a module is also a dynamic library loaded using LoadLibrary/dl_open.

任何人都可以解释文件和模块之间的区别是什么,我创建了自己的模块,以便cmake include命令可以找到并使用它?

Can anyone explain what the difference is between a file and a module in this context, and how I create my own module so that the cmake include command can find and use it?

我在Windows上使用cmake 2.8.1。

I'm using cmake 2.8.1 on Windows.

EDIT

我很相信这里的问题是不了解cmake应该如何工作。我想我应该应该做的是写一些 find_package 可以使用。

I'm pretty confident that the problem here is not understanding how cmake is supposed to work. I think what I should be doing is writing something that find_package can work with.

推荐答案

我相信一个CMake'module'只是一个文件,可以使用 find_package 指令。也就是说,当你运行 find_package(Module)时,它会在MODULE_PATH中搜索一个名为 FindModule.cmake

I believe that a CMake 'module' is simply a file that can be used with the find_package directive. That is, when you run find_package(Module), it searches for a file in the MODULE_PATH that is named FindModule.cmake.

也就是说,如果你包含一个没有扩展名的文件,它也将搜索你的MODULE_PATH file.cmake 。在我正在开发的CMake项目中,我有一个非常相似的目录结构,你的建议。

That said, if you include a file without the extension, it too will search through your MODULE_PATH for that file.cmake. In a CMake project I'm working on, I have a very similar directory structure as to what you propose.

+ root/
  + CMakeLists.txt
  + cmake/
  | + FindMatlab.cmake
  | + TestInline.cmake
  | + stdint.cmake
  + src/
  + include/

在CMakeLists中。 txt我有:

In CMakeLists.txt I have:

set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
find_package (Matlab) # runs FindMatlab.cmake
include(TestInline) # defines a macro:
test_inline (CONFIG_C_INLINE)
include(stdint) # simply executes flat CMake code

也许你的问题是你正在尝试从环境中定义模块路径。相反,请尝试在 中附加 非常CMakeList你试图访问的模块/文件。

Perhaps your issue is that you are trying to define the Module path from the environment. Instead, try to simply append to it within the very CMakeList you try to access the modules/files.

这篇关于对于cmake“include”命令,文件和模块有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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