From 3ba460aa482e8b18b59ab005163451dc9fca070b Mon Sep 17 00:00:00 2001 From: Lionel GUEZ <guez@lmd.ens.fr> Date: Wed, 15 Dec 2021 22:24:26 +0100 Subject: [PATCH] Add cmake submodule Instead of copying files from the cmake repositoty. --- .gitmodules | 3 + CMakeLists.txt | 2 +- FindNetCDF_Fortran.cmake | 70 ----------------------- FindnetCDF.cmake | 117 --------------------------------------- TAGS.cmake | 62 --------------------- cmake | 1 + 6 files changed, 5 insertions(+), 250 deletions(-) create mode 100644 .gitmodules delete mode 100644 FindNetCDF_Fortran.cmake delete mode 100644 FindnetCDF.cmake delete mode 100644 TAGS.cmake create mode 160000 cmake diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..592293e0 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "cmake"] + path = cmake + url = https://github.com/lguez/cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 93ffb3c0..213e5411 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.20) project(Detection_eddies LANGUAGES Fortran) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release Profile) -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") find_package(NetCDF_Fortran REQUIRED) find_package(MPI) diff --git a/FindNetCDF_Fortran.cmake b/FindNetCDF_Fortran.cmake deleted file mode 100644 index 10ee8c81..00000000 --- a/FindNetCDF_Fortran.cmake +++ /dev/null @@ -1,70 +0,0 @@ -list(APPEND CMAKE_MESSAGE_CONTEXT FindNetCDF_Fortran) - -if(TARGET NetCDF_Fortran::netcdff) - set(NetCDF_Fortran_FOUND True) -else() - # Find NetCDF dependency: - - option(FIND_PACKAGE_PREFER_MODULE_netCDF - "Use directly the find module for NetCDF") - - if(${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY) - set(maybe_quiet QUIET) - endif() - - if(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED) - set(maybe_required REQUIRED) - endif() - - if(FIND_PACKAGE_PREFER_MODULE_netCDF) - find_package(netCDF ${maybe_quiet} ${maybe_required}) - else() - find_package(netCDF CONFIG ${maybe_quiet}) - - if(NOT netCDF_FOUND) - find_package(netCDF ${maybe_quiet} ${maybe_required}) - endif() - endif() - - #- - - if(netCDF_FOUND) - find_package(PkgConfig REQUIRED) - - pkg_check_modules(netcdff REQUIRED IMPORTED_TARGET GLOBAL - netcdf-fortran) - - pkg_get_variable(netcdf_fortran_pcfiledir netcdf-fortran pcfiledir) - message(VERBOSE "Location of .pc file: ${netcdf_fortran_pcfiledir}") - - message(VERBOSE - "NetCDF-Fortran include directories: ${netcdff_INCLUDE_DIRS}") - - message(VERBOSE "NetCDF-Fortran libraries: ${netcdff_LINK_LIBRARIES}") - - 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() - -list(POP_BACK CMAKE_MESSAGE_CONTEXT) diff --git a/FindnetCDF.cmake b/FindnetCDF.cmake deleted file mode 100644 index 9269eb89..00000000 --- a/FindnetCDF.cmake +++ /dev/null @@ -1,117 +0,0 @@ -# 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) diff --git a/TAGS.cmake b/TAGS.cmake deleted file mode 100644 index ea3e6d65..00000000 --- a/TAGS.cmake +++ /dev/null @@ -1,62 +0,0 @@ -# -# (C) Copyright 2018 Tillmann Heidsieck -# -# SPDX-License-Identifier: MIT -# - -find_program(CTAGS ctags) - -function(tags_add_dir _dir) - get_property(_subdirlist DIRECTORY "${_dir}" PROPERTY SUBDIRECTORIES) - - foreach(_sd ${_subdirlist}) - tags_add_dir(${_sd}) - endforeach() - - if(NOT _dir STREQUAL CMAKE_SOURCE_DIR) - string(REPLACE "${CMAKE_SOURCE_DIR}/" "" rel_dir "${_dir}") - endif() - - get_property(_targets_list DIRECTORY "${_dir}" PROPERTY - BUILDSYSTEM_TARGETS) - - foreach(_tgt ${_targets_list}) - get_property(_t_files TARGET ${_tgt} PROPERTY SOURCES) - list(FILTER _t_files EXCLUDE REGEX TARGET_OBJECTS) - - foreach(my_file IN LISTS _t_files) - if(my_file MATCHES "${CMAKE_SOURCE_DIR}/(.*)") - list(APPEND _all_source_files ${CMAKE_MATCH_1}) - else() - get_filename_component(my_dir ${my_file} DIRECTORY) - - if(my_dir OR _dir STREQUAL CMAKE_SOURCE_DIR) - list(APPEND _all_source_files ${my_file}) - else() - list(APPEND _all_source_files "${rel_dir}/${my_file}") - endif() - endif() - endforeach() - endforeach() - - set(_all_source_files ${_all_source_files} PARENT_SCOPE) -endfunction() - -if(CTAGS) - ##variable_watch(_all_source_files) - set(SOURCES_LIST "${CMAKE_BINARY_DIR}/sources_list") - set(_all_source_files "") - file(REMOVE "${SOURCES_LIST}") - tags_add_dir(${CMAKE_SOURCE_DIR}) - list(SORT _all_source_files) - list(REMOVE_DUPLICATES _all_source_files) - string(REGEX REPLACE ";" "\n" _asf "${_all_source_files}") - file(APPEND ${SOURCES_LIST} "${_asf}\n") - add_custom_target(TAGS DEPENDS ${CMAKE_SOURCE_DIR}/TAGS) - - add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/TAGS - COMMAND ctags -e --language-force=fortran -L ${SOURCES_LIST} - DEPENDS ${_all_source_files} - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - VERBATIM) -endif() diff --git a/cmake b/cmake new file mode 160000 index 00000000..2ae60707 --- /dev/null +++ b/cmake @@ -0,0 +1 @@ +Subproject commit 2ae607072751decef8d1eeb41d944e00fd819dd1 -- GitLab