Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exclude webkit at all #14

Open
gambr opened this issue Mar 24, 2016 · 30 comments
Open

exclude webkit at all #14

gambr opened this issue Mar 24, 2016 · 30 comments

Comments

@gambr
Copy link

gambr commented Mar 24, 2016

Hi All,
I found that there is a fix to exclude webkit with Qt5 static libraries. In my case I don't use Qt static libraries but I don't need webkit either. So, wouldn't be a better implementation to have a USE_WEBKIT variable so exclude webkit? So that building with USE_WEBKIT = false webkit is skipped even with non static Qt? The Qt5 static libraries case would set that variable properly also.

Moreover I'm not sure the actual PythonQt_QtAll.pro configuration file handles the webkit exclusion with static Qt5 correctly.

Regards,
Gianni

@gambr
Copy link
Author

gambr commented Mar 24, 2016

I modified locally

PythonQt_QtAll.pro

to handle QT_STATIC as env variable like follows:

QT_STATIC = $$(QT_STATIC)
QT += gui svg sql network xml xmlpatterns opengl
isEmpty(QT_STATIC) {
QT += webkit
}

It seems working. If you like to open a pull request then I can do it.

Regards,
Gianni

@Optiligence
Copy link
Contributor

At least the reason why i maintain my fork of this fork is the use of CMake instead of qmake and i think that @Orochimarufan also doesn’t maintain the qmake files.
So if you want to submit a pull request for an webkit opt-out option, please do so for the CMake files.

@gambr
Copy link
Author

gambr commented Mar 24, 2016

OK, but then remove all the stuff related to qmake then (at least *.pro/pri/prf and createSolution.bat). Anyway I used qmake because cmake gives a bunch of errors.

@Optiligence
Copy link
Contributor

I left it in, so it is easier to merge when upstream does changes to it.
If you have problems with the CMake setup, ask about it, that’s nearly the only thing i did for this project.

@gambr
Copy link
Author

gambr commented Apr 4, 2016

Hi Norbert,
I have to modify something to make qt webkit optional. So I would like to understand why you made a fork of pythonqt instead of collaborating to the pythonqt project and update that code instead. Moreover I would like to know if this fork is aligned with which version of pythonqt (3.0, trunk ...?).

Regards,
Gianni

@gambr
Copy link
Author

gambr commented Apr 4, 2016

Hi,
anyway this is the error I get:

PythonQt.cpp
D:\3rd_party\pythonqt\PythonQt-master\src\PythonQt.cpp(857) : error C2121: '#' : invalid character : possibly the result of a macro expansion
D:\3rd_party\pythonqt\PythonQt-master\src\PythonQt.cpp(857) : error C2065: 'endif' : undeclared identifier
D:\3rd_party\pythonqt\PythonQt-master\src\PythonQt.cpp(857) : error C2146: syntax error : missing ')' before identifier 'PyObject_GetAttrString'
D:\3rd_party\pythonqt\PythonQt-master\src\PythonQt.cpp(857) : error C2059: syntax error : ')'
D:\3rd_party\pythonqt\PythonQt-master\src\PythonQt.cpp(2201) : fatal error C1070: mismatched #if/#endif pair in file 'd:\3rd_party\pythonqt\pythonqt-master\src\pythonqt.cpp'
NMAKE : fatal error U1077: 'C:\PROGRA2\MICROS2.0\VC\bin\X86_AM~1\cl.exe' : return code '0x2'
Stop.

And here is the recipe I used:

%comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\vcvarsall.bat"" x86_amd64
set PATH=C:\Program Files (x86)\CMake\bin;%PATH%
cd D:\3rd_party\pythonqt\PythonQt-master\build.qt560_no_icu.win.debug
cmake -DCMAKE_BUILD_TYPE=Debug -DPYTHON_INCLUDE_DIR:PATH="L:\3rd_party\python\Python-2.7.8\win64\include" -DPYTHON_LIBRARY:PATH="L:\3rd_party\python\Python-2.7.8\win64\libs\python27_d.lib" -DDESIRED_QT_VERSION:STRING="5" -DCMAKE_PREFIX_PATH:PATH="D:\3rd_party\qt\qt-everywhere-enterprise-src-5.6.0_no_icu\install" -DQT_EXCLUDE_WEBKIT:BOOL=1 -G "NMake Makefiles" ..
nmake

@Optiligence
Copy link
Contributor

This error has nothing to do with CMake, it tries to use the #endif as macro argument.
First time trying to build PythonQt with vc for me, I used the following changes:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9b42831..63010f8 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,8 @@
 project(PythonQt)
 cmake_minimum_required(VERSION 2.8.10)

