How to use CMAKE_INSTALL_PREFIX

匿名 (未验证) 提交于 2019-12-03 01:30:01

问题:

I want to generate Makefile with install target, making installation to /usr instead of default /usr/local. Assuming that build directory is done in the source subdirectory, I execute:

cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr ..

CMakeCache.txt contains: CMAKE_INSTALL_PREFIX:PATH=/usr (OK?)

Now I execute:

 make make install 

All files are still installed to usr/local. What is wrong?

Edit: There is no CMAKE_INSTALL_PREFIX in any of CMakeLists.txt project files. Before running cmake, I delete everything from the output directory. install directives in CMakeLists.txt look like:

install(TARGETS mylibrary DESTINATION lib)

回答1:

That should be (see the docs):

cmake -DCMAKE_INSTALL_PREFIX=/usr .. 


回答2:

There are two ways to use this variable:

  • passing it as a command line argument just like Job mentioned:

    cmake -DCMAKE_INSTALL_PREFIX= ..

  • assigning value to it in CMakeLists.txt:

    SET(CMAKE_INSTALL_PREFIX )

    But do remember to place it BEFORE PROJECT() command, otherwise it will not work!



回答3:

But do remember to place it BEFORE PROJECT() command, otherwise it will not work!

My first week of using cmake - after some years of GNU autotools - so I am still learning (better then writing m4 macros), but I think modifying CMAKE_INSTALL_PREFIX after setting project is the better place.

CMakeLists.txt

cmake_minimum_required (VERSION 2.8)  set (CMAKE_INSTALL_PREFIX /foo/bar/bubba) message("CIP = ${CMAKE_INSTALL_PREFIX} (should be /foo/bar/bubba") project (BarkBark) message("CIP = ${CMAKE_INSTALL_PREFIX} (should be /foo/bar/bubba") set (CMAKE_INSTALL_PREFIX /foo/bar/bubba) message("CIP = ${CMAKE_INSTALL_PREFIX} (should be /foo/bar/bubba") 

First run (no cache)

CIP = /foo/bar/bubba (should be /foo/bar/bubba -- The C compiler identification is GNU 4.4.7 -- etc, etc,... CIP = /usr/local (should be /foo/bar/bubba CIP = /foo/bar/bubba (should be /foo/bar/bubba -- Configuring done -- Generating done 

Second run

CIP = /foo/bar/bubba (should be /foo/bar/bubba CIP = /foo/bar/bubba (should be /foo/bar/bubba CIP = /foo/bar/bubba (should be /foo/bar/bubba -- Configuring done -- Generating done 

Let me know if I am mistaken, I have a lot of learning to do. It's fun.



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