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