Skip to content

Commit 10fca9b

Browse files
committed
xtensor: Make HighFive compatible with 0.26.
XTensor reorganized its headers in 0.26. This commit introduces come logic to guess the correct path: if the compiler is C++17 or later, use `__has_include` to check both locations; otherwise it must be an xtensor version prior to 0.26, because 0.26 onwards require a C++17 compiler.
1 parent a92b0f8 commit 10fca9b

File tree

9 files changed

+63
-3
lines changed

9 files changed

+63
-3
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,12 @@ HighFive integrates with the following libraries:
214214
- xtensor (optional)
215215
- half (optional)
216216

217+
#### XTensor Header Location
218+
XTensor reorganized their headers in version 0.26. HighFive attempts to guess
219+
where the headers can be found. The guessing can be overridded by setting
220+
`HIGHFIVE_XTENSOR_HEADER_VERSION` to: `1` for finding `xtensor.hpp` in
221+
`<xtensor/xtensor.hpp>` and `2` for `<xtensor/containers/xtensor.hpp>`.
222+
217223
## Versioning & Code Stability
218224
We use semantic versioning. Currently, we're preparing `v3` which contains a
219225
limited set of breaking changes required to eliminate undesireable behaviour or

include/highfive/H5Easy.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
#endif
2929

3030
#ifdef H5_USE_XTENSOR
31-
#include <xtensor/xarray.hpp>
32-
#include <xtensor/xtensor.hpp>
3331
#include "xtensor.hpp"
3432
#endif
3533

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef HIGHFIVE_XTENSOR_HEADER_VERSION
2+
#if __cplusplus >= 201703L
3+
#if __has_include(<xtensor/xtensor.hpp>)
4+
#define HIGHFIVE_XTENSOR_HEADER_VERSION 1
5+
#elif __has_include(<xtensor/container/xtensor.hpp>)
6+
#define HIGHFIVE_XTENSOR_HEADER_VERSION 2
7+
#endif
8+
#endif
9+
#endif
10+

include/highfive/xtensor.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,19 @@
22

33
#include "bits/H5Inspector_decl.hpp"
44
#include "H5Exception.hpp"
5+
#include "bits/xtensor_header_version.hpp"
56

7+
#if HIGHFIVE_XTENSOR_HEADER_VERSION == 1
68
#include <xtensor/xtensor.hpp>
79
#include <xtensor/xarray.hpp>
810
#include <xtensor/xadapt.hpp>
11+
#elif HIGHFIVE_XTENSOR_HEADER_VERSION == 2
12+
#include <xtensor/container/xtensor.hpp>
13+
#include <xtensor/container/xarray.hpp>
14+
#include <xtensor/container/xadapt.hpp>
15+
#else
16+
#error "Set HIGHFIVE_XTENSOR_HEADER_VERSION to `1` for pre 0.26; `2` otherwise."
17+
#endif
918

1019
namespace HighFive {
1120
namespace details {

src/examples/easy_attribute.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,14 @@
1313

1414
// optionally enable plug-in xtensor
1515
#ifdef H5_USE_XTENSOR
16+
#include "bits/xtensor_header_version.hpp"
17+
#if HIGHFIVE_XTENSOR_HEADER_VERSION == 1
1618
#include <xtensor/xtensor.hpp>
19+
#elif HIGHFIVE_XTENSOR_HEADER_VERSION == 2
20+
#include <xtensor/container/xtensor.hpp>
21+
#else
22+
#error "Failed to detect HIGHFIVE_XTENSOR_HEADER_VERSION."
23+
#endif
1724
#endif
1825

1926
// optionally enable plug-in Eigen

src/examples/easy_dumpoptions.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,14 @@
1313

1414
// optionally enable plug-in xtensor
1515
#ifdef H5_USE_XTENSOR
16+
#include <highfive/bits/xtensor_header_version.hpp>
17+
#if HIGHFIVE_XTENSOR_HEADER_VERSION == 1
1618
#include <xtensor/xtensor.hpp>
19+
#elif HIGHFIVE_XTENSOR_HEADER_VERSION == 2
20+
#include <xtensor/container/xtensor.hpp>
21+
#else
22+
#error "Failed to detect HIGHFIVE_XTENSOR_HEADER_VERSION."
23+
#endif
1724
#endif
1825

1926
// optionally enable plug-in Eigen

src/examples/easy_load_dump.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,14 @@
1313

1414
// optionally enable plug-in xtensor
1515
#ifdef H5_USE_XTENSOR
16+
#include <highfive/bits/xtensor_header_version.hpp>
17+
#if HIGHFIVE_XTENSOR_HEADER_VERSION == 1
1618
#include <xtensor/xtensor.hpp>
19+
#elif HIGHFIVE_XTENSOR_HEADER_VERSION == 2
20+
#include <xtensor/container/xtensor.hpp>
21+
#else
22+
#error "Failed to detect HIGHFIVE_XTENSOR_HEADER_VERSION."
23+
#endif
1724
#endif
1825

1926
// optionally enable plug-in Eigen

tests/unit/test_xtensor.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,19 @@
1313
#include <catch2/catch_template_test_macros.hpp>
1414

1515
#include <highfive/highfive.hpp>
16+
#include <highfive/xtensor.hpp>
17+
18+
#if HIGHFIVE_XTENSOR_HEADER_VERSION == 1
1619
#include <xtensor/xtensor.hpp>
1720
#include <xtensor/xview.hpp>
1821
#include <xtensor/xio.hpp>
19-
#include <highfive/xtensor.hpp>
22+
#elif HIGHFIVE_XTENSOR_HEADER_VERSION == 2
23+
#include <xtensor/container/xtensor.hpp>
24+
#include <xtensor/views/xview.hpp>
25+
#include <xtensor/io/xio.hpp>
26+
#else
27+
#error "Failed to detect HIGHFIVE_XTENSOR_HEADER_VERSION."
28+
#endif
2029

2130
#include "data_generator.hpp"
2231

tests/unit/tests_high_five_easy.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,15 @@
2222

2323

2424
#ifdef HIGHFIVE_TEST_XTENSOR
25+
#include <highfive/bits/xtensor_header_version.hpp>
26+
#if HIGHFIVE_XTENSOR_HEADER_VERSION == 1
2527
#include <xtensor/xrandom.hpp>
2628
#include <xtensor/xview.hpp>
29+
#elif HIGHFIVE_XTENSOR_HEADER_VERSION == 2
30+
#include <xtensor/generators/xrandom.hpp>
31+
#include <xtensor/views/xview.hpp>
32+
#else
33+
#error "Failed to detect HIGHFIVE_XTENSOR_HEADER_VERSION."
2734
#endif
2835

2936
#ifdef HIGHFIVE_TEST_EIGEN

0 commit comments

Comments
 (0)