changeset 709:1b04ffb2b35e

CMake: switch to GNUInstallDirs, closes #873 @1h
author David Demelier <markand@malikania.fr>
date Sat, 07 Jul 2018 10:59:19 +0200
parents 0dd4fb9dfcc8
children a17de53db29b
files CMakeLists.txt MIGRATING.md cmake/IrccdOptions.cmake cmake/function/IrccdBuildHtml.cmake cmake/function/IrccdDefineExecutable.cmake cmake/function/IrccdDefineMan.cmake cmake/function/IrccdDefinePlugin.cmake cmake/internal/sysconfig.hpp.in doc/examples/CMakeLists.txt doc/src/irccd.md libcommon/irccd/system.cpp libcommon/irccd/system.hpp systemd/CMakeLists.txt
diffstat 13 files changed, 45 insertions(+), 87 deletions(-) [+]
line wrap: on
line diff
--- a/CMakeLists.txt	Sat Jul 07 09:21:10 2018 +0200
+++ b/CMakeLists.txt	Sat Jul 07 10:59:19 2018 +0200
@@ -66,6 +66,7 @@
 set_property(GLOBAL PROPERTY USE_FOLDERS On)
 
 include(CMakeParseArguments)
+include(GNUInstallDirs)
 
 include(cmake/function/IrccdBuildHtml.cmake)
 include(cmake/function/IrccdDefineExecutable.cmake)
--- a/MIGRATING.md	Sat Jul 07 09:21:10 2018 +0200
+++ b/MIGRATING.md	Sat Jul 07 10:59:19 2018 +0200
@@ -29,12 +29,13 @@
 
   - All options are now starting with `IRCCD_` for better compatibility with
     external projects,
-  - `IRCCD_WITH_CONFDIR` has been renamed to `IRCCD_WITH_SYSCONFDIR`.
+  - CMake now use GNUInstallDirs module to specify installation paths, all
+    IRCCD_WITH_ options have been replaced by CMAKE_INSTALL_ equivalents.
 
 ### Paths
 
   - The default plugins path has been changed from **share/irccd/plugins** to
-    **libexec/irccd/plugins**.
+    **lib64/irccd**.
 
 ### Javascript API
 
--- a/cmake/IrccdOptions.cmake	Sat Jul 07 09:21:10 2018 +0200
+++ b/cmake/IrccdOptions.cmake	Sat Jul 07 10:59:19 2018 +0200
@@ -36,21 +36,6 @@
 # defined automatically from the IRCCD_PLUGINS list.
 #
 
-#
-# Options that controls both installations and the irccd runtime:
-#
-# IRCCD_WITH_BINDIR         Binary directory for irccd, irccdctl
-# IRCCD_WITH_CACHEDIR       Path where to store temporary files
-# IRCCD_WITH_CMAKEDIR       Path where to install CMake configuration files
-# IRCCD_WITH_DATADIR        Path for data files
-# IRCCD_WITH_DOCDIR         Path where to install documentation
-# IRCCD_WITH_MANDIR         Path where to install manuals
-# IRCCD_WITH_PKGCONFIGDIR   Path where to install pkg-config files
-# IRCCD_WITH_PLUGINDIR      Path where plugins must be installed
-# IRCCD_WITH_SYSCONFDIR     Path where to install configuration files
-# IRCCD_WITH_SYSTEMDDIR     Path where to install systemd unit file
-#
-
 # Manual pages on Windows are pretty useless.
 if (WIN32)
     set(DEFAULT_MAN "No")
@@ -85,22 +70,6 @@
 option(IRCCD_WITH_VERA "Enable vera++" On)
 
 #
-# Installation paths.
-# -------------------------------------------------------------------
-#
-
-set(IRCCD_WITH_BINDIR "bin" CACHE STRING "Binary directory")
-set(IRCCD_WITH_CACHEDIR "var/cache/irccd" CACHE STRING "Cache directory")
-set(IRCCD_WITH_CMAKEDIR "lib/cmake" CACHE STRING "Directory for CMake modules")
-set(IRCCD_WITH_DATADIR "share/irccd" CACHE STRING "Directory for additional data")
-set(IRCCD_WITH_DOCDIR "share/doc/irccd" CACHE STRING "Documentation directory")
-set(IRCCD_WITH_MANDIR "share/man" CACHE STRING "Man directory")
-set(IRCCD_WITH_PKGCONFIGDIR "lib/pkgconfig" CACHE STRING "Directory for pkg-config file")
-set(IRCCD_WITH_PLUGINDIR "libexec/irccd/plugins" CACHE STRING "Module prefix where to install")
-set(IRCCD_WITH_SYSCONFDIR "etc/irccd" CACHE STRING "Configuration directory")
-set(IRCCD_WITH_SYSTEMDDIR "/usr/lib/systemd/system" CACHE STRING "Absolute path where to install systemd files")
-
-#
 # Internal dependencies.
 # -------------------------------------------------------------------
 #
