From b57a46c0adabdfe4dae8cc6d04972ee66ee76e84 Mon Sep 17 00:00:00 2001
From: Dominic Kempf <dominic.r.kempf@gmail.com>
Date: Thu, 29 Jan 2015 18:56:47 +0100
Subject: [PATCH] [Bugfix][CMake] Fix problem with compatibility layer and
 parallel builds.

The compatibility layer disabled MPI whenever it did not find
the --enable-parallel flag. This is overeager and harmful if users
are gradually switching to replacing the configure flags with real
cmake flags.

Consider an opts file, with the following content:
CMAKE_FLAGS="-DUSE_MPI=ON"

The compatibility layer would now parse the non-existent CONFIGURE_FLAGS
variable for an --enable-parallel option and disable MPI because it was
not found. The -DCMAKE_DISABLE_FIND_PACKAGE_MPI=TRUE supersedes the USE_MPI=ON
and we get a sequential build.

The fix applied in this patch removes the else clause and only adds
cmake flags when the --enable-parallel flag was found. To still explicitly
allow to force sequential builds, the --disable-parallel flag is parsed
in the same manner.
---
 lib/dunecommonam2cmake.lib | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/lib/dunecommonam2cmake.lib b/lib/dunecommonam2cmake.lib
index dd4f84b3c..41ab033bc 100644
--- a/lib/dunecommonam2cmake.lib
+++ b/lib/dunecommonam2cmake.lib
@@ -21,13 +21,18 @@ dune_common_options_am2cmake()
 
     default_am2cmake_options $CMAKE_PACKAGES
 
-    # Check for --enable-parallel and otherwise deactivate MPI
+    # Check for --enable-parallel and activate MPI
     echo $PARAMS | grep \\-\\-enable-parallel > /dev/null
-    if test "$?" -ne 0 ; then
-	CMAKE_PARAMS="$CMAKE_PARAMS -DCMAKE_DISABLE_FIND_PACKAGE_MPI=TRUE"
-    else
-        CMAKE_PARAMS="$CMAKE_PARAMS -DUSE_MPI=ON"
+    if test "$?" -eq 0 ; then
+	      CMAKE_PARAMS="$CMAKE_PARAMS -DUSE_MPI=ON"
     fi
+
+    # Check for --disable-parallel and deactivate MPI if given
+    echo $PARAMS | grep \\-\\-disable-parallel > /dev/null
+    if test "$?" -eq 0 ; then
+        CMAKE_PARAMS="$CMAKE_PARAMS -DCMAKE_DISABLE_FIND_PACKAGE_MPI=TRUE"
+    fi
+
     # Check for --disable-cxx11check
     echo $PARAMS | grep \\-\\-disable-cxx11check > /dev/null
     if test "$?" -eq 0 ; then
-- 
GitLab