CMakeLists.txt 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # Copyright 2019 Hans Dembinski
  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. cmake_minimum_required(VERSION 3.6)
  5. set(CMAKE_BUILD_TYPE Release) # ok, only set in local scope
  6. if (NOT COMMAND boost_fetch)
  7. # `function` confuses FetchContent, sees empty CMAKE_CURRENT_LIST_DIR
  8. macro(fetch_and_include name)
  9. message(STATUS "Fetching ${name}")
  10. set(fetch_and_include_local_path "${CMAKE_BINARY_DIR}/fetch_and_include/${name}")
  11. if(NOT EXISTS ${fetch_and_include_local_path})
  12. file(DOWNLOAD
  13. "https://raw.githubusercontent.com/boostorg/mincmake/develop/${name}"
  14. "${CMAKE_BINARY_DIR}/fetch_and_include/${name}"
  15. )
  16. endif()
  17. include("${CMAKE_BINARY_DIR}/fetch_and_include/${name}")
  18. endmacro()
  19. fetch_and_include(cmake/boost_fetch.cmake)
  20. endif()
  21. # allow benchmarks to build old versions of the code if we sit inside the boost metaproject
  22. if (NOT TARGET boost_histogram)
  23. add_library(boost_histogram INTERFACE)
  24. add_library(Boost::histogram ALIAS boost_histogram)
  25. target_compile_features(boost_histogram INTERFACE
  26. cxx_alias_templates cxx_variadic_templates cxx_decltype_auto
  27. cxx_defaulted_functions cxx_generic_lambdas cxx_range_for
  28. cxx_relaxed_constexpr cxx_return_type_deduction)
  29. target_include_directories(boost_histogram
  30. INTERFACE
  31. ${CMAKE_CURRENT_SOURCE_DIR}/../include
  32. ${CMAKE_CURRENT_SOURCE_DIR}/../../../
  33. )
  34. set(BENCHMARK_FLAGS) # old versions don't work with -fno-exceptions
  35. else()
  36. set(BENCHMARK_FLAGS -fno-exceptions -fno-rtti)
  37. endif()
  38. option(BENCHMARK_ENABLE_TESTING "" OFF)
  39. boost_fetch(hdembinski/benchmark)
  40. macro(add_benchmark name)
  41. add_executable(${name} "${name}.cpp")
  42. target_compile_options(${name} PRIVATE
  43. -DNDEBUG -O3 -march=native ${BENCHMARK_FLAGS} -funsafe-math-optimizations)
  44. target_link_libraries(${name} PRIVATE Boost::histogram benchmark_main)
  45. endmacro()
  46. add_benchmark(axis_index)
  47. add_benchmark(histogram_filling)
  48. add_benchmark(histogram_iteration)
  49. if (Threads_FOUND)
  50. add_benchmark(histogram_parallel_filling)
  51. endif()
  52. find_package(GSL)
  53. if (GSL_FOUND)
  54. add_benchmark(histogram_filling_gsl)
  55. target_include_directories(histogram_filling_gsl PRIVATE ${GSL_INCLUDE_DIRS})
  56. target_link_libraries(histogram_filling_gsl
  57. PRIVATE ${GSL_LIBRARIES} benchmark_main)
  58. endif()
  59. find_package(ROOT QUIET)
  60. if (ROOT_FOUND)
  61. add_benchmark(histogram_filling_root)
  62. target_include_directories(histogram_filling_root PRIVATE ${ROOT_INCLUDE_DIRS})
  63. target_link_libraries(histogram_filling_root
  64. PRIVATE ${ROOT_LIBRARIES} benchmark_main)
  65. target_compile_options(histogram_filling_root PRIVATE -frtti -fexceptions)
  66. # target_link_options(histogram_filling_root
  67. # PRIVATE ${ROOT_EXE_LINKER_FLAGS})
  68. endif()