--- a/cmake/function/IrccdBuildHtml.cmake	Sat Jul 07 09:21:10 2018 +0200
+++ b/cmake/function/IrccdBuildHtml.cmake	Sat Jul 07 10:59:19 2018 +0200
@@ -129,7 +129,7 @@
         install(
             FILES ${output}
             COMPONENT ${HTML_COMPONENT}
-            DESTINATION ${IRCCD_WITH_DOCDIR}/${dirname}
+            DESTINATION ${CMAKE_INSTALL_DOCDIR}/${dirname}
         )
     endif ()
 
--- a/cmake/function/IrccdDefineExecutable.cmake	Sat Jul 07 09:21:10 2018 +0200
+++ b/cmake/function/IrccdDefineExecutable.cmake	Sat Jul 07 10:59:19 2018 +0200
@@ -74,7 +74,7 @@
     install(
         TARGETS ${EXE_TARGET}
         COMPONENT ${EXE_TARGET}
-        RUNTIME DESTINATION ${IRCCD_WITH_BINDIR}
+        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
     )
 
     # Put the application into a cpack group.
--- a/cmake/function/IrccdDefineMan.cmake	Sat Jul 07 09:21:10 2018 +0200
+++ b/cmake/function/IrccdDefineMan.cmake	Sat Jul 07 10:59:19 2018 +0200
@@ -34,6 +34,6 @@
         set(input ${doc_SOURCE_DIR}/man/${file}.in)
         set(output ${CMAKE_CURRENT_BINARY_DIR}/${file})
         configure_file(${input} ${output} @ONLY)
-        install(FILES ${output} DESTINATION ${IRCCD_WITH_MANDIR}/${man})
+        install(FILES ${output} DESTINATION ${CMAKE_INSTALL_MANDIR}/${man})
     endif ()
 endfunction()
--- a/cmake/function/IrccdDefinePlugin.cmake	Sat Jul 07 09:21:10 2018 +0200
+++ b/cmake/function/IrccdDefinePlugin.cmake	Sat Jul 07 10:59:19 2018 +0200
@@ -65,7 +65,7 @@
     install(
         FILES ${CMAKE_CURRENT_BINARY_DIR}/${name}
         COMPONENT ${PLG_NAME}
-        DESTINATION ${IRCCD_WITH_PLUGINDIR}
+        DESTINATION ${CMAKE_INSTALL_LIBDIR}/irccd
     )
 
     add_custom_target(
@@ -104,7 +104,7 @@
     install(
         TARGETS plugin-${PLG_NAME}
         COMPONENT ${PLG_NAME}
-        LIBRARY DESTINATION ${IRCCD_WITH_PLUGINDIR}
+        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/irccd
     )
 endfunction()
 
--- a/cmake/internal/sysconfig.hpp.in	Sat Jul 07 09:21:10 2018 +0200
+++ b/cmake/internal/sysconfig.hpp.in	Sat Jul 07 10:59:19 2018 +0200
@@ -39,8 +39,6 @@
  * ------------------------------------------------------------------
  */
 
-#define PREFIX                  "@CMAKE_INSTALL_PREFIX@"
-
 #define IRCCD_VERSION_MAJOR     @IRCCD_VERSION_MAJOR@
 #define IRCCD_VERSION_MINOR     @IRCCD_VERSION_MINOR@
 #define IRCCD_VERSION_PATCH     @IRCCD_VERSION_PATCH@
@@ -52,11 +50,12 @@
  * ------------------------------------------------------------------
  */
 
-#define IRCCD_WITH_CACHEDIR       "@IRCCD_WITH_CACHEDIR@"
-#define IRCCD_WITH_DATADIR        "@IRCCD_WITH_DATADIR@"
-#define IRCCD_WITH_BINDIR         "@IRCCD_WITH_BINDIR@"
-#define IRCCD_WITH_SYSCONFDIR     "@IRCCD_WITH_SYSCONFDIR@"
-#define IRCCD_WITH_PLUGINDIR      "@IRCCD_WITH_PLUGINDIR@"
+#define CMAKE_INSTALL_PREFIX        "@CMAKE_INSTALL_PREFIX@"
+#define CMAKE_INSTALL_LOCALSTATEDIR "@CMAKE_INSTALL_LOCALSTATEDIR@"
+#define CMAKE_INSTALL_DATADIR       "@CMAKE_INSTALL_DATADIR@"
+#define CMAKE_INSTALL_BINDIR        "@CMAKE_INSTALL_BINDIR@"
+#define CMAKE_INSTALL_LIBDIR        "@CMAKE_INSTALL_LIBDIR@"
+#define CMAKE_INSTALL_SYSCONFDIR    "@CMAKE_INSTALL_SYSCONFDIR@"
 
 #cmakedefine IRCCD_HAVE_JS
 #cmakedefine IRCCD_HAVE_SSL
--- a/doc/examples/CMakeLists.txt	Sat Jul 07 09:21:10 2018 +0200
+++ b/doc/examples/CMakeLists.txt	Sat Jul 07 10:59:19 2018 +0200
@@ -33,7 +33,7 @@
         ${examples_SOURCE_DIR}/irccd.conf.sample
         ${examples_SOURCE_DIR}/irccdctl.conf.sample
     COMPONENT examples
-    DESTINATION ${IRCCD_WITH_SYSCONFDIR}
+    DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}
 )
 
 setg(CPACK_COMPONENT_EXAMPLES_HIDDEN On)
