Skip to content

Commit

Permalink
Link against MPI, since PETSc requires it but does not search for it
Browse files Browse the repository at this point in the history
  • Loading branch information
francesco-ballarin committed Nov 26, 2023
1 parent 59c43dd commit 7c71e8d
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions rbnicsx/_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ else()
message(FATAL_ERROR "nanobind could not be found.")
endif()

# Check for MPI
find_package(MPI 3 REQUIRED)

# Check for PETSc
find_package(PkgConfig REQUIRED)
set(ENV{PKG_CONFIG_PATH}
Expand Down Expand Up @@ -61,15 +64,16 @@ nanobind_add_module(
rbnicsx/wrappers/rbnicsx.cpp
)

# Add current source directory to include directories
target_include_directories(rbnicsx_cpp PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
# Add MPI and PETSc libraries
target_link_libraries(rbnicsx_cpp PRIVATE MPI::MPI_CXX)
target_link_libraries(rbnicsx_cpp PRIVATE PkgConfig::PETSC)

# Add PETSc and petsc4py include directories
target_include_directories(rbnicsx_cpp PRIVATE ${PETSC_INCLUDE_DIRS})
# Add petsc4py include directories
# (with MPI and PETSc ones already being added by target_link_libraries)
target_include_directories(rbnicsx_cpp PRIVATE ${PETSC4PY_INCLUDE_DIR})

# Add PETSc libraries
target_link_libraries(rbnicsx_cpp PRIVATE PkgConfig::PETSC)
# Add current source directory to include directories
target_include_directories(rbnicsx_cpp PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

# Install the compiled library to the _cpp subdirectory
set_target_properties(rbnicsx_cpp PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)
Expand Down

0 comments on commit 7c71e8d

Please sign in to comment.