-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
60 lines (54 loc) · 2.22 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# common (default) options to cmake
# -DCMAKE_BUILD_TYPE=Release - compile in debug or release mode
# -DBUILD_TESTING=ON - whether to compile tests
# -DCMAKE_VERBOSE_MAKEFILE=OFF - see all the commands
# -DCMAKE_BUILD_MODULE_SYSTEM_INDEPENDENT=OFF - build the library INDEPENDENT of the module system,
# -DCMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX=64 - find extra library paths on some systems (eve.nag62)
# so the build in the build tree works even after a module purge
cmake_minimum_required(VERSION 3.14)
# additional cmake-modules
set(FORCES_CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# get version and date from files (version.txt and version_date.txt)
include(${FORCES_CMAKE_MODULE_PATH}/version.cmake)
get_version(FORCES_VER FORCES_VER_DEV FORCES_DATE)
# create the project
project(FORCES
VERSION ${FORCES_VER}
DESCRIPTION "FORtran library for Computational Environmental Systems"
HOMEPAGE_URL "https://git.ufz.de/chs/forces/"
LANGUAGES Fortran
)
# library module specific settings (defined after coverage definition)
add_subdirectory(./src)
set (LIB_NAME forces)
# add full version and date to pre-processor flags (qoutes need in before hand)
target_compile_definitions(${LIB_NAME} PRIVATE
FORCESVERSION='${FORCES_VER_DEV}'
FORCESDATE='${FORCES_DATE}'
)
# prepare testing
option(BUILD_TESTING "Build with (pfUnit) tests." OFF)
set(BUILD_FORCES_TESTS OFF)
if((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME OR ${LIB_NAME}_BUILD_TESTING) AND BUILD_TESTING)
set(BUILD_FORCES_TESTS ON)
endif()
include(CTest)
# add test directories
if(BUILD_FORCES_TESTS)
message(STATUS "${PROJECT_NAME}: build tests")
add_subdirectory(./src/pf_tests)
endif()
# prepare coverage
if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU" AND CMAKE_WITH_COVERAGE AND BUILD_FORCES_TESTS)
include(${FORCES_CMAKE_MODULE_PATH}/CodeCoverage.cmake)
target_compile_options(${LIB_NAME} PRIVATE -g --coverage)
target_link_libraries(${LIB_NAME} PRIVATE gcov)
SETUP_TARGET_FOR_COVERAGE_LCOV(
NAME coverage
EXECUTABLE ctest
DEPENDENCIES ${LIB_NAME}
EXCLUDE "src/pf_tests/*" "${CMAKE_CURRENT_BINARY_DIR}/*"
LCOV_ARGS --no-external
GENHTML_ARGS -t "${LIB_NAME} coverage" --html-prolog ../doc/html_files/cov_header.prolog
)
endif()