我想用安装目标生成Makefile,安装到/ usr而不是默认的/ usr / local。假设构建目录在源子目录中完成,我执行:
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr ..
CMakeCache.txt包含:CMAKE_INSTALL_PREFIX:PATH=/usr
(好吗?)
现在我执行:
make make install
所有文件仍安装到usr / local。有什么问题?
编辑: 任何CMakeLists.txt项目文件中都没有CMAKE_INSTALL_PREFIX。 在运行cmake之前,我从输出目录中删除了所有内容。 CMakeLists.txt中的install指令如下所示:
install(TARGETS mylibrary DESTINATION lib)
答案 0 :(得分:97)
那应该是(见docs):
cmake -DCMAKE_INSTALL_PREFIX=/usr ..
答案 1 :(得分:20)
使用此变量有两种方法:
将其作为命令行参数传递,就像Job提到的那样:
cmake -DCMAKE_INSTALL_PREFIX=< install_path > ..
在CMakeLists.txt
:
SET(CMAKE_INSTALL_PREFIX < install_path >)
但是请记得将它放在 PROJECT(< project_name>)
命令之前,否则它将无效!
答案 2 :(得分:5)
但请记住将它放在BEFORE PROJECT(&lt; project_name&gt;)命令之下, 否则它将无法工作!
我使用cmake的第一周 - 经过几年的GNU autotools - 所以我还在学习(比编写m4宏更好),但我认为在设置项目之后修改CMAKE_INSTALL_PREFIX 是更好的地方。
的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")
首次运行(无缓存)
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
第二次运行
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
如果我弄错了,请告诉我,我有很多学习要做的事情。这很有趣。