--- a/doc/src/irccd.md	Sat Jul 07 09:21:10 2018 +0200
+++ b/doc/src/irccd.md	Sat Jul 07 10:59:19 2018 +0200
@@ -33,17 +33,17 @@
 files. For example, the files `irccd.conf` and `irccdctl.conf` will be searched
 there.
 
-  - \(W) `%APPDATA%/irccd/config`
-  - \(U) `${XDG_CONFIG_HOME}/irccd`
-  - \(U) `${HOME}/.config/irccd` (if `XDG_CONFIG_HOME` is not set)
-  - `installation-directory/etc`
+  - \(W) %APPDATA%/irccd/config
+  - \(U) ${XDG\_CONFIG\_HOME}/irccd
+  - \(U) ${HOME}/.config/irccd (if XDG\_CONFIG\_HOME is not set)
+  - CMAKE\_INSTALL\_SYSCONFDIR/irccd
 
 Examples:
 
-  - `/home/john/.config/irccd/irccd.conf`
-  - `/usr/local/etc/irccd.conf`
-  - `C:/Program Files/irccd/etc/irccd.conf`
-  - `C:/Users/john/AppData/irccd/config`
+  - /home/john/.config/irccd/irccd.conf
+  - /usr/local/etc/irccd.conf
+  - C:/Program Files/irccd/etc/irccd/irccd.conf
+  - C:/Users/john/AppData/irccd/config
 
 # Plugins
 
@@ -51,18 +51,17 @@
 are not specified by full paths.
 
   - current working directory
-  - \(W) `%APPDATA%/irccd/share/plugins`
-  - \(U) `${XDG_DATA_HOME}/irccd/plugins`
-  - \(U) `${HOME}/.local/share/irccd/plugins` (if `XDG_DATA_HOME` is not set)
-  - \(W) `installation-directory/share/plugins`
-  - \(U) `installation-directory/share/irccd/plugins`
+  - \(W) %APPDATA%/irccd/share/plugins
+  - \(U) ${XDG\_DATA\_HOME}/irccd/plugins
+  - \(U) ${HOME}/.local/share/irccd/plugins (if XDG\_DATA\_HOME is not set)
+  - CMAKE\_INSTALL\_LIBDIR/irccd (both native and Javascript)
 
 Examples:
 
-  - `/home/john/.local/share/irccd/plugins/ask.js`
-  - `/usr/local/share/irccd/plugins/ask.js`
-  - `C:/Users/john/AppDAta/irccd/share/plugins/ask.js`
-  - `C:/Program Files/irccd/share/plugins/ask.js`
+  - /home/john/.local/share/irccd/plugins/ask.js
+  - /usr/local/lib/irccd/plugins/ask.js
+  - C:/Users/john/AppData/irccd/share/plugins/ask.js
+  - C:/Program Files/irccd/lib/irccd/plugins/ask.js
 
 # Templates and formatting
 
--- a/libcommon/irccd/system.cpp	Sat Jul 07 09:21:10 2018 +0200
+++ b/libcommon/irccd/system.cpp	Sat Jul 07 10:59:19 2018 +0200
@@ -50,14 +50,6 @@
 #   include <libproc.h>
 #endif
 
-#if defined(HAVE_SETGID)
-#   include <grp.h>
-#endif
-
-#if defined(HAVE_SETGID)
-#   include <pwd.h>
-#endif
-
 #if defined(HAVE_GETLOGIN)
 #   include <unistd.h>
 #endif
