From 9039d4544bab3581d47bb646c153e0e535f0c5eb Mon Sep 17 00:00:00 2001
From: Gennady Pospelov <g.pospelov@fz-juelich.de>
Date: Tue, 27 Aug 2013 17:22:57 +0200
Subject: [PATCH] PythonAPI and corresponding functional tests are fully
 working from Windows

---
 BornAgain.pro |  2 +-
 Core/Core.pro |  9 +++++++++
 Fit/Fit.pro   | 11 ++++++++++-
 shared.pri    | 41 ++++++++++++++++++++++++++++-------------
 4 files changed, 48 insertions(+), 15 deletions(-)

diff --git a/BornAgain.pro b/BornAgain.pro
index c5394641d1e..e8273592b4a 100644
--- a/BornAgain.pro
+++ b/BornAgain.pro
@@ -5,7 +5,7 @@ include($$PWD/shared.pri)
 SUBDIRS += Core
 SUBDIRS += ThirdParty/gtest
 SUBDIRS += Tests/UnitTests/TestCore
-#TestCore.depends = ThirdParty/gtest
+TestCore.depends = ThirdParty/gtest
 
 SUBDIRS += Tests/FunctionalTests/TestCore
 
diff --git a/Core/Core.pro b/Core/Core.pro
index 3b87a851f43..706cbe1910a 100644
--- a/Core/Core.pro
+++ b/Core/Core.pro
@@ -349,5 +349,14 @@ target.path = $$PWD/../lib
 INSTALLS += target
 QMAKE_DISTCLEAN += $$target.path/$(TARGET)
 isEmpty(MAKEFILE): MAKEFILE="Makefile"
+
+# for python import in Windows we need another extention and preffix
+win32{
+    extra_install.path = $$PWD\..\lib
+    extra_install.extra = $(COPY) /y \"release\BornAgainCore.dll\" \"release\libBornAgainCore.pyd\"
+    extra_install.files = $$PWD\release\libBornAgainCore.pyd
+    INSTALLS += extra_install
+}
+
 QMAKE_POST_LINK = $$MAKE_COMMAND -f $${MAKEFILE} install
 
diff --git a/Fit/Fit.pro b/Fit/Fit.pro
index 8036262a78b..36f5a2faa25 100644
--- a/Fit/Fit.pro
+++ b/Fit/Fit.pro
@@ -96,5 +96,14 @@ target.path = $$PWD/../lib
 INSTALLS += target
 QMAKE_DISTCLEAN += $$target.path/$(TARGET)
 isEmpty(MAKEFILE): MAKEFILE="Makefile"
-QMAKE_POST_LINK = $$MAKE_COMMAND -f $${MAKEFILE} install
+
+# for python import in Windows we need another extention and preffix
+win32{
+    extra_install.path = $$PWD\..\lib
+    extra_install.extra = $(COPY) /y \"release\BornAgainFit.dll\" \"release\libBornAgainFit.pyd\"
+    extra_install.files = $$PWD\release\libBornAgainFit.pyd
+    INSTALLS += extra_install
+}
+
+QMAKE_POST_LINK+= $$MAKE_COMMAND -f $${MAKEFILE} install
 
diff --git a/shared.pri b/shared.pri
index 0ea0548bd00..76d46c07f1d 100644
--- a/shared.pri
+++ b/shared.pri
@@ -2,7 +2,7 @@
 # Common settings for all BornAgain compilations
 # -----------------------------------------------------------------------------
 
