From 6735e90b5cb7810466c0e62ab3ae6bb6b7c4b1c1 Mon Sep 17 00:00:00 2001 From: Andreas Suter Date: Tue, 28 Jul 2026 10:24:11 +0200 Subject: [PATCH] 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 --- CMakeLists.txt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c6557d4..0a4d0e64 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -278,18 +278,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)