diff --git a/CMakeLists.txt b/CMakeLists.txt index ac95fdc..6218880 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 ============================= @@ -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} @@ -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 @@ -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) diff --git a/bindings/pylibROM/pylibROM.cpp b/bindings/pylibROM/pylibROM.cpp index 9d07bc9..b41f5c1 100644 --- a/bindings/pylibROM/pylibROM.cpp +++ b/bindings/pylibROM/pylibROM.cpp @@ -1,6 +1,14 @@ #include #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; @@ -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); @@ -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); diff --git a/bindings/pylibROM/pylibROM_config.h.in b/bindings/pylibROM/pylibROM_config.h.in new file mode 100644 index 0000000..cf1ad19 --- /dev/null +++ b/bindings/pylibROM/pylibROM_config.h.in @@ -0,0 +1,6 @@ +#ifndef PYLIBROM_CONFIG_H_ +#define PYLIBROM_CONFIG_H_ + +#cmakedefine PYLIBROM_HAS_MFEM + +#endif diff --git a/setup.py b/setup.py index d796d4c..e8d4b3c 100644 --- a/setup.py +++ b/setup.py @@ -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