Skip to content

Commit

Permalink
Fix CMake to run tests for optional dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
1uc committed Feb 16, 2024
1 parent aa43041 commit 6952d26
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 37 deletions.
53 changes: 37 additions & 16 deletions cmake/HighFiveOptionalDependencies.cmake
Original file line number Diff line number Diff line change
@@ -1,27 +1,48 @@
if(HIGHFIVE_TEST_BOOST AND NOT TARGET HighFiveBoostDependency)
if(NOT TARGET HighFiveBoostDependency)
add_library(HighFiveBoostDependency INTERFACE)
find_package(Boost REQUIRED)
target_link_libraries(HighFiveBoostDependency INTERFACE Boost::headers)
# TODO check if we need Boost::disable_autolinking to cause:
# -DBOOST_ALL_NO_LIB (does something on MSVC).
if(HIGHFIVE_TEST_BOOST)
find_package(Boost REQUIRED)
target_link_libraries(HighFiveBoostDependency INTERFACE Boost::headers)
# TODO check if we need Boost::disable_autolinking to cause:
# -DBOOST_ALL_NO_LIB (does something on MSVC).
target_compile_definitions(HighFiveBoostDependency INTERFACE HIGHFIVE_TEST_BOOST=1)
endif()
endif()

if(HIGHFIVE_TEST_EIGEN AND NOT TARGET HighFiveEigenDependency)
if(NOT TARGET HighFiveEigenDependency)
add_library(HighFiveEigenDependency INTERFACE)
find_package(Eigen3 REQUIRED NO_MODULE)
target_link_libraries(HighFiveEigenDependency INTERFACE Eigen3::Eigen)
if(HIGHFIVE_TEST_EIGEN AND NOT TARGET HighFiveEigenDependency)
find_package(Eigen3 REQUIRED NO_MODULE)
target_link_libraries(HighFiveEigenDependency INTERFACE Eigen3::Eigen)
target_compile_definitions(HighFiveEigenDependency INTERFACE HIGHFIVE_TEST_EIGEN=1)
endif()
endif()

if(HIGHFIVE_TEST_XTENSOR AND NOT TARGET HighFiveXTensorDependency)
if(NOT TARGET HighFiveXTensorDependency)
add_library(HighFiveXTensorDependency INTERFACE)
find_package(xtensor REQUIRED)
target_link_libraries(HighFiveXTensorDependency INTERFACE xtensor)
if(HIGHFIVE_TEST_XTENSOR AND NOT TARGET HighFiveXTensorDependency)
find_package(xtensor REQUIRED)
target_link_libraries(HighFiveXTensorDependency INTERFACE xtensor)
target_compile_definitions(HighFiveXTensorDependency INTERFACE HIGHFIVE_TEST_XTENSOR=1)
endif()
endif()

if(HIGHFIVE_TEST_OPENCV AND NOT TARGET HighFiveOpenCVDependency)
if(NOT TARGET HighFiveOpenCVDependency)
add_library(HighFiveOpenCVDependency INTERFACE)
find_package(OpenCV REQUIRED)
target_include_directories(HighFiveOpenCVDependency SYSTEM INTERFACE ${OpenCV_INCLUDE_DIRS})
target_link_libraries(HighFiveOpenCVDependency INTERFACE ${OpenCV_LIBS})
target_compile_definitions(HighFiveOpenCVDependency INTERFACE H5_USE_OPENCV)
if(HIGHFIVE_TEST_OPENCV AND NOT TARGET HighFiveOpenCVDependency)
find_package(OpenCV REQUIRED)
target_include_directories(HighFiveOpenCVDependency SYSTEM INTERFACE ${OpenCV_INCLUDE_DIRS})
target_link_libraries(HighFiveOpenCVDependency INTERFACE ${OpenCV_LIBS})
target_compile_definitions(HighFiveOpenCVDependency INTERFACE HIGHFIVE_TEST_OPENCV=1)
endif()
endif()

if(NOT TARGET HighFiveOptionalDependencies)
add_library(HighFiveOptionalDependencies INTERFACE)
target_link_libraries(HighFiveOptionalDependencies INTERFACE
HighFiveBoostDependency
HighFiveEigenDependency
HighFiveXTensorDependency
HighFiveOpenCVDependency
)
endif()
3 changes: 3 additions & 0 deletions tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ endif()
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)
add_executable(${test_name} "${test_name}.cpp")
target_link_libraries(${test_name} HighFive HighFiveWarnings Catch2::Catch2WithMain)
target_link_libraries(${test_name} HighFiveOptionalDependencies)

catch_discover_tests(${test_name})
endforeach()

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

# We need to patch in a call to `mpirun` or equivalent when using
# parallel tests. Somehow, this is not foreseen in Catch2, modify the
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/data_generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <vector>
#include <array>

#ifdef H5_USE_BOOST
#ifdef HIGHFIVE_TEST_BOOST
#include <highfive/boost.hpp>
#endif

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

