From 24af712931cdc2138553534b1a0c3c81120604d6 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Wed, 3 Jul 2019 10:10:18 +0200 Subject: [PATCH] cmake: Use GNUInstallDirs for installation Signed-off-by: Andreas Schneider Reviewed-by: Anderson Toshiyuki Sasaki --- CMakeLists.txt | 13 ++- ConfigureChecks.cmake | 5 +- cmake/Modules/DefineInstallationPaths.cmake | 109 -------------------- config.h.cmake | 4 - include/libssh/CMakeLists.txt | 2 +- libssh.pc.cmake | 4 +- src/CMakeLists.txt | 15 ++- 7 files changed, 16 insertions(+), 136 deletions(-) delete mode 100644 cmake/Modules/DefineInstallationPaths.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index b89c11f7..077b9b7d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,9 +29,9 @@ set(LIBRARY_SOVERSION "4") # add definitions include(DefinePlatformDefaults) -include(DefineInstallationPaths) include(DefineOptions.cmake) include(CPackConfig.cmake) +include(GNUInstallDirs) include(CompilerChecks.cmake) @@ -117,7 +117,7 @@ install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libssh.pc DESTINATION - ${LIB_INSTALL_DIR}/pkgconfig + ${CMAKE_INSTALL_LIBDIR}/pkgconfig COMPONENT pkgconfig ) @@ -136,18 +136,17 @@ write_basic_package_version_file(libssh-config-version.cmake # libssh-config.cmake configure_package_config_file(${PROJECT_NAME}-config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake - INSTALL_DESTINATION ${CMAKE_INSTALL_DIR}/${PROJECT_NAME} - PATH_VARS INCLUDE_INSTALL_DIR LIB_INSTALL_DIR) + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} + PATH_VARS CMAKE_INSTALL_FULL_INCLUDEDIR CMAKE_INSTALL_FULL_LIBDIR) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake DESTINATION - ${CMAKE_INSTALL_DIR}/${PROJECT_NAME} + ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} COMPONENT - devel -) + devel) if (WITH_EXAMPLES) add_subdirectory(examples) diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake index 643a0a4b..39e30a4f 100644 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -9,10 +9,7 @@ include(TestBigEndian) set(PACKAGE ${PROJECT_NAME}) set(VERSION ${PROJECT_VERSION}) -set(DATADIR ${DATA_INSTALL_DIR}) -set(LIBDIR ${LIB_INSTALL_DIR}) -set(PLUGINDIR "${PLUGIN_INSTALL_DIR}-${LIBRARY_SOVERSION}") -set(SYSCONFDIR ${SYSCONF_INSTALL_DIR}) +set(SYSCONFDIR ${CMAKE_INSTALL_SYSCONFDIR}) set(BINARYDIR ${CMAKE_BINARY_DIR}) set(SOURCEDIR ${CMAKE_SOURCE_DIR}) diff --git a/cmake/Modules/DefineInstallationPaths.cmake b/cmake/Modules/DefineInstallationPaths.cmake deleted file mode 100644 index 88e08cad..00000000 --- a/cmake/Modules/DefineInstallationPaths.cmake +++ /dev/null @@ -1,109 +0,0 @@ -if (UNIX OR OS2) - IF (NOT APPLICATION_NAME) - MESSAGE(STATUS "${PROJECT_NAME} is used as APPLICATION_NAME") - SET(APPLICATION_NAME ${PROJECT_NAME}) - ENDIF (NOT APPLICATION_NAME) - - # Suffix for Linux - SET(LIB_SUFFIX - CACHE STRING "Define suffix of directory name (32/64)" - ) - - SET(EXEC_INSTALL_PREFIX - "${CMAKE_INSTALL_PREFIX}" - CACHE PATH "Base directory for executables and libraries" - ) - SET(SHARE_INSTALL_PREFIX - "${CMAKE_INSTALL_PREFIX}/share" - CACHE PATH "Base directory for files which go to share/" - ) - SET(DATA_INSTALL_PREFIX - "${SHARE_INSTALL_PREFIX}/${APPLICATION_NAME}" - CACHE PATH "The parent directory where applications can install their data") - - # The following are directories where stuff will be installed to - SET(BIN_INSTALL_DIR - "${EXEC_INSTALL_PREFIX}/bin" - CACHE PATH "The ${APPLICATION_NAME} binary install dir (default prefix/bin)" - ) - SET(SBIN_INSTALL_DIR - "${EXEC_INSTALL_PREFIX}/sbin" - CACHE PATH "The ${APPLICATION_NAME} sbin install dir (default prefix/sbin)" - ) - SET(LIB_INSTALL_DIR - "${EXEC_INSTALL_PREFIX}/lib${LIB_SUFFIX}" - CACHE PATH "The subdirectory relative to the install prefix where libraries will be installed (default is prefix/lib)" - ) - SET(LIBEXEC_INSTALL_DIR - "${EXEC_INSTALL_PREFIX}/libexec" - CACHE PATH "The subdirectory relative to the install prefix where libraries will be installed (default is prefix/libexec)" - ) - SET(PLUGIN_INSTALL_DIR - "${LIB_INSTALL_DIR}/${APPLICATION_NAME}" - CACHE PATH "The subdirectory relative to the install prefix where plugins will be installed (default is prefix/lib/${APPLICATION_NAME})" - ) - SET(INCLUDE_INSTALL_DIR - "${CMAKE_INSTALL_PREFIX}/include" - CACHE PATH "The subdirectory to the header prefix (default prefix/include)" - ) - - set(CMAKE_INSTALL_DIR - "${LIB_INSTALL_DIR}/cmake" - CACHE PATH "The subdirectory to install cmake config files") - - SET(DATA_INSTALL_DIR - "${DATA_INSTALL_PREFIX}" - CACHE PATH "The parent directory where applications can install their data (default prefix/share/${APPLICATION_NAME})" - ) - SET(HTML_INSTALL_DIR - "${DATA_INSTALL_PREFIX}/doc/HTML" - CACHE PATH "The HTML install dir for documentation (default data/doc/html)" - ) - SET(ICON_INSTALL_DIR - "${DATA_INSTALL_PREFIX}/icons" - CACHE PATH "The icon install dir (default data/icons/)" - ) - SET(SOUND_INSTALL_DIR - "${DATA_INSTALL_PREFIX}/sounds" - CACHE PATH "The install dir for sound files (default data/sounds)" - ) - - SET(LOCALE_INSTALL_DIR - "${SHARE_INSTALL_PREFIX}/locale" - CACHE PATH "The install dir for translations (default prefix/share/locale)" - ) - - SET(XDG_APPS_DIR - "${SHARE_INSTALL_PREFIX}/applications/" - CACHE PATH "The XDG apps dir" - ) - SET(XDG_DIRECTORY_DIR - "${SHARE_INSTALL_PREFIX}/desktop-directories" - CACHE PATH "The XDG directory" - ) - - SET(SYSCONF_INSTALL_DIR - "${EXEC_INSTALL_PREFIX}/etc" - CACHE PATH "The ${APPLICATION_NAME} sysconfig install dir (default prefix/etc)" - ) - SET(MAN_INSTALL_DIR - "${SHARE_INSTALL_PREFIX}/man" - CACHE PATH "The ${APPLICATION_NAME} man install dir (default prefix/man)" - ) - SET(INFO_INSTALL_DIR - "${SHARE_INSTALL_PREFIX}/info" - CACHE PATH "The ${APPLICATION_NAME} info install dir (default prefix/info)" - ) -else() - # Same same - set(BIN_INSTALL_DIR "bin" CACHE PATH "-") - set(SBIN_INSTALL_DIR "sbin" CACHE PATH "-") - set(LIB_INSTALL_DIR "lib${LIB_SUFFIX}" CACHE PATH "-") - set(INCLUDE_INSTALL_DIR "include" CACHE PATH "-") - set(CMAKE_INSTALL_DIR "CMake" CACHE PATH "-") - set(PLUGIN_INSTALL_DIR "plugins" CACHE PATH "-") - set(HTML_INSTALL_DIR "doc/HTML" CACHE PATH "-") - set(ICON_INSTALL_DIR "icons" CACHE PATH "-") - set(SOUND_INSTALL_DIR "soudns" CACHE PATH "-") - set(LOCALE_INSTALL_DIR "lang" CACHE PATH "-") -endif () diff --git a/config.h.cmake b/config.h.cmake index 5e4edc8a..c2590fdc 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -4,10 +4,6 @@ /* Version number of package */ #cmakedefine VERSION "${PROJECT_VERSION}" -#cmakedefine LOCALEDIR "${LOCALE_INSTALL_DIR}" -#cmakedefine DATADIR "${DATADIR}" -#cmakedefine LIBDIR "${LIBDIR}" -#cmakedefine PLUGINDIR "${PLUGINDIR}" #cmakedefine SYSCONFDIR "${SYSCONFDIR}" #cmakedefine BINARYDIR "${BINARYDIR}" #cmakedefine SOURCEDIR "${SOURCEDIR}" diff --git a/include/libssh/CMakeLists.txt b/include/libssh/CMakeLists.txt index 85ffa6f0..acc966e3 100644 --- a/include/libssh/CMakeLists.txt +++ b/include/libssh/CMakeLists.txt @@ -26,7 +26,7 @@ install( FILES ${libssh_HDRS} DESTINATION - ${INCLUDE_INSTALL_DIR}/${APPLICATION_NAME} + ${CMAKE_INSTALL_INCLUDEDIR}/${APPLICATION_NAME} COMPONENT headers ) diff --git a/libssh.pc.cmake b/libssh.pc.cmake index 48fbf7ff..b37cb3fc 100644 --- a/libssh.pc.cmake +++ b/libssh.pc.cmake @@ -1,6 +1,6 @@ Name: ${PROJECT_NAME} Description: The SSH Library Version: ${PROJECT_VERSION} -Libs: -L${LIB_INSTALL_DIR} -lssh -Cflags: -I${INCLUDE_INSTALL_DIR} +Libs: -L${CMAKE_INSTALL_FULL_LIBDIR} -lssh +Cflags: -I${CMAKE_INSTALL_FULL_INCLUDEDIR} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3c7f198c..ab11a0dd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -354,14 +354,11 @@ if (MINGW) endif () -install( - TARGETS - ${LIBSSH_SHARED_LIBRARY} - RUNTIME DESTINATION ${BIN_INSTALL_DIR} - LIBRARY DESTINATION ${LIB_INSTALL_DIR} - ARCHIVE DESTINATION ${LIB_INSTALL_DIR} - COMPONENT libraries -) +install(TARGETS ${LIBSSH_SHARED_LIBRARY} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT libraries) if (BUILD_STATIC_LIB) add_library(${LIBSSH_STATIC_LIBRARY} STATIC ${libssh_SRCS}) @@ -401,7 +398,7 @@ if (BUILD_STATIC_LIB) install(TARGETS ${LIBSSH_STATIC_LIBRARY} DESTINATION - ${LIB_INSTALL_DIR}/${OUTPUT_SUFFIX} + ${CMAKE_INSTALL_LIBDIR}/${OUTPUT_SUFFIX} COMPONENT libraries) endif (WITH_STATIC_LIB)