From c192eada7d3919700f6c55b981a8ac6bb6fe1f27 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Sun, 2 Aug 2020 12:33:58 -0400 Subject: [PATCH] use c99 and cxx11 int32 type --- .github/workflows/ci_linux.yml | 9 +++++++++ .github/workflows/ci_mac.yml | 9 +++++++++ CMakeLists.txt | 2 +- Examples/CMakeLists.txt | 18 +++++++++++++----- Examples/example3.c | 7 ++++--- Examples/example4.cxx | 5 +++-- Examples/fortran_interface.f90 | 6 +++--- Examples/fortran_interface.h | 4 ++-- Examples/fortran_interface.hpp | 4 ++-- Install.md | 2 +- meson.build | 2 +- 11 files changed, 48 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci_linux.yml b/.github/workflows/ci_linux.yml index a2996ce2..44d9097c 100644 --- a/.github/workflows/ci_linux.yml +++ b/.github/workflows/ci_linux.yml @@ -20,3 +20,12 @@ jobs: sudo apt install -yq --no-install-recommends gfortran libhdf5-dev - run: ctest -S setup.cmake -VV + + - name: build examples + run: | + cmake -B Examples/build -S Examples + cmake --build Examples/build + + - name: test examples + run: ctest -V + working-directory: Examples/build diff --git a/.github/workflows/ci_mac.yml b/.github/workflows/ci_mac.yml index 370ac8c2..fb76ae2a 100644 --- a/.github/workflows/ci_mac.yml +++ b/.github/workflows/ci_mac.yml @@ -20,3 +20,12 @@ jobs: env: FC: gfortran-9 CC: gcc-9 + + - name: build examples + run: | + cmake -B Examples/build -S Examples + cmake --build Examples/build + + - name: test examples + run: ctest -V + working-directory: Examples/build diff --git a/CMakeLists.txt b/CMakeLists.txt index 30ac5be0..52d1e65a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ if(NOT CMAKE_BUILD_TYPE) endif() project(h5fortran LANGUAGES C Fortran - VERSION 2.11.2 + VERSION 2.11.3 DESCRIPTION "thin, light object-oriented HDF5 Fortran interface" HOMEPAGE_URL https://github.com/geospace-code/h5fortran) enable_testing() diff --git a/Examples/CMakeLists.txt b/Examples/CMakeLists.txt index 00c3b828..bfe146ce 100644 --- a/Examples/CMakeLists.txt +++ b/Examples/CMakeLists.txt @@ -8,7 +8,7 @@ include(FetchContent) FetchContent_Declare(h5fortran_proj GIT_REPOSITORY https://github.com/geospace-code/h5fortran.git - GIT_TAG v2.11.2 + GIT_TAG v2.11.3 ) FetchContent_MakeAvailable(h5fortran_proj) @@ -23,19 +23,27 @@ target_link_libraries(fortran_interface PRIVATE h5fortran::h5fortran) # --- example 1 add_executable(example1 example1.f90) target_link_libraries(example1 h5fortran::h5fortran) -add_test(NAME h5fortran:Example1 COMMAND $) +add_test(NAME h5fortran:Example1 COMMAND $ +WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) # --- example 2 add_executable(example2 example2.f90) target_link_libraries(example2 h5fortran::h5fortran) -add_test(NAME h5fortran:Example2 COMMAND $) +add_test(NAME h5fortran:Example2 COMMAND $ +WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) # --- example 3 add_executable(example3 example3.c) target_link_libraries(example3 fortran_interface) -add_test(NAME h5fortran:Example3 COMMAND $) +target_compile_features(example3 PRIVATE c_std_99) +# https://en.cppreference.com/w/c/types/integer +add_test(NAME h5fortran:Example3 COMMAND $ +WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) # --- example 4 add_executable(example4 example4.cxx) target_link_libraries(example4 fortran_interface) -add_test(NAME h5fortran:Example4 COMMAND $) +target_compile_features(example3 PRIVATE cxx_std_11) +# https://en.cppreference.com/w/cpp/types/integer +add_test(NAME h5fortran:Example4 COMMAND $ +WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/Examples/example3.c b/Examples/example3.c index bb90aefa..7d44b617 100644 --- a/Examples/example3.c +++ b/Examples/example3.c @@ -1,12 +1,13 @@ #include +#include #include "fortran_interface.h" int main(void) { -long x = 321; -long y; +int_least32_t x = 321; +int_least32_t y; char filename[256] = "h5fortran_example3.h5"; @@ -15,7 +16,7 @@ write_int32(filename, &x); read_int32(filename, &y); if (x != y) { - fprintf(stderr, "ERROR: read/write mismatch value. Expected %ld but got %ld", x, y); + fprintf(stderr, "ERROR: read/write mismatch value. Expected %d but got %d", x, y); return 1; } diff --git a/Examples/example4.cxx b/Examples/example4.cxx index ab95b075..e4887159 100644 --- a/Examples/example4.cxx +++ b/Examples/example4.cxx @@ -1,12 +1,13 @@ #include +#include #include "fortran_interface.hpp" int main(void) { -long x = 321; -long y; +int_least32_t x = 321; +int_least32_t y; char filename[256] = "h5fortran_example4.h5"; diff --git a/Examples/fortran_interface.f90 b/Examples/fortran_interface.f90 index 92d5679c..f702e488 100644 --- a/Examples/fortran_interface.f90 +++ b/Examples/fortran_interface.f90 @@ -1,6 +1,6 @@ module fortran_interface -use, intrinsic :: iso_c_binding, only : C_LONG, C_CHAR, C_NULL_CHAR +use, intrinsic :: iso_c_binding, only : C_INT32_T, C_CHAR, C_NULL_CHAR use h5fortran, only : h5write, h5read implicit none (type, external) @@ -10,7 +10,7 @@ module fortran_interface subroutine write_int32(filename, i32) bind(C) character(kind=C_CHAR) :: filename(256) -integer(C_LONG), intent(in) :: i32 +integer(C_INT32_T), intent(in) :: i32 call h5write(cstr2fstr(filename), '/x', i32) @@ -19,7 +19,7 @@ end subroutine write_int32 subroutine read_int32(filename, i32) bind(C) character(kind=C_CHAR) :: filename(256) -integer(C_LONG), intent(out) :: i32 +integer(C_INT32_T), intent(out) :: i32 call h5read(cstr2fstr(filename), '/x', i32) diff --git a/Examples/fortran_interface.h b/Examples/fortran_interface.h index dd92b2b2..868b1cd7 100644 --- a/Examples/fortran_interface.h +++ b/Examples/fortran_interface.h @@ -1,3 +1,3 @@ -extern void write_int32(char*, long*); +extern void write_int32(char*, int_least32_t*); -extern void read_int32(char*, long*); +extern void read_int32(char*, int_least32_t*); diff --git a/Examples/fortran_interface.hpp b/Examples/fortran_interface.hpp index a72e435f..700836d3 100644 --- a/Examples/fortran_interface.hpp +++ b/Examples/fortran_interface.hpp @@ -1,3 +1,3 @@ -extern "C" void write_int32(char*, long*); +extern "C" void write_int32(char*, int_least32_t*); -extern "C" void read_int32(char*, long*); +extern "C" void read_int32(char*, int_least32_t*); diff --git a/Install.md b/Install.md index 708de3b0..3f70694e 100644 --- a/Install.md +++ b/Install.md @@ -83,7 +83,7 @@ include(FetchContent) FetchContent_Declare(h5fortran_proj GIT_REPOSITORY https://github.com/geospace-code/h5fortran.git - GIT_TAG v2.11.2 + GIT_TAG v2.11.3 ) FetchContent_MakeAvailable(h5fortran_proj) diff --git a/meson.build b/meson.build index 64a0f13b..b2ba0d5f 100644 --- a/meson.build +++ b/meson.build @@ -1,6 +1,6 @@ project('h5fortran', 'fortran', meson_version : '>=0.52.0', - version : '2.11.2', + version : '2.11.3', default_options : ['default_library=static', 'buildtype=release', 'warning_level=3']) subdir('meson')