Skip to content
Snippets Groups Projects
Commit ca86963e authored by Christoph Lehmann's avatar Christoph Lehmann
Browse files

[App] renamed OGS embedded Python module source files

parent 6b1a3216
No related branches found
No related tags found
No related merge requests found
...@@ -7,7 +7,7 @@ target_link_libraries(ogs ...@@ -7,7 +7,7 @@ target_link_libraries(ogs
if(OGS_USE_PYTHON) if(OGS_USE_PYTHON)
# Troubleshooting: # Troubleshooting:
# If you get linker errors, such as ogs.cpp:(.text+0xb4): Warnung: undefinierter Verweis auf »_Py_ZeroStruct« # If you get linker errors, such as ogs.cpp:(.text+0xb4): undefined reference to `_Py_ZeroStruct'
# it could be that OGS is compiled with the wrong Python version. # it could be that OGS is compiled with the wrong Python version.
# I (Ch. Leh.) observed the following: The symbol _Py_ZeroStruct could not be found in /usr/lib/libpython3.6m.so (I intended to compile OGS with Python3). # I (Ch. Leh.) observed the following: The symbol _Py_ZeroStruct could not be found in /usr/lib/libpython3.6m.so (I intended to compile OGS with Python3).
# It's apparently a Python2 symbol (present in /usr/lib/libpython2.7.so) # It's apparently a Python2 symbol (present in /usr/lib/libpython2.7.so)
...@@ -22,7 +22,11 @@ if(OGS_USE_PYTHON) ...@@ -22,7 +22,11 @@ if(OGS_USE_PYTHON)
# I assume (this is only a guess!) that VTK pulls in Python2 dependencies (on my system). # I assume (this is only a guess!) that VTK pulls in Python2 dependencies (on my system).
# I assume that this is related to https://github.com/ufz/ogs/pull/2158. # I assume that this is related to https://github.com/ufz/ogs/pull/2158.
# Workaround: Always make sure that OGS is compiled with the same Python version as VTK. # Workaround: Always make sure that OGS is compiled with the same Python version as VTK.
# TODO: Find out how to properly address the issue. # The error described above should be detected automatically by cmake and an
# appropriate message should be presented. The note is kept for the case
# that the automatic detection does not work due to whatever reason.
add_library(ogs_embedded_python STATIC ogs_embedded_python.cpp)
# Performance warning from # Performance warning from
# https://github.com/pybind/pybind11/blob/master/docs/compiling.rst: # https://github.com/pybind/pybind11/blob/master/docs/compiling.rst:
...@@ -32,16 +36,17 @@ if(OGS_USE_PYTHON) ...@@ -32,16 +36,17 @@ if(OGS_USE_PYTHON)
# minimal set of parameters to ensure that the code using pybind11 compiles, but # minimal set of parameters to ensure that the code using pybind11 compiles, but
# it does not pass these extra compiler flags (i.e. this is up to you). # it does not pass these extra compiler flags (i.e. this is up to you).
# TODO: Enable further compiler/linker flags. # TODO: Enable further compiler/linker flags.
target_link_libraries(ogs PRIVATE pybind11::embed) target_link_libraries(ogs_embedded_python PUBLIC pybind11::embed)
target_compile_definitions(ogs_embedded_python PUBLIC OGS_USE_PYTHON)
add_library(ogs_python_bindings STATIC ogs_python_bindings.cpp) target_link_libraries(ogs_embedded_python PRIVATE
target_link_libraries(ogs_python_bindings PRIVATE pybind11::embed) ProcessLibBoundaryConditionPythonModule)
target_include_directories(ogs_python_bindings PRIVATE ${PYTHON_INCLUDE_DIRS})
target_link_libraries(ogs PRIVATE ogs_python_bindings) target_link_libraries(ogs PRIVATE ogs_embedded_python)
if(BUILD_SHARED_LIBS) if(BUILD_SHARED_LIBS)
target_compile_definitions(ogs_python_bindings OGS_BUILD_SHARED_LIBS) # Add macro definition, because static libs make special handling necessary
# s.t. the embedded OpenGeoSys Python module won't be removed by the linker.
target_compile_definitions(ogs_embedded_python OGS_BUILD_SHARED_LIBS)
endif() endif()
endif() endif()
......
...@@ -42,7 +42,9 @@ ...@@ -42,7 +42,9 @@
#include "NumLib/NumericsConfig.h" #include "NumLib/NumericsConfig.h"
#include "ogs_python_bindings.h" #ifdef OGS_USE_PYTHON
#include "ogs_embedded_python.h"
#endif
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
......
#ifdef OGS_USE_PYTHON /**
* \copyright
* Copyright (c) 2012-2018, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#include <pybind11/embed.h> #include <pybind11/embed.h>
#include <logog/include/logog.hpp>
#include "ogs_python_bindings.h" #include "ogs_embedded_python.h"
#include "ProcessLib/BoundaryCondition/Python/PythonBoundaryConditionModule.h"
PYBIND11_EMBEDDED_MODULE(OpenGeoSys, m)
{
DBUG("Binding Python module OpenGeoSys.");
ProcessLib::pythonBindBoundaryCondition(m);
}
#ifndef OGS_BUILD_SHARED_LIBS #ifndef OGS_BUILD_SHARED_LIBS
extern "C" PyObject* pybind11_init_impl_OpenGeoSys();
// Hackish trick that hopefully ensures that the linker won't strip the symbol // Hackish trick that hopefully ensures that the linker won't strip the symbol
// pointed to by p from the library being built. // pointed to by p from the library being built.
...@@ -34,5 +50,3 @@ pybind11::scoped_interpreter setupEmbeddedPython() ...@@ -34,5 +50,3 @@ pybind11::scoped_interpreter setupEmbeddedPython()
} }
} // namespace ApplicationsLib } // namespace ApplicationsLib
#endif // OGS_USE_PYTHON
#pragma once /**
* \copyright
* Copyright (c) 2012-2018, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#ifdef OGS_USE_PYTHON #pragma once
#include <pybind11/embed.h> #include <pybind11/embed.h>
...@@ -11,5 +18,3 @@ namespace ApplicationsLib ...@@ -11,5 +18,3 @@ namespace ApplicationsLib
pybind11::scoped_interpreter setupEmbeddedPython(); pybind11::scoped_interpreter setupEmbeddedPython();
} // namespace ApplicationsLib } // namespace ApplicationsLib
#endif // OGS_USE_PYTHON
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment