Skip to content

Commit 7d7d227

Browse files
committed
chore: supply a little helper for checking C++ boost-histogram
1 parent a1dcb7a commit 7d7d227

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

examples/cpp/CMakeLists.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# This file lets you quickly build projects with the exact same boost-histogram
2+
# settings that the Python bindings use.
3+
4+
cmake_minimum_required(VERSION 3.14...3.20)
5+
6+
project(BOOST_HISTOGRAM_CPP LANGUAGES CXX)
7+
8+
9+
add_library(boost_histogram_cpp IMPORTED INTERFACE)
10+
11+
# these are the boost header-only libraries required by boost::histogram
12+
target_include_directories(
13+
boost_histogram_cpp
14+
INTERFACE ../../extern/assert/include
15+
../../extern/config/include
16+
../../extern/core/include
17+
../../extern/histogram/include
18+
../../extern/mp11/include
19+
../../extern/throw_exception/include
20+
../../extern/variant2/include)
21+
22+
23+
target_compile_options(boost_histogram_cpp
24+
INTERFACE $<IF:$<CXX_COMPILER_ID:MSVC>,/fp:fast,-funsafe-math-optimizations>)
25+
26+
target_compile_features(boost_histogram_cpp INTERFACE cxx_std_14)
27+
28+
if(PROJECT_NAME STREQUAL CMAKE_PROJECT_NAME)
29+
add_executable(simple simple.cpp)
30+
target_link_libraries(simple PRIVATE boost_histogram_cpp)
31+
endif()

examples/cpp/simple.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <boost/histogram.hpp>
2+
#include <iostream>
3+
4+
int main() {
5+
namespace bh = boost::histogram;
6+
7+
auto h = bh::make_histogram(bh::axis::category<int>{});
8+
9+
std::cout << bh::algorithm::sum(h) << std::endl;
10+
}
11+

0 commit comments

Comments
 (0)