Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit aee2b97

Browse files
authored
Fix CMake to run tests for optional dependencies. (#965)
1 parent a169b83 commit aee2b97

9 files changed

+75
-43
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,18 @@ jobs:
4343
- config:
4444
os: ubuntu-20.04
4545
pkgs: ''
46-
flags: '-DHIGHFIVE_TEST_BOOST:Bool=OFF'
4746
- config:
4847
os: ubuntu-20.04
4948
pkgs: 'libboost-all-dev libopencv-dev'
50-
flags: '-DHIGHFIVE_TEST_OPENCV:Bool=ON -GNinja'
49+
flags: '-DHIGHFIVE_TEST_BOOST:Bool=ON -DHIGHFIVE_TEST_OPENCV:Bool=ON -GNinja'
5150
- config:
5251
os: ubuntu-latest
5352
pkgs: 'libboost-all-dev libeigen3-dev libopencv-dev'
54-
flags: '-DHIGHFIVE_TEST_EIGEN:Bool=ON -DHIGHFIVE_TEST_OPENCV:Bool=ON -GNinja'
53+
flags: '-DHIGHFIVE_TEST_BOOST:Bool=ON -DHIGHFIVE_TEST_EIGEN:Bool=ON -DHIGHFIVE_TEST_OPENCV:Bool=ON -GNinja'
5554
- config:
5655
os: ubuntu-20.04
5756
pkgs: 'libboost-all-dev'
58-
flags: '-DCMAKE_CXX_STANDARD=17'
57+
flags: '-DCMAKE_CXX_STANDARD=17 -DHIGHFIVE_TEST_BOOST:Bool=ON'
5958
- config:
6059
os: ubuntu-22.04
6160
flags: '-DHIGHFIVE_TEST_BOOST=Off -DCMAKE_CXX_STANDARD=20'
@@ -157,7 +156,7 @@ jobs:
157156
- name: Build
158157
env: ${{matrix.env}}
159158
run: |
160-
CMAKE_OPTIONS=(-GNinja)
159+
CMAKE_OPTIONS=(-DHIGHFIVE_TEST_BOOST=ON -GNinja)
161160
source $GITHUB_WORKSPACE/.github/build.sh
162161
163162
- name: Test
Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,48 @@
1-
if(HIGHFIVE_TEST_BOOST AND NOT TARGET HighFiveBoostDependency)
1+
if(NOT TARGET HighFiveBoostDependency)
22
add_library(HighFiveBoostDependency INTERFACE)
3-
find_package(Boost REQUIRED)
4-
target_link_libraries(HighFiveBoostDependency INTERFACE Boost::headers)
5-
# TODO check if we need Boost::disable_autolinking to cause:
6-
# -DBOOST_ALL_NO_LIB (does something on MSVC).
3+
if(HIGHFIVE_TEST_BOOST)
4+
find_package(Boost REQUIRED)
5+
target_link_libraries(HighFiveBoostDependency INTERFACE Boost::headers)
6+
# TODO check if we need Boost::disable_autolinking to cause:
7+
# -DBOOST_ALL_NO_LIB (does something on MSVC).
8+
target_compile_definitions(HighFiveBoostDependency INTERFACE HIGHFIVE_TEST_BOOST=1)
9+
endif()
710
endif()
811

9-
if(HIGHFIVE_TEST_EIGEN AND NOT TARGET HighFiveEigenDependency)
12+
if(NOT TARGET HighFiveEigenDependency)
1013
add_library(HighFiveEigenDependency INTERFACE)
11-
find_package(Eigen3 REQUIRED NO_MODULE)
12-
target_link_libraries(HighFiveEigenDependency INTERFACE Eigen3::Eigen)
14+
if(HIGHFIVE_TEST_EIGEN)
15+
find_package(Eigen3 REQUIRED NO_MODULE)
16+
target_link_libraries(HighFiveEigenDependency INTERFACE Eigen3::Eigen)
17+
target_compile_definitions(HighFiveEigenDependency INTERFACE HIGHFIVE_TEST_EIGEN=1)
18+
endif()
1319
endif()
1420

15-
if(HIGHFIVE_TEST_XTENSOR AND NOT TARGET HighFiveXTensorDependency)
21+
if(NOT TARGET HighFiveXTensorDependency)
1622
add_library(HighFiveXTensorDependency INTERFACE)
17-
find_package(xtensor REQUIRED)
18-
target_link_libraries(HighFiveXTensorDependency INTERFACE xtensor)
23+
if(HIGHFIVE_TEST_XTENSOR)
24+
find_package(xtensor REQUIRED)
25+
target_link_libraries(HighFiveXTensorDependency INTERFACE xtensor)
26+
target_compile_definitions(HighFiveXTensorDependency INTERFACE HIGHFIVE_TEST_XTENSOR=1)
27+
endif()
1928
endif()
2029

21-
if(HIGHFIVE_TEST_OPENCV AND NOT TARGET HighFiveOpenCVDependency)
30+
if(NOT TARGET HighFiveOpenCVDependency)
2231
add_library(HighFiveOpenCVDependency INTERFACE)
23-
find_package(OpenCV REQUIRED)
24-
target_include_directories(HighFiveOpenCVDependency SYSTEM INTERFACE ${OpenCV_INCLUDE_DIRS})
25-
target_link_libraries(HighFiveOpenCVDependency INTERFACE ${OpenCV_LIBS})
26-
target_compile_definitions(HighFiveOpenCVDependency INTERFACE H5_USE_OPENCV)
32+
if(HIGHFIVE_TEST_OPENCV)
33+
find_package(OpenCV REQUIRED)
34+
target_include_directories(HighFiveOpenCVDependency SYSTEM INTERFACE ${OpenCV_INCLUDE_DIRS})
35+
target_link_libraries(HighFiveOpenCVDependency INTERFACE ${OpenCV_LIBS})
36+
target_compile_definitions(HighFiveOpenCVDependency INTERFACE HIGHFIVE_TEST_OPENCV=1)
37+
endif()
38+
endif()
39+
40+
if(NOT TARGET HighFiveOptionalDependencies)
41+
add_library(HighFiveOptionalDependencies INTERFACE)
42+
target_link_libraries(HighFiveOptionalDependencies INTERFACE
43+
HighFiveBoostDependency
44+
HighFiveEigenDependency
45+
HighFiveXTensorDependency
46+
HighFiveOpenCVDependency
47+
)
2748
endif()

tests/unit/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ endif()
99
foreach(test_name tests_high_five_base tests_high_five_multi_dims tests_high_five_easy test_all_types test_high_five_selection tests_high_five_data_type test_legacy)
1010
add_executable(${test_name} "${test_name}.cpp")
1111
target_link_libraries(${test_name} HighFive HighFiveWarnings Catch2::Catch2WithMain)
12+
target_link_libraries(${test_name} HighFiveOptionalDependencies)
13+
1214
catch_discover_tests(${test_name})
1315
endforeach()
1416

@@ -18,6 +20,7 @@ if(HIGHFIVE_PARALLEL_HDF5)
1820
## parallel MPI tests
1921
add_executable(tests_parallel_bin ${tests_parallel_src})
2022
target_link_libraries(tests_parallel_bin HighFive HighFiveWarnings Catch2::Catch2)
23+
target_link_libraries(tests_parallel_bin HighFiveOptionalDependencies)
2124

2225
# We need to patch in a call to `mpirun` or equivalent when using
2326
# parallel tests. Somehow, this is not foreseen in Catch2, modify the

tests/unit/data_generator.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <vector>
88
#include <array>
99

10-
#ifdef H5_USE_BOOST
10+
#ifdef HIGHFIVE_TEST_BOOST
1111
#include <highfive/boost.hpp>
1212
#endif
1313

@@ -200,7 +200,7 @@ struct ContainerTraits<std::array<T, N>>: public STLLikeContainerTraits<std::arr
200200
};
201201

