From 89d9cc77fafa6f0b455367a050c2a69deea272fd Mon Sep 17 00:00:00 2001
From: Walter Van Herck <w.van.herck@fz-juelich.de>
Date: Thu, 6 Nov 2014 17:18:47 +0100
Subject: [PATCH] Inserted file to record python executable found during cmake
 process; this way, the executable can be used directly in the c++ code

---
 Core/Tools/src/PyGenTools.cpp               |  3 ++-
 cmake/modules/SearchInstalledSoftware.cmake |  4 +++-
 cmake/scripts/BAPython.h.in                 | 23 +++++++++++++++++++++
 3 files changed, 28 insertions(+), 2 deletions(-)
 create mode 100644 cmake/scripts/BAPython.h.in

diff --git a/Core/Tools/src/PyGenTools.cpp b/Core/Tools/src/PyGenTools.cpp
index 2a3c9aebbef..271402ce9cc 100644
--- a/Core/Tools/src/PyGenTools.cpp
+++ b/Core/Tools/src/PyGenTools.cpp
@@ -12,6 +12,7 @@
 #include "MultiLayer.h"
 #include "PyGenTools.h"
 #include "Simulation.h"
+#include "BAPython.h"
 
 std::string PyGenTools::genPyScript(Simulation *simulation)
 {
@@ -97,7 +98,7 @@ bool PyGenTools::testPyScript(Simulation *simulation)
 //                simulation->getIntensityData());
 //    boost::scoped_ptr<const OutputData<double> > simulated_data(
 //                    pSimulation->getIntensityData());
-    std::string command = "python PythonScript.py";
+    std::string command = std::string(BORNAGAIN_PYTHON_EXE ) + " PythonScript.py";
     int return_code = std::system(command.c_str());
     (void)return_code;
     if (std::remove("PythonScript.py") != 0) {
diff --git a/cmake/modules/SearchInstalledSoftware.cmake b/cmake/modules/SearchInstalledSoftware.cmake
index 6a3c6deaf70..44089e38343 100644
--- a/cmake/modules/SearchInstalledSoftware.cmake
+++ b/cmake/modules/SearchInstalledSoftware.cmake
@@ -17,7 +17,7 @@ find_package(FFTW REQUIRED)
 
 # --- BOOST ---
 set(Boost_USE_STATIC_LIBS OFF)
-set(Boost_USE_MULTITHREADED ON) 
+set(Boost_USE_MULTITHREADED ON)
 set(Boost_USE_STATIC_RUNTIME OFF)
 add_definitions(-DBOOST_ALL_DYN_LINK) # line is needed for MSVC
 #add_definitions(-DBOOST_LIB_DIAGNOSTIC) # shows during compilation auto-linked libraries
@@ -72,6 +72,8 @@ if(BORNAGAIN_PYTHON OR BORNAGAIN_GUI)
 
     ValidatePythonIntstallation()
 
+    configure_file("${CMAKE_SOURCE_DIR}/cmake/scripts/BAPython.h.in" "${CMAKE_BINARY_DIR}/BAPython.h" @ONLY)
+
     if(NOT PYTHONLIBS_FOUND)
         message(FATAL_ERROR "No Python library has been found")
     endif()
diff --git a/cmake/scripts/BAPython.h.in b/cmake/scripts/BAPython.h.in
new file mode 100644
index 00000000000..5649f9e4181
--- /dev/null
+++ b/cmake/scripts/BAPython.h.in
@@ -0,0 +1,23 @@
+// ************************************************************************** //
+//
+//  BornAgain: simulate and fit scattering at grazing incidence
+//
+//! @file      Tools/inc/BAPython.h
+//! @brief     Defines configuration variables
+//!
+//! @homepage  http://apps.jcns.fz-juelich.de/BornAgain
+//! @license   GNU General Public License v3 or higher (see COPYING)
+//! @copyright Forschungszentrum Jülich GmbH 2013
+//! @authors   Scientific Computing Group at MLZ Garching
+//! @authors   C. Durniak, G. Pospelov, W. Van Herck, J. Wuttke
+//
+// ************************************************************************** //
+
+#ifndef BAPYTHON_H
+#define BAPYTHON_H
+
+/* Configuration file will be automatically regenerated by CMake */
+
+#define BORNAGAIN_PYTHON_EXE "@PYTHON_EXECUTABLE@"
+
+#endif
-- 
GitLab