Skip to content
Snippets Groups Projects
Commit 09f7614f authored by Lionel GUEZ's avatar Lionel GUEZ
Browse files

Try finding NetCDF built with cmake or pkg-config

I found taking advantage of pkg-config useful on Ciclad, because we
already have to play with pkg-config to find NetCDF-Fortran.
parent 7630d0a8
No related branches found
No related tags found
No related merge requests found
# https://gitlab.kitware.com/vtk/vtk/blob/d42d8eb02bc965134eb92dde4aaab92223cb8a6a/CMake/FindNetCDF.cmake
# I have had trouble with this version of FindNetCDF for ml2pl on
# Irene, but, on the other hand, I found this version of FindNetCDF
# useful for NetCDF95 on Ciclad, taking advantage of pkg-config.
#[==[
Provides the following variables:
* `NetCDF_FOUND`: Whether NetCDF was found or not.
* `NetCDF_INCLUDE_DIRS`: Include directories necessary to use NetCDF.
* `NetCDF_LIBRARIES`: Libraries necessary to use NetCDF.
* `NetCDF_VERSION`: The version of NetCDF found.
* `NetCDF::NetCDF`: A target to use with `target_link_libraries`.
#]==]
# Try to find a CMake-built NetCDF.
find_package(netCDF CONFIG QUIET)
if (netCDF_FOUND)
# Forward the variables in a consistent way.
set(NetCDF_FOUND "${netCDF_FOUND}")
set(NetCDF_INCLUDE_DIRS "${netCDF_INCLUDE_DIR}")
set(NetCDF_LIBRARIES "${netCDF_LIBRARIES}")
set(NetCDF_VERSION "${NetCDFVersion}")
if (NOT TARGET NetCDF::NetCDF)
add_library(NetCDF::NetCDF INTERFACE IMPORTED)
set_target_properties(NetCDF::NetCDF PROPERTIES
INTERFACE_LINK_LIBRARIES "${NetCDF_LIBRARIES}")
endif ()
# Skip the rest of the logic in this file.
return ()
endif ()
find_package(PkgConfig QUIET)
if (PkgConfig_FOUND)
pkg_check_modules(_NetCDF QUIET netcdf IMPORTED_TARGET)
if (_NetCDF_FOUND)
# Forward the variables in a consistent way.
set(NetCDF_FOUND "${_NetCDF_FOUND}")
set(NetCDF_INCLUDE_DIRS "${_NetCDF_INCLUDE_DIRS}")
set(NetCDF_LIBRARIES "${_NetCDF_LIBRARIES}")
set(NetCDF_VERSION "${_NetCDF_VERSION}")
if (NOT TARGET NetCDF::NetCDF)
add_library(NetCDF::NetCDF INTERFACE IMPORTED)
set_target_properties(NetCDF::NetCDF PROPERTIES
INTERFACE_LINK_LIBRARIES "PkgConfig::_NetCDF")
endif ()
# Skip the rest of the logic in this file.
return ()
endif ()
endif ()
find_path(NetCDF_INCLUDE_DIR find_path(NetCDF_INCLUDE_DIR
NAMES netcdf.h NAMES netcdf.h
DOC "netcdf include directories") DOC "netcdf include directories")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment