Skip to content

Commit

Permalink
CMake adjustments and add config header for pylibROM
Browse files Browse the repository at this point in the history
  • Loading branch information
ckendrick committed May 30, 2024
1 parent 20c7eec commit fcdf138
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 20 deletions.
38 changes: 22 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ if (USE_MFEM)
find_path(PARMETIS_INCLUDES metis.h
"$ENV{PARMETIS_DIR}/metis/include"
"${LIBROM_DIR}/dependencies/parmetis-4.0.3/metis/include")
set(PYLIBROM_HAS_MFEM 1)
endif()
#===================== pylibROM =============================

Expand All @@ -112,6 +113,9 @@ set(CMAKE_CXX_STANDARD 14)

find_package(MPI REQUIRED)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/bindings/pylibROM/pylibROM_config.h.in
${CMAKE_CURRENT_SOURCE_DIR}/bindings/pylibROM/pylibROM_config.h)

set(SOURCE_DIR "bindings/pylibROM")
include_directories(
${SOURCE_DIR}
Expand All @@ -122,22 +126,6 @@ include_directories(
)
link_libraries(${HDF5_LIBRARIES})

if (USE_MFEM)
target_include_directories(
_pylibROM
${MFEM_INCLUDES}
${HYPRE_INCLUDES}
${PARMETIS_INCLUDES}
${MFEM_C_INCLUDE_DIRS})

target_link_libraries(
_pylibROM
${MFEM}
${HYPRE}
${PARMETIS}
${METIS})
endif()

add_subdirectory("extern/pybind11")

set(PYLIBROM_SOURCES
Expand Down Expand Up @@ -188,4 +176,22 @@ endif()
pybind11_add_module(_pylibROM ${PYLIBROM_SOURCES})
message("building pylibROM...")

if (USE_MFEM)
target_include_directories(
_pylibROM
PUBLIC
${MFEM_INCLUDES}
${HYPRE_INCLUDES}
${PARMETIS_INCLUDES}
${MFEM_C_INCLUDE_DIRS})

target_link_libraries(
_pylibROM
PUBLIC
${MFEM}
${HYPRE}
${PARMETIS}
${METIS})
endif()

target_link_libraries(_pylibROM PRIVATE ROM)
12 changes: 10 additions & 2 deletions bindings/pylibROM/pylibROM.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
#include <pybind11/pybind11.h>

#include "CAROM_config.h"
#include "pylibROM_config.h"

// check that libROM has MFEM if pylibROM is using MFEM
#ifdef PYLIBROM_HAS_MFEM
#ifndef CAROM_HAS_MFEM
#error "libROM was not compiled with MFEM support"
#endif
#endif

namespace py = pybind11;

Expand Down Expand Up @@ -44,7 +52,7 @@ void init_Database(pybind11::module_ &m);
void init_HDFDatabase(pybind11::module_ &m);
void init_CSVDatabase(pybind11::module_ &m);

#ifdef CAROM_HAS_MFEM
#ifdef PYLIBROM_HAS_MFEM
//mfem
void init_mfem_Utilities(pybind11::module_ &m);
void init_mfem_PointwiseSnapshot(pybind11::module_ &m);
Expand Down Expand Up @@ -91,7 +99,7 @@ PYBIND11_MODULE(_pylibROM, m) {
init_STSampling(hyperreduction);
init_Utilities(hyperreduction);

#ifdef CAROM_HAS_MFEM
#ifdef PYLIBROM_HAS_MFEM
py::module mfem = m.def_submodule("mfem");
init_mfem_Utilities(mfem);
init_mfem_PointwiseSnapshot(mfem);
Expand Down
6 changes: 6 additions & 0 deletions bindings/pylibROM/pylibROM_config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef PYLIBROM_CONFIG_H_
#define PYLIBROM_CONFIG_H_

#cmakedefine PYLIBROM_HAS_MFEM

#endif
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ def build_extension(self, ext: CMakeExtension) -> None:
else:
print("Using pre-installed libROM library: %s" % librom_dir)
cmake_args += [f"-DLIBROM_DIR=%s" % librom_dir]
if (not use_mfem):
cmake_args += ["-DUSE_MFEM=OFF"]

cmake_args += ["-DUSE_MFEM={:s}".format('ON' if use_mfem else 'OFF')]

# Set Python_EXECUTABLE instead if you use PYBIND11_FINDPYTHON
# EXAMPLE_VERSION_INFO shows you how to pass a value into the C++ code
Expand Down

0 comments on commit fcdf138

Please sign in to comment.