Skip to content

Update patched-6 branch #44

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

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
193 changes: 152 additions & 41 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,39 @@ cmake_minimum_required(VERSION 2.8)
project(PythonQt)
#-----------------------------------------------------------------------------

#----------------------------------------------------------------------------
# Qt version

# Sanity checks
if(DEFINED Qt5_DIR AND DEFINED QT_QMAKE_EXECUTABLE)
message(FATAL_ERROR
"${PROJECT_NAME} shoult NOT be configured setting both Qt5_DIR and QT_QMAKE_EXECUTABLE options.
To build with Qt4, specify QT_QMAKE_EXECUTABLE. To build with Qt5, specify Qt5_DIR.")
endif()

# Set PythonQt_QT_VERSION
if(DEFINED Qt5_DIR)
message(STATUS "${PROJECT_NAME}: Setting PythonQt_QT_VERSION to 5 because Qt5_DIR is defined.")
set(PythonQt_QT_VERSION 5)
elseif(DEFINED QT_QMAKE_EXECUTABLE)
message(STATUS "${PROJECT_NAME}: Setting PythonQt_QT_VERSION to 4 because QT_QMAKE_EXECUTABLE is defined.")
set(PythonQt_QT_VERSION 4)
else()
set(PythonQt_QT_VERSION 4 CACHE STRING "Pick a version of Qt to use: 4 or 5")
# Set the possible values of Qt version for cmake-gui
set_property(CACHE PythonQt_QT_VERSION PROPERTY STRINGS "4" "5")
endif()

# Requirements
set(minimum_required_qt5_version "5.3.0")
set(minimum_required_qt4_version "4.6.2")
set(minimum_required_qt_version ${minimum_required_qt${PythonQt_QT_VERSION}_version})

# Qt components
set(qt5libs Core Widgets Network OpenGL Sql Svg UiTools WebKitWidgets Xml XmlPatterns)
set(qt4libs core gui network opengl sql svg uitools webkit xml xmlpatterns)
set(qtlibs ${qt${PythonQt_QT_VERSION}libs})

#-----------------------------------------------------------------------------
# Python libraries

Expand Down Expand Up @@ -40,17 +73,41 @@ if(NOT DEFINED PythonQt_INSTALL_INCLUDE_DIR)
set(PythonQt_INSTALL_INCLUDE_DIR include/PythonQt)
endif()

# Since the Qt bindings sources used for both Qt4 and Qt5 are
# grouped using Qt4 naming convention, qt_wrapped_libs variables are the
# same for the two Qt versions.
set(qt4_wrapped_libs ${qt4libs})
set(qt5_wrapped_libs ${qt4libs})
set(qt_wrapped_libs ${qt${PythonQt_QT_VERSION}_wrapped_libs})

set(qt5_wrapped_lib_depends_gui Multimedia)

set(qtlib_to_wraplib_Widgets gui)
set(qtlib_to_wraplib_WebKitWidgets webkit)

# Define PythonQt_Wrap_Qt* options
option(PythonQt_Wrap_QtAll "Make all Qt components available in python" OFF)
foreach(qtlib ${qt_wrapped_libs})
OPTION(PythonQt_Wrap_Qt${qtlib} "Make all of Qt${qtlib} available in python" OFF)
endforeach()

set(qtlibs core gui network opengl sql svg uitools webkit xml xmlpatterns)
# Set qtlib_to_wraplib_* variables
foreach(qtlib ${qtlibs})
OPTION(PythonQt_Wrap_Qt${qtlib} "Make all of Qt${qtlib} available in python" OFF)
string(TOLOWER ${qtlib} qtlib_lowercase)
if(DEFINED qtlib_to_wraplib_${qtlib})
set(qtlib_lowercase ${qtlib_to_wraplib_${qtlib}})
endif()
set(qtlib_to_wraplib_${qtlib} ${qtlib_lowercase})
endforeach()

# Force option if it applies
if(PythonQt_Wrap_QtAll)
list(REMOVE_ITEM qtlibs xmlpatterns) # xmlpatterns wrapper does *NOT* build at all :(
foreach(qtlib ${qtlibs})
set(_qt_wrapped_libs ${qt_wrapped_libs})

# XXX xmlpatterns wrapper does *NOT* build at all :(
list(REMOVE_ITEM _qt_wrapped_libs xmlpatterns)

foreach(qtlib ${_qt_wrapped_libs})
if(NOT ${PythonQt_Wrap_Qt${qtlib}})
set(PythonQt_Wrap_Qt${qtlib} ON CACHE BOOL "Make all of Qt${qtlib} available in python" FORCE)
message(STATUS "Enabling [PythonQt_Wrap_Qt${qtlib}] because of [PythonQt_Wrap_QtAll] evaluates to True")
Expand All @@ -68,40 +125,92 @@ endif()
#-----------------------------------------------------------------------------
# Setup Qt

set(minimum_required_qt_version "4.6.2")
if(PythonQt_QT_VERSION VERSION_GREATER "4")

find_package(Qt4)
# Required components
set(qt_required_components Core Widgets)
foreach(qtlib ${qtlibs})
set(qt_wrapped_lib ${qtlib_to_wraplib_${qtlib}})
if(${PythonQt_Wrap_Qt${qt_wrapped_lib}})
list(APPEND qt_required_components ${qtlib} ${qt${PythonQt_QT_VERSION}_wrapped_lib_depends_${qt_wrapped_lib}})
endif()
endforeach()
if(BUILD_TESTING)
list(APPEND qt_required_components Test)
endif()
list(REMOVE_DUPLICATES qt_required_components)

if(QT4_FOUND)
message(STATUS "${PROJECT_NAME}: Required Qt components [${qt_required_components}]")
find_package(Qt5 ${minimum_required_qt_version} COMPONENTS ${qt_required_components} REQUIRED)

set(found_qt_version ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH})
set(QT_LIBRARIES )
foreach(qtlib ${qt_required_components})
include_directories(${Qt5${qtlib}_INCLUDE_DIRS})
add_definitions(${Qt5${qtlib}_DEFINITIONS})
list(APPEND QT_LIBRARIES ${Qt5${qtlib}_LIBRARIES})
endforeach()

