CMake: add install rule (#241)

* CMake: add MinGW install rule

* CMake: relative packaging paths
This commit is contained in:
Петр Шургалин 2017-12-27 23:09:40 +03:00 committed by Kjell Hedström
parent c79695c387
commit 11f9f06f5c
2 changed files with 69 additions and 44 deletions

View File

@ -76,23 +76,23 @@ IF ( NOT VERSION )
message("windows: Extracting git software version")
execute_process(COMMAND powershell "(git rev-list --branches HEAD | Measure-Object -line).Lines" OUTPUT_VARIABLE GIT_VERSION WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
ELSE()
IF(UNIX OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
message( STATUS "nix: Extracting git software version" )
IF(UNIX OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
message( STATUS "nix: Extracting git software version" )
ELSE()
message( STATUS "unknown platform: extracting git software version" )
message( STATUS "unknown platform: extracting git software version" )
ENDIF()
execute_process(COMMAND bash "-c" "git rev-list --branches HEAD | wc -l | tr -d ' ' | tr -d '\n'" OUTPUT_VARIABLE GIT_VERSION WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
ENDIF()
SET(MINOR_VERSION 3)
math(EXPR VERSION-BASE ${GIT_VERSION}/255)
math(EXPR VERSION-REMAINDER ${GIT_VERSION}%255)
message( STATUS "git build version: ${GIT_VERSION}" )
message( STATUS "version base: ${VERSION-BASE}" )
message( STATUS "version remainder: ${VERSION-REMAINDER}" )
message( STATUS "git build version: ${GIT_VERSION}" )
message( STATUS "version base: ${VERSION-BASE}" )
message( STATUS "version remainder: ${VERSION-REMAINDER}" )
# SET(BUILD_NUMBER ${GIT_VERSION})
SET(BUILD_NUMBER ${VERSION-BASE})
SET(VERSION ${MAJOR_VERSION}.${MINOR_VERSION}.${BUILD_NUMBER}-${VERSION-REMAINDER})
SET(BUILD_NUMBER ${VERSION-BASE})
SET(VERSION ${MAJOR_VERSION}.${MINOR_VERSION}.${BUILD_NUMBER}-${VERSION-REMAINDER})
ENDIF()
message( STATUS "Software Version: ${VERSION}" )
@ -158,27 +158,35 @@ message( STATUS "Software Version: ${VERSION}" )
INCLUDE (${g3log_SOURCE_DIR}/test_unit/Test.cmake)
IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# ==========================================================================
# Only tested on Ubuntu, CentOS and OSX.
# Only tested on Ubuntu, CentOS and OSX.
# For OSX you can also install an older version using 'brew install'
#
# ==========================================================================
#
# Alternative 1:
#
# Alternative 1:
# Package handling is done AFTER all other CMake setup
# usage: make package
# Check the output result and install accordingly.
#
# Alternative 2:
#
# Alternative 2:
# usage: make; sudo make install
#
# ==========================================================================
INCLUDE (${g3log_SOURCE_DIR}/CPackLists.txt)
ENDIF()
IF(MINGW)
# ==========================================================================
#
# usage: make; make install
#
# ==========================================================================
INCLUDE (${g3log_SOURCE_DIR}/CPackLists.txt)
ENDIF()
IF (NOT MSVC)
message( STATUS "\n\n

View File

@ -15,18 +15,19 @@
# DESTINATION include
# COMPONENT headers)
IF(MINGW)
SET(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/g3log")
ENDIF()
IF(NOT MINGW)
IF(NOT CPACK_PACKAGING_INSTALL_PREFIX)
SET(CPACK_PACKAGING_INSTALL_PREFIX /usr/local)
ENDIF()
ENDIF()
SET(CMAKE_INSTALL_LIBDIR lib CACHE PATH "Output dir for libraries")
SET(CMAKE_INSTALL_HEADERDIR include CACHE PATH "Output dir for headers")
IF (${CPACK_INSTALL_PREFIX}.x STREQUAL ".x")
SET(CPACK_INSTALL_PREFIX "/usr/local")
message( STATUS "CPACK_INSTALL_PREFIX: ${CPACK_INSTALL_PREFIX}" )
ENDIF()
SET(CPACK_PACKAGE_NAME g3log)
SET(CPACK_PACKAGE_VERSION_MAJOR ${MAJOR_VERSION})
SET(CPACK_PACKAGE_VERSION_MINOR ${MINOR_VERSION})
@ -40,18 +41,31 @@ SET(CPACK_RESOURCE_FILE_LICENSE ${g3log_SOURCE_DIR}/LICENSE)
SET(CPACK_PACKAGE_VENDOR "KjellKod")
SET(CMAKE_INSTALL_HEADERDIR ${CMAKE_INSTALL_HEADERDIR}/g3log)
IF(NOT MINGW)
INSTALL( TARGETS g3logger
ARCHIVE DESTINATION ${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}
COMPONENT libraries)
INSTALL( TARGETS g3logger
ARCHIVE DESTINATION ${CPACK_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CPACK_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}
COMPONENT libraries)
INSTALL( FILES ${HEADER_FILES}
DESTINATION ${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_HEADERDIR}
COMPONENT headers)
INSTALL( FILES ${HEADER_FILES}
DESTINATION ${CPACK_INSTALL_PREFIX}/${CMAKE_INSTALL_HEADERDIR}
COMPONENT headers)
INSTALL( FILES ${PROJECT_SOURCE_DIR}/cmake/g3loggerConfig.cmake
DESTINATION ${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/cmake/g3logger)
ELSE()
INSTALL( TARGETS g3logger
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT libraries)
INSTALL( FILES ${PROJECT_SOURCE_DIR}/cmake/g3loggerConfig.cmake
DESTINATION ${CPACK_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/cmake/g3logger)
INSTALL( FILES ${HEADER_FILES}
DESTINATION ${CMAKE_INSTALL_HEADERDIR}
COMPONENT headers)
INSTALL( FILES ${PROJECT_SOURCE_DIR}/cmake/g3loggerConfig.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/g3logger)
ENDIF()
SET(CPACK_COMPONENTS_ALL libraries headers)
SET(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "G3Log libraries")
@ -60,31 +74,34 @@ SET(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "G3Log C++ headers")
IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
SET(CPACK_GENERATOR "DEB")
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "KjellKod - Kjell Hedstrom")
message( STATUS "\nTo create installation package: " )
message( STATUS "make package" )
ENDIF()
message( STATUS "\nTo create installation package: " )
message( STATUS "make package" )
message( STATUS "\nOption to install using 'sudo make install" )
message( STATUS "\nOption to install using 'make install'" )
message( STATUS "Installation locations: " )
message( STATUS "====================" )
message( STATUS "Headers: ${CPACK_INSTALL_PREFIX}/${CMAKE_INSTALL_HEADERDIR}" )
message( STATUS "Library installation directory: ${CPACK_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" )
message( STATUS "Headers: ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_HEADERDIR}" )
message( STATUS "Library installation directory: ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" )
message( STATUS "For more information please see g3log/CPackLists.txt\n\n" )
message( STATUS "To install: sudo dpkg -i g3log-***Linux.deb" )
message( STATUS "To list package contents: sudo dpkg --contents g3log-***Linux.deb" )
message( STATUS "List content of the installed package: sudo dpkg -L g3log" )
message( STATUS "To remove: sudo dpkg -r g3log" )
IF(NOT MINGW)
message( STATUS "To install: sudo dpkg -i g3log-***Linux.deb" )
message( STATUS "To list package contents: sudo dpkg --contents g3log-***Linux.deb" )
message( STATUS "List content of the installed package: sudo dpkg -L g3log" )
message( STATUS "To remove: sudo dpkg -r g3log" )
ENDIF()
# NOTE: to change installation locations you can use the settings below
# examples:
# CPACK_INSTALL_PREFIX
# CPACK_PACKAGE_INSTALL_DIRECTORY
# CPACK_PACKAGING_INSTALL_PREFIX
# CPACK_OUTPUT_FILE_PREFIX
# CMAKE_INSTALL_PREFIX
# CMAKE_INSTALL_HEADERDIR
# CMAKE_INSTALL_LIBDIR
INCLUDE(CPack)
INCLUDE(CPack)