Skip to content

Commit 356647d

Browse files
committed
cmake: make search warapper optional
rank-1 size-0 allocate cmake: windows
1 parent 7ce4d9c commit 356647d

File tree

9 files changed

+45
-49
lines changed

9 files changed

+45
-49
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ if(NOT CMAKE_BUILD_TYPE)
44
endif()
55
project(hdf5iface
66
LANGUAGES Fortran
7-
VERSION 2.3.0
7+
VERSION 2.3.1
88
HOMEPAGE_URL https://github.com/scivision/h5fortran)
99
enable_testing()
1010

cmake/Modules/FindHDF5.cmake

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ The following variable can be set to guide the search for HDF5 libraries and inc
132132
include(SelectLibraryConfigurations)
133133
include(FindPackageHandleStandardArgs)
134134

135+
cmake_policy(SET CMP0074 NEW)
136+
135137
# List of the valid HDF5 components
136138
set(HDF5_VALID_LANGUAGE_BINDINGS C CXX Fortran)
137139

@@ -463,15 +465,16 @@ if(NOT HDF5_ROOT)
463465
set(HDF5_ROOT $ENV{HDF5_ROOT})
464466
endif()
465467
if(HDF5_ROOT)
466-
set(_HDF5_SEARCH_OPTS NO_DEFAULT_PATH)
468+
set(_HDF5_SEARCH_OPTS NO_CMAKE_PATH NO_CMAKE_SYSTEM_PATH
469+
NO_CMAKE_PACKAGE_REGISTRY NO_CMAKE_SYSTEM_PACKAGE_REGISTRY
470+
NO_CMAKE_ENVIRONMENT_PATH NO_SYSTEM_ENVIRONMENT_PATH)
467471
else()
468472
set(_HDF5_SEARCH_OPTS)
469473
endif()
470474

471475
# Try to find HDF5 using an installed hdf5-config.cmake
472476
if(NOT HDF5_FOUND AND NOT HDF5_NO_FIND_PACKAGE_CONFIG_FILE)
473477
find_package(HDF5 QUIET NO_MODULE
474-
HINTS ${HDF5_ROOT}
475478
${_HDF5_SEARCH_OPTS}
476479
)
477480
if( HDF5_FOUND)
@@ -552,7 +555,7 @@ if(NOT HDF5_FOUND AND NOT HDF5_NO_FIND_PACKAGE_CONFIG_FILE)
552555
endif()
553556
endif()
554557

555-
if(NOT HDF5_FOUND)
558+
if(NOT HDF5_FOUND AND HDF5_SEARCH_WRAPPER)
556559
set(_HDF5_NEED_TO_SEARCH False)
557560
set(HDF5_COMPILER_NO_INTERROGATE True)
558561
# Only search for languages we've enabled
@@ -596,7 +599,6 @@ if(NOT HDF5_FOUND)
596599
# search options with the wrapper
597600
find_program(HDF5_${__lang}_COMPILER_EXECUTABLE
598601
NAMES ${HDF5_${__lang}_COMPILER_NAMES} NAMES_PER_DIR
599-
HINTS ${HDF5_ROOT}
600602
PATH_SUFFIXES bin Bin
601603
DOC "HDF5 ${__lang} Wrapper compiler. Used only to detect HDF5 compile flags."
602604
${_HDF5_SEARCH_OPTS}
@@ -637,7 +639,6 @@ if(NOT HDF5_FOUND)
637639
find_library(HDF5_${__lang}_LIBRARY_${L}
638640
NAMES ${_HDF5_SEARCH_NAMES_LOCAL} ${L} NAMES_PER_DIR
639641
HINTS ${HDF5_${__lang}_LIBRARY_DIRS}
640-
${HDF5_ROOT}
641642
${_HDF5_SEARCH_OPTS_LOCAL}
642643
)
643644
unset(_HDF5_SEARCH_OPTS_LOCAL)
@@ -669,7 +670,6 @@ if(NOT HDF5_FOUND)
669670
find_library(HDF5_${__lang}_LIBRARY_${L}
670671
NAMES ${_HDF5_SEARCH_NAMES_LOCAL} ${L} NAMES_PER_DIR
671672
HINTS ${HDF5_${__lang}_LIBRARY_DIRS}
672-
${HDF5_ROOT}
673673
${_HDF5_SEARCH_OPTS_LOCAL}
674674
)
675675
unset(_HDF5_SEARCH_OPTS_LOCAL)
@@ -752,7 +752,6 @@ endif()
752752

753753
find_program( HDF5_DIFF_EXECUTABLE
754754
NAMES h5diff
755-
HINTS ${HDF5_ROOT}
756755
PATH_SUFFIXES bin Bin
757756
${_HDF5_SEARCH_OPTS}
758757
DOC "HDF5 file differencing tool." )
@@ -786,7 +785,6 @@ if( NOT HDF5_FOUND )
786785
endif()
787786

788787
find_path(HDF5_${__lang}_INCLUDE_DIR ${HDF5_INCLUDE_FILENAME}
789-
HINTS ${HDF5_ROOT}
790788
PATHS $ENV{HOME}/.local/include
791789
PATH_SUFFIXES include Include ${_path_suffixes}
792790
${_HDF5_SEARCH_OPTS}
@@ -817,19 +815,19 @@ if( NOT HDF5_FOUND )
817815
endif()
818816
find_library(HDF5_${LIB}_LIBRARY_DEBUG
819817
NAMES ${THIS_LIBRARY_SEARCH_DEBUG}
820-
HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib
818+
PATH_SUFFIXES lib Lib
821819
${_HDF5_SEARCH_OPTS}
822820
)
823821
find_library( HDF5_${LIB}_LIBRARY_RELEASE
824822
NAMES ${THIS_LIBRARY_SEARCH_RELEASE}
825-
HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib
823+
PATH_SUFFIXES lib Lib
826824
${_HDF5_SEARCH_OPTS}
827825
)
828826
# patch for HDF5 1.10.6 name change
829827
if(NOT HDF5_${LIB}_LIBRARY_RELEASE AND (LIB STREQUAL hdf5_hl_fortran))
830828
find_library( HDF5_${LIB}_LIBRARY_RELEASE
831829
NAMES hdf5hl_fortran hdf5hl_fortran-shared
832-
HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib
830+
PATH_SUFFIXES lib Lib
833831
${_HDF5_SEARCH_OPTS}
834832
)
835833
endif()
@@ -863,12 +861,12 @@ if( NOT HDF5_FOUND )
863861
endif()
864862
find_library(HDF5_${LIB}_LIBRARY_DEBUG
865863
NAMES ${THIS_LIBRARY_SEARCH_DEBUG}
866-
HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib
864+
PATH_SUFFIXES lib Lib
867865
${_HDF5_SEARCH_OPTS}
868866
)
869867
find_library( HDF5_${LIB}_LIBRARY_RELEASE
870868
NAMES ${THIS_LIBRARY_SEARCH_RELEASE}
871-
HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib
869+
PATH_SUFFIXES lib Lib
872870
${_HDF5_SEARCH_OPTS}
873871
)
874872
select_library_configurations( HDF5_${LIB} )
@@ -970,4 +968,4 @@ if (HDF5_FIND_DEBUG)
970968
message(STATUS "HDF5_${__lang}_HL_LIBRARY: ${HDF5_${__lang}_HL_LIBRARY}")
971969
message(STATUS "HDF5_${__lang}_HL_LIBRARIES: ${HDF5_${__lang}_HL_LIBRARIES}")
972970
endforeach()
973-
endif()
971+
endif()

cmake/compilers.cmake

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,27 @@
22
# check_fortran_source_compiles("real, dimension(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1) :: x; end" f08rank15 SRC_EXT f90)
33

44
if(CMAKE_Fortran_COMPILER_ID STREQUAL Intel)
5-
if(NOT WIN32)
6-
set(FFLAGS -stand f18 -warn declarations -traceback -warn -heap-arrays)
5+
if(WIN32)
6+
set(CMAKE_Fortran_FLAGS "/stand:f18 /warn:declarations /traceback /warn /heap-arrays ")
77
else()
8-
set(FFLAGS /stand:f18 /warn:declarations /traceback /warn /heap-arrays)
9-
# Note: -g is /debug:full for ifort Windows
8+
set(CMAKE_Fortran_FLAGS "-stand f18 -warn declarations -traceback -warn -heap-arrays ")
109
endif()
1110
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL GNU)
12-
list(APPEND FFLAGS -march=native -fimplicit-none)
11+
string(APPEND CMAKE_Fortran_FLAGS "-march=native -fimplicit-none ")
1312

1413
if(CMAKE_BUILD_TYPE STREQUAL Debug)
15-
list(APPEND FFLAGS -fcheck=all)
14+
string(APPEND CMAKE_Fortran_FLAGS "-fcheck=all ")
1615
endif()
1716

1817
if(CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER_EQUAL 8)
19-
list(APPEND FFLAGS -std=f2018)
18+
string(APPEND CMAKE_Fortran_FLAGS "-std=f2018 ")
2019
endif()
2120

22-
list(APPEND FFLAGS -Wall -Wextra -Wpedantic -Werror=array-bounds -Warray-temporaries)
21+
string(APPEND CMAKE_Fortran_FLAGS "-Wall -Wextra -Wpedantic ")
2322
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL PGI)
24-
set(FFLAGS -C -Mdclchk)
23+
set(CMAKE_Fortran_FLAGS "-C -Mdclchk ")
2524
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL Flang)
26-
set(FFLAGS -W)
25+
set(CMAKE_Fortran_FLAGS "-W ")
2726
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL NAG)
28-
list(APPEND FFLAGS -u -C=all)
27+
set(CMAKE_Fortran_FLAGS "-u -C=all ")
2928
endif()

cmake/hdf5.cmake

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,38 @@
11
# don't enclose this all in "if(NOT DEFINED HDF5OK)" because CMake intermittantly doesn't cache needed HDF5 variables.
2-
# if(BUILD_SHARED_LIBS)
3-
# set(HDF5_USE_STATIC_LIBRARIES false)
4-
# else()
5-
# set(HDF5_USE_STATIC_LIBRARIES true)
6-
# endif()
72

8-
if(WIN32) # pkg-config is goofed up for Windows, including MSYS2
3+
set(HDF5_SEARCH_WRAPPER true)
4+
set(HDF5_USE_STATIC_LIBRARIES true)
5+
6+
# Intel HDF5 for Windows has some real issues from the factory, this makes it work:
7+
if(WIN32 AND CMAKE_Fortran_COMPILER_ID STREQUAL Intel)
98
set(HDF5_NO_FIND_PACKAGE_CONFIG_FILE true)
9+
set(HDF5_SEARCH_WRAPPER false)
10+
set(HDF5_USE_STATIC_LIBRARIES false)
1011
endif()
1112

1213
# set(HDF5_FIND_DEBUG true)
1314

14-
find_package(HDF5 COMPONENTS Fortran Fortran_HL)
15+
find_package(HDF5 REQUIRED COMPONENTS Fortran HL)
16+
if(MINGW)
17+
set(HDF5_INCLUDE_DIRS ${HDF5_INCLUDE_DIRS}/static)
18+
message(${HDF5_INCLUDE_DIRS})
19+
endif()
20+
1521
set(HDF5_LIBRARIES ${HDF5_Fortran_HL_LIBRARIES} ${HDF5_Fortran_LIBRARIES} ${HDF5_LIBRARIES})
1622
list(APPEND HDF5_INCLUDE_DIRS ${HDF5_Fortran_INCLUDE_DIRS})
1723

18-
if(NOT DEFINED HDF5OK)
24+
if(DEFINED HDF5OK)
25+
return()
26+
endif()
1927

2028
message(STATUS "HDF5 include: ${HDF5_INCLUDE_DIRS}")
21-
2229
message(STATUS "HDF5 library: ${HDF5_LIBRARIES}")
2330
if(HDF5_Fortran_COMPILER_EXECUTABLE)
2431
message(STATUS "HDF5 Fortran compiler: ${HDF5_Fortran_COMPILER_EXECUTABLE}")
2532
endif()
2633
if(HDF5_Fortran_DEFINITIONS)
2734
message(STATUS "HDF5 compiler defs: ${HDF5_Fortran_DEFINITIONS}")
2835
endif()
29-
endif()
3036

3137
set(CMAKE_REQUIRED_INCLUDES ${HDF5_INCLUDE_DIRS})
3238
set(CMAKE_REQUIRED_LIBRARIES ${HDF5_LIBRARIES})
@@ -35,8 +41,6 @@ include(CheckFortranSourceCompiles)
3541
file(READ ${CMAKE_SOURCE_DIR}/src/tests/test_minimal.f90 _code)
3642
check_fortran_source_compiles(${_code} HDF5OK SRC_EXT f90)
3743

38-
set(HDF5OK ${HDF5OK} CACHE BOOL "HDF5 library working?")
39-
4044
if(NOT HDF5OK)
41-
message(WARNING "HDF5 library may not be working with ${CMAKE_Fortran_COMPILER_ID} ${CMAKE_Fortran_COMPILER_VERSION}")
42-
endif()
45+
message(FATAL_ERROR "HDF5 library not working with ${CMAKE_Fortran_COMPILER_ID} ${CMAKE_Fortran_COMPILER_VERSION}")
46+
endif(NOT HDF5OK)

meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
project('h5fortran', 'fortran',
22
meson_version : '>=0.52.0',
3-
version : '2.3.0',
3+
version : '2.3.1',
44
default_options : ['default_library=static', 'buildtype=release', 'warning_level=3'])
55

66
subdir('meson')

src/tests/test_hdf5_ifc.f90

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ subroutine test_string_rw(path)
294294
character(2) :: value
295295
character(1024) :: val1k
296296
character(:), allocatable :: final
297-
integer :: i
298297

299298
call h5f%initialize(path//'/test_string.h5', ierr, status='new', action='rw')
300299
call h5f%write('/little', '42', ierr)

src/tests/test_shape.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
type(hdf5_file) :: h5f
77
character(1024) :: argv
8-
character(:), allocatable :: fn, dname, cmd
8+
character(:), allocatable :: fn, dname
99
integer(HSIZE_T), allocatable :: dims(:)
1010
integer :: ierr
1111
logical :: exists

src/write.f90

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@
7676
!! sentinel value for unused property
7777
endif
7878

79-
print *, dname, size(dims)
8079
if(exists) return
8180

8281
if(size(dims) == 0) then

src/writer.f90

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
module procedure hdf_write_scalar
1010

1111
integer(HID_T) :: dtype
12-
integer(HSIZE_T) :: dims(rank(value))
12+
integer(HSIZE_T), allocatable :: dims(:)
13+
allocate(dims(0))
1314

1415
select type (value)
1516
type is (character(*))
@@ -18,25 +19,21 @@
1819
return
1920
type is (real(real64))
2021
dtype = h5kind_to_type(kind(value),H5_REAL_KIND)
21-
dims = shape(value)
2222
call hdf_setup_write(self,dname,dtype,dims, ierr)
2323
if (ierr /= 0) return
2424
call h5dwrite_f(self%did, dtype, value, dims, ierr)
2525
type is (real(real32))
2626
dtype = h5kind_to_type(kind(value),H5_REAL_KIND)
27-
dims = shape(value)
2827
call hdf_setup_write(self,dname,dtype,dims, ierr)
2928
if (ierr /= 0) return
3029
call h5dwrite_f(self%did, dtype, value, dims, ierr)
3130
type is (integer(int32))
3231
dtype = h5kind_to_type(kind(value),H5_INTEGER_KIND)
33-
dims = shape(value)
3432
call hdf_setup_write(self,dname,dtype,dims, ierr)
3533
if (ierr /= 0) return
3634
call h5dwrite_f(self%did, dtype, value, dims, ierr)
3735
type is (integer(int64))
3836
dtype = h5kind_to_type(kind(value),H5_INTEGER_KIND)
39-
dims = shape(value)
4037
call hdf_setup_write(self,dname,dtype,dims, ierr)
4138
if (ierr /= 0) return
4239
call h5dwrite_f(self%did, dtype, value, dims, ierr)

0 commit comments

Comments
 (0)