cmake: more appropriate use of CMAKE_INSTALL_PREFIX

CMAKE_INSTALL_PREFIX is supposed to be used to set an install prefix
of e.g. /usr or /usr/local. Because we need to install files to /etc,
we had been requiring CMAKE_INSTALL_PREFIX=/ and installing using
relative paths.

The best practice method is to install to /etc using absolute paths,
and then allow CMAKE_INSTALL_PREFIX to set where the final binaries
actually go. Now that it actually has some meaning, the systemd
service is generated to incorporate that path.

Those wishing to use "make install" to install laminar to a subdir
should use "make DESTDIR=path/to/subdir install" and NOT modify
CMAKE_INSTALL_PREFIX.

Documentation and packaging scripts updated accordingly.
pull/137/head
Oliver Giles 4 years ago
parent de948c149e
commit 1bb545e3f9

@ -116,12 +116,14 @@ if(BUILD_TESTS)
target_link_libraries(laminar-tests ${GTEST_LIBRARY} capnp-rpc capnp kj-http kj-async kj pthread sqlite3 z)
endif()
set(SYSTEMD_UNITDIR lib/systemd/system CACHE PATH "Path to systemd unit files")
set(BASH_COMPLETIONS_DIR usr/share/bash-completion/completions CACHE PATH "Path to bash completions directory")
set(ZSH_COMPLETIONS_DIR usr/share/zsh/site-functions CACHE PATH "Path to zsh completions directory")
install(TARGETS laminard RUNTIME DESTINATION usr/sbin)
install(TARGETS laminarc RUNTIME DESTINATION usr/bin)
install(FILES etc/laminar.service DESTINATION ${SYSTEMD_UNITDIR})
install(FILES etc/laminar.conf DESTINATION etc)
set(SYSTEMD_UNITDIR /lib/systemd/system CACHE PATH "Path to systemd unit files")
set(BASH_COMPLETIONS_DIR /usr/share/bash-completion/completions CACHE PATH "Path to bash completions directory")
set(ZSH_COMPLETIONS_DIR /usr/share/zsh/site-functions CACHE PATH "Path to zsh completions directory")
install(TARGETS laminard RUNTIME DESTINATION sbin)
install(TARGETS laminarc RUNTIME DESTINATION bin)
install(FILES etc/laminar.conf DESTINATION /etc)
install(FILES etc/laminarc-completion.bash DESTINATION ${BASH_COMPLETIONS_DIR} RENAME laminarc)
install(FILES etc/laminarc-completion.zsh DESTINATION ${ZSH_COMPLETIONS_DIR} RENAME _laminarc)
configure_file(etc/laminar.service.in laminar.service @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/laminar.service DESTINATION ${SYSTEMD_UNITDIR})

@ -24,7 +24,7 @@ Then compile and install laminar with:
```bash
git clone https://github.com/ohwgiles/laminar.git
cd laminar
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr
make -j4
sudo make install
```

@ -28,7 +28,7 @@ RUN apk add --no-cache --virtual .build -X http://dl-3.alpinelinux.org/alpine/ed
zlib-dev \
rapidjson-dev && \
cd /build/laminar && \
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/ && \
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr && \
make -j4 && \
make install && \
apk del .build && \

@ -5,7 +5,7 @@ After=network.target
[Service]
User=laminar
EnvironmentFile=-/etc/laminar.conf
ExecStart=/usr/sbin/laminard
ExecStart=@CMAKE_INSTALL_PREFIX@/sbin/laminard
[Install]
WantedBy=multi-user.target

@ -54,7 +54,7 @@ Lightweight Continuous Integration Service
%prep
%build
cmake3 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/ -DSYSTEMD_UNITDIR=%{_unitdir} %{_sourcedir}/laminar-$VERSION
cmake3 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr -DSYSTEMD_UNITDIR=%{_unitdir} %{_sourcedir}/laminar-$VERSION
pwd
make

@ -51,7 +51,7 @@ Lightweight Continuous Integration Service
%prep
%build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/ -DSYSTEMD_UNITDIR=%{_unitdir} %{_sourcedir}/laminar-$VERSION
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr -DSYSTEMD_UNITDIR=%{_unitdir} %{_sourcedir}/laminar-$VERSION
pwd
make

@ -17,7 +17,7 @@ docker run --rm -i -v $SOURCE_DIR:/laminar:ro -v $OUTPUT_DIR:/output $DOCKER_TAG
mkdir /build
cd /build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/ -DZSH_COMPLETIONS_DIR=/usr/share/zsh/functions/Completion/Unix /laminar
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr -DZSH_COMPLETIONS_DIR=/usr/share/zsh/functions/Completion/Unix /laminar
make -j4
mkdir laminar
make DESTDIR=laminar install/strip

@ -30,7 +30,7 @@ cmake \
-DCMAKE_OBJCOPY=/usr/bin/arm-linux-gnueabihf-objcopy \
-DCMAKE_STRIP=/usr/bin/arm-linux-gnueabihf-strip \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/ \
-DCMAKE_INSTALL_PREFIX=/usr \
-DZSH_COMPLETIONS_DIR=/usr/share/zsh/functions/Completion/Unix \
/laminar
make -j4

Loading…
Cancel
Save