In this recipe, we set out to find the MPI implementation: library, header files, compiler wrappers, and launcher. To do so, we will leverage the FindMPI.cmake standard CMake module:
- First, we define the minimum CMake version, project name, supported language, and language standard:
cmake_minimum_required(VERSION 3.9 FATAL_ERROR)project(recipe-06 LANGUAGES CXX)set(CMAKE_CXX_STANDARD 11)set(CMAKE_CXX_EXTENSIONS OFF)set(CMAKE_CXX_STANDARD_REQUIRED ON)
- We then call find_package to locate the MPI implementation:
find_package(MPI REQUIRED)
- We define the executable name and, source, and similarly to the previous recipe, link against the imported target:
add_executable(hello-mpi hello-mpi.cpp)target_link_libraries(hello-mpi PUBLIC ...