Browse Source

added cmake install invocation

Max von Buelow 6 years ago
parent
commit
5922cc6769
2 changed files with 20 additions and 11 deletions
  1. 9 1
      CMakeLists.txt
  2. 11 10
      README.md

+ 9 - 1
CMakeLists.txt

@@ -2,6 +2,9 @@ cmake_minimum_required(VERSION 3.0)
 
 project(MilterFrom C)
 
+option(WITH_SYSTEMD "Install Systemd unit files" ON)
+set(SYSTEMD_UNITDIR "${CMAKE_INSTALL_PREFIX}/lib/systemd/system" CACHE PATH "Systemd unit directory")
+
 list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
 
 find_package(Threads REQUIRED)
@@ -9,4 +12,9 @@ find_package(Milter REQUIRED)
 
 add_executable(milterfrom src/milterfrom.c)
 target_include_directories(milterfrom PRIVATE ${Milter_INCLUDE_DIRS})
-target_link_libraries(milterfrom ${Milter_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
+target_link_libraries(milterfrom ${Milter_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
+
+install(TARGETS milterfrom DESTINATION bin)
+if(NOT WIN32 AND WITH_SYSTEMD)
+	install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/milterfrom.service DESTINATION ${SYSTEMD_UNITDIR})
+endif()

+ 11 - 10
README.md

@@ -12,15 +12,22 @@ This code is beta. It would be great if someone who has more experience with lib
 * git cmake make gcc
 * libmilter1.0.1 libmilter-dev
 
-## Build
+## Build and install
 ```bash
 mkdir build
 cd $_
-cmake ..
+cmake -DWITH_SYSTEMD=ON ..
 make
+make install # this installs the executable and the Systemd unit
+systemctl daemon-reload
 ```
 
-## Install (on a Systemd environment)
+If you wish to install to a custom directory:
+```bash
+cmake -DWITH_SYSTEMD=ON -DCMAKE_INSTALL_PREFIX=/tmp/your/path ..
+```
+
+## Configure (on a Systemd and Postfix environment)
 Add a user:
 ```bash
 groupadd milterfrom
@@ -30,12 +37,6 @@ mkdir /var/spool/postfix/milterfrom
 chown milterfrom:milterfrom /var/spool/postfix/milterfrom
 ```
 
-Move the binary and the service file:
-```bash
-cp milterfrom /usr/local/bin
-cp ../systemd/milterfrom.service /etc/systemd/system/
-```
-
 Configure postfix to use the milter:
 ```
 postconf -e "smtpd_milters = unix:/milterfrom/milterfrom$([[ $(postconf -h smtpd_milters) != "" ]] && echo -n ", " && postconf -h smtpd_milters)"
@@ -86,7 +87,7 @@ closed
 ## Run
 To start the daemon directly, run the following (Remove the `-d` to run in foreground):
 ```bash
-./milterfrom -u milterfrom -g milterfrom -m 002 -d -p /var/run/milterfrom.pid -s /var/spool/postfix/milterfrom/milterfrom
+milterfrom -u milterfrom -g milterfrom -m 002 -d -p /var/run/milterfrom.pid -s /var/spool/postfix/milterfrom/milterfrom
 ```
 
 ## License