Skip to content

Commit 0a4e279

Browse files
committed
cmake: find hdf5.mod that may be missing from include_dirs
find auxiliary libraries needed by hdf5 when compiler wrapper is not working
1 parent 7da83f0 commit 0a4e279

File tree

5 files changed

+83
-9
lines changed

5 files changed

+83
-9
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ if(NOT CMAKE_BUILD_TYPE)
33
set(CMAKE_BUILD_TYPE Release CACHE STRING "Debug or Release")
44
endif()
55
project(h5fortran
6-
LANGUAGES Fortran
7-
VERSION 2.5.3
6+
LANGUAGES C Fortran
7+
VERSION 2.5.4
88
DESCRIPTION "thin, light, easy HDF5 Fortran interface"
99
HOMEPAGE_URL https://github.com/scivision/h5fortran)
1010
enable_testing()

cmake/Modules/FindSZIP.cmake

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2+
# file Copyright.txt or https://cmake.org/licensing for details.
3+
4+
#[=======================================================================[.rst:
5+
6+
FindSZIP
7+
---------
8+
9+
by Michael Hirsch, Ph.D. www.scivision.dev
10+
11+
Finds SZIP developed by HDF Group & used by HDF5.
12+
13+
14+
Result Variables
15+
^^^^^^^^^^^^^^^^
16+
17+
``SZIP_FOUND``
18+
SZIP libraries were found
19+
``SZIP_INCLUDE_DIRS``
20+
SZIP include directory
21+
``SZIP_LIBRARIES``
22+
SZIP library files
23+
24+
25+
Targets
26+
^^^^^^^
27+
28+
``SZIP::SZIP``
29+
SZIP Imported Target
30+
#]=======================================================================]
31+
32+
find_library(SZIP_LIBRARY NAMES szip sz)
33+
34+
find_path(SZIP_INCLUDE_DIR NAMES szlib.h)
35+
36+
include(FindPackageHandleStandardArgs)
37+
find_package_handle_standard_args(SZIP
38+
REQUIRED_VARS SZIP_LIBRARY SZIP_INCLUDE_DIR)
39+
40+
if(SZIP_FOUND)
41+
set(SZIP_INCLUDE_DIRS ${SZIP_INCLUDE_DIR})
42+
set(SZIP_LIBRARIES ${SZIP_LIBRARY})
43+
44+
if(NOT TARGET SZIP::SZIP)
45+
add_library(SZIP::SZIP UNKNOWN IMPORTED)
46+
set_target_properties(SZIP::SZIP PROPERTIES
47+
IMPORTED_LOCATION ${SZIP_LIBRARY}
48+
INTERFACE_INCLUDE_DIRECTORIES ${SZIP_INCLUDE_DIR})
49+
endif()
50+
endif()
51+
52+
mark_as_advanced(SZIP_LIBRARY SZIP_INCLUDE_DIR)

cmake/hdf5.cmake

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,51 @@
11
# don't enclose this all in "if(NOT DEFINED HDF5OK)" because CMake intermittantly doesn't cache needed HDF5 variables.
22

33
set(HDF5_USE_STATIC_LIBRARIES true)
4-
54
# Intel HDF5 for Windows has some real issues from the factory, this makes it work:
65
if(WIN32 AND CMAKE_Fortran_COMPILER_ID STREQUAL Intel)
76
set(HDF5_NO_FIND_PACKAGE_CONFIG_FILE true)
8-
set(HDF5_SEARCH_WRAPPER false)
97
set(HDF5_USE_STATIC_LIBRARIES false)
108
endif()
119

1210
find_package(HDF5 REQUIRED COMPONENTS Fortran HL)
13-
if(MINGW)
14-
set(HDF5_INCLUDE_DIRS ${HDF5_INCLUDE_DIRS}/static)
11+
list(APPEND HDF5_INCLUDE_DIRS ${HDF5_Fortran_INCLUDE_DIRS})
12+
# this is because HDF5's CONFIG files are incorrect (at least for 1.10.5)
13+
find_path(HDF5_MODULE_DIR NAMES hdf5.mod HINTS ${HDF5_INCLUDE_DIRS} PATH_SUFFIXES static)
14+
if(HDF5_MODULE_DIR)
15+
list(APPEND HDF5_INCLUDE_DIRS ${HDF5_MODULE_DIR})
16+
set(SZIP_ROOT "${HDF5_MODULE_DIR}/..;${HDF5_MODULE_DIR}/../..")
17+
set(ZLIB_ROOT ${SZIP_ROOT})
1518
endif()
19+
list(REMOVE_DUPLICATES HDF5_INCLUDE_DIRS)
1620

21+
# in case the compiler wrapper didn't work
1722
set(HDF5_LIBRARIES ${HDF5_Fortran_HL_LIBRARIES} ${HDF5_Fortran_LIBRARIES} ${HDF5_LIBRARIES})
18-
list(APPEND HDF5_INCLUDE_DIRS ${HDF5_Fortran_INCLUDE_DIRS})
23+
24+
find_package(SZIP)
25+
if(SZIP_FOUND)
26+
list(APPEND HDF5_LIBRARIES SZIP::SZIP)
27+
endif()
28+
find_package(ZLIB)
29+
if(ZLIB_FOUND)
30+
list(APPEND HDF5_LIBRARIES ZLIB::ZLIB)
31+
endif()
32+
set(THREADS_PREFER_PTHREAD_FLAG true)
33+
find_package(Threads)
34+
if(Threads_FOUND)
35+
list(APPEND HDF5_LIBRARIES Threads::Threads)
36+
endif()
37+
list(APPEND HDF5_LIBRARIES ${CMAKE_DL_LIBS})
38+
if(UNIX)
39+
list(APPEND HDF5_LIBRARIES m)
40+
endif()
1941

2042
if(DEFINED HDF5OK)
2143
return()
2244
endif()
2345

2446
message(STATUS "HDF5 include: ${HDF5_INCLUDE_DIRS}")
2547
message(STATUS "HDF5 library: ${HDF5_LIBRARIES}")
48+
# we don't use these because they may come from a broken compiler wrapper
2649
if(HDF5_Fortran_COMPILER_EXECUTABLE)
2750
message(STATUS "HDF5 Fortran compiler: ${HDF5_Fortran_COMPILER_EXECUTABLE}")
2851
endif()

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.5.3',
3+
version : '2.5.4',
44
default_options : ['default_library=static', 'buildtype=release', 'warning_level=3'])
55

66
subdir('meson')

src/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ target_include_directories(h5fortran PRIVATE ${HDF5_INCLUDE_DIRS}
77
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
88
$<INSTALL_INTERFACE:include>)
99
target_link_libraries(h5fortran PRIVATE ${HDF5_LIBRARIES})
10-
target_compile_options(h5fortran PRIVATE ${HDF5_Fortran_DEFINITIONS})
1110
set_target_properties(h5fortran PROPERTIES
1211
Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include
1312
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}

0 commit comments

Comments
 (0)