From 0a75c1eb9c5610056945eba3c5dbbfe46cf8e92d Mon Sep 17 00:00:00 2001
From: Rene Halver <r.halver@fz-juelich.de>
Date: Mon, 30 Nov 2020 14:30:37 +0100
Subject: [PATCH] fixed some Fortran related bugs

---
 CMakeLists.txt | 38 ++++++++++++++++++++++++++------------
 1 file changed, 26 insertions(+), 12 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index c725b8d..8ca301f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -15,26 +15,35 @@ option(CM_ALL_AUTO_DOC "Enables creation of auto-documentation")
 cmake_policy(SET CMP0004 OLD)
 
 enable_language(CXX)
+enable_language(C)
+
+if (CM_ALL_USE_F08)
+    if (CM_ALL_FORTRAN)
+        message(FATAL_ERROR "Flag for Fortran 08 MPI interface set, while Fortran interface is not enabled!")
+    endif (CM_ALL_FORTRAN)
+endif (CM_ALL_USE_F08)
 
 if (CM_ALL_FORTRAN)
     enable_language(Fortran)
+# todo(s.schulz): This should be extended for other compilers, if they
+#                 support standard checking. The Intel Fortran compiler
+#                 does not.
+    if(CM_ALL_USE_F08)
+        add_compile_options($<$<AND:$<COMPILE_LANGUAGE:Fortran>,$<Fortran_COMPILER_ID:GNU>>:-std=f2008>)
+    else()
+        add_compile_options($<$<AND:$<COMPILE_LANGUAGE:Fortran>,$<Fortran_COMPILER_ID:GNU>>:-std=f2003>)
+    endif()
+    add_compile_options($<$<AND:$<COMPILE_LANGUAGE:Fortran>,$<Fortran_COMPILER_ID:GNU>>:-fbacktrace>)
+    add_compile_options($<$<AND:$<COMPILE_LANGUAGE:Fortran>,$<Fortran_COMPILER_ID:Intel>>:-traceback>)
 endif (CM_ALL_FORTRAN)
 
 # set standards compliance flags
 set(CMAKE_CXX_STANDARD 11)
 set(CMAKE_CXX_STANDARD_REQUIRED ON)
 set(CMAKE_CXX_EXTENSIONS OFF)
-# todo(s.schulz): This should be extended for other compilers, if they
-#                 support standard checking. The Intel Fortran compiler
-#                 does not.
-if(CM_ALL_USE_F08)
-    add_compile_options($<$<AND:$<COMPILE_LANGUAGE:Fortran>,$<Fortran_COMPILER_ID:GNU>>:-std=f2008>)
-else()
-    add_compile_options($<$<AND:$<COMPILE_LANGUAGE:Fortran>,$<Fortran_COMPILER_ID:GNU>>:-std=f2003>)
-endif()
-add_compile_options($<$<AND:$<COMPILE_LANGUAGE:Fortran>,$<Fortran_COMPILER_ID:GNU>>:-fbacktrace>)
-add_compile_options($<$<AND:$<COMPILE_LANGUAGE:Fortran>,$<Fortran_COMPILER_ID:Intel>>:-traceback>)
-add_compile_options("$<$<AND:$<CONFIG:Debug>,$<COMPILE_LANGUAGE:Fortran>,$<Fortran_COMPILER_ID:GNU>>:-Wall;-Wextra>")
+if (CM_ALL_FORTRAN)
+    add_compile_options("$<$<AND:$<CONFIG:Debug>,$<COMPILE_LANGUAGE:Fortran>,$<Fortran_COMPILER_ID:GNU>>:-Wall;-Wextra>")
+endif (CM_ALL_FORTRAN)
 add_compile_options("$<$<AND:$<CONFIG:Debug>,$<COMPILE_LANGUAGE:C>,$<C_COMPILER_ID:GNU>>:-Wall;-Wextra>")
 add_compile_options("$<$<AND:$<CONFIG:Debug>,$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:GNU>>:-Wall;-Wextra>")
 
@@ -46,7 +55,12 @@ project(ALL
 # add custom find-scripts to module path
 set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
 
-find_package(MPI REQUIRED)
+if (CM_ALL_FORTRAN)
+    find_package(MPI REQUIRED COMPONENTS CXX Fortran)
+else()
+    find_package(MPI REQUIRED COMPONENTS CXX)
+endif (CM_ALL_FORTRAN)
+
 
 if(CM_ALL_VTK_OUTPUT)
     message("Using VTK output")
-- 
GitLab