How to use CMake to install

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-16 13:21:08

问题


I can build my projects successfully with CMake, but can I use it to install the results?

With Make I add the target install and call that from the command line. I cannot figure out if this is possible with CMake.

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:

  1. mkdir build
  2. cd build
  3. cmake ..
  4. cmake --build .

Here I would expect to do something like this:

  1. cmake --install .

回答1:


You can use the command cmake --build . --target install --config Debug for installation.

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.

In CMake 3.15 and newer, you can use the simpler cmake --install command to Install a Project:

cmake --install . --config Debug

It additionally supports --prefix, --component and --strip.



来源:https://stackoverflow.com/questions/48428647/how-to-use-cmake-to-install

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