Skip to content

Commit c5a8871

Browse files
committed
MSYS2 works OK
better search init unused []
1 parent e123cd3 commit c5a8871

File tree

7 files changed

+87
-33
lines changed

7 files changed

+87
-33
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ before_install:
3434

3535
install: meson build
3636

37-
script: meson test -C build
37+
script: meson test -C build -v

README.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Object-oriented Fortran 2018 HDF5 interface
77

88
Straightforward single-file/module access to HDF5.
9-
Uses Fortran 2008 `submodule` for clean, templatable structure.
9+
Uses Fortran 2008 `submodule` for clean template structure.
1010
This thin object-oriented modern Fortran library abstracts away the messy parts of HDF5 so that you can read/write various types/ranks of data with a single command.
1111

1212
Polymorphic API with read/write for types integer, real32, real64 with rank:
@@ -21,23 +21,24 @@ Tested on systems with HDF5 1.8 and 1.10 including:
2121
* MacOS (homebrew)
2222
* Ubuntu 16.04 / 18.04 (gfortran 6 or newer)
2323
* Windows Subsystem for Linux.
24+
* Windows MSYS2
2425

25-
Note: Currently, Cygwin does not have Fortran HDF5 libraries.
26+
Currently, Cygwin does not have *Fortran* HDF5 libraries.
2627

2728
## Build
2829

2930
Requirements:
3031

31-
* modern Fortran 2008 compiler (such as gfortran ≥ 5.4.1, etc.)
32+
* modern Fortran 2008 compiler
3233
* HDF5 Fortran library (1.8 or 1.10)
3334
* Mac: `brew install gcc hdf5`
3435
* Linux: `apt install gfortran libhdf5-dev`
3536
* Windows Subsystem for Linux: `apt install gfortran libhdf5-dev`
37+
* Windows MSYS2: `pacman -S mingw-w64-x86_64-hdf5`
3638

3739
Note that some precompiled HDF5 libraries include C / C++ without Fortran.
38-
We have included a test in the build system to ensure that HDF5 links in Fortran before trying to buidl the OOHDF5 library.
3940

40-
Build this HDF5 OO Fortran interface with other Meson or CMake.
41+
Build this HDF5 OO Fortran interface with Meson or CMake.
4142
The library `libh5oo` is built, link it into your program as usual.
4243