if(${found_qt_version} VERSION_LESS ${minimum_required_qt_version})
message(FATAL_ERROR "error: PythonQt requires Qt >= ${minimum_required_qt_version} -- you cannot use Qt ${found_qt_version}.")
endif()
set(QT_VERSION_MAJOR ${Qt5Core_VERSION_MAJOR})
set(QT_VERSION_MINOR ${Qt5Core_VERSION_MINOR})

macro(pythonqt_wrap_cpp)
qt5_wrap_cpp(${ARGV})
endmacro()

else()

# Enable required qt module
foreach(qtlib network opengl sql svg uitools webkit xml xmlpatterns)
string(TOUPPER ${qtlib} qtlib_uppercase)
if (NOT ${QT_QT${qtlib_uppercase}_FOUND})
message(FATAL_ERROR "QT_QT${qtlib_uppercase} *not* FOUND - Try to disable PythonQt_Wrap_Qt${qtlib}")
find_package(Qt4)

if(QT4_FOUND)

set(found_qt_version ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH})

if(${found_qt_version} VERSION_LESS ${minimum_required_qt_version})
message(FATAL_ERROR "error: PythonQt requires Qt >= ${minimum_required_qt_version} -- you cannot use Qt ${found_qt_version}.")
endif()
set(QT_USE_QT${qtlib_uppercase} ${PythonQt_Wrap_Qt${qtlib}})
endforeach()

set(QT_USE_QTTEST ${BUILD_TESTING})
# Enable required qt module
foreach(qtlib ${qt_wrapped_libs})
string(TOUPPER ${qtlib} qtlib_uppercase)
if (NOT ${QT_QT${qtlib_uppercase}_FOUND})
message(FATAL_ERROR "QT_QT${qtlib_uppercase} *not* FOUND - Try to disable PythonQt_Wrap_Qt${qtlib}")
endif()
set(QT_USE_QT${qtlib_uppercase} ${PythonQt_Wrap_Qt${qtlib}})
endforeach()

