Permalink
Browse files

Use template for CMake installation.

  • Loading branch information...
isaachier committed Sep 7, 2017
1 parent aa2df66 commit e13e72e17692f5dc0036460d734c637b563f3ac7
Showing with 69 additions and 32 deletions.
  1. +69 −32 CMakeLists.txt
  2. 0 cmake/{double-conversionConfig.cmake.in → Config.cmake.in}
View
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.0)
project(double-conversion VERSION 2.0.1)
project(double-conversion VERSION 3.0.0)
set(headers
double-conversion/bignum.h
@@ -28,11 +28,7 @@ target_include_directories(
$<INSTALL_INTERFACE:include>)
# pick a version #
set(double-conversion_SOVERSION_MAJOR 1)
set(double-conversion_SOVERSION_MINOR 0)
set(double-conversion_SOVERSION_PATCH 0)
set(double-conversion_SOVERSION ${double-conversion_SOVERSION_MAJOR}.${double-conversion_SOVERSION_MINOR}.${double-conversion_SOVERSION_PATCH})
set_property(TARGET double-conversion PROPERTY SOVERSION ${double-conversion_SOVERSION})
set_property(TARGET double-conversion PROPERTY SOVERSION ${PROJECT_VERSION})
# set up testing if requested
option(BUILD_TESTING "Build test programs" OFF)
@@ -42,34 +38,75 @@ if(BUILD_TESTING)
add_subdirectory(test)
endif()
include(GNUInstallDirs)
install(TARGETS double-conversion EXPORT double-conversionTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES ${headers}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/double-conversion)
####
# Installation (https://github.com/forexample/package-example)
# Layout. This works for all platforms:
# * <prefix>/lib/cmake/<PROJECT-NAME>
# * <prefix>/lib/
# * <prefix>/include/
set(config_install_dir "lib/cmake/${PROJECT_NAME}")
set(include_install_dir "include")
set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
# Configuration
set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
set(targets_export_name "${PROJECT_NAME}Targets")
set(namespace "${PROJECT_NAME}::")
# Include module with function 'write_basic_package_version_file'
include(CMakePackageConfigHelpers)
configure_package_config_file(
cmake/double-conversionConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/double-conversion/double-conversionConfig.cmake"
INSTALL_DESTINATION "${LIB_INSTALL_DIR}/double-conversion/cmake")
# Configure '<PROJECT-NAME>ConfigVersion.cmake'
# Note: PROJECT_VERSION is used as a VERSION
write_basic_package_version_file(
"${PROJECT_BINARY_DIR}/double-conversion/double-conversionConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)
"${version_config}" COMPATIBILITY SameMajorVersion
)
# Configure '<PROJECT-NAME>Config.cmake'
# Use variables:
# * targets_export_name
# * PROJECT_NAME
configure_package_config_file(
"cmake/Config.cmake.in"
"${project_config}"
INSTALL_DESTINATION "${config_install_dir}"
)
# Targets:
# * <prefix>/lib/libdouble-conversion.a
# * header location after install: <prefix>/include/double-conversion/*.h
# * headers can be included by C++ code `#include <double-conversion/*.h>`
install(
TARGETS double-conversion
EXPORT "${targets_export_name}"
LIBRARY DESTINATION "lib"
ARCHIVE DESTINATION "lib"
RUNTIME DESTINATION "bin"
INCLUDES DESTINATION "${include_install_dir}"
)
# Headers:
# * double-conversion/*.h -> <prefix>/include/double-conversion/*.h
install(
FILES ${headers}
DESTINATION "${include_install_dir}/double-conversion"
)
export(EXPORT double-conversionTargets
FILE "${CMAKE_CURRENT_BINARY_DIR}/double-conversion/double-conversionTargets.cmake"
NAMESPACE double-conversion::)
# Config
# * <prefix>/lib/cmake/double-conversion/double-conversionConfig.cmake
# * <prefix>/lib/cmake/double-conversion/double-conversionConfigVersion.cmake
install(
FILES "${project_config}" "${version_config}"
DESTINATION "${config_install_dir}"
)
set(ConfigPackageLocation lib/cmake/double-conversion)
install(EXPORT double-conversionTargets
FILE double-conversionTargets.cmake
NAMESPACE double-conversion::
DESTINATION ${ConfigPackageLocation})
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/double-conversion/double-conversionConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/double-conversion/double-conversionConfigVersion.cmake"
DESTINATION ${ConfigPackageLocation}
COMPONENT Devel)
# Config
# * <prefix>/lib/cmake/double-conversion/double-conversionTargets.cmake
install(
EXPORT "${targets_export_name}"
NAMESPACE "${namespace}"
DESTINATION "${config_install_dir}"
)
File renamed without changes.

0 comments on commit e13e72e

Please sign in to comment.