CMakeLists.txt 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. cmake_minimum_required(VERSION 3.15)
  2. project(MathFunctions)
  3. # make cache variables for install destinations
  4. include(GNUInstallDirs)
  5. # specify the C++ standard
  6. set(CMAKE_CXX_STANDARD 11)
  7. set(CMAKE_CXX_STANDARD_REQUIRED True)
  8. # create library
  9. add_library(MathFunctions STATIC MathFunctions.cxx)
  10. # add include directories
  11. target_include_directories(MathFunctions
  12. PUBLIC
  13. "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
  14. "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
  15. )
  16. # install the target and create export-set
  17. install(TARGETS MathFunctions
  18. EXPORT MathFunctionsTargets
  19. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  20. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  21. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  22. INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
  23. )
  24. # install header file
  25. install(FILES MathFunctions.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
  26. # generate and install export file
  27. install(EXPORT MathFunctionsTargets
  28. FILE MathFunctionsTargets.cmake
  29. NAMESPACE MathFunctions::
  30. DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/MathFunctions
  31. )
  32. # include CMakePackageConfigHelpers macro
  33. include(CMakePackageConfigHelpers)
  34. # set version
  35. set(version 3.4.1)
  36. set_property(TARGET MathFunctions PROPERTY VERSION ${version})
  37. set_property(TARGET MathFunctions PROPERTY SOVERSION 3)
  38. set_property(TARGET MathFunctions PROPERTY
  39. INTERFACE_MathFunctions_MAJOR_VERSION 3)
  40. set_property(TARGET MathFunctions APPEND PROPERTY
  41. COMPATIBLE_INTERFACE_STRING MathFunctions_MAJOR_VERSION
  42. )
  43. # generate the version file for the config file
  44. write_basic_package_version_file(
  45. "${CMAKE_CURRENT_BINARY_DIR}/MathFunctionsConfigVersion.cmake"
  46. VERSION "${version}"
  47. COMPATIBILITY AnyNewerVersion
  48. )
  49. # create config file
  50. configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
  51. "${CMAKE_CURRENT_BINARY_DIR}/MathFunctionsConfig.cmake"
  52. INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/MathFunctions
  53. )
  54. # install config files
  55. install(FILES
  56. "${CMAKE_CURRENT_BINARY_DIR}/MathFunctionsConfig.cmake"
  57. "${CMAKE_CURRENT_BINARY_DIR}/MathFunctionsConfigVersion.cmake"
  58. DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/MathFunctions
  59. )
  60. # generate the export targets for the build tree
  61. export(EXPORT MathFunctionsTargets
  62. FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/MathFunctionsTargets.cmake"
  63. NAMESPACE MathFunctions::
  64. )