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:
Here I would expect to do something like this:
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
.
You can use the install
command on your CMakeLists that will generate installation rules for your project. A basic example is shown bellow but check the cmake documentation if you need something more complex.
project (Test)
add_executable(test main.cpp)
install(TARGETS test DESTINATION bin)
Then after generate the makefiles you can ust type sudo make install
and the test application will be installed on system bin folder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With