@@ -6,8 +6,7 @@ isEmpty( PYTHON_VERSION ) {
66 PYTHON_VERSION=$$(PYTHON_VERSION)
77}
88isEmpty( PYTHON_VERSION ) {
9- win32:PYTHON_VERSION=27
10- unix:PYTHON_VERSION=2.7
9+ PYTHON_VERSION=2.7
1110}
1211
1312isEmpty( PYTHON_DIR ) {
@@ -30,8 +29,18 @@ PYTHON_VERSION_MINOR=$$section(PYTHON_VERSION, ., 1, 1)
3029# Python 2.x has problems:
3130# 1) https://wiki.gentoo.org/wiki/Project:Python/Strict_aliasing
3231# 2) deprecated implicit cast of string literals to char*
33- equals(PYTHON_VERSION_MAJOR, 2):gcc:QMAKE_CXXFLAGS *= -fno-strict-aliasing -Wno-error=write-strings
32+ equals(PYTHON_VERSION_MAJOR, 2) {
33+ gcc:QMAKE_CXXFLAGS *= -fno-strict-aliasing -Wno-write-strings
34+ # Qt 5.4 adds this option, but this is not compatible with the Python API
35+ msvc: QMAKE_CXXFLAGS -= -Zc:strictStrings
36+ }
37+
3438contains(PKGCONFIG, "python.*"){
39+ # If `pkg-config` is configured, use `qmake PKGCONFIG+=python3.8-embed CONFIG+=...`
40+ # or `PKGCONFIG+=python2.7m`-like form for older versions,
41+ # see `pkg-config --list-all | grep python` for details.
42+ # This can help with GNU/Linux (including macOS with Homebrew), MSYS2/MinGW environment,
43+ # and also with OpenEmbedded and other cross-builds
3544 CONFIG += link_pkgconfig
3645 PYTHON_PKGCONFIG = $$member($$unique($$find(PKGCONFIG, "python.*")), 1, 1)
3746 # add rpath
@@ -63,8 +72,26 @@ contains(PKGCONFIG, "python.*"){
6372 DEBUG_EXT =
6473 }
6574
66- win32:INCLUDEPATH += $$(PYTHON_PATH)/PC $$(PYTHON_PATH)/include
67- win32:LIBS += $$(PYTHON_LIB)/python$${PYTHON_VERSION}$${DEBUG_EXT}.lib
75+ isEmpty(PYTHON_PATH):PYTHON_PATH=$(PYTHON_PATH)
76+ isEmpty(PYTHON_PATH)|!exists("$$PYTHON_PATH\\include") | !exists("$$PYTHON_PATH\\libs\\") {
77+ error("PYTHON_PATH must be set to correct folder with \\libs and \\include subfolders ")
78+ }
79+
80+ #We need to destinguish 64-bit build to add a workaround option
81+ #The only known problematic case is MinGW with external (MSVC-built) Python2
82+ mingw:equals(PYTHON_VERSION_MAJOR, 2): isEmpty(QMAKE_TARGET.arch):system(\
83+ $$system_quote($$system_path($${PYTHON_PATH}/python.exe)) -c \
84+ $$system_quote(import sysconfig;exit(0 if 0 <= sysconfig.get_platform().find(\'win-amd64\') else 1))\
85+ ):DEFINES += MS_WIN64
86+
87+ INCLUDEPATH += $$shell_path($${PYTHON_PATH}/include)
88+
89+ LIBS += $$shell_path(-L$${PYTHON_PATH}/libs)
90+ LIBS += -lpython$${PYTHON_VERSION_MAJOR}$${PYTHON_VERSION_MINOR}$${DEBUG_EXT}
91+
92+ # Hack for "CONFIG+=testcase" and 'make check' to add python's dll to PATH
93+ deppath += $$shell_path($${PYTHON_PATH})
94+
6895} else:unix {
6996 # on linux, python-config is used to autodetect Python.
7097 # make sure that you have installed a matching python-dev package.
0 commit comments