From 1bb545e3f95178aa024f791f6e01510c9d421440 Mon Sep 17 00:00:00 2001 From: Oliver Giles Date: Sat, 20 Jun 2020 15:59:35 +1200 Subject: [PATCH] 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. --- CMakeLists.txt | 16 +++++++++------- README.md | 2 +- docker/Dockerfile | 2 +- etc/{laminar.service => laminar.service.in} | 2 +- pkg/centos7-x86_64.sh | 2 +- pkg/centos8-x86_64.sh | 2 +- pkg/debian10-amd64.sh | 2 +- pkg/debian10-armhf.sh | 2 +- 8 files changed, 16 insertions(+), 14 deletions(-) rename etc/{laminar.service => laminar.service.in} (79%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 82de4ce..c58f45e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}) diff --git a/README.md b/README.md index 867dae8..3e85973 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/docker/Dockerfile b/docker/Dockerfile index cd18eec..378ae1b 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -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 && \ diff --git a/etc/laminar.service b/etc/laminar.service.in similarity index 79% rename from etc/laminar.service rename to etc/laminar.service.in index 1b44b37..c2ebd01 100644 --- a/etc/laminar.service +++ b/etc/laminar.service.in @@ -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 diff --git a/pkg/centos7-x86_64.sh b/pkg/centos7-x86_64.sh index 773eb54..b72e6f4 100755 --- a/pkg/centos7-x86_64.sh +++ b/pkg/centos7-x86_64.sh @@ -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 diff --git a/pkg/centos8-x86_64.sh b/pkg/centos8-x86_64.sh index a6781b1..a2f41c1 100755 --- a/pkg/centos8-x86_64.sh +++ b/pkg/centos8-x86_64.sh @@ -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 diff --git a/pkg/debian10-amd64.sh b/pkg/debian10-amd64.sh index 064c04a..127ed36 100755 --- a/pkg/debian10-amd64.sh +++ b/pkg/debian10-amd64.sh @@ -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 diff --git a/pkg/debian10-armhf.sh b/pkg/debian10-armhf.sh index 2f55933..6010e3e 100755 --- a/pkg/debian10-armhf.sh +++ b/pkg/debian10-armhf.sh @@ -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