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

Update to commit 77a8f46 from cmake repository

parent 1b75e88d
No related branches found
No related tags found
No related merge requests found
# https://gitlab.kitware.com/vtk/vtk/-/blob/master/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`.
* `NetCDF_HAS_PARALLEL`: Whether or not NetCDF was found with parallel IO support.
#]==]
list(APPEND CMAKE_MESSAGE_CONTEXT FindNetCDF)
function(FindNetCDF_get_is_parallel_aware include_dir)
file(STRINGS "${include_dir}/netcdf_meta.h" _netcdf_lines
REGEX "#define[ \t]+NC_HAS_PARALLEL[ \t]")
string(REGEX REPLACE ".*NC_HAS_PARALLEL[ \t]*([0-1]+).*" "\\1"
_netcdf_has_parallel "${_netcdf_lines}")
if (_netcdf_has_parallel)
set(NetCDF_HAS_PARALLEL TRUE PARENT_SCOPE)
else()
set(NetCDF_HAS_PARALLEL FALSE PARENT_SCOPE)
endif()
endfunction()
# 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}")
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(NetCDF
REQUIRED_VARS NetCDF_INCLUDE_DIRS NetCDF_LIBRARIES
VERSION_VAR NetCDF_VERSION)
if (NOT TARGET NetCDF::NetCDF)
add_library(NetCDF::NetCDF INTERFACE IMPORTED)
if (TARGET "netCDF::netcdf")
# 4.7.3
set_target_properties(NetCDF::NetCDF PROPERTIES
INTERFACE_LINK_LIBRARIES "netCDF::netcdf")
elseif (TARGET "netcdf")
set_target_properties(NetCDF::NetCDF PROPERTIES
INTERFACE_LINK_LIBRARIES "netcdf")
else ()
set_target_properties(NetCDF::NetCDF PROPERTIES
INTERFACE_LINK_LIBRARIES "${netCDF_LIBRARIES}")
endif ()
endif ()
FindNetCDF_get_is_parallel_aware("${NetCDF_INCLUDE_DIRS}")
else()
find_package(PkgConfig QUIET)
if (PkgConfig_FOUND)
pkg_check_modules(_NetCDF QUIET netcdf IMPORTED_TARGET)
if (_NetCDF_FOUND)
unset(netCDF_DIR CACHE)
pkg_get_variable(netcdf_pcfiledir netcdf pcfiledir)
message(VERBOSE "Location of .pc file: ${netcdf_pcfiledir}")
message(VERBOSE "NetCDF include directories: ${_NetCDF_INCLUDE_DIRS}")
message(VERBOSE "NetCDF libraries: ${_NetCDF_LINK_LIBRARIES}")
# 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}")
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(NetCDF
REQUIRED_VARS NetCDF_LIBRARIES
# This is not required because system-default include paths
# are not reported by `FindPkgConfig`, so this might be
# empty. Assume that if we have a library, the include
# directories are fine (if any) since PkgConfig reported that
# the package was found. NetCDF_INCLUDE_DIRS
VERSION_VAR 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 ()
FindNetCDF_get_is_parallel_aware("${_NetCDF_INCLUDEDIR}")
endif ()
endif ()
if (NOT PkgConfig_FOUND OR NOT _NetCDF_FOUND)
find_path(NetCDF_INCLUDE_DIR
NAMES netcdf.h
DOC "netcdf include directories")
##mark_as_advanced(NetCDF_INCLUDE_DIR)
find_library(NetCDF_LIBRARY
NAMES netcdf
DOC "netcdf library")
##mark_as_advanced(NetCDF_LIBRARY)
if (NetCDF_INCLUDE_DIR)
unset(netCDF_DIR CACHE)
file(STRINGS "${NetCDF_INCLUDE_DIR}/netcdf_meta.h" _netcdf_version_lines
REGEX "#define[ \t]+NC_VERSION_(MAJOR|MINOR|PATCH|NOTE)")
string(REGEX REPLACE ".*NC_VERSION_MAJOR *\([0-9]*\).*" "\\1"
_netcdf_version_major "${_netcdf_version_lines}")
string(REGEX REPLACE ".*NC_VERSION_MINOR *\([0-9]*\).*" "\\1"
_netcdf_version_minor "${_netcdf_version_lines}")
string(REGEX REPLACE ".*NC_VERSION_PATCH *\([0-9]*\).*" "\\1"
_netcdf_version_patch "${_netcdf_version_lines}")
string(REGEX REPLACE ".*NC_VERSION_NOTE *\"\([^\"]*\)\".*" "\\1"
_netcdf_version_note "${_netcdf_version_lines}")
set(NetCDF_VERSION
"${_netcdf_version_major}.${_netcdf_version_minor}.${_netcdf_version_patch}${_netcdf_version_note}")
unset(_netcdf_version_major)
unset(_netcdf_version_minor)
unset(_netcdf_version_patch)
unset(_netcdf_version_note)
unset(_netcdf_version_lines)
FindNetCDF_get_is_parallel_aware("${NetCDF_INCLUDE_DIR}")
endif ()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(NetCDF
REQUIRED_VARS NetCDF_LIBRARY NetCDF_INCLUDE_DIR
VERSION_VAR NetCDF_VERSION)
if (NetCDF_FOUND)
set(NetCDF_INCLUDE_DIRS "${NetCDF_INCLUDE_DIR}")
set(NetCDF_LIBRARIES "${NetCDF_LIBRARY}")
if (NOT TARGET NetCDF::NetCDF)
add_library(NetCDF::NetCDF UNKNOWN IMPORTED)
set_target_properties(NetCDF::NetCDF PROPERTIES
IMPORTED_LOCATION "${NetCDF_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${NetCDF_INCLUDE_DIR}")
endif ()
endif ()
endif()
endif ()
list(POP_BACK CMAKE_MESSAGE_CONTEXT)
list(APPEND CMAKE_MESSAGE_CONTEXT FindNetCDF_Fortran) list(APPEND CMAKE_MESSAGE_CONTEXT FindNetCDF_Fortran)
if (NOT TARGET NetCDF_Fortran::netcdff) if(TARGET NetCDF_Fortran::netcdff)
find_package(PkgConfig REQUIRED) set(NetCDF_Fortran_FOUND True)
else()
# Find NetCDF dependency:
pkg_check_modules(netcdff REQUIRED IMPORTED_TARGET GLOBAL option(use_find_netcdf_module "Use the find module for NetCDF")
netcdf-fortran)
pkg_get_variable(netcdf_fortran_pcfiledir netcdf-fortran pcfiledir) unset(extraArgs)
message(VERBOSE "Location of .pc file: ${netcdf_fortran_pcfiledir}")
message(VERBOSE if(${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)
"NetCDF-Fortran include directories: ${netcdff_INCLUDE_DIRS}") list(APPEND extraArgs QUIET)
endif()
if(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED)
list(APPEND extraArgs REQUIRED)
endif()
if(use_find_netcdf_module)
find_package(netCDF ${extraArgs})
else()
find_package(netCDF CONFIG ${extraArgs})
endif()
message(VERBOSE "NetCDF-Fortran libraries: ${netcdff_LINK_LIBRARIES}") #-
if(PKG_CONFIG_VERSION_STRING VERSION_LESS "0.29.2" if(netCDF_FOUND)
OR PKG_CONFIG_VERSION_STRING VERSION_GREATER "1.1") find_package(PkgConfig REQUIRED)
# pkg-config strips system flags out of cflags. They do not appear
# with prefix -isystem when pkg-config is run with
# --cflags-only-I. So cmake does not get them. So we have to
# duplicate the call to pkg_get_variable that is already in
# pkg_check_modules.
# Version > 1.1 means we are using pkgconf from pkgconf.org
pkg_get_variable(pkg_netcdf_fortran_includedir netcdf-fortran includedir)
target_include_directories(PkgConfig::netcdff INTERFACE pkg_check_modules(netcdff REQUIRED IMPORTED_TARGET GLOBAL
${pkg_netcdf_fortran_includedir}) netcdf-fortran)
pkg_get_variable(netcdf_fortran_pcfiledir netcdf-fortran pcfiledir)
message(VERBOSE "Location of .pc file: ${netcdf_fortran_pcfiledir}")
message(VERBOSE message(VERBOSE
"pkg_netcdf_fortran_includedir: ${pkg_netcdf_fortran_includedir}") "NetCDF-Fortran include directories: ${netcdff_INCLUDE_DIRS}")
endif()
target_link_libraries(PkgConfig::netcdff INTERFACE NetCDF::NetCDF) message(VERBOSE "NetCDF-Fortran libraries: ${netcdff_LINK_LIBRARIES}")
add_library(NetCDF_Fortran::netcdff ALIAS PkgConfig::netcdff)
if(PKG_CONFIG_VERSION_STRING VERSION_LESS "0.29.2"
OR PKG_CONFIG_VERSION_STRING VERSION_GREATER "1.1")
# pkg-config strips system flags out of cflags. They do not appear
# with prefix -isystem when pkg-config is run with
# --cflags-only-I. So cmake does not get them. So we have to
# duplicate the call to pkg_get_variable that is already in
# pkg_check_modules.
# Version > 1.1 means we are using pkgconf from pkgconf.org
pkg_get_variable(pkg_netcdf_fortran_includedir netcdf-fortran includedir)
target_include_directories(PkgConfig::netcdff INTERFACE
${pkg_netcdf_fortran_includedir})
message(VERBOSE
"pkg_netcdf_fortran_includedir: ${pkg_netcdf_fortran_includedir}")
endif()
target_link_libraries(PkgConfig::netcdff INTERFACE netCDF::netcdf)
add_library(NetCDF_Fortran::netcdff ALIAS PkgConfig::netcdff)
set(NetCDF_Fortran_FOUND True)
else()
set(NetCDF_Fortran_FOUND False)
endif()
endif() endif()
list(POP_BACK CMAKE_MESSAGE_CONTEXT) list(POP_BACK CMAKE_MESSAGE_CONTEXT)
# Adapted from
# https://gitlab.kitware.com/vtk/vtk/-/blob/master/CMake/FindnetCDF.cmake
#[==[
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`.
* `netCDF_HAS_PARALLEL`: Whether or not netCDF was found with parallel IO support.
#]==]
list(APPEND CMAKE_MESSAGE_CONTEXT FindnetCDF)
function(FindnetCDF_get_is_parallel_aware include_dir)
file(STRINGS "${include_dir}/netcdf_meta.h" _netcdf_lines
REGEX "#define[ \t]+NC_HAS_PARALLEL[ \t]")
string(REGEX REPLACE ".*NC_HAS_PARALLEL[ \t]*([0-1]+).*" "\\1"
_netcdf_has_parallel "${_netcdf_lines}")
if (_netcdf_has_parallel)
set(netCDF_HAS_PARALLEL TRUE PARENT_SCOPE)
else()
set(netCDF_HAS_PARALLEL FALSE PARENT_SCOPE)
endif()
endfunction()
find_package(PkgConfig QUIET)
if (PkgConfig_FOUND)
pkg_check_modules(_netCDF QUIET netcdf IMPORTED_TARGET)
if (_netCDF_FOUND)
unset(netCDF_DIR CACHE)
pkg_get_variable(netcdf_pcfiledir netcdf pcfiledir)
message(VERBOSE "Location of .pc file: ${netcdf_pcfiledir}")
message(VERBOSE "netCDF include directories: ${_netCDF_INCLUDE_DIRS}")
message(VERBOSE "netCDF libraries: ${_netCDF_LINK_LIBRARIES}")
# 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}")
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(netCDF
REQUIRED_VARS netCDF_LIBRARIES
# This is not required because system-default include paths
# are not reported by `FindPkgConfig`, so this might be
# empty. Assume that if we have a library, the include
# directories are fine (if any) since PkgConfig reported that
# the package was found. netCDF_INCLUDE_DIRS
VERSION_VAR 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 ()
FindnetCDF_get_is_parallel_aware("${_netCDF_INCLUDEDIR}")
endif ()
endif ()
if (NOT PkgConfig_FOUND OR NOT _netCDF_FOUND)
find_path(netCDF_INCLUDE_DIR
NAMES netcdf.h
DOC "netcdf include directories")
##mark_as_advanced(netCDF_INCLUDE_DIR)
find_library(netCDF_LIBRARY
NAMES netcdf
DOC "netcdf library")
##mark_as_advanced(netCDF_LIBRARY)
if (netCDF_INCLUDE_DIR)
unset(netCDF_DIR CACHE)
file(STRINGS "${netCDF_INCLUDE_DIR}/netcdf_meta.h" _netcdf_version_lines
REGEX "#define[ \t]+NC_VERSION_(MAJOR|MINOR|PATCH|NOTE)")
string(REGEX REPLACE ".*NC_VERSION_MAJOR *\([0-9]*\).*" "\\1"
_netcdf_version_major "${_netcdf_version_lines}")
string(REGEX REPLACE ".*NC_VERSION_MINOR *\([0-9]*\).*" "\\1"
_netcdf_version_minor "${_netcdf_version_lines}")
string(REGEX REPLACE ".*NC_VERSION_PATCH *\([0-9]*\).*" "\\1"
_netcdf_version_patch "${_netcdf_version_lines}")
string(REGEX REPLACE ".*NC_VERSION_NOTE *\"\([^\"]*\)\".*" "\\1"
_netcdf_version_note "${_netcdf_version_lines}")
set(netCDF_VERSION
"${_netcdf_version_major}.${_netcdf_version_minor}.${_netcdf_version_patch}${_netcdf_version_note}")
unset(_netcdf_version_major)
unset(_netcdf_version_minor)
unset(_netcdf_version_patch)
unset(_netcdf_version_note)
unset(_netcdf_version_lines)
FindnetCDF_get_is_parallel_aware("${netCDF_INCLUDE_DIR}")
endif ()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(netCDF
REQUIRED_VARS netCDF_LIBRARY netCDF_INCLUDE_DIR
VERSION_VAR netCDF_VERSION)
if (netCDF_FOUND)
set(netCDF_INCLUDE_DIRS "${netCDF_INCLUDE_DIR}")
set(netCDF_LIBRARIES "${netCDF_LIBRARY}")
if (NOT TARGET netCDF::netcdf)
add_library(netCDF::netcdf UNKNOWN IMPORTED)
set_target_properties(netCDF::netcdf PROPERTIES
IMPORTED_LOCATION "${netCDF_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${netCDF_INCLUDE_DIR}")
endif ()
endif ()
endif()
list(POP_BACK CMAKE_MESSAGE_CONTEXT)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment