且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

cmake在哪里寻找.cmake脚本?

更新时间:2022-05-23 23:47:38


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 tell cmake 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.