Commit 9ecb1875 authored by Sebastian Müller's avatar Sebastian Müller 🐈
Browse files

Merge branch 'release_5.11.2' into 'master'

Release 5.11.2

See merge request !87
parents 6f6e14f1 9e23f74a
# Created by .ignore support plugin (hsz.mobi)
# ignore Doxygen specific files
html
latex
doxygen_warn.txt
# Exclusions
./mhm
*.g90
......@@ -7,6 +12,7 @@
*.mod
*.a
*.so
mhm_env/
src/*/*.release/
src/*/*.debug/
test_domain/output_b1/
......
......@@ -4,12 +4,15 @@
# enabled = true
# This will prevent git clone conflicts for jobs ran in parallel
variables:
GIT_DEPTH: 10
stages:
- info
- build
- valgrind
- test
- coverage
- check-cases
- code-analysis
- deploy
show-env-vars:
......@@ -33,7 +36,9 @@ documentation:
- develop
stage: build
variables:
GIT_DEPTH: 0
GIT_CLONE_PATH: $CI_BUILDS_DIR/$CI_RUNNER_SHORT_TOKEN/$CI_PROJECT_PATH/$CI_COMMIT_REF_NAME/$CI_JOB_NAME
GIT_FETCH_EXTRA_FLAGS: --all --no-tags --prune --quiet
script:
- module load foss/2019b
- module load texlive/2019
......@@ -51,19 +56,13 @@ documentation:
- rm -rf latex
# same for master
- git checkout master
- test -f doc/doxygen-1.8.8.config && cp doc/doxygen-1.8.8.config doc/doxygen.config
- doxygen doc/doxygen.config > doxygen_log_mas.txt
- cd latex/ && make > ../doxygen_latex_mas.txt
- cp refman.pdf ../html/mhm_doc.pdf
- cp refman.pdf ../mhm_doc_mas.pdf
- cd .. && mv html html_mas
# care about warnings file (maybe missing on master)
- |
if [ -f doxygen_warn.txt ]; then
mv doxygen_warn.txt doxygen_warn_mas.txt
else
touch doxygen_warn_mas.txt
fi
- mv doxygen_warn.txt doxygen_warn_mas.txt
artifacts:
name: "$CI_COMMIT_REF_NAME"
paths:
......@@ -320,7 +319,7 @@ valgrind-intel20:
check-nag62:
when: always
stage: test
stage: check-cases
variables:
GIT_CLONE_PATH: $CI_BUILDS_DIR/$CI_RUNNER_SHORT_TOKEN/$CI_PROJECT_PATH/$CI_COMMIT_REF_NAME/$CI_JOB_NAME
needs:
......@@ -337,7 +336,7 @@ check-nag62:
check-nag62DEBUG:
when: always
stage: test
stage: check-cases
variables:
GIT_CLONE_PATH: $CI_BUILDS_DIR/$CI_RUNNER_SHORT_TOKEN/$CI_PROJECT_PATH/$CI_COMMIT_REF_NAME/$CI_JOB_NAME
needs:
......@@ -355,7 +354,7 @@ check-nag62DEBUG:
check-gcc73:
when: always
stage: test
stage: check-cases
variables:
GIT_CLONE_PATH: $CI_BUILDS_DIR/$CI_RUNNER_SHORT_TOKEN/$CI_PROJECT_PATH/$CI_COMMIT_REF_NAME/$CI_JOB_NAME
needs:
......@@ -372,7 +371,7 @@ check-gcc73:
check-gcc73MPI:
when: always
stage: test
stage: check-cases
variables:
GIT_CLONE_PATH: $CI_BUILDS_DIR/$CI_RUNNER_SHORT_TOKEN/$CI_PROJECT_PATH/$CI_COMMIT_REF_NAME/$CI_JOB_NAME
needs:
......@@ -389,7 +388,7 @@ check-gcc73MPI:
check-gcc83:
when: always
stage: test
stage: check-cases
variables:
GIT_CLONE_PATH: $CI_BUILDS_DIR/$CI_RUNNER_SHORT_TOKEN/$CI_PROJECT_PATH/$CI_COMMIT_REF_NAME/$CI_JOB_NAME
needs:
......@@ -406,7 +405,7 @@ check-gcc83:
check-gcc83MPI:
when: always
stage: test
stage: check-cases
variables:
GIT_CLONE_PATH: $CI_BUILDS_DIR/$CI_RUNNER_SHORT_TOKEN/$CI_PROJECT_PATH/$CI_COMMIT_REF_NAME/$CI_JOB_NAME
needs:
......@@ -423,7 +422,7 @@ check-gcc83MPI:
check-intel18:
when: always
stage: test
stage: check-cases
variables:
GIT_CLONE_PATH: $CI_BUILDS_DIR/$CI_RUNNER_SHORT_TOKEN/$CI_PROJECT_PATH/$CI_COMMIT_REF_NAME/$CI_JOB_NAME
needs:
......@@ -440,7 +439,7 @@ check-intel18:
check-intel18MPI:
when: always
stage: test
stage: check-cases
variables:
GIT_CLONE_PATH: $CI_BUILDS_DIR/$CI_RUNNER_SHORT_TOKEN/$CI_PROJECT_PATH/$CI_COMMIT_REF_NAME/$CI_JOB_NAME
needs:
......@@ -457,7 +456,7 @@ check-intel18MPI:
check-intel20:
when: always
stage: test
stage: check-cases
variables:
GIT_CLONE_PATH: $CI_BUILDS_DIR/$CI_RUNNER_SHORT_TOKEN/$CI_PROJECT_PATH/$CI_COMMIT_REF_NAME/$CI_JOB_NAME
needs:
......@@ -474,7 +473,7 @@ check-intel20:
check-intel20MPI:
when: always
stage: test
stage: check-cases
variables:
GIT_CLONE_PATH: $CI_BUILDS_DIR/$CI_RUNNER_SHORT_TOKEN/$CI_PROJECT_PATH/$CI_COMMIT_REF_NAME/$CI_JOB_NAME
needs:
......@@ -489,9 +488,27 @@ check-intel20MPI:
paths:
- check/logs/
unittest-gcc83:
when: always
stage: code-analysis
variables:
GIT_CLONE_PATH: $CI_BUILDS_DIR/$CI_RUNNER_SHORT_TOKEN/$CI_PROJECT_PATH/$CI_COMMIT_REF_NAME/$CI_JOB_NAME
needs:
- job: cmake-gcc83
script:
# we need pfUnit
- source moduleLoadScripts/eve.gcc83pfUnit
# create build folder
- mkdir build && cd build
# run cmake with testing support and build mhm
- cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=ON ..
- make -j 4
# run all pfUnit tests in src/tests
- ctest -V
coverage-gcc73:
when: always
stage: coverage
stage: code-analysis
variables:
GIT_CLONE_PATH: $CI_BUILDS_DIR/$CI_RUNNER_SHORT_TOKEN/$CI_PROJECT_PATH/$CI_COMMIT_REF_NAME/$CI_JOB_NAME
needs:
......@@ -505,7 +522,7 @@ coverage-gcc73:
# create build folder
- mkdir build && cd build
# run cmake with coverage support
- cmake -DCMAKE_WITH_COVERAGE:STRING=ON ..
- cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_WITH_COVERAGE=ON ..
# run all check-case for coverage calculation
- make mhm_coverage_CI
# copy the output to a top-level folder
......
mkdir release
cd release/
cmake ..
cmake -DCMAKE_BUILD_TYPE=Release ..
make -j 4
cd ..
cp release/mhm .
\ No newline at end of file
mkdir mpi_release
cd mpi_release/
cmake -DCMAKE_WITH_MPI:STRING=ON ..
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_WITH_MPI=ON ..
make -j 4
cd ..
cp mpi_release/mhm ./mhm_mpi
\ No newline at end of file
mkdir mpi_debug
cd mpi_debug/
cmake -DCMAKE_WITH_MPI:STRING=ON -DCMAKE_BUILD_TYPE=Debug ..
cmake -DCMAKE_WITH_MPI=ON -DCMAKE_BUILD_TYPE=Debug ..
make -j 4
cd ..
cp mpi_debug/mhm ./mhm_mpi_debug
\ No newline at end of file
mkdir openmp_release
cd openmp_release/
cmake -DCMAKE_WITH_OpenMP:STRING=ON ..
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_WITH_OpenMP=ON ..
make -j 4
cd ..
cp openmp_release/mhm ./mhm_openmp
\ No newline at end of file
mkdir openmp_debug
cd openmp_debug/
cmake -DCMAKE_WITH_OpenMP:STRING=ON -DCMAKE_BUILD_TYPE=Debug ..
cmake -DCMAKE_WITH_OpenMP=ON -DCMAKE_BUILD_TYPE=Debug ..
make -j 4
cd ..
cp openmp_debug/mhm ./mhm_openmp_debug
\ No newline at end of file
conda create -y --prefix ./mhm_env
conda activate ./mhm_env
conda config --add channels conda-forge
conda config --set channel_priority strict
conda install -y cmake make fortran-compiler netcdf-fortran
cmake -DCMAKE_BUILD_TYPE=Release -B build -S .
cmake --build build --parallel
cmake --install build --prefix $CONDA_PREFIX
#-D CMAKE_BUILD_MODULE_SYSTEM_INDEPENDENT:STRING=ON
set(CMAKE_BUILD_MODULE_SYSTEM_INDEPENDENT ON CACHE STRING "build the module INDEPENDENT of the module system, so the build in the build tree works even after a module purge")
#-D CMAKE_BUILD_MODULE_SYSTEM_INDEPENDENT=ON
option(CMAKE_BUILD_MODULE_SYSTEM_INDEPENDENT
"build the module INDEPENDENT of the module system, so the build in the build tree works even after a module purge"
ON
)
##-D CMAKE_WITH_MPI:STRING=ON
set(CMAKE_WITH_MPI OFF CACHE STRING "build the module with MPI, so it can be executed using mpirun")
#set(CMAKE_pgiFortran ON CACHE STRING "Code exchange for pgi compiler dependent issues")
#set(CMAKE_MPR_STANDALONE ON CACHE STRING "If set to ON, only MPR is compiled")
#set(CMAKE_ABSOFT ON CACHE STRING "Documentation to be added. If you you are developer, you might edit this string in CMakeLists.txt")
##-D CMAKE_WITH_MPI=ON
option(CMAKE_WITH_MPI "build the module with MPI, so it can be executed using mpirun" ON)
#option(CMAKE_pgiFortran "Code exchange for pgi compiler dependent issues" ON)
#option(CMAKE_MPR_STANDALONE "If set to ON, only MPR is compiled" ON)
#option(CMAKE_ABSOFT "Documentation to be added. If you you are developer, you might edit this string in CMakeLists.txt" ON)
# set set specific path where to search for the netCDF directory
set(CMAKE_NETCDF_DIR "/path/to/netcdfdir/" CACHE STRING "set set specific place where to search for the netCDF directory")
set(CMAKE_NETCDF_DIR "/path/to/netcdfdir/" CACHE PATH "set set specific place where to search for the netCDF directory")
# This cmake file is not meant to be edited for a special setup.
# For special setups use cache line files or command line options, as described a few
# lines ahead concerning module INDEPENDENT builds
# mHM cmake script
cmake_minimum_required(VERSION 3.12)
# check version file
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/version.txt")
file(STRINGS "version.txt" MHMVERSION LIMIT_COUNT 1)
else()
set(MHMVERSION "0.0.0-dev0") # default version
endif()
# version should be of the form (semver.org):
# - 1.2.3-dev0 (development with number)
# - 1.2.3-rc1 (release candidate with number)
# - 1.2.3 (release)
# remove possible "v" prefix and find major.minor.patch version
string(REGEX MATCH "^v?([0-9]+)" _ ${MHMVERSION})
set(ver_major ${CMAKE_MATCH_1})
string(REGEX MATCH "^v?[0-9]+\.([0-9]+)" _ ${MHMVERSION})
set(ver_minor ${CMAKE_MATCH_1})
string(REGEX MATCH "^v?[0-9]+\.[0-9]+\.([0-9]+)" _ ${MHMVERSION})
set(ver_patch ${CMAKE_MATCH_1})
# find pre-release tag
string(REGEX MATCH ".*-(.+)" _ ${MHMVERSION})
set(ver_pre ${CMAKE_MATCH_1})
# create the version string for cmake (fill up with 0)
if ("${ver_major}" STREQUAL "")
set(ver_major 0) # default version
endif()
if ("${ver_minor}" STREQUAL "")
set(ver_minor 0) # default version
endif()
if ("${ver_patch}" STREQUAL "")
set(ver_patch 0) # default version
endif()
set(ver_final ${ver_major}.${ver_minor}.${ver_patch}) # full version
# check date file (if not a development version)
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/version_date.txt" AND (NOT (${ver_pre} MATCHES "^dev.*")))
file(STRINGS "version_date.txt" MHMDATE LIMIT_COUNT 1)
else()
string(TIMESTAMP MHMDATE "%Y-%m-%d") # current date
endif()
# additional cmake-modules
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules)
# get version and date from files (version.txt and version_date.txt)
include(version)
get_version(MHM_VER MHM_VER_DEV MHM_DATE)
# create the project
project(mhm
VERSION ${ver_final}
DESCRIPTION "The mesoscale Hydrological Model"
HOMEPAGE_URL "https://www.ufz.de/mhm"
LANGUAGES Fortran)
message("mhm VERSION: ${mhm_VERSION} (from ${MHMVERSION})")
message("mhm DATE: ${MHMDATE}")
# add version to pre-processor flags (qoutes need in before hand)
add_compile_definitions(MHMVERSION='${MHMVERSION}')
# add date to pre-processor flags (qoutes need in before hand)
add_compile_definitions(MHMDATE='${MHMDATE}')
# The variable "CMAKE_BUILD_MODULE_SYSTEM_INDEPENDENT" can be set before executing cmake via a cache command:
# $cmake -DCMAKE_BUILD_MODULE_SYSTEM_INDEPENDENT:STRING=ON ..
# or cache file:
# $cmake -C ../CMakeCacheFiles/eve ..
# or after executing CMake editing the CMakeCache.txt, preferably with a corresponding cmake editor i.e ccmake
set(CMAKE_BUILD_MODULE_SYSTEM_INDEPENDENT OFF CACHE STRING "build the module INDEPENDENT of the module system, so the build in the build tree works even after a module purge")
message(STATUS "build INDEPENDENT of module system ${CMAKE_BUILD_MODULE_SYSTEM_INDEPENDENT}")
# set specific place where to search for the netCDF directory
set(CMAKE_NETCDF_DIR " " CACHE STRING "set set specific place where to search for the netCDF directory")
message(STATUS "search in additional directory ${CMAKE_NETCDF_DIR} for netCDF")
# The variable "CMAKE_WITH_MPI" can be set before executing cmake via a cache command:
# $cmake -DCMAKE_WITH_MPI:STRING=ON ..
# or in a cache file:
# $cmake -C ../CMakeCacheFiles/example
# or after executing CMake editing the CMakeCache.txt, preferably with a corresponding cmake editor i.e. ccmake
set(CMAKE_WITH_MPI OFF CACHE STRING "build the module with MPI, so it can be executed using mpirun")
# same with OpenMP
set(CMAKE_WITH_OpenMP OFF CACHE STRING "build the module with OpenMP parallelization")
# same with lapack
set(CMAKE_WITH_LAPACK OFF CACHE STRING "build the module with lapack library")
# same with coverage
set(CMAKE_WITH_COVERAGE OFF CACHE STRING "build the module with gcov coverage support")
# additional cmake-modules created for the purpose of finding netCDF or other libraries ly in the source_directory in
# a folder named cmake-modules. This command tells cmake to search there for Find<module>.cmake files
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules)
set (NETCDF_F90 "YES")
# the FindNetCDFF.cmake file can be found after we added the cmake-modules folder to the CMAKE_MODULE_PATH
# the build fails, if it is not present
find_package(NetCDFF REQUIRED)
# from that module we gain the following variables:
# NETCDF_INCLUDES : the include directory
# NETCDF_LINK_LIBRARIES : the absolute path to and with the libraries
# NETCDF_CFLAGS_OTHER : additional compilation flags
# NETCDF_LDFLAGS_OTHER : additional linking flags
# if cmake provides a findLIBRARY module, this gets invoked via find_package(LIBRARY)
if (CMAKE_WITH_MPI)
# find if there is an MPI setup on the system and if so, set corresponding variables
find_package(MPI)
if (NOT ${MPI_Fortran_FOUND})
message(FATAL_ERROR "MPI required but not found")
else()
message(STATUS "found MPI_Fortran_COMPILER ${MPI_Fortran_COMPILER}")
endif()
add_definitions("-DMPI")
endif()
if (CMAKE_WITH_OpenMP)
# find if there is an OpenMP setup on the system and if so, set corresponding variables
find_package(OpenMP)
if (NOT ${OpenMP_Fortran_FOUND})
message(FATAL_ERROR "OpenMP required but not found")
endif()
endif()
if (CMAKE_WITH_LAPACK)
# find if there is an LAPACK library on the system and if so, set corresponding variables
find_package(LAPACK)
if (NOT ${LAPACK_FOUND})
message(FATAL_ERROR "lapack required but not found")
endif()
endif()
include_directories(${NETCDF_INCLUDES} ${MPI_Fortran_INCLUDE_PATH} ${OpenMP_Fortran_LIBRARY})
# ifort and gfortran need the flag -cpp to interpret pre-processor directives
# the nag compiler is not able to interpret the flag -cpp but can interpret these definitions anyway
# so we check whether the compiler is able to use the flag -cpp
# for that we need the module CheckFortranCompilerFlag
include(CheckFortranCompilerFlag)
CHECK_Fortran_COMPILER_FLAG("-cpp" CPP_FLAG)
# if the flag exists, we add it to the compilation flags
if (CPP_FLAG)
set(ADDITIONAL_GCC_FLAGS "-cpp")
endif()
# this function adds definitions but also creates a corresponding CMAKE variable with CACHE STRING
# i.e.:
# The variable "${defCMakeName}" can be set before executing cmake via a cache command cmake -D...
# or in a cache file:
# $cmake -C ../CMakeCacheFiles/example
# or after executing CMake editing the CMakeCache.txt, preferably with a corresponding cmake editor i.e. ccmake
# cmake ..
function(cpp_definitions defName defCMakeName value cacheString)
set(${defCMakeName} "${value}" CACHE STRING "${cacheString}")
if (${defCMakeName})
add_definitions("${defName}")
endif()
endfunction()
# add pre-processor -fpp for NAG
CHECK_Fortran_COMPILER_FLAG("-fpp" FPP_FLAG)
# if the flag exists, we add it to the compilation flags
if (FPP_FLAG)
set(ADDITIONAL_GCC_FLAGS "-fpp")
endif()
# Add definitions. These should later be set via the cache line file and only have a default value here.
cpp_definitions("-DpgiFortran" "CMAKE_pgiFortran" "OFF" "Code exchange for pgi compiler dependent issues")
cpp_definitions("-DMPR_STANDALONE" "CMAKE_MPR_STANDALONE" "OFF" "If set to ON, only MPR is compiled")
cpp_definitions("-DABSOFT" "CMAKE_ABSOFT" "OFF" "Documentation to be added. If you you are developer, you might edit this string in CMakeLists.txt")
# Compile.
#
# This is not recommended but wished by some members of our working group. With this command
# all files in src with the ending f90 or h are written into sources, and therefore linked
# together to the executable, if relevant or not
file(GLOB_RECURSE sources src/*.f90 src/*.h)
# this command is able to create dependencies, compile and add the sources in the right order
add_executable(mhm ${sources})
# the libraries are added to the executable by the linker, using the full path and using the
# rpath option, except the libraries are located in ${CMAKE_Fortran_IMPLICIT_LINK_DIRECTORIES}.
target_link_libraries(mhm ${NETCDF_LINK_LIBRARIES} ${MPI_Fortran_LIBRARIES} ${OpenMP_Fortran_LIBRARIES} ${LAPACK_LIBRARIES})
set_property(TARGET mhm PROPERTY COMPILE_FLAGS "${CMAKE_Fortran_FLAGS} ${ADDITIONAL_GCC_FLAGS} ${NETCDF_CFLAGS_OTHER} ${MPI_Fortran_COMPILE_FLAGS} ${OpenMP_Fortran_FLAGS}")
set_property(TARGET mhm PROPERTY LINK_FLAGS "${NETCDF_LDFLAGS_OTHER} ${MPI_Fortran_LINK_FLAGS} ${OpenMP_Fortran_FLAGS} ${LAPACK_LINKER_FLAGS}")
# set compiling flags for debug and realese version
if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -ffree-form -ffixed-line-length-132")
set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} -pedantic-errors -Wall -W -O -g -Wno-maybe-uninitialized")
set(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE} -O3")
cpp_definitions("-DGFORTRAN" "CMAKE_GFORTRAN" "ON" "Code exchange for gfortran compiler dependent issues")
if (CMAKE_WITH_COVERAGE)
include(CodeCoverage)
APPEND_COVERAGE_COMPILER_FLAGS()
SETUP_TARGET_FOR_COVERAGE_LCOV(NAME mhm_coverage_CI
EXECUTABLE ../CI-scripts/run_cmake_coverage.sh
DEPENDENCIES mhm
EXCLUDE src/lib/*
GENHTML_ARGS -t "mHM coverage" --html-prolog ../doc/html_files/cov_header.prolog)
endif()
endif()
if(CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -nofixed -assume byterecl -fp-model source -m64 -assume realloc-lhs ") # precise -> source: suppress warning, computation identical
set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} -warn all -g -debug -traceback -fp-stack-check -O0 -debug -check all")
set(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE} -O3 -qoverride-limits")
cpp_definitions("-DINTEL" "CMAKE_INTEL" "ON" "Code exchange for intel compiler dependent issues")
endif()
if(CMAKE_Fortran_COMPILER_ID MATCHES "NAG")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -colour -unsharedf95 -ideclient")
set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} -g -nan -O0 -C=all -strict95 -ieee=stop")
set(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE} -O4 -ieee=full")
cpp_definitions("-DNAG" "CMAKE_NAG" "ON" "Code exchange for NAG compiler dependent issues")
endif()
message(STATUS "the following debug flags will be used: ${CMAKE_Fortran_FLAGS_DEBUG}")
# Usually that works fine, except, one is on a module system and tries to execute the executable
# in the end without having the modules loaded. A workaround is provided using the variable
# CMAKE_BUILD_MODULE_SYSTEM_INDEPENDENT
# if this variable is set to ON (do not set the variable inside of this cmake file), then the
# paths are added to the INSTALL_RPATH, and via the second command also to the build.
# It is a bit of a mess and workaround though.
VERSION ${MHM_VER}
DESCRIPTION "The mesoscale Hydrological Model"
HOMEPAGE_URL "https://www.ufz.de/mhm"
LANGUAGES Fortran
)
# add full version and date to pre-processor flags (qoutes need in before hand)
add_compile_definitions(MHMVERSION='${MHM_VER_DEV}' MHMDATE='${MHM_DATE}')
# Compile
add_subdirectory(./src) # the lib folder containing mhm_lib
option(BUILD_MHM_DRIVER "Build mHM library with mHM Driver." ON)
if(BUILD_MHM_DRIVER)
add_executable(mhm ./src/mHM/mhm_driver.f90)
target_link_libraries(mhm PRIVATE mhm_lib)
# add install option
install(TARGETS mhm DESTINATION bin)
endif()
# setup coverage with GNU
if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU" AND CMAKE_WITH_COVERAGE)
include(CodeCoverage)
append_coverage_compiler_flags()
SETUP_TARGET_FOR_COVERAGE_LCOV(
NAME mhm_coverage_CI
EXECUTABLE ../CI-scripts/run_cmake_coverage.sh
DEPENDENCIES mhm mhm_lib
EXCLUDE src/lib/*
GENHTML_ARGS -t "mHM coverage" --html-prolog ../doc/html_files/cov_header.prolog
)
endif()
# automatically enable testing (OFF by default)
option(BUILD_TESTING "Build with pfUnit tests." OFF)
include(CTest)
# add pfunit test folder
if(BUILD_TESTING)
add_subdirectory(./src/tests)
endif()
# With this, paths are added to the INSTALL_RPATH, and via the second command also to the build.
if (CMAKE_BUILD_MODULE_SYSTEM_INDEPENDENT)
set_target_properties(mhm PROPERTIES INSTALL_RPATH "${CMAKE_Fortran_IMPLICIT_LINK_DIRECTORIES}")
set_target_properties(mhm PROPERTIES BUILD_WITH_INSTALL_RPATH ON)
set_target_properties(mhm
PROPERTIES
INSTALL_RPATH "${CMAKE_Fortran_IMPLICIT_LINK_DIRECTORIES}"
BUILD_WITH_INSTALL_RPATH ON
)
endif()
#set_target_properties(mhm PROPERTIES SKIP_BUILD_RPATH OFF)
#set_target_properties(mhm PROPERTIES INSTALL_RPATH_USE_LINKPATH ON)
# possibility to create symlinks to the build or to the source directory, so a copy of mhm does not have to be done. On the other
# hand, only for the test domains the executable would not be copied or linked to a predictable location. So it may be a good
# idea to not copy it with the cmake setup
#add_custom_target(link_namelists ALL "${CMAKE_COMMAND}" -E create_symlink "${CMAKE_CURRENT_SOURCE_DIR}/mhm.nml" "${CMAKE_CURRENT_BINARY_DIR}/mhm.nml")
# get_preproc_flag : get correct fortran pre-processor flag
#
# get_preproc_flag(FLAG)
#
# will store pre-processor flag in "FLAG" (-fpp or -cpp)
function(get_preproc_flag preprog_flag)
include(CheckFortranCompilerFlag)
# check pre-processor -fpp for NAG or Intel
CHECK_Fortran_COMPILER_FLAG("-fpp" FPP_FLAG)
# check -cpp for other compilers
CHECK_Fortran_COMPILER_FLAG("-cpp" CPP_FLAG)
# if the flag exists, we add it to the compilation flags
if(FPP_FLAG)
set(preprog_flag_ "-fpp")
elseif(CPP_FLAG)
set(preprog_flag_ "-cpp")
else()
message(FATAL_ERROR "Compiler does not support -fpp or -cpp")
endif()
set(${preprog_flag} ${preprog_flag_} PARENT_SCOPE)
message(STATUS "Pre-Processor Flag: '${preprog_flag_}'")
endfunction()
# this function adds definitions but also creates a corresponding CMAKE_* variable with CACHE STRING
# $cmake -C ../CMakeCacheFiles/example
# adding cpp_definitions(DEFNAME OFF "some info")
# will enable the pre-processor directive DEFNAME and can be controlled by
# cmake -DCMAKE_DEFNAME=ON ..
function(cpp_definitions defName value cacheString)
option(CMAKE_${defName} ${cacheString} ${value})
if (CMAKE_${defName})
add_compile_definitions(${defName})
endif()
endfunction()
# The variable "CMAKE_BUILD_MODULE_SYSTEM_INDEPENDENT" can be set before executing cmake via a cache command:
# $cmake -DCMAKE_BUILD_MODULE_SYSTEM_INDEPENDENT=ON ..
# or cache file:
# $cmake -C ../CMakeCacheFiles/eve ..
# or after executing CMake editing the CMakeCache.txt, preferably with a corresponding cmake editor i.e ccmake
option(CMAKE_BUILD_MODULE_SYSTEM_INDEPENDENT "build the module INDEPENDENT of the module system, so the build in the build tree works even after a module purge")
message(STATUS "build INDEPENDENT of module system ${CMAKE_BUILD_MODULE_SYSTEM_INDEPENDENT}")
# set specific place where to search for the netCDF directory
set(CMAKE_NETCDF_DIR "" CACHE PATH "set set specific place where to search for the netCDF directory")
message(STATUS "search in additional directory '${CMAKE_NETCDF_DIR}' for netCDF")
# The variable "CMAKE_WITH_MPI" can be set before executing cmake via a cache command:
# $cmake -DCMAKE_WITH_MPI=ON ..
# or in a cache file:
# $cmake -C ../CMakeCacheFiles/example
# or after executing CMake editing the CMakeCache.txt,
# preferably with a corresponding cmake editor i.e. ccmake
# same with OpenMP, lapack, coverage (all OFF by default)
option(CMAKE_WITH_MPI "build the module with MPI, so it can be executed using mpirun")
option(CMAKE_WITH_OpenMP "build the module with OpenMP parallelization")
option(CMAKE_WITH_LAPACK "build the module with lapack library")
option(CMAKE_WITH_COVERAGE "build the module with gcov coverage support")
# if cmake provides a findLIBRARY module, this gets invoked via find_package(LIBRARY)
if (CMAKE_WITH_MPI)
# find if there is an MPI setup on the system and if so, set corresponding variables
find_package(MPI)
if (NOT ${MPI_Fortran_FOUND})
message(FATAL_ERROR "MPI required but not found")
else()
message(STATUS "found MPI_Fortran_COMPILER ${MPI_Fortran_COMPILER}")
endif()
endif()
if (CMAKE_WITH_OpenMP)
# find if there is an OpenMP setup on the system and if so, set corresponding variables
find_package(OpenMP)
if (NOT ${OpenMP_Fortran_FOUND})
message(FATAL_ERROR "OpenMP required but not found")
endif()
endif()
if (CMAKE_WITH_LAPACK)
# find if there is an LAPACK library on the system and if so, set corresponding variables
find_package(LAPACK)
if (NOT ${LAPACK_FOUND})
message(FATAL_ERROR "lapack required but not found")
endif()
endif()
# get_version : get version information form files
#
# version.txt - version string
# version_date.txt - version date sting
#
# get_version(VER VER_DEV DATE)