Commit 3674fb6f authored by Sebastian Müller's avatar Sebastian Müller 🐈
Browse files

Cmake: cleanup

parent 37292b45
Pipeline #25003 canceled with stages
in 21 minutes and 49 seconds
# 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)
# check version file
# additional cmake-modules
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake-modules)
# get version and date from files (version.txt and version_date.txt)
include(version)
......@@ -7,36 +14,20 @@ 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)
VERSION ${FORCES_VER}
DESCRIPTION "FORtran library for Computational Environmental Systems"
HOMEPAGE_URL "https://git.ufz.de/chs/forces/"
LANGUAGES Fortran
)
# add full version and date to pre-processor flags (qoutes need in before hand)
add_compile_definitions(FORCESVERSION='${FORCES_VER_DEV}' FORCESDATE='${FORCES_DATE}')
# 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
# library module specific settings
add_subdirectory(./src)
# automatically enables testing
option(BUILD_TESTING "Build with pfUnit tests." OFF)
option(BUILD_TESTING "Build with (pfUnit) tests." OFF)
include(CTest)
if((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME OR ${LIB_NAME}_BUILD_TESTING) AND BUILD_TESTING)
add_subdirectory(./src/pf_tests)
add_subdirectory(./src/tests)
endif()
# 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
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")
# library module specific settings
add_subdirectory(./src)
set (LIB_NAME forces)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/cmake-modules)
set (LIB_NAME forces)
file(GLOB sources ./mo_*.f90)
# --- find preprocessor (cpp/fpp and fypp)
include(fortranpreprocessor)
......@@ -45,12 +45,10 @@ target_link_libraries(${LIB_NAME} PUBLIC NetCDF::NetCDF_Fortran)
include(compileoptions)
if (CMAKE_WITH_MPI)
message(STATUS "FORCES: use MPI")
target_compile_definitions(${LIB_NAME} PRIVATE MPI)
target_link_libraries(${LIB_NAME} PUBLIC MPI::MPI_Fortran)
endif()
if (CMAKE_WITH_OpenMP)
message(STATUS "FORCES: use OpenMP")
target_link_libraries(${LIB_NAME} PUBLIC OpenMP::OpenMP_Fortran)
endif()
......
set (LIB_NAME forces)
enable_testing()
set (LIB_NAME forces)
file ( COPY ./files DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file ( GLOB sources ./test_*.f90)
......@@ -10,16 +9,10 @@ foreach ( UNIT_TEST ${sources} )
get_filename_component ( test_name_ext ${UNIT_TEST} NAME )
get_filename_component ( test_name ${UNIT_TEST} NAME_WE )
add_executable(${test_name} ${test_name_ext})
# set_target_properties ( ${test_name}
# PROPERTIES
# COMPILE_FLAGS "${ADDITIONAL_GCC_FLAGS}"
# )
# message(STATUS "Testing enabled for ${TEST_DIR}")
target_link_libraries(${test_name} ${LIB_NAME})
add_test(NAME ${test_name} COMMAND ${test_name})
# set compiling flags for debug and relese version
# set compiling flags for debug and relese version
# set compiling flags for debug and relese version
if(CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
target_compile_definitions(${test_name} PRIVATE "INTEL")
target_compile_options(${test_name} PRIVATE
......@@ -53,7 +46,7 @@ foreach ( UNIT_TEST ${sources} )
endif()
list(APPEND testnames ${testname})
endforeach()
# TODO: fix coverage
if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
if (CMAKE_WITH_COVERAGE)
include(CodeCoverage)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment