Commit 42a00188 authored by Andreas Schuh's avatar Andreas Schuh

Configure and install CMake package configuration file to help find_package…

Configure and install CMake package configuration file to help find_package locate the gflags package.
parent 6f2a78a2
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
# ----------------------------------------------------------------------------
# includes
set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include (utils)
# ----------------------------------------------------------------------------
# package information
set (PROJECT_NAME "gflags")
......@@ -11,6 +17,13 @@ set (PACKAGE_BUGREPORT "https://code.google.com/p/gflags/issues/")
project (${PROJECT_NAME})
version_numbers (
${PACKAGE_VERSION}
PACKAGE_VERSION_MAJOR
PACKAGE_VERSION_MINOR
PACKAGE_VERSION_PATCH
)
# ----------------------------------------------------------------------------
# configure options
option (BUILD_SHARED_LIBS "Request build of shared libraries." OFF)
......@@ -136,5 +149,38 @@ add_library (gflags ${GFLAGS_SRCS})
# ----------------------------------------------------------------------------
# installation
install (TARGETS gflags DESTINATION lib)
install (FILES ${PUBLIC_HDRS} DESTINATION include/${GFLAGS_NAMESPACE})
if (WIN32)
set (LIBRARY_INSTALL_DIR Lib)
set (INCLUDE_INSTALL_DIR Include)
set (CONFIG_INSTALL_DIR CMake)
else ()
set (LIBRARY_INSTALL_DIR lib)
set (INCLUDE_INSTALL_DIR include)
set (CONFIG_INSTALL_DIR cmake/${PACKAGE_NAME})
endif ()
install (TARGETS ${PACKAGE_NAME} DESTINATION ${LIBRARY_INSTALL_DIR} EXPORT gflags-lib)
install (FILES ${PUBLIC_HDRS} DESTINATION ${INCLUDE_INSTALL_DIR}/${GFLAGS_NAMESPACE})
file (RELATIVE_PATH INSTALL_PREFIX_REL2CONFIG_DIR "${CMAKE_INSTALL_PREFIX}" "${CMAKE_INSTALL_PREFIX}/${CONFIG_INSTALL_DIR}")
configure_file (cmake/config.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-install.cmake" @ONLY)
configure_file (cmake/version.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake" @ONLY)
install (
FILES "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-install.cmake"
RENAME ${PACKAGE_NAME}-config.cmake
DESTINATION ${CONFIG_INSTALL_DIR}
)
install (
FILES "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake"
DESTINATION ${CONFIG_INSTALL_DIR}
)
install (EXPORT gflags-lib DESTINATION ${CONFIG_INSTALL_DIR} FILE ${PACKAGE_NAME}-export.cmake)
# ----------------------------------------------------------------------------
# support direct use of build tree
set (INSTALL_PREFIX_REL2CONFIG_DIR .)
export (TARGETS gflags FILE "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-export.cmake")
configure_file (cmake/config.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config.cmake" @ONLY)
## gflags CMake configuration file
# library version information
set (@PACKAGE_NAME@_VERSION_STRING "@PACKAGE_VERSION@")
set (@PACKAGE_NAME@_VERSION_MAJOR @PACKAGE_VERSION_MAJOR@)
set (@PACKAGE_NAME@_VERSION_MINOR @PACKAGE_VERSION_MINOR@)
set (@PACKAGE_NAME@_VERSION_PATCH @PACKAGE_VERSION_PATCH@)
# import targets
include ("${CMAKE_CURRENT_LIST_DIR}/@PACKAGE_NAME@-export.cmake")
# installation prefix
get_filename_component (CMAKE_CURRENT_LIST_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
get_filename_component (_INSTALL_PREFIX "${CMAKE_CURRENT_LIST_DIR}/@INSTALL_PREFIX_REL2CONFIG_DIR@" ABSOLUTE)
# include directory
set (@PACKAGE_NAME@_INCLUDE_DIR "${_INSTALL_PREFIX}/@INCLUDE_INSTALL_DIR@")
# gflags library
set (@PACKAGE_NAME@_LIBRARIES gflags)
# unset private variables
unset (_INSTALL_PREFIX)
## @file utils.cmake
# @brief Utility CMake functions.
# ----------------------------------------------------------------------------
## @brief Extract version numbers from version string.
#
# @param [in] VERSION Version string in the format "MAJOR[.MINOR[.PATCH]]".
# @param [out] MAJOR Major version number if given or 0.
# @param [out] MINOR Minor version number if given or 0.
# @param [out] PATCH Patch number if given or 0.
#
# @returns See @c [out] parameters.
function (version_numbers VERSION MAJOR MINOR PATCH)
if (VERSION MATCHES "([0-9]+)(\\.[0-9]+)?(\\.[0-9]+)?(rc[1-9][0-9]*|[a-z]+)?")
if (CMAKE_MATCH_1)
set (VERSION_MAJOR ${CMAKE_MATCH_1})
else ()
set (VERSION_MAJOR 0)
endif ()
if (CMAKE_MATCH_2)
set (VERSION_MINOR ${CMAKE_MATCH_2})
string (REGEX REPLACE "^\\." "" VERSION_MINOR "${VERSION_MINOR}")
else ()
set (VERSION_MINOR 0)
endif ()
if (CMAKE_MATCH_3)
set (VERSION_PATCH ${CMAKE_MATCH_3})
string (REGEX REPLACE "^\\." "" VERSION_PATCH "${VERSION_PATCH}")
else ()
set (VERSION_PATCH 0)
endif ()
else ()
set (VERSION_MAJOR 0)
set (VERSION_MINOR 0)
set (VERSION_PATCH 0)
endif ()
set ("${MAJOR}" "${VERSION_MAJOR}" PARENT_SCOPE)
set ("${MINOR}" "${VERSION_MINOR}" PARENT_SCOPE)
set ("${PATCH}" "${VERSION_PATCH}" PARENT_SCOPE)
endfunction ()
## gflags CMake configuration version file
# -----------------------------------------------------------------------------
# library version
set (PACKAGE_VERSION "@PACKAGE_VERSION@")
# -----------------------------------------------------------------------------
# check compatibility
# Perform compatibility check here using the input CMake variables.
# See example in http://www.cmake.org/Wiki/CMake_2.6_Notes.
set (PACKAGE_VERSION_COMPATIBLE TRUE)
set (PACKAGE_VERSION_UNSUITABLE FALSE)
if ("${PACKAGE_FIND_VERSION_MAJOR}" EQUAL "@PACKAGE_VERSION_MAJOR@")
if ("${PACKAGE_FIND_VERSION_MINOR}" EQUAL "@PACKAGE_VERSION_MINOR@")
set (PACKAGE_VERSION_EXACT TRUE)
endif ()
endif ()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment