Skip to content

Commit 9739523

Browse files
Test cmake install and build examples (#578)
* [github] test install with cmake and build examples * [cmake] install custom cmake find modules * [cmake] add required dependencies in exported config * [cmake] only use custom FindHDF5 from config if cmake < 3.19 * [clang] remove deprecated implicit definitions * [examples] require c++17 if not using boost * [cmake] hdf5 link must be public * [examples] remove complex_io.cpp (linking error) * [examples] fix image_h5 example * [examples] fix writer examples * [doc] add github workflow badge to readme * [cmake] remove unecessary addition to module path * Revert "[examples] remove complex_io.cpp (linking error)" This reverts commit 23cd78c. * [clang] resolve compiler warnings * [cmake] add option to include the examples in the project * [examples] fix complex_io example * [clang] resolve compiler warnings in examples
1 parent 323674e commit 9739523

27 files changed

+94
-141
lines changed

.github/workflows/cmake-build.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,5 +249,15 @@ jobs:
249249
cmake --build . -- -j 2
250250
- name: run tests
251251
run: |
252-
cd build
253252
ctest --extra-verbose --no-tests=error
253+
working-directory: build
254+
- name: install with cmake
255+
run: |
256+
cmake --build . --target install
257+
working-directory: build
258+
- name: build examples
259+
run: |
260+
mkdir examples_build
261+
cd examples_build
262+
cmake ../examples -DCMAKE_BUILD_TYPE=Release
263+
cmake --build . -- -j 2

CMakeLists.txt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ if (NOT H5CPP_BUILD_SHARED)
2121
set(BUILD_SHARED_LIBS OFF)
2222
endif()
2323
option(H5CPP_LOCAL_MODULES "Build h5cpp using cmake local modules first")
24+
option(H5CPP_BUILD_EXAMPLES "Include the examples in the project" OFF)
2425

2526
#=============================================================================
2627
# Conan
@@ -117,6 +118,9 @@ option(H5CPP_BUILD_DOCS "Build documentation" ON)
117118
if(H5CPP_BUILD_DOCS)
118119
add_subdirectory(doc)
119120
endif()
121+
if (H5CPP_BUILD_EXAMPLES)
122+
add_subdirectory(examples)
123+
endif()
120124

121125
#=============================================================================
122126
# install the examples directory to the documentation directory
@@ -158,13 +162,20 @@ install(FILES ${PROJECT_BINARY_DIR}/${PACKAGE_VERSION_FILE_NAME}
158162
COMPONENT development)
159163

160164
#
161-
# create and install the package file
165+
# create and install the package file and cmake modules
162166
#
163167
configure_file("${PACKAGE_CONFIG_FILE_NAME}.in" ${PACKAGE_CONFIG_FILE_NAME} @ONLY)
164-
install(FILES ${PROJECT_BINARY_DIR}/${PACKAGE_CONFIG_FILE_NAME}
168+
install(FILES
169+
${PROJECT_BINARY_DIR}/${PACKAGE_CONFIG_FILE_NAME}
170+
cmake/FindSZIP.cmake
165171
DESTINATION ${CMAKE_INSTALL_PACKAGEDIR}
166172
COMPONENT development)
167173

174+
install(FILES
175+
cmake/FindHDF5.cmake
176+
DESTINATION ${CMAKE_INSTALL_PACKAGEDIR}/hdf5
177+
COMPONENT development)
178+
168179
#
169180
# uninstall target
170181
#

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# C++ wrapper for the HDF5 C-library
22

3-
[![docs](https://img.shields.io/badge/Documentation-webpages-ADD8E6.svg)](https://ess-dmsc.github.io/h5cpp/index.html) [![DOI](https://zenodo.org/badge/99373936.svg)](https://zenodo.org/badge/latestdoi/99373936) [![Join the chat at https://gitter.im/h5cpp/community](https://badges.gitter.im/h5cpp/community.svg)](https://gitter.im/h5cpp/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
3+
![github workflow](https://github.com/ess-dmsc/h5cpp/actions/workflows/cmake-build.yml/badge.svg) [![docs](https://img.shields.io/badge/Documentation-webpages-ADD8E6.svg)](https://ess-dmsc.github.io/h5cpp/index.html) [![DOI](https://zenodo.org/badge/99373936.svg)](https://zenodo.org/badge/latestdoi/99373936) [![Join the chat at https://gitter.im/h5cpp/community](https://badges.gitter.im/h5cpp/community.svg)](https://gitter.im/h5cpp/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
44

55

66
*h5cpp* is a new C++ wrapper for HDF5s C-API.

examples/CMakeLists.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
cmake_minimum_required(VERSION 3.0.0)
22
project(h5cpp-examples LANGUAGES CXX C)
3-
set(CMAKE_CXX_STANDARD 11)
43

5-
find_package(h5cpp REQUIRED)
4+
get_directory_property(IS_TOP_LEVEL PARENT_DIRECTORY)
5+
if (NOT IS_TOP_LEVEL)
6+
find_package(h5cpp REQUIRED)
7+
endif()
8+
9+
if (NOT H5CPP_BOOST_ENABLED)
10+
set(CMAKE_CXX_STANDARD 17)
11+
else()
12+
set(CMAKE_CXX_STANDARD 11)
13+
endif()
614

715
add_executable(basic_files basic_files.cpp)
816
target_link_libraries(basic_files PRIVATE h5cpp::h5cpp)
@@ -60,4 +68,3 @@ endif ()
6068
if (H5CPP_MPI_ENABLED)
6169
add_subdirectory(mpi)
6270
endif ()
63-

examples/append_scalar_data.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,23 @@
2727

2828
using namespace hdf5;
2929

30-
node::Dataset create_dataset(const node::Group parent_group)
31-
{
32-
property::LinkCreationList lcpl;
33-
property::DatasetCreationList dcpl;
30+
namespace {
31+
node::Dataset create_dataset(const node::Group & parent_group)
32+
{
33+
property::LinkCreationList lcpl;
34+
property::DatasetCreationList dcpl;
3435

35-
// in order to append data we have to use a chunked layout of the dataset
36-
dcpl.layout(property::DatasetLayout::Chunked);
37-
dcpl.chunk(Dimensions{1024});
36+
// in order to append data we have to use a chunked layout of the dataset
37+
dcpl.layout(property::DatasetLayout::Chunked);
38+
dcpl.chunk(Dimensions{1024});
3839

39-
// create dataspace (infinitely extensible) and datatype
40-
dataspace::Simple space({0},{dataspace::Simple::unlimited});
41-
auto type = datatype::create<int>();
40+
// create dataspace (infinitely extensible) and datatype
41+
dataspace::Simple space({0},{dataspace::Simple::unlimited});
42+
auto type = datatype::create<int>();
4243

43-
// finally create the dataset
44-
return node::Dataset(parent_group,"data",type,space,lcpl,dcpl);
44+
// finally create the dataset
45+
return node::Dataset(parent_group,"data",type,space,lcpl,dcpl);
46+
}
4547
}
4648

4749
int main()

examples/append_vector_data.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,28 @@ using namespace hdf5;
3232
using Bins = std::vector<int>;
3333
static const int nbins = 6;
3434

35-
node::Dataset create_dataset(const node::Group parent_group,const Bins bins)
36-
{
37-
property::LinkCreationList lcpl;
38-
property::DatasetCreationList dcpl;
39-
dcpl.layout(property::DatasetLayout::Chunked);
40-
dcpl.chunk({100,bins.size()});
35+
namespace {
36+
node::Dataset create_dataset(const node::Group & parent_group,const Bins & bins)
37+
{
38+
property::LinkCreationList lcpl;
39+
property::DatasetCreationList dcpl;
40+
dcpl.layout(property::DatasetLayout::Chunked);
41+
dcpl.chunk({100,bins.size()});
4142

42-
dataspace::Simple space{{0,bins.size()},{dataspace::Simple::unlimited,nbins}};
43-
auto type = datatype::create(bins);
43+
dataspace::Simple space{{0,bins.size()},{dataspace::Simple::unlimited,nbins}};
44+
auto type = datatype::create(bins);
4445

45-
return node::Dataset(parent_group,"data",type,space,lcpl,dcpl);
46-
}
46+
return node::Dataset(parent_group,"data",type,space,lcpl,dcpl);
47+
}
4748

48-
void print_data(const std::string &prefix,const Bins &bins)
49-
{
50-
std::cout<<prefix;
51-
std::for_each(bins.begin(),bins.end(),
52-
[](int value) { std::cout<<value<<" "; });
53-
std::cout<<std::endl;
49+
void print_data(const std::string &prefix,const Bins &bins)
50+
{
51+
std::cout<<prefix;
52+
std::for_each(bins.begin(),bins.end(),
53+
[](int value) { std::cout<<value<<" "; });
54+
std::cout<<std::endl;
55+
}
5456
}
55-
5657
int main()
5758
{
5859
file::File f = file::create("append_vector_data.h5",

examples/complex_io.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
// Created on: Oct 07, 2017
2424
//
2525
#include <h5cpp/hdf5.hpp>
26+
#include <h5cpp/contrib/stl/stl.hpp>
27+
2628
#include <iostream>
2729
#include <complex>
2830

examples/image_h5.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ class TypeTrait<Image<PixelT>>
6868
hdf5::Dimensions{value.ny(),value.nx()});
6969
}
7070

71-
const static DataspaceType & get(const Image<PixelT> &value)
71+
const static DataspaceType & get(const Image<PixelT> &value, DataspacePool &)
7272
{
7373
const static DataspaceType & cref_ = Simple(hdf5::Dimensions{value.ny(),value.nx()},
7474
hdf5::Dimensions{value.ny(),value.nx()});
75+
return cref_;
7576
}
7677

7778
static void *ptr(Image<PixelT> &value)

examples/mpi/writer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ int main(int argc,char **argv)
5151

5252
node::Dataset dataset = root_group.create_dataset("mpi_ids",
5353
datatype::create<int>(),
54-
dataspace::Simple{{total_procs}});
55-
dataspace::Hyperslab slab{{my_id},{1},{1},{1}};
54+
dataspace::Simple{{static_cast<hsize_t>(total_procs)}});
55+
dataspace::Hyperslab slab{{static_cast<hsize_t>(my_id)},{1},{1},{1}};
5656
dataset.write(my_id,slab);
5757
}
5858

examples/mpi/writer_extend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ node::Dataset create_dataset(const node::Group &base)
5050
dcpl.layout(property::DatasetLayout::Chunked);
5151
dcpl.chunk({1024*1024});
5252

53-
return base.create_dataset("extended_data",file_type,file_space,lcpl,dcpl);
53+
return base.create_dataset("extended_data",file_type,file_space,dcpl,lcpl);
5454
}
5555

5656
int main(int argc,char **argv)

0 commit comments

Comments
 (0)