I am trying to apply openmp and mpi techniques to an open source C program which requires \"cmake . && make\" to be built. I already found at How to set linker flags
In modern CMake 3.X which is target based, the CMakeLists.txt should look like this:
cmake_minimum_required(VERSION 3.0)
project(main)
find_package(MPI REQUIRED)
# add this line only when you are using openmpi which has a different c++ bindings
add_definitions(-DOMPI_SKIP_MPICXX)
# Use imported targets would make things much eazier. Thanks Levi for pointing it out.
add_executable(main main.cpp)
target_link_libraries(main
PRIVATE
MPI_C)
# Old way.
#target_link_libraries(main
# PRIVATE
# ${MPI_C_LIBRARIES})
#target_include_directories(main
# PRIVATE
# ${MPI_C_INCLUDE_PATH})