CMake 与外部项目:找不到特定文件

发布于 2024-10-09 11:57:00 字数 1037 浏览 0 评论 0原文

我们的存储库中有一些依赖库。主要部分是用cmake构建的。现在,cmake-makefiles 将构建没有 cmake 构建系统的依赖库。对于一个特定的库,应该使用一个“Makefile.squirrel”。该库的 cmakelists.txt:

cmake_minimum_required (VERSION 2.8)

include(ExternalProject)

ExternalProject_Add(squirrel,
    SOURCE_DIR "./"
    UPDATE_COMMAND ""
    BUILD_IN_SOURCE 1
    CONFIGURE_COMMAND ""
    BUILD_COMMAND "make -f ${CMAKE_CURRENT_SOURCE_DIR}/Makefile.squirrel"
    INSTALL_COMMAND ""
    )

但是,当运行 make 时,我收到一条错误消息:

[ 93%] Performing build step for 'squirrel,'
/bin/sh: make -f /home/enrico/projekte/projectname/dependencies/SQUIRREL2/Makefile.squirrel: not found
make[2]: *** [dependencies/SQUIRREL2/squirrel,-prefix/src/squirrel,-stamp/squirrel,-build] Error 127
make[1]: *** [dependencies/SQUIRREL2/CMakeFiles/squirrel,.dir/all] Error 2
make: *** [all] Error 2

/home/enrico/projekte/projectname/dependencies/SQUIRREL2/Makefile.squirrel< 上的 ls -lA /em> 表明该文件存在。

对文件路径进行硬编码(不是解决方案的选项)也不起作用。

有什么想法或提示吗?

We have some dependency libraries in our repository. The main part is build with cmake. Now the cmake-makefiles shall build the dependency libraries, which do not have a cmake build system. For one specific library there is a "Makefile.squirrel" which should be used. The cmakelists.txt for that library:

cmake_minimum_required (VERSION 2.8)

include(ExternalProject)

ExternalProject_Add(squirrel,
    SOURCE_DIR "./"
    UPDATE_COMMAND ""
    BUILD_IN_SOURCE 1
    CONFIGURE_COMMAND ""
    BUILD_COMMAND "make -f ${CMAKE_CURRENT_SOURCE_DIR}/Makefile.squirrel"
    INSTALL_COMMAND ""
    )

However, when running make I get an error message:

[ 93%] Performing build step for 'squirrel,'
/bin/sh: make -f /home/enrico/projekte/projectname/dependencies/SQUIRREL2/Makefile.squirrel: not found
make[2]: *** [dependencies/SQUIRREL2/squirrel,-prefix/src/squirrel,-stamp/squirrel,-build] Error 127
make[1]: *** [dependencies/SQUIRREL2/CMakeFiles/squirrel,.dir/all] Error 2
make: *** [all] Error 2

ls -lA on /home/enrico/projekte/projectname/dependencies/SQUIRREL2/Makefile.squirrel shows that the file exists.

Hardcoding the file path (not an option for the solution) does not work, too.

Any ideas or hints?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故乡的云 2024-10-16 11:57:00

三个观察结果:

1)您使用“松鼠”作为项目名称。 CMake 函数的参数以空格分隔,因此逗号是您给出的名称的一部分。 (可能不是您想要的。)

2)您应该使用:

SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}"

而不是

SOURCE_DIR "./"

因为“./”无论如何都是相对于该完整路径名的。

3)问题的真正根源是你的 BUILD_COMMAND 值:

BUILD_COMMAND "make -f ${CMAKE_CURRENT_SOURCE_DIR}/Makefile.squirrel"

它应该是:

BUILD_COMMAND make -f ${CMAKE_CURRENT_SOURCE_DIR}/Makefile.squirrel

如果那里有引号,那么 shell 正在寻找名为“make -f .../Makefile.squirrel”的实际文件,因为 CMake 解析参数空格,但双引号告诉 CMake“这正是包含空格的一个参数...”如果 ${CMAKE_CURRENT_SOURCE_DIR} 的扩展值中有空格,则 CMake 将正确双引号(或转义,具体取决于平台/ shell) 当它在生成的 makefile 中生成命令时执行它。

Three observations:

1) You're using "squirrel," as the name of the project. Arguments to CMake functions are space separated, so the comma is part of the name you've given. (Probably not what you want.)

2) You should use:

SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}"

rather than

SOURCE_DIR "./"

Because the "./" is simply relative to that full path name anyhow.

3) The real source of your problem is your BUILD_COMMAND value:

BUILD_COMMAND "make -f ${CMAKE_CURRENT_SOURCE_DIR}/Makefile.squirrel"

It should read:

BUILD_COMMAND make -f ${CMAKE_CURRENT_SOURCE_DIR}/Makefile.squirrel

If you have the quotes there, then the shell is looking for an actual file named "make -f .../Makefile.squirrel" because CMake parses arguments by spaces, but the double quotes tell CMake "this is exactly one argument that includes spaces..." If there are spaces in the expanded value of ${CMAKE_CURRENT_SOURCE_DIR} then CMake will properly double quote (or escape, depending on the platform/shell) it when it generates the command in its generated makefiles.

瑾夏年华 2024-10-16 11:57:00

您可以尝试编写一个使用正确的 makefile 调用 make 的脚本。只需将 CMAKE_CURRENT_SOURCE_DIR 导出到脚本读取的环境变量即可。

You could try writing a script that calls make with the correct makefile. Just export the CMAKE_CURRENT_SOURCE_DIR to an environmental variable that the script reads.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文