1cmake_minimum_required(VERSION 3.0) 2project(double-conversion VERSION 3.1.5) 3 4if(BUILD_SHARED_LIBS AND MSVC) 5 set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) 6endif() 7 8set(headers 9 double-conversion/bignum.h 10 double-conversion/cached-powers.h 11 double-conversion/diy-fp.h 12 double-conversion/double-conversion.h 13 double-conversion/double-to-string.h 14 double-conversion/fast-dtoa.h 15 double-conversion/fixed-dtoa.h 16 double-conversion/ieee.h 17 double-conversion/string-to-double.h 18 double-conversion/strtod.h 19 double-conversion/utils.h) 20 21add_library(double-conversion 22 double-conversion/bignum.cc 23 double-conversion/bignum-dtoa.cc 24 double-conversion/cached-powers.cc 25 double-conversion/double-to-string.cc 26 double-conversion/fast-dtoa.cc 27 double-conversion/fixed-dtoa.cc 28 double-conversion/string-to-double.cc 29 double-conversion/strtod.cc 30 ${headers}) 31target_include_directories( 32 double-conversion PUBLIC 33 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>) 34 35# pick a version # 36set_target_properties(double-conversion PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION 3) 37 38# set up testing if requested 39option(BUILD_TESTING "Build test programs" OFF) 40if(BUILD_TESTING) 41 enable_testing() 42 include(CTest) 43 add_subdirectory(test) 44endif() 45 46#### 47# Installation (https://github.com/forexample/package-example) 48 49include(GNUInstallDirs) 50 51# Layout. This works for all platforms: 52# * <prefix>/lib/cmake/<PROJECT-NAME> 53# * <prefix>/lib/ 54# * <prefix>/include/ 55set(config_install_dir "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") 56 57set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated") 58 59# Configuration 60set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake") 61set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake") 62set(targets_export_name "${PROJECT_NAME}Targets") 63set(namespace "${PROJECT_NAME}::") 64 65# Include module with function 'write_basic_package_version_file' 66include(CMakePackageConfigHelpers) 67 68# Configure '<PROJECT-NAME>ConfigVersion.cmake' 69# Note: PROJECT_VERSION is used as a VERSION 70write_basic_package_version_file( 71 "${version_config}" COMPATIBILITY SameMajorVersion 72) 73 74# Configure '<PROJECT-NAME>Config.cmake' 75# Use variables: 76# * targets_export_name 77# * PROJECT_NAME 78configure_package_config_file( 79 "cmake/Config.cmake.in" 80 "${project_config}" 81 INSTALL_DESTINATION "${config_install_dir}" 82) 83 84# Targets: 85# * <prefix>/lib/libdouble-conversion.a 86# * header location after install: <prefix>/include/double-conversion/*.h 87# * headers can be included by C++ code `#include <double-conversion/*.h>` 88install( 89 TARGETS double-conversion 90 EXPORT "${targets_export_name}" 91 LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" 92 ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" 93 RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" 94 INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" 95) 96 97# Headers: 98# * double-conversion/*.h -> <prefix>/include/double-conversion/*.h 99install( 100 FILES ${headers} 101 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/double-conversion" 102) 103 104# Config 105# * <prefix>/lib/cmake/double-conversion/double-conversionConfig.cmake 106# * <prefix>/lib/cmake/double-conversion/double-conversionConfigVersion.cmake 107install( 108 FILES "${project_config}" "${version_config}" 109 DESTINATION "${config_install_dir}" 110) 111 112# Config 113# * <prefix>/lib/cmake/double-conversion/double-conversionTargets.cmake 114install( 115 EXPORT "${targets_export_name}" 116 NAMESPACE "${namespace}" 117 DESTINATION "${config_install_dir}" 118) 119