MPI_COMPILE_FLAGS is list instead of a string
In CMake-3.11.4 and CMake-3.12.1 MPI_COMPILE_FLAGS
is a list and hence adding it to e.g. CMAKE_CXX_FLAGS will lead to semicolons being injected.
When running mpicc --showme
it outputs
-fexceptions -pthread
so there are two compile flags here.
When now using a CMakeLists.txt
like:
cmake_minimum_required(VERSION 3.1)
find_package(MPI)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MPI_COMPILE_FLAGS}")
message("CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
one will get an output like:
CXX_FLAGS: -fexceptions;-pthread
which will lead to compile errors.
As a side note in CMake-3.9.6 this isn't a problem as -pthread
doesn't get added to MPI_COMPILE_FLAGS
and hence there is only one item in the list.
Found here: https://github.com/espressomd/espresso/pull/2244
Workaround is pretty simple:
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -286,7 +286,10 @@ endif(WITH_VALGRIND_INSTRUMENTATION)
#######################################################################
find_package(MPI REQUIRED)
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MPI_COMPILE_FLAGS}")
+# Workaround for https://gitlab.kitware.com/cmake/cmake/issues/18349
+foreach(_MPI_FLAG ${MPI_COMPILE_FLAGS})
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_MPI_FLAG}")
+endforeach()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MPI_LINK_FLAGS}")
include_directories(SYSTEM ${MPI_INCLUDE_PATH})
list(APPEND LIBRARIES ${MPI_LIBRARIES})
Edited by Christoph Junghans