Installation (“Deployment”)#
“Prefix”: Where Everything Comes Together#
Multiple projects usually are installed into one prefix ⟶
/usrSubdirectories
bin/: executableslib/(orlib64): librariesinclude/: header files (usually comes with-devor-develdistro packages, as do static libraries)share/: data files(more)
Build parameter:
CMAKE_INSTALL_PREFIX(default:/usr/local)
$ cmake -DCMAKE_INSTALL_PREFIX=/tmp/install /path/to/source
Installing Targets#
cmake_minimum_required(VERSION 3.16)
project(Demo)
add_library(hello hello.c hello-name.c)
set_property(TARGET hello PROPERTY VERSION "1")
install(TARGETS hello DESTINATION lib) # <-- lands in <prefix>/lib/
install(FILES hello.h hello-name.h
DESTINATION include) # <-- lands in <prefix>/include/
add_executable(hello-first hello-first.c)
target_link_libraries(hello-first hello)
install(TARGETS hello-first DESTINATION bin) # <-- lands in <prefix>/bin/
add_executable(hello-second hello-second.c)
target_link_libraries(hello-second hello)
install(TARGETS hello-second DESTINATION bin) # <-- lands in <prefix>/bin/
Doing The Installation (make install)#
$ cmake -DCMAKE_INSTALL_PREFIX=/tmp/install /home/jfasch/work/jfasch-home/trainings/material/soup/cmake/07-install-basic
$ make
$ make install
...
Install the project...
-- Install configuration: ""
-- Installing: /tmp/install/lib/libhello.a
-- Installing: /tmp/install/bin/hello-first
-- Installing: /tmp/install/bin/hello-second
$ tree /tmp/install/
/tmp/install/
├── bin
│ ├── hello-first
│ └── hello-second
└── lib
└── libhello.a