From 1a9c3495840c44016a7d26aed3ac8dcaaaae224a Mon Sep 17 00:00:00 2001 From: Lionel GUEZ <guez@lmd.ens.fr> Date: Thu, 16 Sep 2021 12:31:52 +0200 Subject: [PATCH] Update to commit 1e3dc4d from cmake repository --- cmake/FindNetCDF.cmake | 177 +++++++++++++++++---------------- cmake/FindNetCDF_Fortran.cmake | 19 ++-- 2 files changed, 104 insertions(+), 92 deletions(-) diff --git a/cmake/FindNetCDF.cmake b/cmake/FindNetCDF.cmake index cbd252c8..6e82a0d6 100644 --- a/cmake/FindNetCDF.cmake +++ b/cmake/FindNetCDF.cmake @@ -7,18 +7,21 @@ #[==[ 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. +* `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}") + 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() @@ -28,6 +31,7 @@ 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}") @@ -56,89 +60,94 @@ if (netCDF_FOUND) endif () FindNetCDF_get_is_parallel_aware("${NetCDF_INCLUDE_DIRS}") - # Skip the rest of the logic in this file. - return () -endif () +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 () -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(STATUS "${CMAKE_CURRENT_LIST_FILE}") - message(STATUS "-- Location of .pc file: ${netcdf_pcfiledir}") - message(STATUS "-- NetCDF include directories: ${_NetCDF_INCLUDE_DIRS}") - message(STATUS "-- 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}") + 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_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 + REQUIRED_VARS NetCDF_LIBRARY NetCDF_INCLUDE_DIR 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}") - # Skip the rest of the logic in this file. - return () - endif () -endif () + if (NetCDF_FOUND) + set(NetCDF_INCLUDE_DIRS "${NetCDF_INCLUDE_DIR}") + set(NetCDF_LIBRARIES "${NetCDF_LIBRARY}") -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}") + 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 () -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 () +list(POP_BACK CMAKE_MESSAGE_CONTEXT) diff --git a/cmake/FindNetCDF_Fortran.cmake b/cmake/FindNetCDF_Fortran.cmake index a898ea0f..1d4f9c48 100644 --- a/cmake/FindNetCDF_Fortran.cmake +++ b/cmake/FindNetCDF_Fortran.cmake @@ -1,3 +1,5 @@ +list(APPEND CMAKE_MESSAGE_CONTEXT FindNetCDF_Fortran) + if (NOT TARGET NetCDF_Fortran::NetCDF_Fortran) find_package(PkgConfig REQUIRED) @@ -5,14 +7,12 @@ if (NOT TARGET NetCDF_Fortran::NetCDF_Fortran) netcdf-fortran) pkg_get_variable(netcdf_fortran_pcfiledir netcdf-fortran pcfiledir) - message(STATUS "${CMAKE_CURRENT_LIST_FILE}") - message(STATUS "-- Location of .pc file: ${netcdf_fortran_pcfiledir}") + message(VERBOSE "Location of .pc file: ${netcdf_fortran_pcfiledir}") - message(STATUS - "-- NetCDF-Fortran include directories: ${NetCDF_Fortran_INCLUDE_DIRS}") + message(VERBOSE + "NetCDF-Fortran include directories: ${NetCDF_Fortran_INCLUDE_DIRS}") - message(STATUS - "-- NetCDF-Fortran libraries: ${NetCDF_Fortran_LINK_LIBRARIES}") + message(VERBOSE "NetCDF-Fortran libraries: ${NetCDF_Fortran_LINK_LIBRARIES}") if(PKG_CONFIG_VERSION_STRING VERSION_LESS "0.29.2" OR PKG_CONFIG_VERSION_STRING VERSION_GREATER "1.1") @@ -27,9 +27,12 @@ if (NOT TARGET NetCDF_Fortran::NetCDF_Fortran) target_include_directories(PkgConfig::NetCDF_Fortran INTERFACE ${pkg_netcdf_fortran_includedir}) - message(STATUS - "-- pkg_netcdf_fortran_includedir: ${pkg_netcdf_fortran_includedir}") + message(VERBOSE + "pkg_netcdf_fortran_includedir: ${pkg_netcdf_fortran_includedir}") endif() + target_link_libraries(PkgConfig::NetCDF_Fortran INTERFACE NetCDF::NetCDF) add_library(NetCDF_Fortran::NetCDF_Fortran ALIAS PkgConfig::NetCDF_Fortran) endif() + +list(POP_BACK CMAKE_MESSAGE_CONTEXT) -- GitLab