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

Cmake: tackle openmp bug

parent adae4165
......@@ -2,11 +2,9 @@
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
include(version)
get_version(MHM_VER MHM_VER_DEV MHM_DATE)
# create the project
project(mhm
VERSION ${MHM_VER}
......@@ -15,16 +13,13 @@ project(mhm
LANGUAGES Fortran
)
# add full version and date to pre-processor flags (qoutes need in before hand)
add_compile_definitions(
MHMVERSION='${MHM_VER_DEV}'
MHMDATE='${MHM_DATE}'
)
add_compile_definitions(MHMVERSION='${MHM_VER_DEV}' MHMDATE='${MHM_DATE}')
# add all compile options (MPI, OpenMP, Lapack, Coverage)
include(compileoptions)
# 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)
include(CodeCoverage)
......
......@@ -31,17 +31,14 @@ if (CMAKE_WITH_MPI)
else()
message(STATUS "found MPI_Fortran_COMPILER ${MPI_Fortran_COMPILER}")
endif()
# add_compile_definitions(MPI)
endif()
if (CMAKE_WITH_OpenMP)
# find if there is an OpenMP setup on the system and if so, set corresponding variables
find_package(OpenMP)
find_package(OpenMP)
if (NOT ${OpenMP_Fortran_FOUND})
message(FATAL_ERROR "OpenMP required but not found")
endif()
endif()
if (CMAKE_WITH_LAPACK)
# find if there is an LAPACK library on the system and if so, set corresponding variables
find_package(LAPACK)
......
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../cmake-modules)
set (LIB_NAME mhm_lib)
# use all mo_*.f90 files for the library
file(GLOB_RECURSE sources ./*mo_*.f90)
add_library(${LIB_NAME} ${sources})
# target_include_directories(${LIB_NAME} PRIVAT ${CMAKE_CURRENT_SOURCE_DIR})
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../cmake-modules)
# add all compile options (MPI, OpenMP, Lapack, Coverage)
include(compileoptions)
......@@ -26,17 +25,33 @@ cpp_definitions("-DMPR_STANDALONE" "CMAKE_MPR_STANDALONE" "OFF" "If set to ON, o
cpp_definitions("-DABSOFT" "CMAKE_ABSOFT" "OFF" "Documentation to be added. If you you are developer, you might edit this string in CMakeLists.txt")
# target_link_options would be better but is only available for cmake >=3.13
# target_link_options(${LIB_NAME} PUBLIC ${NETCDF_LDFLAGS_OTHER})
set_property(TARGET ${LIB_NAME} PROPERTY LINK_FLAGS ${NETCDF_LDFLAGS_OTHER})
# target_link_options(${LIB_NAME} PUBLIC
# ${NETCDF_LDFLAGS_OTHER}
# ${MPI_Fortran_LINK_FLAGS}
# ${OpenMP_Fortran_FLAGS}
# ${LAPACK_LINKER_FLAGS}
# )
set_property(TARGET ${LIB_NAME} PROPERTY LINK_FLAGS
"${NETCDF_LDFLAGS_OTHER} ${MPI_Fortran_LINK_FLAGS} ${OpenMP_Fortran_FLAGS} ${LAPACK_LINKER_FLAGS}"
)
target_compile_options(${LIB_NAME} PUBLIC
${XPP_FLAG}
${NETCDF_CFLAGS_OTHER}
${MPI_Fortran_COMPILE_FLAGS}
${OpenMP_Fortran_FLAGS}
)
target_include_directories(${LIB_NAME} PUBLIC
${NETCDF_INCLUDES}
${MPI_Fortran_INCLUDE_PATH}
${OpenMP_Fortran_LIBRARY}
)
target_compile_options(${LIB_NAME} PUBLIC ${NETCDF_CFLAGS_OTHER} ${XPP_FLAG})
target_link_libraries(${LIB_NAME} PUBLIC ${NETCDF_LINK_LIBRARIES} ${MPI_Fortran_LIBRARIES})
target_include_directories(${LIB_NAME} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
# ${CMAKE_CURRENT_BINARY_DIR} # ?!
)
target_link_libraries(${LIB_NAME} PUBLIC
${NETCDF_LINK_LIBRARIES}
${MPI_Fortran_LIBRARIES}
${OpenMP_Fortran_LIBRARIES}
${LAPACK_LIBRARIES}
)
# by setting compile options and definitions PUBLIC, they are also used by
# programms linking agains it (mhm exe in this case)
if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
......@@ -45,7 +60,7 @@ 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>
)
)
if(CMAKE_WITH_COVERAGE)
target_compile_options(${LIB_NAME} PUBLIC -g -fprofile-arcs -ftest-coverage)
endif()
......@@ -72,7 +87,10 @@ endif()
# Show compile options
get_target_property(MAIN_CFLAGS ${LIB_NAME} COMPILE_OPTIONS)
message(STATUS "Target compiler flags are: ${MAIN_CFLAGS}")
message(STATUS "mhm_lib compiler flags are: ${MAIN_CFLAGS}")
# Show compile options
get_target_property(MAIN_CDEFS ${LIB_NAME} COMPILE_DEFINITIONS)
message(STATUS "mhm_lib compiler defs are: ${MAIN_CDEFS}")
# add pfunit test folder
if(BUILD_TESTING)
......
Markdown is supported
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