title: CMake: build fails when compiling a C++ shared lib depending on MPI
body: <h1>Problem overview</h1>
  
  <p>I'm using CMake to build a project which contains a library based on MPI. The lib has to be built as both shared and static. When I build the project on my Fedora 20 system, everything goes without problem. When I build it on a Mac OS X El Capitan system, the building process fails with an error of the type:</p>
  
  <pre><code>ld: symbol(s) not found for architecture x86_64
  </code></pre>
  
  <h1>Additional remarks</h1>
  
  <ul>
  <li>I cannot activate the option forcing automatic compilation of libs as both shared and static because this specific library is the only one that needs to be built as both.</li>
  <li>Forcing the replacement of the C++ compiler command by the MPI wrapper (<code>mpicxx</code>) results in a successful build but completely breaks CLion's code analysis.</li>
  </ul>
  
  <h1>Minimal (non)working example</h1>
  
  <p>File: <code>MPILib.h</code></p>
  
  <pre><code>#include &lt;mpi.h&gt;
  void MPILib();
  </code></pre>
  
  <p>File: <code>MPILib.c</code></p>
  
  <pre><code>#include "MPILib.h"
  void MPILib() { MPI_Init(NULL, NULL); }
  </code></pre>
  
  <p>File: <code>CMakeLists.txt</code></p>
  
  <pre><code>cmake_minimum_required(VERSION 2.6)
  
  enable_language(CXX)
  set(CMAKE_MACOSX_RPATH 0)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")
  
  find_package(MPI REQUIRED)
  include_directories(SYSTEM ${MPI_INCLUDE_PATH})
  
  add_library(mpilib_shared SHARED MPILib.cpp MPILib.h)
  add_library(mpilib_static STATIC MPILib.cpp MPILib.h)
  </code></pre>
  
  <p>Build commands:</p>
  
  <ul>
  <li><code>cmake .</code></li>
  <li><code>make mpilib_static</code> (succeeds)</li>
  <li><code>make mpilib_shared</code> (fails)</li>
  </ul>