make linking python optional
[mussa.git] / qui / mussagl.cpp
index 1b6dd95464f83a4ed851d23f95705e0dd79a904b..15b01b23a3799fb0a7b83d930cfbdf9cb7cad12f 100644 (file)
@@ -1,5 +1,7 @@
 #include <boost/filesystem/operations.hpp>
+#ifdef USE_PYTHON
 #include <boost/python.hpp>
+#endif
 
 using namespace boost::filesystem;
 
@@ -22,8 +24,6 @@ int main(int argc, char **argv)
 
   QApplication app(argc, argv, opts.useGUI);
   Q_INIT_RESOURCE(icons);
-  //PyImport_AppendInittab("mussa", initmussa);
-  Py_Initialize();
 
   initialize_mussa(opts, argc, argv);
 
@@ -32,7 +32,9 @@ int main(int argc, char **argv)
   }
 
   try {
+#ifdef USE_PYTHON
     if (opts.runAsPythonInterpeter) {
+      Py_Initialize();
       boost::python::object main_module((boost::python::handle<>(boost::python::borrowed(PyImport_AddModule("__main__")))));
       boost::python::object main_namespace = main_module.attr("__dict__");
 
@@ -52,7 +54,9 @@ int main(int argc, char **argv)
       int result = boost::python::extract<int>(square(3));
       std::cout << "C++ has " << result << std::endl;
       PyRun_InteractiveLoop(stdin, "mussa");
-    } else if (opts.useGUI) { 
+    } else 
+#endif /* USE_PYTHON */
+    if (opts.useGUI) { 
       MussaWindow win(opts.analysis);
       win.show();
       app.exec();
@@ -62,13 +66,16 @@ int main(int argc, char **argv)
     qFatal(e.what());
   } catch (boost::filesystem::filesystem_error e) {
     qFatal(e.what());
-  } catch (boost::python::error_already_set e) {
+  }
+#ifdef USE_PYTHON
+  catch (boost::python::error_already_set e) {
     PyErr_Print();
-  }  catch (std::runtime_error e) {
+  }
+#endif /* USE_PYTHON */
+  catch (std::runtime_error e) {
     qFatal(e.what());
   } catch (...) {
     qFatal("unrecognized exception");
   }
-  Py_Finalize();
   return 1; 
 }