[CMake] how to use the FindMPI module correctly?

Alexander Droste alexander.ra.droste at googlemail.com
Sat Apr 4 09:45:10 EDT 2015


Thanks, that really clears things up for me!

--Alex

On 04.04.15 14:39, Mark Abraham wrote:
> On 03/04/2015 8:24 pm, "Alexander Droste" <
> alexander.ra.droste at googlemail.com> wrote:
>>
>> Hello everyone,
>>
>> based on the documentation here:
>> http://www.cmake.org/cmake/help/v3.0/module/FindMPI.html
>>
>> and posts on SO:
>>
> http://stackoverflow.com/questions/23163075/how-to-compile-an-mpi-included-c-program-using-cmake
>>
>> I'm still not a 100% sure if I set up my CMake project correctly.
>> This is what I do:
>>
>> #------------------------
>> #...
>> find_package(MPI REQUIRED)
>> add_executable(core.x main.c)
>>
>> include_directories(SYSTEM ${MPI_C_INCLUDE_PATH})
>> link_directories(${MPI_C_LINK_FLAGS})
>> set(CMAKE_COMPILE_FLAGS ${CMAKE_COMPILE_FLAGS} ${MPI_C_COMPILE_FLAGS})
>> target_link_libraries(core.x ${MPI_C_LIBRARIES})
>> #-------------------------
>>
>> Is this the correct way? Am I missing s.th.? I am especially unsure about
> the compile flags variable.
>>
>> At "Usage" (CMake documentation) it said that "To use this module, simply
> call FindMPI from a CMakeLists.txt file". So can I break down the MPI setup
> to a single command. How do I call FindMPI? Or is it done by calling
> find_package like I did?
>>
>> The program build runs fine but I would like to ensure
>> that the cmake project is set up as correct and generic as possible.
>
> I think that most projects have no need of most of the functionality
> provided by FindMPI. Instead, you can tell CMake in the first place that
> the MPI wrapper compiler is your compiler, and leave the wrapper compiler
> alone to do its job. Otherwise, you have to coordinate that FindMPI is
> finding the wrapper compiler that you intend, and that it wraps the same
> compiler CMake is using, so that the flags FindMPI gets from the wrapper
> compiler can then work with CMake's compiler, because you can't change that
> compiler once it is set.
>
> The main exception would be a project where you want to build both MPI and
> non-MPI binaries from the same configuration. But you can still achieve
> this by using the wrapper compiler for everything... The non-MPI binary
> just won't link things that aren't used.
>
> Mark
>
>> Greetings,
>> Alex
>> --
>>
>> Powered by www.kitware.com
>>
>> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>>
>> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>>
>> CMake Support: http://cmake.org/cmake/help/support.html
>> CMake Consulting: http://cmake.org/cmake/help/consulting.html
>> CMake Training Courses: http://cmake.org/cmake/help/training.html
>>
>> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/cmake
>


More information about the CMake mailing list