CMake EXTERNALPROJECT_ADD与Git存储库的正确用法是什么? [英] What is the correct usage of CMake EXTERNALPROJECT_ADD with a Git repository?
问题描述
我想学习如何使用cmake外部项目模块下载和编译外部库。
I would like to learn how to download and compile external libraries using the cmake external project module.
例如,假设我想从SFML库下载源代码 https://github.com/LaurentGomila/SFML.git
并编译它。我试过使用像下面的东西。不幸的是,我不知道为什么它是不是编译后源克隆:(
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})
推荐答案
也许你的变量不包含你认为的值它们包含...仔细检查你的sfml_ *变量的值。还要仔细检查CMake变量GIT_EXECUTABLE是否包含你期望的值,包括ExternalProject ...
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...
下面的CMakeLists.txt文件适用于我在Mac上使用CMake 2.8.5:
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}
)
在安装过程中,由于我没有运行makesudo,所以拒绝了权限,安装到绝对路径/Library/Frameworks/sndfile.framework
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"
另一条建议。我注意到你正在安装/应用程序/ CMake 2.8-5.app/Contents/share/cmake-2.8/Modules/FindSFML.cmake直接进入CMake安装...通常不鼓励,因为对CMake的修改如果用户卸载并重新安装CMake,安装可能会消失。或者简单地升级到另一个CMake。或使用也安装在计算机上的第二或第三个CMake。
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.
您应该在自己的安装中创建一个项目配置文件,CMake可以找到它 - 在标准位置查找包的规则。阅读CMake find_package文档的详细信息,了解项目配置文件的完整详细信息:
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
这篇关于CMake EXTERNALPROJECT_ADD与Git存储库的正确用法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!