What is INSTALL_DIR useful for in ExternalProject_Add command?

試著忘記壹切 提交于 2019-12-05 13:11:44

问题


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:

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

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

in the ExternalProject_Add command.

So, what is INSTALL_DIR useful for? What am I doing wrong?

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?


回答1:


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

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.

Also, it will set the property that you can gather through ExternalProject_Get_Property(${project_name} install_dir) command.

And that's pretty much it.

// As of CMake version 3.2.2



来源:https://stackoverflow.com/questions/29533159/what-is-install-dir-useful-for-in-externalproject-add-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!