@@ -87,8 +79,8 @@
  */
 boost::filesystem::path base_directory()
 {
-    static const boost::filesystem::path bindir(IRCCD_WITH_BINDIR);
-    static const boost::filesystem::path prefix(PREFIX);
+    static const boost::filesystem::path bindir(CMAKE_INSTALL_BINDIR);
+    static const boost::filesystem::path prefix(CMAKE_INSTALL_PREFIX);
 
     boost::filesystem::path path(".");
 
@@ -121,16 +113,13 @@
  *
  * Compute the system directory path for the given component.
  *
- * Use with the build options like IRCCD_WITH_CACHEDIR, IRCCD_WITH_PLUGINDIR,
- * ...
- *
  * Referenced by:
  *   - cachedir,
  *   - datadir,
  *   - sysconfigdir,
  *   - plugindir.
  */
-std::string system_directory(const std::string& component)
+boost::filesystem::path system_directory(const std::string& component)
 {
     boost::filesystem::path path(component);
 
@@ -425,7 +414,7 @@
 
 boost::filesystem::path cachedir()
 {
-    return system_directory(IRCCD_WITH_CACHEDIR);
+    return system_directory(CMAKE_INSTALL_LOCALSTATEDIR) / "cache/irccd";
 }
 
 // }}}
@@ -434,7 +423,7 @@
 
 boost::filesystem::path datadir()
 {
-    return system_directory(IRCCD_WITH_DATADIR);
+    return system_directory(CMAKE_INSTALL_DATADIR);
 }
 
 // }}}
@@ -443,7 +432,7 @@
 
 boost::filesystem::path sysconfdir()
 {
-    return system_directory(IRCCD_WITH_SYSCONFDIR);
+    return system_directory(CMAKE_INSTALL_SYSCONFDIR) / "irccd";
 }
 
 // }}}
@@ -452,7 +441,7 @@
 
 boost::filesystem::path plugindir()
 {
-    return system_directory(IRCCD_WITH_PLUGINDIR);
+    return system_directory(CMAKE_INSTALL_LIBDIR) / "irccd";
 }
 
 // }}}
--- a/libcommon/irccd/system.hpp	Sat Jul 07 09:21:10 2018 +0200
+++ b/libcommon/irccd/system.hpp	Sat Jul 07 10:59:19 2018 +0200
@@ -91,7 +91,7 @@
 
 /**
  * Get the cache directory as specified as compile time option
- * IRCCD_WITH_CACHEDIR, if the value is absolute, it is returned as-is.
+ * CMAKE_INSTALL_LOCALSTATEDIR, if the value is absolute, it is returned as-is.
  *
  * If the component is relative, it is evaluated using the binary executable
  * path.
@@ -103,7 +103,7 @@
 boost::filesystem::path cachedir();
 
 /**
- * Like cachedir but for IRCCD_WITH_DATADIR.
+ * Like cachedir but for CMAKE_INSTALL_DATADIR.
  *
  * \return the evaluated data directory.
  * \see cachedir
@@ -112,7 +112,7 @@
 boost::filesystem::path datadir();
 
 /**
- * Like cachedir but for IRCCD_WITH_SYSCONFIGDIR.
+ * Like cachedir but for CMAKE_INSTALL_SYSCONFDIR.
  *
  * \return the evaluated config directory.
  * \see cachedir
@@ -122,7 +122,7 @@
  boost::filesystem::path sysconfdir();
 
 /**
- * Like cachedir but for IRCCD_WITH_PLUGINDIR.
+ * Like cachedir but for CMAKE_INSTALL_LIBDIR.
  *
  * \return the evaluated system plugin directory.
  * \see cachedir
--- a/systemd/CMakeLists.txt	Sat Jul 07 09:21:10 2018 +0200
+++ b/systemd/CMakeLists.txt	Sat Jul 07 10:59:19 2018 +0200
@@ -19,7 +19,7 @@
 project(contrib)
 
 if (IRCCD_WITH_SYSTEMD)
-    set(PATH "${CMAKE_INSTALL_PREFIX}/${IRCCD_WITH_BINDIR}/irccd")
+    set(PATH "${CMAKE_INSTALL_FULL_BINDIR}/irccd")
 
     configure_file(
         ${CMAKE_CURRENT_SOURCE_DIR}/irccd.service
@@ -28,6 +28,6 @@
 
     install(
         FILES ${CMAKE_CURRENT_BINARY_DIR}/irccd.service
-        DESTINATION ${IRCCD_WITH_SYSTEMDDIR}
+        DESTINATION "/usr/lib/systemd/system"
     )
 endif()