Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add support for Baselibs built with shared libraries, zstandard #280

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Changed

- Added support for Baselibs built with netCDF as a shared library
- Add `NETCDF_INCLUDE_DIR` as alias to `INC_NETCDF` for spack compatibility

### Fixed

- Updated the CI to work with latest Baselibs
Expand Down
25 changes: 19 additions & 6 deletions external_libraries/FindBaselibs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ if (Baselibs_FOUND)

set (INC_HDF5 ${BASEDIR}/include/hdf5)
set (INC_NETCDF ${BASEDIR}/include/netcdf)
set (NETCDF_INCLUDE_DIR ${INC_NETCDF})
set (INC_HDF ${BASEDIR}/include/hdf)

# Need to do a bit of kludgy stuff here to allow Fortran linker to
Expand Down Expand Up @@ -183,22 +184,34 @@ if (Baselibs_FOUND)
# We also need to append the pthread flag at link time
list(APPEND NETCDF_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})

# Now we try to detect if the netcdf library was linked statically or
# dynamically by looking for hdf5 in NETCDF_LIBRARIES. Could be fragile,
# but nf-config --flibs for a shared build should never have libhdf5
if ("hdf5" IN_LIST NETCDF_LIBRARIES)
set(NETCDF_LIBRARY_TYPE STATIC)
set(NETCDF_LIBRARY_SUFFIX ${CMAKE_STATIC_LIBRARY_SUFFIX})
else ()
set(NETCDF_LIBRARY_TYPE SHARED)
set(NETCDF_LIBRARY_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX})
endif ()
message(STATUS "Detected that NetCDF in Baselibs was built as ${NETCDF_LIBRARY_TYPE}")

# Create targets
# - NetCDF C
add_library(NetCDF::NetCDF_C STATIC IMPORTED)
add_library(NetCDF::NetCDF_C ${NETCDF_LIBRARY_TYPE} IMPORTED)
set_target_properties(NetCDF::NetCDF_C PROPERTIES
IMPORTED_LOCATION ${BASEDIR}/lib/libnetcdf.a
INTERFACE_INCLUDE_DIRECTORIES "${INC_NETCDF}"
IMPORTED_LOCATION ${BASEDIR}/lib/libnetcdf${NETCDF_LIBRARY_SUFFIX}
INTERFACE_INCLUDE_DIRECTORIES "${NETCDF_INCLUDE_DIR}"
INTERFACE_LINK_LIBRARIES "${NETCDF_LIBRARIES}"
INTERFACE_LINK_DIRECTORIES "${BASEDIR}/lib"
)
set(NetCDF_C_FOUND TRUE CACHE BOOL "NetCDF C Found" FORCE)

# - NetCDF Fortran
add_library(NetCDF::NetCDF_Fortran STATIC IMPORTED)
add_library(NetCDF::NetCDF_Fortran ${NETCDF_LIBRARY_TYPE} IMPORTED)
set_target_properties(NetCDF::NetCDF_Fortran PROPERTIES
IMPORTED_LOCATION ${BASEDIR}/lib/libnetcdff.a
INTERFACE_INCLUDE_DIRECTORIES "${INC_NETCDF}"
IMPORTED_LOCATION ${BASEDIR}/lib/libnetcdff${NETCDF_LIBRARY_SUFFIX}
INTERFACE_INCLUDE_DIRECTORIES "${NETCDF_INCLUDE_DIR}"
INTERFACE_LINK_LIBRARIES "${NETCDF_LIBRARIES}"
INTERFACE_LINK_DIRECTORIES "${BASEDIR}/lib"
)
Expand Down
2 changes: 1 addition & 1 deletion python/f2py/UseF2Py.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ macro (add_f2py_module _name)
if (Baselibs_FOUND)

# include dirs
foreach(_dir ${INC_NETCDF})
foreach(_dir ${NETCDF_INCLUDE_DIR})
list(APPEND _inc_opts "-I${_dir}")
endforeach()

Expand Down
2 changes: 1 addition & 1 deletion python/f2py2/UseF2Py2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ macro (add_f2py2_module _name)
if (Baselibs_FOUND)

# include dirs
foreach(_dir ${INC_NETCDF})
foreach(_dir ${NETCDF_INCLUDE_DIR})
list(APPEND _inc_opts "-I${_dir}")
endforeach()

Expand Down
2 changes: 1 addition & 1 deletion python/f2py3/UseF2Py3.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ macro (add_f2py3_module _name)
if (Baselibs_FOUND)

# include dirs
foreach(_dir ${INC_NETCDF})
foreach(_dir ${NETCDF_INCLUDE_DIR})
list(APPEND _inc_opts "-I${_dir}")
endforeach()

Expand Down