在ExternalProject_Add命令中INSTALL_DIR有什么用? [英] What is INSTALL_DIR useful for in ExternalProject_Add command?
问题描述
我不了解ExternalProject_Add命令中INSTALL_DIR的用法.我尝试使用它,但是它似乎不起作用.这是使用快速编译的Eigen库的CMakeLists.txt的示例:
I don't understand the usage of INSTALL_DIR in ExternalProject_Add command. I try to use it but it does not seem to work. Here is an example of a CMakeLists.txt, using Eigen library which compiles quickly:
cmake_minimum_required (VERSION 2.6)
project (example CXX)
include(ExternalProject)
include(ProcessorCount)
set(CMAKE_VERBOSE_MAKEFILE ON)
ProcessorCount(N)
if(NOT N EQUAL 0)
set(CMAKE_BUILD_FLAGS -j${N})
endif()
ExternalProject_Add
(
mylib
PREFIX myprefix
DOWNLOAD_COMMAND wget http://bitbucket.org/eigen/eigen/get/3.2.4.tar.gz && tar xvzf 3.2.4.tar.gz -C mylib --strip-components=1
)
我选择了以下项目层次结构:
I chose the following project hierarchy:
project
CMakeLists.txt
build/
在构建存储库中,输入:
From build repository, I type:
cmake ..
make
安装过程失败,并显示以下消息:
The installation process fails with the following message:
文件无法创建目录:/usr/local/include/eigen3.
可能需要管理权限.
file cannot create directory: /usr/local/include/eigen3.
Maybe need administrative privileges.
据我了解,这意味着我需要在配置步骤中定义一个前缀":
As far as I understand, it means that I need to define a "prefix" during the configuration step:
cmake -D CMAKE_INSTALL_PREFIX=$INSTALL_DIR ..
但是,已经在ExternalProject_Add命令中定义了INSTALL_DIR变量.但是,通过添加
But, the INSTALL_DIR variable is already defined in the ExternalProject_Add command. However, I get the same error when I modify the value of INSTALL_DIR by adding
INSTALL_DIR myprefix/src/install
在ExternalProject_Add命令中.
in the ExternalProject_Add command.
那么,INSTALL_DIR有什么用? 我在做什么错了?
So, what is INSTALL_DIR useful for? What am I doing wrong?
当然,我知道如何提供自己的配置命令来添加前缀并解决问题.但这不是我的问题.我的问题是:如果必须这样做,INSTALL_DIR的目的是什么?
Of course, I know how to provide my own configuration command to add a prefix and solve the problem. But it is not my question. My question is: if I have to do that, what is the purpose of INSTALL_DIR?
推荐答案
From what I found in this discussion https://www.mail-archive.com/cmake@cmake.org/msg51663.html (scroll to the end of the page to navigate through the thread messages) it is indeed pretty common thing to use CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/contrib
此外,通过潜入ExternalProject.cmake
模块,我发现设置该目录的唯一作用是CMake将在执行其他操作之前创建在INSTALL_DIR中指定的目录.
Furthermore, lurking through the ExternalProject.cmake
module I found out that the only effect setting this directory has is that CMake will create directory specified in INSTALL_DIR before doing anything else.
此外,它将设置您可以通过ExternalProject_Get_Property(${project_name} install_dir)
命令收集的属性.
Also, it will set the property that you can gather through ExternalProject_Get_Property(${project_name} install_dir)
command.
差不多了.
//自CMake 3.2.2版起
// As of CMake version 3.2.2
这篇关于在ExternalProject_Add命令中INSTALL_DIR有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!