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

CMake: better compile flag control

parent 23db9cdc
Pipeline #85580 passed with stages
in 9 minutes and 42 seconds
......@@ -19,9 +19,16 @@ project(FORCES
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)
add_compile_definitions(FORCESVERSION='${FORCES_VER_DEV}' FORCESDATE='${FORCES_DATE}')
target_compile_definitions(${LIB_NAME} PRIVATE
FORCESVERSION='${FORCES_VER_DEV}'
FORCESDATE='${FORCES_DATE}'
)
# prepare testing
option(BUILD_TESTING "Build with (pfUnit) tests." OFF)
......@@ -31,10 +38,17 @@ if((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME OR ${LIB_NAME}_BUILD_TESTING) AND B
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(CodeCoverage)
append_coverage_compiler_flags()
target_compile_options(${LIB_NAME} PRIVATE -g --coverage)
target_link_libraries(${LIB_NAME} PRIVATE gcov)
SETUP_TARGET_FOR_COVERAGE_LCOV(
NAME coverage
EXECUTABLE ctest
......@@ -44,11 +58,3 @@ if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU" AND CMAKE_WITH_COVERAGE AND BUILD_FOR
GENHTML_ARGS -t "${LIB_NAME} coverage" --html-prolog ../doc/html_files/cov_header.prolog
)
endif()
# library module specific settings (defined after coverage definition)
add_subdirectory(./src)
if(BUILD_FORCES_TESTS)
# add test directories (defined after coverage definition)
add_subdirectory(./src/pf_tests)
endif()
......@@ -2,8 +2,7 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/cmake-modules
set (LIB_NAME forces)
file(GLOB sources ./mo_*.f90 ./mo_*.F90)
# --- find preprocessor (fypp)
# find preprocessor (fypp)
include(fortranpreprocessor)
find_program(FYPP fypp)
if(NOT FYPP)
......@@ -26,6 +25,7 @@ else()
endif()
# add sources
file(GLOB sources ./mo_*.f90 ./mo_*.F90)
add_library(${LIB_NAME} ${sources} ${fyppOutFiles})
target_include_directories(${LIB_NAME} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
......@@ -50,7 +50,6 @@ target_link_libraries(${LIB_NAME} PUBLIC NetCDF::NetCDF_Fortran)
# add all compile options (MPI, OpenMP, Lapack, Coverage)
include(compileoptions)
if (CMAKE_WITH_MPI)
target_compile_definitions(${LIB_NAME} PRIVATE MPI)
target_link_libraries(${LIB_NAME} PUBLIC MPI::MPI_Fortran)
......@@ -65,7 +64,7 @@ if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
target_compile_definitions(${LIB_NAME} PRIVATE "GFORTRAN")
target_compile_options(${LIB_NAME} PRIVATE
-ffree-form -ffixed-line-length-132
$<$<CONFIG:DEBUG>:-fbacktrace -pedantic-errors -Wall -W -O -g -Wno-maybe-uninitialized>
$<$<CONFIG:DEBUG>:-Og -g -Wall -Wextra -fimplicit-none -fbacktrace -fcheck=all -ffpe-trap=zero,overflow,underflow -finit-real=snan -pedantic-errors>
$<$<CONFIG:RELEASE>:-O3 -fno-peel-loops>
)
endif()
......
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