202202
// -- Boost -------------------------------------------------------------------
203-
#ifdef H5_USE_BOOST
203+
#ifdef HIGHFIVE_TEST_BOOST
204204
template <class T, size_t n>
205205
struct ContainerTraits<boost::multi_array<T, n>> {
206206
using container_type = typename boost::multi_array<T, n>;

tests/unit/supported_types.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <array>
77
#include <tuple>
88

9-
#ifdef H5_USE_BOOST
9+
#ifdef HIGHFIVE_TEST_BOOST
1010
#include <boost/multi_array.hpp>
1111
#endif
1212

@@ -30,7 +30,7 @@ struct STDArray {
3030
using type = std::array<typename C::template type<T>, n>;
3131
};
3232

33-
#ifdef H5_USE_BOOST
33+
#ifdef HIGHFIVE_TEST_BOOST
3434
template <size_t n, class C = type_identity>
3535
struct BoostMultiArray {
3636
template <class T>
@@ -83,7 +83,7 @@ using scalar_types = typename ConcatenateTuples<numeric_scalar_types, std::tuple
8383
using scalar_types_boost = typename ConcatenateTuples<numeric_scalar_types, std::tuple<bool>>::type;
8484

8585
using supported_array_types = typename ConcatenateTuples<
86-
#ifdef H5_USE_BOOST
86+
#ifdef HIGHFIVE_TEST_BOOST
8787
typename ContainerProduct<BoostMultiArray<3>, scalar_types_boost>::type,
8888
typename ContainerProduct<STDVector<BoostMultiArray<3>>, scalar_types_boost>::type,
8989
typename ContainerProduct<STDArray<5, BoostMultiArray<3>>, scalar_types_boost>::type,

tests/unit/tests_high_five.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ using base_test_types = std::tuple<int,
4242
dcomplex,
4343
fcomplex>;
4444

45-
#ifdef H5_USE_HALF_FLOAT
45+
#ifdef HIGHFIVE_TEST_HALF_FLOAT
4646
#include <highfive/half_float.hpp>
4747

4848
using float16_t = half_float::half;

tests/unit/tests_high_five_base.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
#include <highfive/highfive.hpp>
2828
#include "tests_high_five.hpp"
2929

30-
#ifdef H5_USE_BOOST
30+
#ifdef HIGHFIVE_TEST_BOOST
3131
#include <highfive/boost.hpp>
3232
#endif
3333

34-
#ifdef H5_USE_EIGEN
34+
#ifdef HIGHFIVE_TEST_EIGEN
3535
#include <highfive/eigen.hpp>
3636
#endif
3737

@@ -1529,7 +1529,7 @@ struct CreateEmptyVector {
15291529
}
15301530
};
15311531

1532-
#ifdef H5_USE_BOOST
1532+
#ifdef HIGHFIVE_TEST_BOOST
15331533
template <int n_dim>
15341534
struct CreateEmptyBoostMultiArray {
15351535
using container_type = boost::multi_array<int, static_cast<long unsigned>(n_dim)>;
@@ -1546,7 +1546,7 @@ struct CreateEmptyBoostMultiArray {
15461546
#endif
15471547

15481548

1549-
#ifdef H5_USE_EIGEN
1549+
#ifdef HIGHFIVE_TEST_EIGEN
15501550
struct CreateEmptyEigenVector {
15511551
using container_type = Eigen::VectorXi;
15521552

@@ -1676,7 +1676,7 @@ void check_empty_everything(const std::vector<size_t>& dims) {
16761676
}
16771677
}
16781678

1679-
#ifdef H5_USE_EIGEN
1679+
#ifdef HIGHFIVE_TEST_EIGEN
16801680
template <int ndim>
16811681
void check_empty_eigen(const std::vector<size_t>&) {}
16821682

@@ -1703,13 +1703,13 @@ void check_empty(const std::vector<size_t>& dims) {
17031703
check_empty_everything<CreateEmptyVector<ndim>>(dims);
17041704
}
17051705

1706-
#ifdef H5_USE_BOOST
1706+
#ifdef HIGHFIVE_TEST_BOOST
17071707
SECTION("boost::multi_array") {
17081708
check_empty_everything<CreateEmptyBoostMultiArray<ndim>>(dims);
17091709
}
17101710
#endif
17111711

1712-
#ifdef H5_USE_EIGEN
1712+
#ifdef HIGHFIVE_TEST_EIGEN
17131713
check_empty_eigen<ndim>(dims);
17141714
#endif
17151715
}
@@ -2559,7 +2559,7 @@ TEST_CASE("HighFiveDataTypeClass") {
25592559
CHECK(((Float | String) & String) == String);
25602560
}
25612561

2562-
#ifdef H5_USE_EIGEN
2562+
#ifdef HIGHFIVE_TEST_EIGEN
25632563

25642564
template <typename T>
25652565
void test_eigen_vec(File& file, const std::string& test_flavor, const T& vec_input, T& vec_output) {
@@ -2636,7 +2636,7 @@ TEST_CASE("HighFiveEigen") {
26362636
CHECK_THROWS(test_eigen_vec(file, ds_name_flavor, vec_in, vec_out));
26372637
}
26382638

2639-
#ifdef H5_USE_BOOST
2639+
#ifdef HIGHFIVE_TEST_BOOST
26402640
// boost::multi_array<of EigenVector3f>
26412641
{
26422642
ds_name_flavor = "BMultiEigenVector3f";

tests/unit/tests_high_five_easy.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,22 @@
2020

2121
#include <stdio.h>
2222

23-
#include <highfive/H5Easy.hpp>
2423

25-
#ifdef H5_USE_XTENSOR
24+
#ifdef HIGHFIVE_TEST_XTENSOR
2625
#include <xtensor/xrandom.hpp>
2726
#include <xtensor/xview.hpp>
2827
#endif
2928

29+
#ifdef HIGHFIVE_TEST_EIGEN
30+
#include <Eigen/Dense>
31+
#endif
32+
33+
#ifdef HIGHFIVE_TEST_OPENCV
34+
#define H5_USE_OPENCV
35+
#endif
36+
37+
#include <highfive/H5Easy.hpp>
38+
3039
#include <catch2/catch_test_macros.hpp>
3140

3241
TEST_CASE("H5Easy_Compression") {
@@ -179,7 +188,7 @@ TEST_CASE("H5Easy_Attribute_scalar") {
179188
CHECK(c == c_r);
180189
}
181190

182-
#ifdef H5_USE_XTENSOR
191+
#ifdef HIGHFIVE_TEST_XTENSOR
183192
TEST_CASE("H5Easy_extend1d") {
184193
H5Easy::File file("h5easy_extend1d.h5", H5Easy::File::Overwrite);
185194

@@ -304,7 +313,7 @@ TEST_CASE("H5Easy_Attribute_xtensor") {
304313
}
305314
#endif
306315

307-
#ifdef H5_USE_EIGEN
316+
#ifdef HIGHFIVE_TEST_EIGEN
308317
TEST_CASE("H5Easy_Eigen_MatrixX") {
309318
H5Easy::File file("h5easy_eigen_MatrixX.h5", H5Easy::File::Overwrite);
310319

@@ -439,7 +448,7 @@ TEST_CASE("H5Easy_Attribute_Eigen_MatrixX") {
439448
}
440449
#endif
441450

442-
#ifdef H5_USE_OPENCV
451+
#ifdef HIGHFIVE_TEST_OPENCV
443452
TEST_CASE("H5Easy_OpenCV_Mat_") {
444453
H5Easy::File file("h5easy_opencv_Mat_.h5", H5Easy::File::Overwrite);
445454

tests/unit/tests_high_five_multi_dims.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <highfive/highfive.hpp>
1414

1515

16-
#ifdef H5_USE_BOOST
16+
#ifdef HIGHFIVE_TEST_BOOST
1717
#include <boost/multi_array.hpp>
1818
#include <highfive/boost.hpp>
1919
#endif
@@ -128,7 +128,7 @@ TEMPLATE_LIST_TEST_CASE("vector of array", "[template]", numerical_test_types) {
128128
}
129129

130130

131-
#ifdef H5_USE_BOOST
131+
#ifdef HIGHFIVE_TEST_BOOST
132132

133133
template <typename T>
134134
void MultiArray3DTest() {

0 commit comments

Comments
 (0)