CMakeLists.txt 1.75 KB
Newer Older
1
# mHM cmake script
2
cmake_minimum_required(VERSION 3.12)
3
4
# additional cmake-modules
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules)
5

6
7
8
# get version and date from file
include(version)
get_version(MHM_VER MHM_VER_DEV MHM_DATE)
9
10
11

# create the project
project(mhm
Sebastian Müller's avatar
Sebastian Müller committed
12
13
14
15
16
  VERSION ${MHM_VER}
  DESCRIPTION "The mesoscale Hydrological Model"
  HOMEPAGE_URL "https://www.ufz.de/mhm"
  LANGUAGES Fortran
  )
17
18
# add full version and date to pre-processor flags (qoutes need in before hand)
add_compile_definitions(
Sebastian Müller's avatar
Sebastian Müller committed
19
  MHMVERSION='${MHM_VER_DEV}'
20
  MHMDATE='${MHM_DATE}'
Sebastian Müller's avatar
Sebastian Müller committed
21
  )
22

23
24
25
26
27
28
29
# Compile
add_subdirectory(./src)  # the lib folder containing mhm_lib
add_executable(mhm ./src/mHM/mhm_driver.f90)
target_link_libraries(mhm PRIVATE mhm_lib)

# setup coverage with GNU
if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU" AND CMAKE_WITH_COVERAGE)
Sebastian Müller's avatar
Sebastian Müller committed
30
31
32
33
  include(CodeCoverage)
  APPEND_COVERAGE_COMPILER_FLAGS()
  SETUP_TARGET_FOR_COVERAGE_LCOV(NAME mhm_coverage_CI
    EXECUTABLE ../CI-scripts/run_cmake_coverage.sh
34
    DEPENDENCIES mhm mhm_lib
Sebastian Müller's avatar
Sebastian Müller committed
35
36
    EXCLUDE src/lib/*
    GENHTML_ARGS -t "mHM coverage" --html-prolog ../doc/html_files/cov_header.prolog)
37
endif()
38

39
40
# 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
41
# CMAKE_BUILD_MODULE_SYSTEM_INDEPENDENT
42
43
44
# 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.
45
if (CMAKE_BUILD_MODULE_SYSTEM_INDEPENDENT)
Sebastian Müller's avatar
Sebastian Müller committed
46
47
48
49
50
  set_target_properties(mhm
    PROPERTIES
    INSTALL_RPATH "${CMAKE_Fortran_IMPLICIT_LINK_DIRECTORIES}"
    BUILD_WITH_INSTALL_RPATH ON
  )
51
endif()