cmake 在哪里寻找 .cmake 脚本?
Where does cmake look for .cmake scripts?
我正在尝试 execute_process
在 cmake
中这样
execute_process(COMMAND ${CMAKE_COMMAND} -P myScript.cmake
这仅在文件 myScript.cmake
位于同一工作目录中时有效。
三个相关问题:
cmake
是否有标准位置来查找 .cmake
脚本?
- 有没有我可以定义的
cmake
变量来告诉 cmake
去哪里找?或
- 我是否应该始终提供脚本的完整路径(即
-P ${PATH_VAR}/myScript.cmake
)?
Does cmake
have a standard location to look for .cmake
scripts?
为了execute_process
, no. The find_XXX
commands (e.g. find_file
) and include
,尽管如此。
Is there a cmake
variable I can define to tell cmake
where to look?
同样,execute_process
,没有。对于find_xxx
或include
,您可以设置变量CMAKE_MODULE_PATH
。
Should I always give a full path to the script (i.e., -P ${PATH_VAR}/myScript.cmake
)?
这是个不错的选择;通过完整路径不会留下不确定的余地。但是,您也可以使用相对路径。 execute_process
的默认工作目录是 CMAKE_BINARY_DIR
,因此您可以将路径传递给相对于该目录的脚本。
或者,您可以在 execute_process
调用中将 WORKING_DIRECTORY
指定为完整路径或相对于 CMAKE_BINARY_DIR
.
如果您觉得您的脚本位于标准位置,您可以考虑 "finding" 首先调用 find_file
。如果找到,这将生成脚本的完整路径,并且该变量可以在您的 execute_process
调用中使用。
我正在尝试 execute_process
在 cmake
中这样
execute_process(COMMAND ${CMAKE_COMMAND} -P myScript.cmake
这仅在文件 myScript.cmake
位于同一工作目录中时有效。
三个相关问题:
cmake
是否有标准位置来查找.cmake
脚本?- 有没有我可以定义的
cmake
变量来告诉cmake
去哪里找?或 - 我是否应该始终提供脚本的完整路径(即
-P ${PATH_VAR}/myScript.cmake
)?
Does
cmake
have a standard location to look for.cmake
scripts?
为了execute_process
, no. The find_XXX
commands (e.g. find_file
) and include
,尽管如此。
Is there a
cmake
variable I can define to tellcmake
where to look?
同样,execute_process
,没有。对于find_xxx
或include
,您可以设置变量CMAKE_MODULE_PATH
。
Should I always give a full path to the script (i.e.,
-P ${PATH_VAR}/myScript.cmake
)?
这是个不错的选择;通过完整路径不会留下不确定的余地。但是,您也可以使用相对路径。 execute_process
的默认工作目录是 CMAKE_BINARY_DIR
,因此您可以将路径传递给相对于该目录的脚本。
或者,您可以在 execute_process
调用中将 WORKING_DIRECTORY
指定为完整路径或相对于 CMAKE_BINARY_DIR
.
如果您觉得您的脚本位于标准位置,您可以考虑 "finding" 首先调用 find_file
。如果找到,这将生成脚本的完整路径,并且该变量可以在您的 execute_process
调用中使用。