+#set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wa,-mbig-obj")
+set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /bigobj")
 set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})

 #-----------------------------------------------------------------------------
diff --git a/src/PythonQt.cpp b/src/PythonQt.cpp
index 794b230..477c177 100644
--- a/src/PythonQt.cpp
+++ b/src/PythonQt.cpp
@@ -850,11 +850,10 @@ QVariant PythonQt::evalCode(PyObject* object, PyObject* pycode) {
       dict = PyObject_GetAttrString(object, "__dict__");
       globals = PyObject_GetAttrString(PyImport_ImportModule(
 #ifdef PY3K
-                                         PyUnicode_AsUTF8(
+                                         PyUnicode_AsUTF8(PyObject_GetAttrString(object, "__module__"))),"__dict__");
 #else
-                                         PyString_AS_STRING(
+                                         PyString_AS_STRING(PyObject_GetAttrString(object, "__module__"))),"__dict__");
 #endif
-                                           PyObject_GetAttrString(object, "__module__"))),"__dict__");
     }
     PyObject* r = NULL;
     if (dict) {

@Optiligence
Copy link
Contributor

To disable Qt5WebKit you can comment line 8 and 9 in extensions/PythonQt_QtAll/CMakeLists.txt.
I’m not sure if it is that helpful to make the list of modules a non-internal cache variable.

The fork was created (as the description states) because it added Qt5 and Python3 support as well as an improved CMake build system, things upstream didn’t want to support back then.
Only the Qt5 support has been added officially since.
I just couldn’t get myself to start a conversation to pull the rest of the changes. (I want to build and run the PythonQt generator from CMake, something I haven’t taken to time to do so)

I irregularly merge upstream, so it doesn’t track any release, but also not trunk. (r403 at the moment, which is a few commits after v3.0)

@gambr
Copy link
Author

gambr commented Apr 5, 2016

"This error has nothing to do with CMake, it tries to use the #endif as macro argument. "
I'm not saying the problem in strictly related to CMake but I don't have that issue building with qmake (yes, qmake) the official PythonQt3.0.

@gambr
Copy link
Author

gambr commented Apr 5, 2016

"To disable Qt5WebKit you can comment line 8 and 9 in extensions/PythonQt_QtAll/CMakeLists.txt. "
I already changed that file in a different way. You can see a QT_EXCLUDE_WEBKIT:BOOL=1 in my cmake command line. That option excludes the webkit and here are my modifications:

extensions\PythonQt_QtAll\PythonQt_QtAll.cpp
use #ifndef QT_EXCLUDE_WEBKIT instead of #ifndef QT_STATIC

extensions\PythonQt_QtAll\CMakeLists.txt
if(NOT QT_STATIC)#WebKit is not available in static builds
set(QT_EXCLUDE_WEBKIT)
endif()
if(NOT QT_EXCLUDE_WEBKIT)
set(QT ${QT} WebKit)
set(WebKitWidgets WebKitWidgets)
endif()

QT_STATIC is not the same as "exclude webkit". QT_STATIC means use static Qt and use that define to exclude webkit seems a trick.

@gambr
Copy link
Author

gambr commented Apr 5, 2016

In the meanwhile I can say your modifications on "src/PythonQt.cpp" work fine, thanks.
But the lines you added to PythonQtImporter.cpp wrt the official 3.0 version does not work. Here is the error:

PythonQtImporter.cpp
D:\3rd_party\pythonqt\PythonQt-master\src\PythonQtImporter.cpp(356) : error C2065: 'PyExc_FileNotFoundError' : undeclared identifier

@gambr
Copy link
Author

gambr commented Apr 5, 2016

The python version I use is 2.7 so I surrounded PythonQtImporter_get_data implementation with "ifdef PY3K" and nmake built correctly the static libs.
Now I need shared libraries. And in debug mode I have the following error.

[ 93%] Linking CXX shared library Qt5Python27_d.dll
LINK : fatal error LNK1104: cannot open file 'python27.lib'

I set the "python27_d.lib" in PYTHON_LIBRARY for cmake but it seems the release version of python library is used.

@gambr
Copy link
Author

gambr commented Apr 5, 2016

While in release mode, trying to build shared libraries, with the same option and python27.lib in release mode I get a different error:

[ 93%] Linking CXX shared library Qt5Python27.dll
Creating library Qt5Python27.lib and object Qt5Python27.exp
PythonQt.cpp.obj : error LNK2019: unresolved external symbol "void __cdecl PythonQt_init_QtGuiBuiltin(struct _object *)" (?PythonQt_init_QtGuiBuiltin@@YAXPEAU_object@@@z) referenced in function "public: static void __cdecl PythonQt::init(int,class QByteArray const &)" (?init@PythonQt@@SAXHAEBVQByteArray@@@z)
PythonQt.cpp.obj : error LNK2019: unresolved external symbol "void __cdecl PythonQt_init_QtCoreBuiltin(struct _object *)" (?PythonQt_init_QtCoreBuiltin@@YAXPEAU_object@@@z) referenced in function "public: static void __cdecl PythonQt::init(int,class QByteArray const &)" (?init@PythonQt@@SAXHAEBVQByteArray@@@z)
Qt5Python27.dll : fatal error LNK1120: 2 unresolved externals

@gambr
Copy link
Author

gambr commented Apr 5, 2016

I realized a couple of errors related to release mode build.
First of all I use Qt 5.6.0, so I had to modify CMakeLists.txt to add the proper Qt version:
if("${generated_cpp_suffix}" STREQUAL "_55" OR "${generated_cpp_suffix}" STREQUAL "_56")

Then I'm not sure the "#ifndef QT_STATIC" precompiler statement works correctly in "extensions\PythonQt_QtAll\PythonQt_QtAll.cpp". AFAIK to pass that define from cmake to the source code an add_definitions() cmake command should be required in CMakeLists.txt

@Optiligence
Copy link
Contributor

Yes.

Qt5WebKit also has to be disabled in the code and if Qt5.6 is used, it needs to be told to also use the wrappers for Qt5.4.
see http://pastebin.com/KqY3i4SQ
This successfully builds all combinations (debug/release, static/shared), but no guarantee it will actually work.

I’m happy to get it tested, so i’m just curious: why use this fork, if the official PythonQt built with qmake and you don’t use Python3 or want CMake?
I still build without the latest commit to PythonQtImporter.cpp.
There is a python27_d.lib? I don’t have this.

@Optiligence
Copy link
Contributor

QT_STATIC is defined by Qt itself.
If the used modules are going to be modular (user configurable), CMake must add defines for each of them.

@gambr
Copy link
Author

gambr commented Apr 5, 2016

We want to add the pythonQt build in out build system and cmake is fine. I built with qmake just to make a test. We don't like to use qmake in out build system.

@gambr
Copy link
Author

gambr commented Apr 5, 2016

"QT_STATIC is defined by Qt itself."
Honestly I didn't get. I have Qt already built and I understand the CMakeList.txt uses QT_STATIC so I think it must be passed to cmake as option. But in this case if there isn't an add_definitions() to pass it to the source code then "#ifndef QT_STATIC" would be always add the containing piece of code.

@Orochimarufan
Copy link
Owner

I just pushed a fix for PythonQtImporter.get_data 3134043

@gambr
Copy link
Author

gambr commented Apr 5, 2016

"There is a python27_d.lib? I don’t have this."
Well, anybody can build a python library on their own. Anyway, if I pass "-DPYTHON_LIBRARY:PATH="L:\3rd_party\python\Python-2.7.8\win64\libs\python27_d.lib"" to cmake then I expect that lib is used to link. Does it make sense?

@Optiligence
Copy link
Contributor

Yeah, but it populates PYTHON_LIBRARIES and if it was found successfully before, it may contain the previous value of PYTHON_LIBRARY. It should work if you set it at your first CMake run.

@gambr
Copy link
Author

gambr commented Apr 5, 2016

If understood correctly I can say I build out of source and I clean the build dir before running cmake. When I run cmake I read as follows:

-- Found PythonLibs: L:/3rd_party/python/Python-2.7.8/win64/libs/python27_d.lib (found suitable version "2.7.8", minimum required is "2.6")
-- Building Qt5Python27 + Qt5Python27_QtAll (shared Qt 5.6.0 + Python 2.7.8 | Debug | Shared)
-- Configuring done
-- Generating done
-- Build files have been written to: D:/3rd_party/pythonqt/PythonQt-master/build.qt560_no_icu.win.debug

But then running nmake I get the error:

[ 31%] Linking CXX shared library Qt5Python27_d.dll
LINK : fatal error LNK1104: cannot open file 'python27.lib'

@Optiligence
Copy link
Contributor

try cleaning the CMakeCache (in the gui or remove the .txt file in the build dir) and build again
it just prints the content of PYTHON_LIBRARY and it has to get the python27.lib from somewhere

@gambr
Copy link
Author

gambr commented Apr 5, 2016

I removed completly the build dir where CMakeCache.txt and all other generated files are located (I perform an "out of source" build). I removed a path to a python installation from %PATH% env variable. I run cmake and then nmake but I always get the same error in debug mode. On the contrary the release mode works fine.

@Optiligence
Copy link
Contributor

Then print all the variables set by FindPythonLibs.cmake in your CMake installation to find out what happens.

@gambr
Copy link
Author

gambr commented Apr 6, 2016

I added both "-DPYTHON_DEBUG_LIBRARY" and "-DPYTHON_LIBRARY" to cmake command line and here is the list of variables. The build problem in debug mode is not solved.

-- PYTHONLIBS_FOUND=TRUE
-- PYTHONLIBS_VERSION_STRING=2.7.8
-- PYTHON_DEBUG_LIBRARIES=L:/3rd_party/python/Python-2.7.8/win64/libs/python27_d.lib
-- PYTHON_DEBUG_LIBRARY=L:/3rd_party/python/Python-2.7.8/win64/libs/python27_d.lib
-- PYTHON_INCLUDE_DIR=L:/3rd_party/python/Python-2.7.8/win64/include
-- PYTHON_INCLUDE_DIRS=L:/3rd_party/python/Python-2.7.8/win64/include
-- PYTHON_INCLUDE_PATH=L:/3rd_party/python/Python-2.7.8/win64/include
-- PYTHON_LIBRARIES=optimized;L:/3rd_party/python/Python-2.7.8/win64/libs/python27.lib;debug;L:/3rd_party/python/Python-2.7.8/win64/libs/python27_d.lib
-- PYTHON_LIBRARY=optimized;L:/3rd_party/python/Python-2.7.8/win64/libs/python27.lib;debug;L:/3rd_party/python/Python-2.7.8/win64/libs/python27_d.lib
-- PYTHON_LIBRARY=optimized;L:/3rd_party/python/Python-2.7.8/win64/libs/python27.lib;debug;L:/3rd_party/python/Python-2.7.8/win64/libs/python27_d.lib
-- PYTHON_LIBRARY_DEBUG=L:/3rd_party/python/Python-2.7.8/win64/libs/python27_d.lib
-- PYTHON_LIBRARY_DEBUG=L:/3rd_party/python/Python-2.7.8/win64/libs/python27_d.lib
-- PYTHON_LIBRARY_RELEASE=L:/3rd_party/python/Python-2.7.8/win64/libs/python27.lib
-- PYTHON_LIBRARY_RELEASE=L:/3rd_party/python/Python-2.7.8/win64/libs/python27.lib
-- PythonLibs_FOUND=TRUE
-- PythonQtAll=ON
-- PythonQt_BINARY_DIR=D:/3rd_party/pythonqt/PythonQt-master/build.qt560_no_icu.win.debug
-- PythonQt_DEBUG=OFF
-- PythonQt_Python=OFF
-- PythonQt_Python3=OFF
-- PythonQt_Python3=OFF
-- PythonQt_Qt5=ON
-- PythonQt_SOURCE_DIR=D:/3rd_party/pythonqt/PythonQt-master
-- PythonQt_VERSION=2.3.0

@gambr
Copy link
Author

gambr commented Apr 6, 2016

I also tried to add "-DPythonQt_DEBUG=ON" to cmake command line and I get the build error:

PythonQtClassInfo.cpp
D:\3rd_party\pythonqt\PythonQt-master\src\PythonQtClassInfo.cpp(287) : error C2227: left of '->constData' must point to class/struct/union/generic type
type is 'const char *'

I think that "meta->className()" is enough in this case since it already returns a "const char*"

@gambr
Copy link
Author

gambr commented Apr 6, 2016

There is also a syntax error:

PythonQtMethodInfo.cpp
D:\3rd_party\pythonqt\PythonQt-master\src\PythonQtMethodInfo.cpp(53) : error C2059: syntax error : ')'

It seems nobody have ever built with this option then ...

@Optiligence
Copy link
Contributor

python uses auto linking with vc, so the CMake settings sadly don’t matter: from pyconfig.h

#           ifdef _DEBUG
#               pragma comment(lib,"python27_d.lib")
#           else
#               pragma comment(lib,"python27.lib")
#           endif /* _DEBUG */

and PythonQt abuses it (maybe rightly so, because the debug lib doesn’t exist in the official distribution): from PythonQtPythonInclude.h

// If PYTHONQT_USE_RELEASE_PYTHON_FALLBACK is enabled, try to link
// release Python DLL if it is available by undefining _DEBUG while
// including Python.h

So remove the definition of PYTHONQT_USE_RELEASE_PYTHON_FALLBACK from the top level CMake file and it will link to python27_d.lib in debug mode

It seems nobody have ever built with this option then ...

Ever is a bit of a stretch, if it’s rarely used, errors will sneak in, thx for testing.

@gambr
Copy link
Author

gambr commented Apr 8, 2016

Thanks for the help! Now I can generate both debug and release libraries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants