我有一个关于CMake的问题:最近很多模块已被添加到标准安装,如GLEW或Mercurial。cmake查找模块wrt版本
但是很多的安装基础的可能有没有可用的所有新模块的旧版本,所以你不得不出货自己的版本(例如)FindGLEW.cmake
是否可以检查是否一个给定的FindXXX模块是可用的,在这种情况下使用它,否则提供一个适当的替代?或者甚至在运行时检查cmake版本(但这并不总是可靠的,并且很难维护)...?
感谢您的任何帮助。
我有一个关于CMake的问题:最近很多模块已被添加到标准安装,如GLEW或Mercurial。cmake查找模块wrt版本
但是很多的安装基础的可能有没有可用的所有新模块的旧版本,所以你不得不出货自己的版本(例如)FindGLEW.cmake
是否可以检查是否一个给定的FindXXX模块是可用的,在这种情况下使用它,否则提供一个适当的替代?或者甚至在运行时检查cmake版本(但这并不总是可靠的,并且很难维护)...?
感谢您的任何帮助。
的CMake的的include
命令w.r.t模块的默认搜索行为是:
文件名称为
<modulename>.cmake
首先搜索的CMAKE_MODULE_PATH
,然后在CMake的模块目录。
(还有更多了一点 - 看到的文档或运行cmake --help-command include
)
你问的似乎是与此相反;首先检查CMake模块目录中的官方模块,如果不存在,请回退以使用您自己的模块。
假设你的模块在${CMAKE_SOURCE_DIR}/my_cmake_modules
,你可以做反向的CMake的默认行为:
set(CMAKE_MODULE_PATH ${CMAKE_ROOT}/Modules ${CMAKE_SOURCE_DIR}/my_cmake_modules)
如果你的名字你自己的模块正是按照官方的,那么这应该实现自己的目标。如果要回复到正常CMake的行为在你的脚本以后,你可以这样做:
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/my_cmake_modules)
作为一种可能的替代上述方案中,我发现这个cmake的政策
CMP0017
Prefer files from the CMake module directory when including from
there.
Starting with CMake 2.8.4, if a cmake-module shipped with CMake (i.e.
located in the CMake module directory) calls include() or
find_package(), the files located in the the CMake module directory
are preferred over the files in CMAKE_MODULE_PATH. This makes sure
that the modules belonging to CMake always get those files included
which they expect, and against which they were developed and tested.
In call other cases, the files found in CMAKE_MODULE_PATH still take
precedence over the ones in the CMake module directory. The OLD
behaviour is to always prefer files from CMAKE_MODULE_PATH over files
from the CMake modules directory.
This policy was introduced in CMake version 2.8.4. CMake version
2.8.9 warns when the policy is not set and uses OLD behavior. Use the
cmake_policy command to set it to OLD or NEW explicitly.
希望这有助于。
这就是我一直在寻找的行为!谢谢 – koda