用GIT存储库对CMAKE ExternalProject_ADD的正确用法是什么?

发布于 12-05 06:45 字数 349 浏览 1 评论 0原文

我想学习如何使用CMAKE外部项目模块下载和编译外部库。

例如,可以说我想从sfml库https://github.com/laurentgomila/sfml.git下载源。我尝试使用以下内容。不幸的是,我无法弄清楚为什么在源被克隆后没有编译:(

EXTERNALPROJECT_ADD(sfml
PREFIX ${sfml_PREFIX}

GIT_REPOSITORY https://github.com/LaurentGomila/SFML.git

INSTALL_DIR ${sfml_INSTALL_DIR}
CMAKE_ARGS ${sfml_CMAKE_ARGS})

I would like to learn how to download and compile external libraries using the cmake external project module.

For example, lets say that I wanted to download the source from the SFML library https://github.com/LaurentGomila/SFML.git and compile it. I have tried using something like the following. Unfortunately, I can't figure out why it is not compiling after the source gets cloned :(

EXTERNALPROJECT_ADD(sfml
PREFIX ${sfml_PREFIX}

GIT_REPOSITORY https://github.com/LaurentGomila/SFML.git

INSTALL_DIR ${sfml_INSTALL_DIR}
CMAKE_ARGS ${sfml_CMAKE_ARGS})

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

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

发布评论

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

评论(1

美人如玉2024-12-12 06:45:46

也许您的变量不包含您认为它们包含的值...仔细检查 sfml_* 变量的值。还要仔细检查 CMake 变量 GIT_EXECUTABLE 是否具有您在包含ExternalProject后所期望的值...

以下 CMakeLists.txt 文件在我的 Mac 上使用 CMake 2.8.5 工作:

cmake_minimum_required(VERSION 2.8)
project(SfmlBuilder)
include(ExternalProject)

set(sfml_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/sfml")
set(sfml_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/sfml")
set(sfml_CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${sfml_INSTALL_DIR})

message("sfml_PREFIX='${sfml_PREFIX}'")
message("sfml_INSTALL_DIR='${sfml_INSTALL_DIR}'")
message("sfml_CMAKE_ARGS='${sfml_CMAKE_ARGS}'")
message("GIT_EXECUTABLE='${GIT_EXECUTABLE}'")

ExternalProject_Add(sfml
  PREFIX ${sfml_PREFIX}
  GIT_REPOSITORY https://github.com/LaurentGomila/SFML.git
  INSTALL_DIR ${sfml_INSTALL_DIR}
  CMAKE_ARGS ${sfml_CMAKE_ARGS}
)

它在安装过程中失败,权限被拒绝,因为我没有以 sudo 的方式运行“make”,它尝试安装到绝对路径“/Library/Frameworks/sndfile.framework”

也是另一条建议。我注意到您正在将“/Applications/CMake 2.8-5.app/Contents/share/cmake-2.8/Modules/FindSFML.cmake”直接安装到 CMake 安装中...通常不鼓励这样做,因为对 CMake 的修改如果用户卸载并重新安装 CMake,安装可能会消失。或者干脆升级到另一个 CMake。或者使用也安装在计算机上的第二个或第三个 CMake。

您应该在自己的安装中创建一个项目配置文件,CMake 可以使用其内置规则在标准位置查找包。有关项目配置文件的完整详细信息,请阅读 CMake find_package 文档的细则:

http://cmake.org/cmake/help/cmake-2-8-docs.html#command:find_package

Perhaps your variables do not contain the values you think they contain... Double check the value of your sfml_* variables. Also double check that the CMake variable GIT_EXECUTABLE has the value you expect after including ExternalProject...

The following CMakeLists.txt file works for me on my Mac using CMake 2.8.5:

cmake_minimum_required(VERSION 2.8)
project(SfmlBuilder)
include(ExternalProject)

set(sfml_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/sfml")
set(sfml_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/sfml")
set(sfml_CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${sfml_INSTALL_DIR})

message("sfml_PREFIX='${sfml_PREFIX}'")
message("sfml_INSTALL_DIR='${sfml_INSTALL_DIR}'")
message("sfml_CMAKE_ARGS='${sfml_CMAKE_ARGS}'")
message("GIT_EXECUTABLE='${GIT_EXECUTABLE}'")

ExternalProject_Add(sfml
  PREFIX ${sfml_PREFIX}
  GIT_REPOSITORY https://github.com/LaurentGomila/SFML.git
  INSTALL_DIR ${sfml_INSTALL_DIR}
  CMAKE_ARGS ${sfml_CMAKE_ARGS}
)

It fails during the install for me with a permission denied because I did not run "make" as sudo, and it tries to install into the absolute path "/Library/Frameworks/sndfile.framework"

One other piece of advice, too. I notice you're installing "/Applications/CMake 2.8-5.app/Contents/share/cmake-2.8/Modules/FindSFML.cmake" directly into the CMake installation... That is generally discouraged, as that modification to the CMake installation is likely to disappear if the user uninstalls and re-installs CMake. Or simply upgrades to another CMake. Or uses a 2nd or 3rd CMake that is also installed on the computer.

You should instead create a project config file in your own installation, that CMake can find with it's built-in rules for finding packages at standard locations. Read the fine print of the CMake find_package documentation for the full details on project config files:

http://cmake.org/cmake/help/cmake-2-8-docs.html#command:find_package

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