Skip to content

Commit a4d321d

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 a4d321d

File tree

13 files changed

+93
-5
lines changed

13 files changed

+93
-5
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ dependencies:
88
- eigen
99
- graphviz
1010
- hdf5
11-
- xtensor
11+
- xtensor<0.26
1212
- xtl

.github/mamba_env_cxx17.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
channels:
2+
- conda-forge
3+
dependencies:
4+
- boost-cpp
5+
- catch2
6+
- cmake
7+
- doxygen
8+
- eigen
9+
- graphviz
10+
- hdf5
11+
- xtensor>=0.26
12+
- xtl

.github/mamba_env_cxx20.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
channels:
2+
- conda-forge
3+
dependencies:
4+
- boost-cpp
5+
- catch2
6+
- cmake
7+
- doxygen
8+
- eigen
9+
- graphviz
10+
- hdf5
11+
- xtensor<0.26
12+
- xtl

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ jobs:
358358

359359
- uses: mamba-org/setup-micromamba@v2
360360
with:
361-
environment-file: .github/mamba_env.yaml
361+
environment-file: .github/mamba_env_cxx${{matrix.cxxstd}}.yaml
362362
environment-name: win-test
363363

364364
- name: Build

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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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/containers/xtensor.hpp>)
6+
#define HIGHFIVE_XTENSOR_HEADER_VERSION 2
7+
#else
8+
#error "Unable to guess HIGHFIVE_XTENSOR_HEADER_VERSION. Please set manually."
9+
#endif
10+
#else
11+
#define HIGHFIVE_XTENSOR_HEADER_VERSION 1
12+
#endif
13+
#endif

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/containers/xtensor.hpp>
13+
#include <xtensor/containers/xarray.hpp>
14+
#include <xtensor/containers/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/containers/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/containers/xtensor.hpp>
21+
#else
22+
#error "Failed to detect HIGHFIVE_XTENSOR_HEADER_VERSION."
23+
#endif
1724
#endif
1825

1926
// optionally enable plug-in Eigen

0 commit comments

Comments
 (0)