CMakeLists.txt 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. # Copyright Peter Dimov, Hans Dembinski 2018-2019
  2. # Distributed under the Boost Software License, Version 1.0.
  3. # See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt
  4. # Warning: Boost-CMake support is incomplete; testing works, install target doesn't
  5. cmake_minimum_required(VERSION 3.6)
  6. project(BoostHistogram VERSION 1.72.0 LANGUAGES CXX)
  7. add_library(boost_histogram INTERFACE)
  8. set_property(TARGET boost_histogram PROPERTY EXPORT_NAME histogram)
  9. add_library(Boost::histogram ALIAS boost_histogram)
  10. target_compile_features(boost_histogram INTERFACE
  11. cxx_alias_templates cxx_variadic_templates cxx_decltype_auto
  12. cxx_defaulted_functions cxx_generic_lambdas cxx_range_for
  13. cxx_relaxed_constexpr cxx_return_type_deduction)
  14. target_include_directories(boost_histogram
  15. INTERFACE
  16. $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>)
  17. target_link_libraries(boost_histogram
  18. INTERFACE
  19. Boost::assert
  20. Boost::config
  21. Boost::core
  22. Boost::mp11
  23. Boost::throw_exception
  24. Boost::variant2
  25. )
  26. if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
  27. ###########################################################
  28. # Setup `check_histogram` target to build and run all tests.
  29. ###########################################################
  30. # `function` confuses FetchContent, sees empty CMAKE_CURRENT_LIST_DIR
  31. macro(fetch_and_include name)
  32. message(STATUS "Fetching ${name}")
  33. set(fetch_and_include_local_path "${CMAKE_BINARY_DIR}/fetch_and_include/${name}")
  34. if(NOT EXISTS ${fetch_and_include_local_path})
  35. file(DOWNLOAD
  36. "https://raw.githubusercontent.com/boostorg/mincmake/develop/${name}"
  37. "${CMAKE_BINARY_DIR}/fetch_and_include/${name}"
  38. )
  39. endif()
  40. include("${CMAKE_BINARY_DIR}/fetch_and_include/${name}")
  41. endmacro()
  42. fetch_and_include(cmake/boost_test.cmake)
  43. fetch_and_include(cmake/boost_fetch.cmake)
  44. boost_fetch(boostorg/assert TAG develop)
  45. boost_fetch(boostorg/config TAG develop)
  46. boost_fetch(boostorg/core TAG develop)
  47. boost_fetch(boostorg/mp11 TAG develop)
  48. boost_fetch(boostorg/throw_exception TAG develop)
  49. boost_fetch(boostorg/variant2 TAG develop)
  50. ## No cmake support yet
  51. # boost_fetch(boostorg/accumulators TAG develop)
  52. # boost_fetch(boostorg/range TAG develop)
  53. # boost_fetch(boostorg/serialization TAG develop)
  54. # boost_fetch(boostorg/units TAG develop)
  55. find_package(Threads) # for optional multi-threaded tests
  56. enable_testing()
  57. add_custom_target(histogram_check
  58. COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>
  59. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  60. COMMENT "Build and then run all the tests and examples.")
  61. ###########################################################
  62. # Setup 'install' target and package config file.
  63. ###########################################################
  64. ## installings targets doesn't work currently, fails with errors like
  65. # Target "boost_variant" INTERFACE_INCLUDE_DIRECTORIES property contains
  66. # path:
  67. #
  68. # "/path/to/histogram/build/_deps/boostorg_variant-src/include"
  69. #
  70. # which is prefixed in the build directory.Target "boost_variant"
  71. # INTERFACE_INCLUDE_DIRECTORIES property contains path:
  72. #
  73. # "/path/to/histogram/build/_deps/boostorg_variant-src/include"
  74. #
  75. # which is prefixed in the source directory.
  76. # set(CONFIG_INSTALL_DIR lib/cmake/${PROJECT_NAME}-${PROJECT_VERSION})
  77. #
  78. # install(TARGETS boost_histogram
  79. # boost_assert
  80. # boost_config
  81. # boost_core
  82. # boost_mp11
  83. # boost_throw_exception
  84. # boost_variant2
  85. # EXPORT ${PROJECT_NAME}Targets)
  86. # install(EXPORT ${PROJECT_NAME}Targets
  87. # DESTINATION ${CONFIG_INSTALL_DIR}
  88. # NAMESPACE Boost::
  89. # FILE ${PROJECT_NAME}Config.cmake)
  90. #
  91. # install(DIRECTORY include/ DESTINATION include)
  92. endif()
  93. if (COMMAND boost_test)
  94. add_subdirectory(test)
  95. endif()
  96. if (COMMAND boost_fetch)
  97. add_subdirectory(benchmark)
  98. endif()