Skip to content

Commit

Permalink
Apply cmake-format on cmake files
Browse files Browse the repository at this point in the history
  • Loading branch information
francesco-ballarin committed Nov 27, 2023
1 parent 2f3b57f commit b5a3280
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions rbnicsx/_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,26 @@ set(CMAKE_CXX_EXTENSIONS OFF)
message(STATUS "Build type is ${CMAKE_BUILD_TYPE}")

# Find python
find_package(Python COMPONENTS Interpreter Development REQUIRED)
find_package(
Python
COMPONENTS Interpreter Development
REQUIRED
)

# Find nanobind
execute_process(
COMMAND ${Python_EXECUTABLE} -m nanobind --cmake_dir
OUTPUT_VARIABLE NANOBIND_CMAKE_DIR
RESULT_VARIABLE NANOBIND_CMAKE_DIR_COMMAND_RESULT
ERROR_VARIABLE NANOBIND_CMAKE_DIR_COMMAND_ERROR
OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND ${Python_EXECUTABLE} -m nanobind --cmake_dir
OUTPUT_VARIABLE NANOBIND_CMAKE_DIR
RESULT_VARIABLE NANOBIND_CMAKE_DIR_COMMAND_RESULT
ERROR_VARIABLE NANOBIND_CMAKE_DIR_COMMAND_ERROR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT NANOBIND_CMAKE_DIR_COMMAND_RESULT)
list(APPEND CMAKE_PREFIX_PATH "${NANOBIND_CMAKE_DIR}")
find_package(nanobind CONFIG REQUIRED)
message(STATUS "Found nanobind python wrappers at ${NANOBIND_CMAKE_DIR}")
list(APPEND CMAKE_PREFIX_PATH "${NANOBIND_CMAKE_DIR}")
find_package(nanobind CONFIG REQUIRED)
message(STATUS "Found nanobind python wrappers at ${NANOBIND_CMAKE_DIR}")
else()
message(FATAL_ERROR "nanobind could not be found.")
message(FATAL_ERROR "nanobind could not be found.")
endif()

# Check for MPI
Expand All @@ -35,41 +39,39 @@ find_package(MPI 3 REQUIRED)
# Check for PETSc
find_package(PkgConfig REQUIRED)
set(ENV{PKG_CONFIG_PATH}
"$ENV{PETSC_DIR}/$ENV{PETSC_ARCH}/lib/pkgconfig:$ENV{PETSC_DIR}/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}"
"$ENV{PETSC_DIR}/$ENV{PETSC_ARCH}/lib/pkgconfig:$ENV{PETSC_DIR}/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}"
)
pkg_search_module(PETSC REQUIRED IMPORTED_TARGET PETSc>=3.15 petsc>=3.15)

# Check for petsc4py
execute_process(
COMMAND ${Python_EXECUTABLE} -c "import petsc4py; print(petsc4py.get_include())"
OUTPUT_VARIABLE PETSC4PY_INCLUDE_DIR
RESULT_VARIABLE PETSC4PY_INCLUDE_COMMAND_RESULT
ERROR_VARIABLE PETSC4PY_INCLUDE_COMMAND_ERROR
OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND ${Python_EXECUTABLE} -c
"import petsc4py; print(petsc4py.get_include())"
OUTPUT_VARIABLE PETSC4PY_INCLUDE_DIR
RESULT_VARIABLE PETSC4PY_INCLUDE_COMMAND_RESULT
ERROR_VARIABLE PETSC4PY_INCLUDE_COMMAND_ERROR
OUTPUT_STRIP_TRAILING_WHITESPACE
)

if(NOT PETSC4PY_INCLUDE_COMMAND_RESULT)
message(STATUS "Found petsc4py include directory at ${PETSC4PY_INCLUDE_DIR}")
message(STATUS "Found petsc4py include directory at ${PETSC4PY_INCLUDE_DIR}")
else()
message(FATAL_ERROR "petsc4py could not be found.")
message(FATAL_ERROR "petsc4py could not be found.")
endif()

# Compile rbnicsx C++ backend and nanobind wrappers
nanobind_add_module(
rbnicsx_cpp
NOMINSIZE
rbnicsx/_backends/frobenius_inner_product.cpp
rbnicsx/_backends/petsc_error.cpp
rbnicsx/wrappers/_backends.cpp
rbnicsx/wrappers/rbnicsx.cpp
rbnicsx_cpp NOMINSIZE rbnicsx/_backends/frobenius_inner_product.cpp
rbnicsx/_backends/petsc_error.cpp rbnicsx/wrappers/_backends.cpp
rbnicsx/wrappers/rbnicsx.cpp
)

# Add MPI and PETSc libraries
target_link_libraries(rbnicsx_cpp PRIVATE MPI::MPI_CXX)
target_link_libraries(rbnicsx_cpp PRIVATE PkgConfig::PETSC)

# Add petsc4py include directories
# (with MPI and PETSc ones already being added by target_link_libraries)
# 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 current source directory to include directories
Expand Down

0 comments on commit b5a3280

Please sign in to comment.