问题描述
我做 cmake .&&全部安装
.这有效,但安装到 /usr/local
.
I do cmake . && make all install
. This works, but installs to /usr/local
.
我需要安装到不同的前缀(例如,安装到 /usr
).
I need to install to a different prefix (for example, to /usr
).
要安装到 /usr
而不是 /usr/local
的 cmake
和 make
命令行是什么?
What is the cmake
and make
command line to install to /usr
instead of /usr/local
?
推荐答案
您可以在命令行中传入任何 CMake 变量,或使用 ccmake/cmake-gui 编辑缓存的变量.在命令行中,
You can pass in any CMake variable on the command line, or edit cached variables using ccmake/cmake-gui. On the command line,
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr . && make all install
将配置项目,构建所有目标并安装到/usr 前缀.类型 (PATH) 不是绝对必要的,但会导致基于 Qt 的 cmake-gui 显示目录选择器对话框.
Would configure the project, build all targets and install to the /usr prefix. The type (PATH) is not strictly necessary, but would cause the Qt based cmake-gui to present the directory chooser dialog.
作为评论的一些小补充清楚地表明,对某些人来说,提供简单的等效是不够的.最佳实践是使用外部构建目录,即不直接使用源代码.还要使用更通用的 CMake 语法来抽象生成器.
mkdir build && cd build && cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr .. && cmake --build . --target install --config Release
您可以看到它变得更长了,并且不再直接等效,而是以相当简洁的形式更接近最佳实践...... --config 仅用于多配置生成器(即 MSVC),被其他人忽略.
You can see it gets quite a bit longer, and isn't directly equivalent anymore, but is closer to best practices in a fairly concise form... The --config is only used by multi-configuration generators (i.e. MSVC), ignored by others.
这篇关于什么是 CMake 等效于 'configure --prefix=DIR &&使所有安装'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!