-#CONFIG  += BORNAGAIN_PYTHON # provide python bindings compilation
+CONFIG  += BORNAGAIN_PYTHON # provide python bindings compilation
 
 win32 {
     MAKE_COMMAND = mingw32-make
@@ -279,26 +279,42 @@ CONFIG(BORNAGAIN_PYTHON) {
     WhichPython=$$system(which python)
   }
   win32 {
-    WhichPython="C:/Python27"
+    WhichPython="C:/Python27/python.exe"
   }
   isEmpty(WhichPython) {
     # we do not have python
     error("Can not find any sign of python")
   } else {
+    #pythonsysincdir=$$system("$${WhichPython} -c \"import sys; sys.stdout.write(sys.prefix + \'/include/python\' + sys.version[:3])\" ")
+    #pythonsyslibdir=$$system("$${WhichPython} -c \"import sys; sys.stdout.write(sys.prefix + \'/libs\' )\" ")
+    pythonvers=$$system("$${WhichPython} -c \"import sys; sys.stdout.write(sys.version[:3])\" ")
+    pythonnumpy=$$system("$${WhichPython} -c \"import sys; import numpy; sys.stdout.write(numpy.get_include())\" ")
     # we have python
-    pythonvers=$$system("python -c \"import sys; sys.stdout.write(sys.version[:3])\" ")
     macx|unix {
-      pythonsysincdir=$$system("python -c 'import sys; sys.stdout.write(sys.prefix + \"/include/python\" + sys.version[:3])'")
-      pythonsyslibdir=$$system("python -c 'import sys; sys.stdout.write(sys.prefix + \"/lib\" )'")
+      pythonsysincdir=$$system("$${WhichPython} -c \"import sys; sys.stdout.write(sys.prefix + \'/include/python\' + sys.version[:3])\" ")
+      pythonsyslibdir=$$system("$${WhichPython} -c \"import sys; sys.stdout.write(sys.prefix + \'/lib\' )\" ")
+#      pythonvers=$$system("python -c \"import sys; sys.stdout.write(sys.version[:3])\" ")
+#      pythonsysincdir=$$system("python -c 'import sys; sys.stdout.write(sys.prefix + \"/include/python\" + sys.version[:3])'")
+#      pythonsyslibdir=$$system("python -c 'import sys; sys.stdout.write(sys.prefix + \"/lib\" )'")
+#      pythonnumpy=$$system("python -c \"import sys; import numpy; sys.stdout.write(numpy.get_include())\" ")
     }
     win32 {
-      pythonsysincdir=$${WhichPython}/include
-      pythonsyslibdir=$${WhichPython}/libs
+      pythonsysincdir=$$system("$${WhichPython} -c \"import sys; sys.stdout.write(sys.prefix + \'/include')\" ")
+      pythonsyslibdir=$$system("$${WhichPython} -c \"import sys; sys.stdout.write(sys.prefix + \'/libs\' )\" ")
+#      pythonsysincdir=$${WhichPython}/include
+#      pythonsyslibdir=$${WhichPython}/libs
+#      pythonvers=$$system("$${WhichPython}/python.exe -c \"import sys; sys.stdout.write(sys.version[:3])\" ")
+#      pythonnumpy=$$system("$${WhichPython}/python.exe -c \"import sys; import numpy; sys.stdout.write(numpy.get_include())\" ")
     }
-    message(we have python)
-    message($$pythonvers)
-    message($$pythonsysincdir)
-    message($$pythonsyslibdir)
+#    pythonsysincdir=$$system("$${WhichPython} -c \"import sys; sys.stdout.write(sys.prefix + \'/include/python\' + sys.version[:3])\" ")
+#    pythonsyslibdir=$$system("$${WhichPython} -c \"import sys; sys.stdout.write(sys.prefix + \'/libs\' )\" ")
+#    pythonvers=$$system("$${WhichPython} -c \"import sys; sys.stdout.write(sys.version[:3])\" ")
+#    pythonnumpy=$$system("$${WhichPython} -c \"import sys; import numpy; sys.stdout.write(numpy.get_include())\" ")
+
+    message(pythonvers : $$pythonvers)
+    message(pythoninc  : $$pythonsysincdir)
+    message(pythonlib  : $$pythonsyslibdir)
+    message(pythonnumpy: $$pythonnumpy)
     lessThan(pythonvers, 2.6): error("BornAgain requires python 2.6 or greater")
     INCLUDEPATH += $$pythonsysincdir
     #LIBS += -L$$pythonsyslibdir -lpython$$pythonvers -lboost_python
@@ -308,10 +324,9 @@ CONFIG(BORNAGAIN_PYTHON) {
     win32 {
       PYTHON_LIB_DIRECTIVE="-lpython27"
     }
-    LIBS += -lboost_python -L$$pythonsyslibdir $$PYTHON_LIB_DIRECTIVE
+    LIBS += -lboost_python$${BOOST_LIB_SUFFIX} -L$$pythonsyslibdir $$PYTHON_LIB_DIRECTIVE
 
     # we need to know the location of numpy
-    pythonnumpy=$$system("python -c \"import sys; import numpy; sys.stdout.write(numpy.get_include())\" ")
     !exists($$pythonnumpy/numpy/arrayobject.h): error("Can't find numpy/arrayobject.h in $$pythonnumpy, you have to install python-numpy-devel")
     INCLUDEPATH += $$pythonnumpy
   }
-- 
GitLab