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