# Enable QtTest in Qt4 is the option BUILD_TESTING was activated
set(QT_USE_QTTEST ${BUILD_TESTING})

include(${QT_USE_FILE})
else()
message(FATAL_ERROR "error: Qt4 was not found on your system. You probably need to set the QT_QMAKE_EXECUTABLE variable")
endif()

macro(pythonqt_wrap_cpp)
qt4_wrap_cpp(${ARGV})
endmacro()

include(${QT_USE_FILE})
else()
message(FATAL_ERROR "error: Qt4 was not found on your system. You probably need to set the QT_QMAKE_EXECUTABLE variable")
endif()

if(UNIX)
find_package(OpenGL)
if(OPENGL_FOUND)
list(APPEND QT_LIBRARIES ${OPENGL_LIBRARIES})
endif()
endif()
#-----------------------------------------------------------------------------
# The variable "generated_cpp_suffix" allows to conditionnally compile the generated wrappers
# associated with the Qt version being used.

set(generated_cpp_suffix_46 _47)
set(generated_cpp_suffix_52 _50)
set(generated_cpp_suffix_51 _50)

set(generated_cpp_suffix "_${QT_VERSION_MAJOR}${QT_VERSION_MINOR}")
if("${generated_cpp_suffix}" STREQUAL "_46")
set(generated_cpp_suffix "_47") # Also use 4.7 wrappers for 4.6.x version
if(DEFINED generated_cpp_suffix_${QT_VERSION_MAJOR}${QT_VERSION_MINOR})
set(generated_cpp_suffix "${generated_cpp_suffix_${QT_VERSION_MAJOR}${QT_VERSION_MINOR}}")
elseif(${QT_VERSION_MAJOR}.${QT_VERSION_MINOR} VERSION_GREATER "5.4")
set(generated_cpp_suffix "_54")
endif()

#-----------------------------------------------------------------------------
Expand Down Expand Up @@ -181,15 +290,15 @@ set(moc_sources

#-----------------------------------------------------------------------------
# Add extra sources
foreach(qtlib core gui network opengl sql svg uitools webkit xml xmlpatterns)
foreach(qtlib ${qt_wrapped_libs})

if (${PythonQt_Wrap_Qt${qtlib}})

ADD_DEFINITIONS(-DPYTHONQT_WRAP_Qt${qtlib})

set(file_prefix generated_cpp${generated_cpp_suffix}/com_trolltech_qt_${qtlib}/com_trolltech_qt_${qtlib})

foreach(index RANGE 0 11)
foreach(index RANGE 0 12)

# Source files
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file_prefix}${index}.cpp)
Expand All @@ -208,19 +317,9 @@ foreach(qtlib core gui network opengl sql svg uitools webkit xml xmlpatterns)
endif()
endforeach()

#-----------------------------------------------------------------------------
# UI files
set(ui_sources )

#-----------------------------------------------------------------------------
# Resources
set(qrc_sources )

#-----------------------------------------------------------------------------
# Do wrapping
qt4_wrap_cpp(gen_moc_sources ${moc_sources})
qt4_wrap_ui(gen_ui_sources ${ui_sources})
qt4_add_resources(gen_qrc_sources ${qrc_sources})
pythonqt_wrap_cpp(gen_moc_sources ${moc_sources})

#-----------------------------------------------------------------------------
# Build the library
Expand All @@ -232,8 +331,6 @@ include_directories(
add_library(PythonQt SHARED
${sources}
${gen_moc_sources}
${gen_ui_sources}
${gen_qrc_sources}
)
set_target_properties(PythonQt PROPERTIES DEFINE_SYMBOL PYTHONQT_EXPORTS)

Expand Down Expand Up @@ -270,16 +367,30 @@ if(BUILD_TESTING)
tests/PythonQtTestMain.cpp
)

set_property(SOURCE tests/PythonQtTestMain.cpp PROPERTY COMPILE_DEFINITIONS "main=tests_PythonQtTestMain")

list(APPEND test_sources
tests/PythonQtTests.cpp
tests/PythonQtTests.h
)

QT4_WRAP_CPP(test_sources
pythonqt_wrap_cpp(test_sources
tests/PythonQtTests.h
)

set_property(SOURCE tests/PythonQtTestMain.cpp PROPERTY COMPILE_DEFINITIONS "main=tests_PythonQtTestMain")
if(PythonQt_Wrap_Qtcore)
include_directories(generated_cpp${generated_cpp_suffix})

list(APPEND test_sources
tests/PythonQtTestCleanup.cpp
tests/PythonQtTestCleanup.h
)
pythonqt_wrap_cpp(test_sources
tests/PythonQtTestCleanup.h
)

set_property(SOURCE tests/PythonQtTestMain.cpp APPEND PROPERTY COMPILE_DEFINITIONS "PythonQt_Wrap_Qtcore")
endif()

add_executable(PythonQtCppTests ${test_sources})
target_link_libraries(PythonQtCppTests PythonQt)
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Prerequisites
Build instructions
------------------

By default, the `patched-3` version will be checked out.
By default, the `patched-5` version will be checked out.

```
git clone git://github.com/commontk/PythonQt.git
Expand Down Expand Up @@ -64,7 +64,9 @@ florianlink (8):
```

### patched-5
* Based on patched-4 + [r395](http://sourceforge.net/p/pythonqt/code/395/)
* Based on patched-4 + [r403](http://sourceforge.net/p/pythonqt/code/403/) excluding commit [r397](http://sourceforge.net/p/pythonqt/code/397/)
* List of bug fixes:
* Fix for memory leaks and cleanup crash
* List of features:
* CMake:
* Fix install rules
Expand Down
58 changes: 58 additions & 0 deletions generated_cpp_50/PythonQt_QtBindings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

#include "PythonQt_QtBindings.h"

#include "PythonQt.h"

void PythonQt_init_QtGui(PyObject*);
void PythonQt_init_QtSvg(PyObject*);
void PythonQt_init_QtSql(PyObject*);
void PythonQt_init_QtNetwork(PyObject*);
void PythonQt_init_QtCore(PyObject*);
void PythonQt_init_QtWebKit(PyObject*);
void PythonQt_init_QtOpenGL(PyObject*);
void PythonQt_init_QtXml(PyObject*);
void PythonQt_init_QtXmlPatterns(PyObject*);
void PythonQt_init_QtUiTools(PyObject*);

PYTHONQT_EXPORT void PythonQt_init_QtBindings()
{
#ifdef PYTHONQT_WRAP_Qtcore
PythonQt_init_QtCore(0);
#endif

#ifdef PYTHONQT_WRAP_Qtgui
PythonQt_init_QtGui(0);
#endif

#ifdef PYTHONQT_WRAP_Qtnetwork
PythonQt_init_QtNetwork(0);
#endif

#ifdef PYTHONQT_WRAP_Qtopengl
PythonQt_init_QtOpenGL(0);
#endif

#ifdef PYTHONQT_WRAP_Qtsql
PythonQt_init_QtSql(0);
#endif

#ifdef PYTHONQT_WRAP_Qtsvg
PythonQt_init_QtSvg(0);
#endif

#ifdef PYTHONQT_WRAP_Qtuitools
PythonQt_init_QtUiTools(0);
#endif

#ifdef PYTHONQT_WRAP_Qtwebkit
PythonQt_init_QtWebKit(0);
#endif

#ifdef PYTHONQT_WRAP_Qtxml
PythonQt_init_QtXml(0);
#endif

#ifdef PYTHONQT_WRAP_Qtxmlpatterns
PythonQt_init_QtXmlPatterns(0);
#endif
};
10 changes: 10 additions & 0 deletions generated_cpp_50/PythonQt_QtBindings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef _PYTHONQT_QTBINDINGS_H
#define _PYTHONQT_QTBINDINGS_H

#include "PythonQtSystem.h"

/// Initialize Qt bindings enabled at configuration time
PYTHONQT_EXPORT void PythonQt_init_QtBindings();

#endif

Loading