aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2018-05-07 17:45:51 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2018-05-08 08:28:00 +0000
commit65afd324370d2a9788d52ef5213dc88f5e3912a0 (patch)
tree47c252cbd1ea07b82f693d9e9b6db8d5036e88f9 /examples
parent928a5249dad9543a669ab07a0108aca26c0642cb (diff)
Fix a few scriptableapplication bugs
1) Remove LIBPATH because that causes linker warnings on macOS, and its usage is deprecated on Windows. 2) Remove all qmake clang related code, as well as clang code from pyside2_config.py. It used to be needed on Windows because we didn't deploy libclang.dll to the PySide2 dir. Now that we do, the code is unnecessary. 3) Remove README.txt reference. 4) Add clarifying comments in README.md. 5) Remove NO_DEFAULT_PATH from find_library because that causes a failure to find the python library on Ubuntu (makes sense because the specified libdir is /usr/lib, but the actual library is under /usr/lib/[arch], and disabling the option forces CMake not to look under the arch dir. 6) Fix rpath to PySide2 dir not being embedded on Linux (presumably because the link flags style changed to absolute paths, not sure). 7) Fix README to be more precise about how MSBuild needs to be invoked, and how to run the executable. 8) Improve the error handling in the project files. 9) Refactor pyside2_config.py usage. Change-Id: I402d5c42ef7e01e94d3827682564e95ee280b40b Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'examples')
-rw-r--r--examples/scriptableapplication/CMakeLists.txt15
-rw-r--r--examples/scriptableapplication/README.md55
-rw-r--r--examples/scriptableapplication/pyside2.pri17
-rw-r--r--examples/scriptableapplication/pyside2_config.py68
-rw-r--r--examples/scriptableapplication/scriptableapplication.pro10
5 files changed, 76 insertions, 89 deletions
diff --git a/examples/scriptableapplication/CMakeLists.txt b/examples/scriptableapplication/CMakeLists.txt
index be5b17398..7e57a291b 100644
--- a/examples/scriptableapplication/CMakeLists.txt
+++ b/examples/scriptableapplication/CMakeLists.txt
@@ -28,7 +28,7 @@ macro(pyside2_config option output_var)
OUTPUT_STRIP_TRAILING_WHITESPACE)
if ("${${output_var}}" STREQUAL "")
- message(FATAL_ERROR "Got empty string when running: pyside2_config.py ${option}")
+ message(FATAL_ERROR "Error: Calling pyside2_config.py ${option} returned no output.")
endif()
if(is_list)
string (REPLACE " " ";" ${output_var} "${${output_var}}")
@@ -43,14 +43,11 @@ if(NOT EXISTS ${SHIBOKEN_PATH})
message(FATAL_ERROR "Shiboken executable not found at path: ${SHIBOKEN_PATH}")
endif()
+pyside2_config(--pyside2 PYSIDE2_DIR)
pyside2_config(--python-include PYTHON_INCLUDE_DIR)
pyside2_config(--pyside2-include PYSIDE2_INCLUDE_DIR 1)
-pyside2_config(--pyside2-shared-libraries-cmake PYSIDE2_SHARED_LIBRARIES 1)
-if(WIN32)
+pyside2_config(--pyside2-shared-libraries-cmake PYSIDE2_SHARED_LIBRARIES 0)
pyside2_config(--python-link-cmake PYTHON_LINKING_DATA 0)
-else()
-pyside2_config(--python-link-cmake PYTHON_LINKING_DATA 1)
-endif()
# Get all relevant Qt include dirs, to pass them on to shiboken.
get_property(QT_CORE_INCLUDE_DIRS TARGET Qt5::Core PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
@@ -124,8 +121,8 @@ endforeach()
# =============================================================================================
# Enable rpaths so that the example can be executed from the build dir.
set(CMAKE_SKIP_BUILD_RPATH FALSE)
-set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
-SET(CMAKE_INSTALL_RPATH "")
+set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
+set(CMAKE_INSTALL_RPATH ${PYSIDE2_DIR})
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# =============================================================================================
# !!! End of dubious section.
@@ -152,7 +149,7 @@ target_link_libraries(${PROJECT_NAME} PRIVATE ${PYSIDE2_SHARED_LIBRARIES})
# Find and link to the python library.
list(GET PYTHON_LINKING_DATA 0 PYTHON_LIBDIR)
list(GET PYTHON_LINKING_DATA 1 PYTHON_LIB)
-find_library(PYTHON_LINK_FLAGS ${PYTHON_LIB} PATHS ${PYTHON_LIBDIR} HINTS ${PYTHON_LIBDIR} NO_DEFAULT_PATH)
+find_library(PYTHON_LINK_FLAGS ${PYTHON_LIB} PATHS ${PYTHON_LIBDIR} HINTS ${PYTHON_LIBDIR})
target_link_libraries(${PROJECT_NAME} PRIVATE ${PYTHON_LINK_FLAGS})
# Same as CONFIG += no_keywords to avoid syntax errors in object.h due to the usage of the word Slot
diff --git a/examples/scriptableapplication/README.md b/examples/scriptableapplication/README.md
index 98e12b7b4..d359581f1 100644
--- a/examples/scriptableapplication/README.md
+++ b/examples/scriptableapplication/README.md
@@ -10,7 +10,7 @@ The header `wrappedclasses.h` is passed to Shiboken which generates
class wrappers and headers in a sub directory called **AppLib/**
which are linked to the application.
-The files `pythonutils.{cpp,h}` contains some code which binds the
+The files `pythonutils.{cpp,h}` contain some code which binds the
instance of **MainWindow** to a variable called **'mainWindow'** in
the global Python namespace (`__main___`).
It is then possible to run Python script snippets like:
@@ -29,24 +29,29 @@ consideration:
* Make sure that a --standalone PySide2 package (bundled with Qt libraries)
is installed into the current active Python environment
(system or virtualenv)
-* qmake to be in your PATH:
+* qmake has to be in your PATH:
* so that CMake find_package(Qt5) works (used for include headers),
- * and also for using the proper qmake version when building with qmake
+ * used for building the application with qmake instead of CMake
* use the same Qt version for building the example application, as was used
for building PySide2, this is to ensure binary compatibility between the
newly generated bindings libraries, the PySide2 libraries and the
Qt libraries.
For Windows you will also need:
-* Visual studio environment to be active in your terminal
+* a Visual Studio environment to be active in your terminal
* Correct visual studio architecture chosen (32 vs 64 bit)
-* Make sure that your Qt + Python + PySide + app build configuration
- is the same (either or all Release, which is more likely, or all Debug).
+* Make sure that your Qt + Python + PySide2 package + app build configuration
+ is the same (all Release, which is more likely, or all Debug).
+* Make sure that your Qt + Python + PySide2 package + app are built with the
+ same version of MSVC, to avoid mixing of C++ runtime libraries.
+ In principle this means that if you use the python.org provided Python
+ interpreters, you need to use MSVC2015 for Python 3 projects, and MSVC2008
+ for Python 2 projects. Which also means that you can't use official Qt
+ packages, because none of the supported ones are built with MSVC2008.
-Both build options will use the `pyside2.pri` file to configure the project
-using the current PySide2/Shiboken2 installation (via `pyside2_config.py`).
-
-Keep in mind that Clang libraries must be on your path.
+Both build options will use the `pyside2_config.py` file to configure the project
+using the current PySide2/Shiboken2 installation (for qmake via pyside2.pri,
+and for CMake via the project CMakeLists.txt).
### Using CMake
@@ -54,7 +59,7 @@ Keep in mind that Clang libraries must be on your path.
To build this example with CMake you will need a recent version of CMake (3.1+).
You can build this example by executing the following commands
-(slightly adapted to your file system) in a terminal:
+(slightly adapted to your file system layout) in a terminal:
On macOS/Linux:
```bash
@@ -71,7 +76,9 @@ On Windows:
cd C:\pyside-setup\examples\scriptableapplication
mkdir build
cd build
-cmake -H.. -B. -G "NMake Makefiles JOM" -DCMAKE_BUILD_TYPE=Release
+cmake -H.. -B. -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release
+# or if you have jom available
+# cmake -H.. -B. -G "NMake Makefiles JOM" -DCMAKE_BUILD_TYPE=Release
nmake # or jom
scriptableapplication.exe
```
@@ -86,7 +93,7 @@ You can build this example by executing:
mkdir build
cd build
qmake ..
-make # or nmake for Windows
+make # or nmake / jom for Windows
```
#### Windows troubleshooting
@@ -109,12 +116,19 @@ cmake -H.. -B. -G "Visual Studio 14 Win64" -DCMAKE_BUILD_TYPE=Release
If the `-G "Visual Studio 14 Win64"` option is used, a `sln` file
will be generated, and can be used with `MSBuild`
-instead of `nmake/jom`
+instead of `nmake/jom`.
```bash
-MSBuild scriptableapplication.sln "/p:DebugType=None"
+MSBuild scriptableapplication.sln "/p:Configuration=Release"
```
+Note that using the "NMake Makefiles JOM" generator is preferred to
+the MSBuild one, because in the latter case the executable is placed
+into a directory other than the one that contains the dependency
+dlls (shiboken, pyside). This leads to execution problems if the
+application is started within the Release subdirectory and not the
+one containing the dependencies.
+
## Virtualenv Support
If the application is started from a terminal with an activated python
@@ -122,14 +136,15 @@ virtual environment, that environment's packages will be used for the
python module import process.
In this case, make sure that the application was built while the
`virtualenv` was active, so that the build system picks up the correct
-python shared library.
+python shared library and PySide2 package.
-## Shared Libraries Notes
+## Linux Shared Libraries Notes
-For this example's purpose, we are using the absolute path of the
+For this example's purpose, we link against the absolute paths of the
shared libraries (`libshiboken` and `libpyside`) because the
-installation of the modules is being made via wheels, and there is
-no clean solution to include symbolic links into the package.
+installation of the modules is being done via wheels, and there is
+no clean solution to include symbolic links in the package
+(so that regular -lshiboken works).
## Windows Notes
diff --git a/examples/scriptableapplication/pyside2.pri b/examples/scriptableapplication/pyside2.pri
index acab9e961..59f7fd983 100644
--- a/examples/scriptableapplication/pyside2.pri
+++ b/examples/scriptableapplication/pyside2.pri
@@ -1,20 +1,25 @@
+PYSIDE2 = $$system(python $$PWD/pyside2_config.py --pyside2)
+isEmpty(PYSIDE2): error(Unable to locate the PySide2 package location)
+
PYTHON_INCLUDE = $$system(python $$PWD/pyside2_config.py --python-include)
-isEmpty(PYTHON_INCLUDE): error(Unable to locate Python)
+isEmpty(PYTHON_INCLUDE): error(Unable to locate the Python include headers directory)
+
PYTHON_LFLAGS = $$system(python $$PWD/pyside2_config.py --python-link)
+isEmpty(PYTHON_LFLAGS): error(Unable to locate the Python library for linking)
-PYSIDE2 = $$system(python $$PWD/pyside2_config.py --pyside2)
-isEmpty(PYSIDE2): error(Unable to locate PySide2)
PYSIDE2_INCLUDE = $$system(python $$PWD/pyside2_config.py --pyside2-include)
+isEmpty(PYSIDE2_INCLUDE): error(Unable to locate the PySide2 include headers directory)
+
PYSIDE2_LFLAGS = $$system(python $$PWD/pyside2_config.py --pyside2-link)
+isEmpty(PYSIDE2_LFLAGS): error(Unable to locate the PySide2 libraries for linking)
+
PYSIDE2_SHARED_LIBRARIES = $$system(python $$PWD/pyside2_config.py --pyside2-shared-libraries)
-CLANG_BIN_DIR = $$system(python $$PWD/pyside2_config.py --clang-bin-dir)
+isEmpty(PYSIDE2_SHARED_LIBRARIES): error(Unable to locate the used PySide2 shared libraries)
INCLUDEPATH += "$$PYTHON_INCLUDE" $$PYSIDE2_INCLUDE
LIBS += $$PYTHON_LFLAGS $$PYSIDE2_LFLAGS
-LIBPATH += $$PYTHON_LFLAGS $$PYSIDE2_LFLAGS
!build_pass:message(INCLUDEPATH is $$INCLUDEPATH)
!build_pass:message(LIBS are $$LIBS)
-!build_pass:message(LIBPATH is $$LIBPATH)
!build_pass:message(Using $$PYSIDE2)
diff --git a/examples/scriptableapplication/pyside2_config.py b/examples/scriptableapplication/pyside2_config.py
index 781c30b64..ce9c707c1 100644
--- a/examples/scriptableapplication/pyside2_config.py
+++ b/examples/scriptableapplication/pyside2_config.py
@@ -1,6 +1,6 @@
#############################################################################
##
-## Copyright (C) 2017 The Qt Company Ltd.
+## Copyright (C) 2018 The Qt Company Ltd.
## Contact: http://www.qt.io/licensing/
##
## This file is part of the Qt for Python examples of the Qt Toolkit.
@@ -40,8 +40,6 @@
import os, glob, re, sys, imp
from distutils import sysconfig
-if sys.platform == 'win32':
- import winreg
usage = """
Utility to determine include/link options of PySide2 and Python for qmake
@@ -54,7 +52,6 @@ Options:
--pyside2-include Print PySide2 include paths
--pyside2-link Print PySide2 link flags
--pyside2-shared-libraries Print paths of PySide2 shared libraries (.so's, .dylib's, .dll's)
- --clang-bin-dir Print path to the clang bin directory
-a Print all
--help/-h Print this help
"""
@@ -92,11 +89,11 @@ def linkOption(lib):
# libraries when compiling the project
baseName = os.path.basename(lib)
link = ' -l'
- if sys.platform in ['linux', 'linux2']: # Linux: 'libfoo.so' -> '-lfoo'
+ if sys.platform in ['linux', 'linux2']: # Linux: 'libfoo.so' -> '/absolute/path/libfoo.so'
link = lib
- elif sys.platform in ['darwin']: # Linux: 'libfoo.so' -> '-lfoo'
+ elif sys.platform in ['darwin']: # Darwin: 'libfoo.so' -> '-lfoo'
link += os.path.splitext(baseName[3:])[0]
- else:
+ else: # Windows: 'libfoo.dll' -> 'libfoo.dll'
link += os.path.splitext(baseName)[0]
return link
@@ -138,10 +135,7 @@ def pythonLinkCmake():
flags = pythonLinkData()
libdir = flags['libdir']
lib = re.sub(r'.dll$', '.lib', flags['lib'])
- if sys.platform == 'win32':
- return '{};{}'.format(libdir, lib)
- else:
- return '{} {}'.format(libdir, lib)
+ return '{};{}'.format(libdir, lib)
def pythonLinkData():
# @TODO Fix to work with static builds of Python
@@ -221,87 +215,71 @@ def pyside2SharedLibraries():
else:
libs_string = ''
for lib in libs:
- libs_string += ' ' + lib
+ libs_string += lib + ' '
return libs_string
def pyside2SharedLibrariesCmake():
libs = pyside2SharedLibrariesData()
- result = ' '.join(libs)
+ result = ';'.join(libs)
return result
-def clangBinPath():
- source = 'LLVM_INSTALL_DIR'
- clangDir = os.environ.get(source, None)
- if not clangDir:
- source = 'CLANG_INSTALL_DIR'
- clangDir = os.environ.get(source, None)
- if not clangDir:
- source = 'llvm-config'
- try:
- output = run_process_output([source, '--prefix'])
- if output:
- clangDir = output[0]
- except OSError:
- pass
- if clangDir:
- return os.path.realpath(clangDir + os.path.sep + 'bin')
- return ''
-
option = sys.argv[1] if len(sys.argv) == 2 else '-a'
if option == '-h' or option == '--help':
print(usage)
sys.exit(0)
+generic_error = (' Did you forget to activate your virtualenv? Or perhaps'
+ ' you forgot to build / install PySide2 into your currently active Python'
+ ' environment?')
+pyside2_error = 'Unable to locate PySide2.' + generic_error
+pyside2_libs_error = 'Unable to locate the PySide2 shared libraries.' + generic_error
+python_link_error = 'Unable to locate the Python library for linking.'
+
if option == '--pyside2' or option == '-a':
pySide2 = findPySide2()
if pySide2 is None:
- sys.exit('Unable to locate PySide2')
+ sys.exit(pyside2_error)
print(pySide2)
if option == '--pyside2-link' or option == '-a':
l = pyside2Link()
if l is None:
- sys.exit('Unable to locate PySide2')
+ sys.exit(pyside2_error)
+
print(l)
if option == '--pyside2-include' or option == '-a':
i = pyside2Include()
if i is None:
- sys.exit('Unable to locate PySide2')
+ sys.exit(pyside2_error)
print(i)
if option == '--python-include' or option == '-a':
i = pythonInclude()
if i is None:
- sys.exit('Unable to locate Python')
+ sys.exit('Unable to locate the Python include headers directory.')
print(i)
if option == '--python-link' or option == '-a':
l = pythonLinkQmake()
if l is None:
- sys.exit('Unable to locate Python')
+ sys.exit(python_link_error)
print(l)
if option == '--python-link-cmake' or option == '-a':
l = pythonLinkCmake()
if l is None:
- sys.exit('Unable to locate Python')
+ sys.exit(python_link_error)
print(l)
if option == '--pyside2-shared-libraries' or option == '-a':
l = pyside2SharedLibraries()
if l is None:
- sys.exit('Unable to locate the PySide2 shared libraries')
+ sys.exit(pyside2_libs_error)
print(l)
if option == '--pyside2-shared-libraries-cmake' or option == '-a':
l = pyside2SharedLibrariesCmake()
if l is None:
- sys.exit('Unable to locate the PySide2 shared libraries')
- print(l)
-
-if option == '--clang-bin-dir' or option == '-a':
- l = clangBinPath()
- if l is None:
- sys.exit('Unable to locate Clang')
+ sys.exit(pyside2_libs_error)
print(l)
diff --git a/examples/scriptableapplication/scriptableapplication.pro b/examples/scriptableapplication/scriptableapplication.pro
index ee96afde0..8a09b0abf 100644
--- a/examples/scriptableapplication/scriptableapplication.pro
+++ b/examples/scriptableapplication/scriptableapplication.pro
@@ -24,15 +24,7 @@ win32:SHIBOKEN_OPTIONS += --avoid-protected-hack
# Prepare the shiboken tool
QT_TOOL.shiboken.binary = $$system_path($$PYSIDE2/shiboken2)
-win32 {
- # Add the libclang/bin subdir to PATH.
- CLANG_PATH.name = PATH
- CLANG_PATH.value = $$CLANG_BIN_DIR
- CLANG_PATH.CONFIG += prepend
- exists($$CLANG_PATH.value): QT_TOOL_ENV = CLANG_PATH
-}
qtPrepareTool(SHIBOKEN, shiboken)
-QT_TOOL_ENV =
# Shiboken run that adds the module wrapper to GENERATED_SOURCES
shiboken.output = $$WRAPPER_DIR/applib_module_wrapper.cpp
@@ -90,4 +82,4 @@ HEADERS += \
mainwindow.h \
pythonutils.h
-OTHER_FILES += $$TYPESYSTEM_FILE $$WRAPPED_HEADER pyside2_config.py README.txt
+OTHER_FILES += $$TYPESYSTEM_FILE $$WRAPPED_HEADER pyside2_config.py README.md