cmake在哪里寻找.cmake脚本? [英] Where does cmake look for .cmake scripts?
问题描述
我正在尝试像这样在 cmake
中执行 execute_process
I am trying to execute_process
in cmake
like this
execute_process(COMMAND ${CMAKE_COMMAND} -P myScript.cmake
这仅在文件 myScript.cmake
在同一工作目录中时有效。
This only works if the file, myScript.cmake
is in the same working directory.
三个相关问题:
-
cmake
是否有标准位置要查找.cmake
脚本吗? - 是否可以定义一个
cmake
变量来告诉cmake
在哪里看?或 - 我应该始终给出脚本的完整路径(即
-P $ { PATH_VAR} /myScript.cmake
)?
- Does
cmake
have a standard location to look for.cmake
scripts? - Is there a
cmake
variable I can define to tellcmake
where to look? or - Should I always give a full path to the script (i.e.,
-P ${PATH_VAR}/myScript.cmake
)?
推荐答案
cmake
是否有标准位置来查找.cmake
脚本?
Does
cmake
have a standard location to look for.cmake
scripts?
对于 execute_process
,否。 find_XXX
命令(例如> find_file
)和 include
可以。
For execute_process
, no. The find_XXX
commands (e.g. find_file
) and include
do though.
我是否可以定义
cmake
变量来告诉cmake
在哪里查看?
Is there a
cmake
variable I can define to tellcmake
where to look?
再次,对于 execute_process
,否 find_xxx
或 include
,您可以设置变量 CMAKE_MODULE_PATH
。
Again, for execute_process
, no. For find_xxx
or include
, you can set the variable CMAKE_MODULE_PATH
.
我应该始终给出脚本的完整路径(即
-P $ {PATH_VAR} /myScript.cmake
) ?
这是一个不错的选择;通过完整的路径不会有不确定的余地,但是,您也可以摆脱相对路径。 execute_process
的默认工作目录是 CMAKE_BINARY_DIR
,因此您可以相对于脚本传递路径。
That's a good option; passing a full path leaves no room for uncertainty. However, you can get away with a relative path too. The default working directory for execute_process
is the CMAKE_BINARY_DIR
, so you can pass the path to the script relative to that.
或者,您可以在 execute_process
调用中指定 WORKING_DIRECTORY
作为完整路径或相对于 CMAKE_BINARY_DIR
。
Alternatively you can specify the WORKING_DIRECTORY
in the execute_process
call either as a full path or relative to the CMAKE_BINARY_DIR
.
如果您认为脚本位于标准位置,则可以考虑先使用 find_file
。这将找到脚本的完整路径,并且可以在您的 execute_process
调用中使用该变量。
If you feel your script is in a standard location, you could consider "finding" it first using a call to find_file
. This would yield the full path to the script if found and that variable can be used in your execute_process
call.
这篇关于cmake在哪里寻找.cmake脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!