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

Add cmake submodule

Instead of copying files from the cmake repositoty.
parent a86422ee
No related branches found
No related tags found
No related merge requests found
[submodule "cmake"]
path = cmake
url = https://github.com/lguez/cmake
cmake_minimum_required(VERSION 3.20) cmake_minimum_required(VERSION 3.20)
project(Detection_eddies LANGUAGES Fortran) project(Detection_eddies LANGUAGES Fortran)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release Profile) 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(NetCDF_Fortran REQUIRED)
find_package(MPI) find_package(MPI)
......
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)
# 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)
#
# (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()
Subproject commit 2ae607072751decef8d1eeb41d944e00fd819dd1
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