Skip to content

Commit 3095ec5

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 3095ec5

16 files changed

+131
-8
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: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Unit Tests
22

33
concurrency:
44
group: ${{ github.workflow }}#${{ github.ref }}
5-
cancel-in-progress: ${{ github.ref == 'main' }}
5+
cancel-in-progress: ${{ github.ref != 'main' }}
66

77
on:
88
workflow_dispatch:
@@ -317,11 +317,18 @@ jobs:
317317

318318
- name: Build
319319
run: |
320+
if (( ${{ matrix.cxxstd }} > 14 ))
321+
then
322+
TEST_XTENSOR=On
323+
else
324+
TEST_XTENSOR=Off
325+
fi
326+
320327
CMAKE_OPTIONS=(
321328
-GNinja
322329
-DHIGHFIVE_TEST_BOOST:BOOL=ON
323330
-DHIGHFIVE_TEST_EIGEN:BOOL=ON
324-
-DHIGHFIVE_TEST_XTENSOR:BOOL=ON
331+
-DHIGHFIVE_TEST_XTENSOR:BOOL=${TEST_XTENSOR}
325332
-DHIGHFIVE_BUILD_DOCS:BOOL=FALSE
326333
-DCMAKE_CXX_STANDARD=${{matrix.cxxstd}}
327334
)
@@ -358,18 +365,27 @@ jobs:
358365

359366
- uses: mamba-org/setup-micromamba@v2
360367
with:
361-
environment-file: .github/mamba_env.yaml
368+
environment-file: .github/mamba_env_cxx${{matrix.cxxstd}}.yaml
362369
environment-name: win-test
363370

364371
- name: Build
365372
shell: bash -l {0}
366373
run: |
374+
if (( ${{ matrix.cxxstd }} == 17 ))
375+
then
376+
XTENSOR_HEADER_VERSION=2
377+
else
378+
# Both C++14 and C++20 use 0.26
379+
XTENSOR_HEADER_VERSION=1
380+
fi
381+
367382
CMAKE_OPTIONS=(
368383
-DCMAKE_CXX_STANDARD=${{matrix.cxxstd}}
369384
-DHIGHFIVE_UNIT_TESTS=ON
370385
-DHIGHFIVE_TEST_BOOST:BOOL=ON
371386
-DHIGHFIVE_TEST_EIGEN:BOOL=ON
372387
-DHIGHFIVE_TEST_XTENSOR:BOOL=ON
388+
-DHIGHFIVE_XTENSOR_HEADER_VERSION=$XTENSOR_HEADER_VERSION
373389
)
374390
source $GITHUB_WORKSPACE/.github/build.sh
375391

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ option(HIGHFIVE_FIND_HDF5 "Find and link with HDF5." On)
3939

4040
set(HIGHFIVE_CMAKE_INSTALL_DIR "lib/cmake/HighFive" CACHE STRING
4141
"Directory where HighFive's CMake code will be installed. Default: lib/cmake/HighFive")
42-
42+
set(HIGHFIVE_XTENSOR_HEADER_VERSION "0" CACHE STRING "XTensor header version: 1 for <xtensor/xtensor.hpp>, 2 for <xtensor/containers/xtensor.hpp>, and 0 for automatic detection.")
4343

4444
# Configure Tests & Examples
4545
# --------------------------

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

cmake/HighFiveConfig.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@ if(NOT TARGET HighFive)
2020
add_library(HighFiveInclude ALIAS HighFive::Include)
2121
endif()
2222

23+
if(HIGHFIVE_XTENSOR_HEADER_VERSION)
24+
target_compile_definitions(HighFive::HighFive PUBLIC
25+
HIGHFIVE_XTENSOR_HEADER_VERSION=${HIGHFIVE_XTENSOR_HEADER_VERSION}
26+
)
27+
endif()
2328

cmake/HighFiveOptionalDependencies.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ if(NOT TARGET HighFiveXTensorDependency)
2727
find_package(xtensor REQUIRED)
2828
target_link_libraries(HighFiveXTensorDependency INTERFACE xtensor)
2929
target_compile_definitions(HighFiveXTensorDependency INTERFACE HIGHFIVE_TEST_XTENSOR=1)
30+
31+
if(HIGHFIVE_XTENSOR_HEADER_VERSION)
32+
target_compile_definitions(HighFiveXTensorDependency INTERFACE
33+
HIGHFIVE_XTENSOR_HEADER_VERSION=${HIGHFIVE_XTENSOR_HEADER_VERSION})
34+
endif()
3035
endif()
3136
endif()
3237

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: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// clang-format off
2+
#if HIGHFIVE_XTENSOR_HEADER_VERSION
3+
#if __cplusplus >= 201703L
4+
#if __has_include(<xtensor/xtensor.hpp>)
5+
#define HIGHFIVE_XTENSOR_HEADER_VERSION 1
6+
#elif __has_include(<xtensor/containers/xtensor.hpp>)
7+
#define HIGHFIVE_XTENSOR_HEADER_VERSION 2
8+
#else
9+
#error "Unable to guess HIGHFIVE_XTENSOR_HEADER_VERSION. Please set manually."
10+
#endif
11+
#elif __cplusplus == 201402L
12+
// XTensor 0.26 and newer require C++17. Hence, if we have C++14, only
13+
// `HIGHFIVE_XTENSOR_HEADER_VERSION == 1` makes sense.
14+
#define HIGHFIVE_XTENSOR_HEADER_VERSION 1
15+
#elif defined(_MSC_VER) && __cplusplus == 199711L
16+
#error \
17+
"Use /Zc:__cplusplus to make MSVC set __cplusplus correctly or HIGHFIVE_XTENSOR_HEADER_VERSION to skip xtensor version deduction."
18+
#else
19+
#error "HighFive requires C++14 or newer."
20+
#endif
21+
#endif
22+
// clang-format on

0 commit comments

Comments
 (0)