4344
### Meson
@@ -48,6 +49,17 @@ meson build
4849
meson test -C build
4950
```
5051

52+
If HDF5 isn't found, you may need to specify on the command line:
53+
54+
* `-Dh5libdir`: HDF5 library directory
55+
* `-Dh5incdir`: HDF5 include directory
56+
57+
For MSYS2 this might be like:
58+
59+
```posh
60+
meson build -Dh5libdir=c:/msys64/mingw64/lib -Dh5incdir=c:/msys64/mingw64/include/static
61+
```
62+
5163
### CMake
5264

5365
```sh
@@ -63,7 +75,8 @@ cd build
6375
ctest -V
6476
```
6577

66-
If you need to specify a particular HDF5 library, use
78+
To specify a particular HDF5 library, use
79+
6780
```sh
6881
cmake -DHDF5_ROOT=/path/to/hdf5lib -B build
6982
```

build/.ignore

Whitespace-only changes.

cmake/hdf5.cmake

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
11
find_package(HDF5 REQUIRED COMPONENTS Fortran Fortran_HL)
22

3+
if(WIN32)
4+
# Needed for MSYS2, this directory wasn't in CMake 3.15.2 FindHDF5
5+
if(EXISTS ${HDF5_INCLUDE_DIRS}/static)
6+
list(APPEND HDF5_INCLUDE_DIRS ${HDF5_INCLUDE_DIRS}/static)
7+
endif()
8+
endif()
9+
10+
message(STATUS "HDF5 includes: ${HDF5_INCLUDE_DIRS} ${HDF5_Fortran_INCLUDE_DIRS}")
11+
message(STATUS "HDF5 library: ${HDF5_Fortran_LIBRARIES} H5LT library: ${HDF5_Fortran_HL_LIBRARIES}")
12+
if(HDF5_Fortran_COMPILER_EXECUTABLE)
13+
message(STATUS "HDF5 Fortran compiler: ${HDF5_Fortran_COMPILER_EXECUTABLE}")
14+
endif()
15+
if(HDF5_Fortran_DEFINITIONS)
16+
message(STATUS "HDF5 compiler defs: ${HDF5_Fortran_DEFINITIONS}")
17+
endif()
18+
319
set(CMAKE_REQUIRED_INCLUDES ${HDF5_INCLUDE_DIRS} ${HDF5_Fortran_INCLUDE_DIRS})
420
set(CMAKE_REQUIRED_LIBRARIES ${HDF5_Fortran_LIBRARIES} ${HDF5_Fortran_HL_LIBRARIES})
521

622
include(CheckFortranSourceCompiles)
723
check_fortran_source_compiles("use h5lt; end" hasHDF5 SRC_EXT f90)
824

925
if(NOT hasHDF5)
10-
message(FATAL_ERROR "HDF5 library not working with ${CMAKE_Fortran_COMPILER_ID} ${CMAKE_Fortran_COMPILER_VERSION}")
26+
message(WARNING "HDF5 library may not be working with ${CMAKE_Fortran_COMPILER_ID} ${CMAKE_Fortran_COMPILER_VERSION}")
1127
endif()

cmake/meson.build

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
quiet = ['-w']
2+
3+
fc = meson.get_compiler('fortran')
4+
f18flag = fc.first_supported_argument(['-std=f2018', '-stand f18', '/stand:f18'])
5+
if fc.get_id() == 'gcc'
6+
add_project_arguments('-fimplicit-none', f18flag, language : 'fortran')
7+
quiet = ['-Wno-compare-reals', '-Wno-maybe-uninitialized']
8+
elif fcid == 'intel'
9+
add_project_arguments('-warn', '-heap-arrays', f18flag, language : 'fortran')
10+
elif fcid == 'intel-cl'
11+
add_project_arguments('/warn', '/heap-arrays', f18flag, language : 'fortran')
12+
elif fcid == 'pgi'
13+
add_project_arguments('-C', '-Mdclchk', language : 'fortran')
14+
endif
15+
16+
17+
hdf5 = dependency('hdf5', language : 'fortran', required: false)
18+
h5incdir = []
19+
if not hdf5.found()
20+
h5libdir = get_option('h5libdir')
21+
if h5libdir == ''
22+
h5libdir = []
23+
endif
24+
h5incdir = include_directories(get_option('h5incdir'))
25+
hdf5_libs = []
26+
foreach name : ['hdf5', 'hdf5_fortran', 'hdf5_hl', 'hdf5_hl_fortran', # msys2 names
27+
'hdf5_serial', 'hdf5_serial_fortran',
28+
'hdf5_serial_hl', 'hdf5_serialhl_fortran']
29+
lib = fc.find_library(name, required: false, dirs: h5libdir)
30+
if lib.found()
31+
hdf5_libs += lib
32+
endif
33+
endforeach
34+
if hdf5_libs.length() == 0
35+
error('could not find HDF5 library')
36+
endif
37+
# hdf5 = declare_dependency(dependencies: hdf5_libs, include_directories: h5incdir) # meson bug?
38+
hdf5 = hdf5_libs
39+
endif
40+
h5run = fc.run('use h5lt; end', dependencies: hdf5, include_directories: h5incdir, name: 'HDF5 runs')
41+
if h5run.returncode() != 0
42+
warning('HDF5 possible linking problems: ' + h5run.stdout() + h5run.stderr())
43+
endif

meson.build

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,15 @@
11
project('Object-oriented HDF5 Fortran', 'fortran',
22
meson_version : '>=0.51.2',
3-
version : '1.0.0')
3+
version : '1.0.0',
4+
default_options : ['default_library=static', 'buildtype=release', 'warning_level=3'])
45

5-
quiet = ['-w']
6-
7-
fc = meson.get_compiler('fortran')
8-
if fc.get_id() == 'gcc'
9-
add_project_arguments('-O', '-fimplicit-none', '-Wextra', '-Wpedantic', language : 'fortran')
10-
quiet = ['-Wno-compare-reals', '-Wno-maybe-uninitialized']
11-
if fc.version().version_compare('>=8')
12-
add_project_arguments('-std=f2018', language : 'fortran')
13-
endif
14-
elif fcid == 'intel'
15-
add_project_arguments('-warn', '-heap-arrays', '-stand f18', language : 'fortran')
16-
elif fcid == 'intel-cl'
17-
add_project_arguments('/warn', '/heap-arrays', '/stand:f18', language : 'fortran')
18-
elif fcid == 'pgi'
19-
add_project_arguments('-C', '-Mdclchk', language : 'fortran')
20-
endif
21-
22-
hdf5 = dependency('hdf5', language : 'fortran')
23-
24-
h5run = fc.run('use h5lt; end', dependencies: hdf5, name: 'HDF5')
25-
if h5run.returncode() != 0
26-
error('HDF5 linking problems: ' + h5run.stderr())
27-
endif
6+
subdir('cmake')
287

298
subdir('src')
309
ooh5 = library('oohdf5',
3110
sources: hdf5_src,
32-
dependencies: hdf5
11+
dependencies: hdf5,
12+
include_directories: h5incdir
3313
)
3414

3515
# --- testing

meson_options.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
option('h5libdir', type : 'string', description : 'HDF5 library directory', yield: true)
2+
option('h5incdir', type : 'string', description : 'HDF5 include directory', yield: true)

0 commit comments

Comments
 (0)