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

CMake: use add_compile_definitions for controlable cpp flags; further cleanup

parent f32b79d3
......@@ -2,7 +2,7 @@
cmake_minimum_required(VERSION 3.12)
# additional cmake-modules
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules)
# get version and date from file
# 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
......
......@@ -29,8 +29,8 @@ endfunction()
# 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()
set(${defCMakeName} "${value}" CACHE STRING "${cacheString}")
if (${defCMakeName})
add_compile_definitions("${defName}")
endif()
endfunction()
......@@ -6,7 +6,7 @@ add_library(${LIB_NAME} ${sources})
# add all compile options (MPI, OpenMP, Lapack, Coverage)
include(compileoptions)
# the FindNetCDFF.cmake automatically used by find_package(NetCDFF ...)
# FindNetCDFF.cmake is automatically used by find_package(NetCDFF ...)
set(NETCDF_F90 "YES") # required interface
find_package(NetCDFF REQUIRED)
# from that module we gain the following variables:
......@@ -15,14 +15,13 @@ find_package(NetCDFF REQUIRED)
# NETCDF_CFLAGS_OTHER : additional compilation flags
# NETCDF_LDFLAGS_OTHER : additional linking flags
# get pre-processor flag for current compiler (either -fpp or -cpp)
# and 'cpp_definitions' function
# get pre-processor flag for current compiler (-fpp or -cpp) and 'cpp_definitions' function
include(checkfortranpreprocessor)
get_preproc_flag(XPP_FLAG)
# 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")
cpp_definitions("pgiFortran" "CMAKE_pgiFortran" "OFF" "Code exchange for pgi compiler dependent issues")
cpp_definitions("MPR_STANDALONE" "CMAKE_MPR_STANDALONE" "OFF" "If set to ON, only MPR is compiled")
cpp_definitions("ABSOFT" "CMAKE_ABSOFT" "OFF" "Documentation to be added. If you you are developer, you might edit this string in CMakeLists.txt")
# all compile and link options are PUBLIC in order to be forwared to 'mhm' exe
# target_link_options only available in cmake 3.13
......@@ -64,15 +63,13 @@ if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
-ffree-form -ffixed-line-length-132
$<$<CONFIG:DEBUG>:-pedantic-errors -Wall -W -O -g -Wno-maybe-uninitialized>
$<$<CONFIG:RELEASE>:-O3>
$<$<BOOL:CMAKE_WITH_COVERAGE>:-g -fprofile-arcs -ftest-coverage>
)
if(CMAKE_WITH_COVERAGE)
target_compile_options(${LIB_NAME} PUBLIC -g -fprofile-arcs -ftest-coverage)
endif()
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
# https://discourse.cmake.org/t/preserving-options-with-spaces-in-add-compile-options/1551/2
target_compile_definitions(${LIB_NAME} PUBLIC INTEL)
target_compile_options(${LIB_NAME} PUBLIC
-nofixed "SHELL:-assume byterecl" "SHELL:-fp-model source" -m64 "SHELL:-assume realloc-lhs"
-nofixed "SHELL:-assume byterecl" "SHELL:-fp-model source" -m64 "SHELL:-assume realloc-lhs"
$<$<CONFIG:DEBUG>:-g "SHELL:-warn all" "SHELL:-check all" -debug -traceback -fp-stack-check -O0>
$<$<CONFIG:RELEASE>:-O3 -qoverride-limits>
)
......@@ -97,7 +94,7 @@ get_target_property(MAIN_CDEFS ${LIB_NAME} COMPILE_DEFINITIONS)
message(STATUS "mhm_lib compiler defs are: ${MAIN_CDEFS}")
# automatically enable testing (OFF by default)
option(BUILD_TESTING "" OFF)
option(BUILD_TESTING "Build with pfUnit tests." OFF)
include(CTest)
# add pfunit test folder
......
......@@ -7,12 +7,8 @@ if(PFUNIT_FOUND)
file(GLOB testfiles ./*.pf)
foreach(file ${testfiles})
get_filename_component(testname ${file} NAME_WE)
add_pfunit_ctest(${testname}
TEST_SOURCES ${file}
LINK_LIBRARIES ${LIB_NAME}
)
add_pfunit_ctest(${testname} TEST_SOURCES ${file} LINK_LIBRARIES ${LIB_NAME})
endforeach()
else()
message(STATUS "No test program found, install PFUNIT")
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