cmake: find HDF4 under /usr/local/hdf4 and MacPorts, accept libhdf naming

HDF4 built with its own CMake build system (rather than autotools) is
commonly installed under a non-standard prefix like /usr/local/hdf4,
which CMake's default find_path/find_library search does not cover,
and names the low-level library 'hdf' instead of 'df'.

Verified working on macOS 27.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-01 14:48:27 +02:00
co-authored by Claude Sonnet 5
parent a53b1fe5d9
commit 20720ec950
+10 -2
View File
@@ -315,18 +315,26 @@ if (nexus)
find_package(HDF5 COMPONENTS CXX REQUIRED)
if (HAVE_HDF4)
#--- check for HDF4 -----------------------------------------------------------
# Find HDF4 manually (pkg-config often doesn't have hdf4)
# Find HDF4 manually (pkg-config often doesn't have hdf4). In addition to the
# standard system locations, also look under /usr/local/hdf4 and /opt/local
# (MacPorts), which are common self-built/ported install prefixes and are not
# part of CMake's default search path. HDF4 built with its own CMake build
# system (as opposed to the autotools build) names the low-level library
# 'hdf' instead of 'df', so both names are accepted.
find_path(HDF4_INCLUDE_DIR
NAMES mfhdf.h
HINTS /usr/local/hdf4/include /opt/local/include/hdf
PATH_SUFFIXES hdf
)
find_library(HDF4_DF_LIBRARY
NAMES df libdf
NAMES df libdf hdf libhdf
HINTS /usr/local/hdf4/lib /opt/local/lib
)
find_library(HDF4_MFHDF_LIBRARY
NAMES mfhdf libmfhdf
HINTS /usr/local/hdf4/lib /opt/local/lib
)
if (HDF4_INCLUDE_DIR AND HDF4_DF_LIBRARY AND HDF4_MFHDF_LIBRARY)