如何使用CMake安装 [英] How to use CMake to install
问题描述
我可以使用CMake成功构建项目,但是可以使用它来安装结果吗?
I can build my projects successfully with CMake, but can I use it to install the results?
使用 Make
,我添加目标 install
并从命令行调用它.我不知道使用CMake是否可以做到这一点.
With Make
I add the target install
and call that from the command line. I cannot figure out if this is possible with CMake.
最终目标是以平台可移植的方式安装静态库,动态库和相应的头文件.我如何想象它会如何工作:在Linux上,复制到/usr/include
和/usr/lib
.在Windows上,它可能是用户提供的包含include和lib文件夹的文件夹.
The final goal is to install a static library, dynamic library and corresponding header files in a platform-portable way. How I imagine it would work: On Linux, copy to /usr/include
and /usr/lib
. On Windows it would probably be a user-provided folder with an include and lib folder.
安装规则暗示可能会发生这种情况.但是我该如何使用呢?
The install rule suggests that something like this is possible. But how do I actually use it?
目前,我正在执行以下操作:
Currently I do the following:
- mkdir构建
- cd版本
- cmake ..
- cmake --build.
在这里,我希望做这样的事情:
Here I would expect to do something like this:
- cmake --install.
推荐答案
您可以使用命令 cmake --build.--target install --config调试
进行安装.
You can use the command cmake --build . --target install --config Debug
for installation.
CMake的构建工具模式支持在这种情况下感兴趣的其他参数.您可以选择通过-target
选项构建的目标,通过-config
选项构建的配置,并通过-
选项.请参阅文档( 构建工具模式 ).
CMake's build tool mode supports further arguments that are of interest in this case.
You can select the target to build by --target
option, the configuration to build by --config
option, and pass arguments to the underlying build tool by means of the --
option. See the documentation (Build Tool Mode) for the build-tool-mode.
在CMake 3.15和更高版本中,您可以使用更简单的 cmake --install
命令来
In CMake 3.15 and newer, you can use the simpler cmake --install
command to Install a Project:
cmake --install.--config调试
它还支持-前缀
,-component
和-strip
.
这篇关于如何使用CMake安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!