// -- Boost -------------------------------------------------------------------
#ifdef H5_USE_BOOST
#ifdef HIGHFIVE_TEST_BOOST
template <class T, size_t n>
struct ContainerTraits<boost::multi_array<T, n>> {
using container_type = typename boost::multi_array<T, n>;
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/supported_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <array>
#include <tuple>

#ifdef H5_USE_BOOST
#ifdef HIGHFIVE_TEST_BOOST
#include <boost/multi_array.hpp>
#endif

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

#ifdef H5_USE_BOOST
#ifdef HIGHFIVE_TEST_BOOST
template <size_t n, class C = type_identity>
struct BoostMultiArray {
template <class T>
Expand Down Expand Up @@ -83,7 +83,7 @@ using scalar_types = typename ConcatenateTuples<numeric_scalar_types, std::tuple
using scalar_types_boost = typename ConcatenateTuples<numeric_scalar_types, std::tuple<bool>>::type;

using supported_array_types = typename ConcatenateTuples<
#ifdef H5_USE_BOOST
#ifdef HIGHFIVE_TEST_BOOST
typename ContainerProduct<BoostMultiArray<3>, scalar_types_boost>::type,
typename ContainerProduct<STDVector<BoostMultiArray<3>>, scalar_types_boost>::type,
typename ContainerProduct<STDArray<5, BoostMultiArray<3>>, scalar_types_boost>::type,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/tests_high_five.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ using base_test_types = std::tuple<int,
dcomplex,
fcomplex>;

#ifdef H5_USE_HALF_FLOAT
#ifdef HIGHFIVE_TEST_HALF_FLOAT
#include <highfive/half_float.hpp>

using float16_t = half_float::half;
Expand Down
18 changes: 9 additions & 9 deletions tests/unit/tests_high_five_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
#include <highfive/highfive.hpp>
#include "tests_high_five.hpp"

#ifdef H5_USE_BOOST
#ifdef HIGHFIVE_TEST_BOOST
#include <highfive/boost.hpp>
#endif

#ifdef H5_USE_EIGEN
#ifdef HIGHFIVE_TEST_EIGEN
#include <highfive/eigen.hpp>
#endif

Expand Down Expand Up @@ -1529,7 +1529,7 @@ struct CreateEmptyVector {
}
};

#ifdef H5_USE_BOOST
#ifdef HIGHFIVE_TEST_BOOST
template <int n_dim>
struct CreateEmptyBoostMultiArray {
using container_type = boost::multi_array<int, static_cast<long unsigned>(n_dim)>;
Expand All @@ -1546,7 +1546,7 @@ struct CreateEmptyBoostMultiArray {
#endif


#ifdef H5_USE_EIGEN
#ifdef HIGHFIVE_TEST_EIGEN
struct CreateEmptyEigenVector {
using container_type = Eigen::VectorXi;

Expand Down Expand Up @@ -1676,7 +1676,7 @@ void check_empty_everything(const std::vector<size_t>& dims) {
}
}

#ifdef H5_USE_EIGEN
#ifdef HIGHFIVE_TEST_EIGEN
template <int ndim>
void check_empty_eigen(const std::vector<size_t>&) {}

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

#ifdef H5_USE_BOOST
#ifdef HIGHFIVE_TEST_BOOST
SECTION("boost::multi_array") {
check_empty_everything<CreateEmptyBoostMultiArray<ndim>>(dims);
}
#endif

#ifdef H5_USE_EIGEN
#ifdef HIGHFIVE_TEST_EIGEN
check_empty_eigen<ndim>(dims);
#endif
}
Expand Down Expand Up @@ -2559,7 +2559,7 @@ TEST_CASE("HighFiveDataTypeClass") {
CHECK(((Float | String) & String) == String);
}

#ifdef H5_USE_EIGEN
#ifdef HIGHFIVE_TEST_EIGEN

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

#ifdef H5_USE_BOOST
#ifdef HIGHFIVE_TEST_BOOST
// boost::multi_array<of EigenVector3f>
{
ds_name_flavor = "BMultiEigenVector3f";
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/tests_high_five_easy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include <highfive/H5Easy.hpp>

#ifdef H5_USE_XTENSOR
#ifdef HIGHFIVE_TEST_XTENSOR
#include <xtensor/xrandom.hpp>
#include <xtensor/xview.hpp>
#endif
Expand Down Expand Up @@ -179,7 +179,7 @@ TEST_CASE("H5Easy_Attribute_scalar") {
CHECK(c == c_r);
}

#ifdef H5_USE_XTENSOR
#ifdef HIGHFIVE_TEST_XTENSOR
TEST_CASE("H5Easy_extend1d") {
H5Easy::File file("h5easy_extend1d.h5", H5Easy::File::Overwrite);

Expand Down Expand Up @@ -304,7 +304,7 @@ TEST_CASE("H5Easy_Attribute_xtensor") {
}
#endif

#ifdef H5_USE_EIGEN
#ifdef HIGHFIVE_TEST_EIGEN
TEST_CASE("H5Easy_Eigen_MatrixX") {
H5Easy::File file("h5easy_eigen_MatrixX.h5", H5Easy::File::Overwrite);

Expand Down Expand Up @@ -439,7 +439,7 @@ TEST_CASE("H5Easy_Attribute_Eigen_MatrixX") {
}
#endif

#ifdef H5_USE_OPENCV
#ifdef HIGHFIVE_TEST_OPENCV
TEST_CASE("H5Easy_OpenCV_Mat_") {
H5Easy::File file("h5easy_opencv_Mat_.h5", H5Easy::File::Overwrite);

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/tests_high_five_multi_dims.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <highfive/highfive.hpp>


#ifdef H5_USE_BOOST
#ifdef HIGHFIVE_TEST_BOOST
#include <boost/multi_array.hpp>
#include <highfive/boost.hpp>
#endif
Expand Down Expand Up @@ -128,7 +128,7 @@ TEMPLATE_LIST_TEST_CASE("vector of array", "[template]", numerical_test_types) {
}


#ifdef H5_USE_BOOST
#ifdef HIGHFIVE_TEST_BOOST

template <typename T>
void MultiArray3DTest() {
Expand Down

0 comments on commit 6952d26

Please sign in to comment.