Skip to content

Create a new patched-9 branch #56

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 38 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
f01a4b7
Add README file specific to CTK github fork
jcfr Jul 10, 2012
9c135e3
Fix "_invalid_parameter_noinfo_noreturn" link error
jcfr May 28, 2013
44fb97b
Update Readme.md to use new url format for svn revision reference
jcfr Sep 10, 2013
22c9bd9
Add CMake testing support
jcfr Sep 10, 2013
6da0b4e
Revert part of r91 preventing QFlags from being wrapped
jcfr Sep 10, 2013
d213b78
fix problem in CMake error message
mwoehlke-kitware May 21, 2014
809b821
allow specifying install directories
mwoehlke-kitware May 21, 2014
3fa4ecc
remove trailing spaces in CMakeLists.txt
mwoehlke-kitware May 21, 2014
97ad91a
Fix unused variable warning in PythonQtSlot
texpert May 7, 2015
ff506f7
Ensure "PythonQtUtils.h" is installed when building using CMake
jcfr May 10, 2015
5d1b5ca
Update README.md to describe the "patched-5" branch
jcfr Aug 31, 2015
db06a16
Update README.md to describe the "patched-6" branch
jcfr Aug 31, 2015
ae54223
Add missing refcount decrements when creating wrappers
msmolens Aug 28, 2015
ef6a1f2
Fix refcount of PyInt_Type when creating enum wrapper
msmolens Aug 31, 2015
c3d8c86
Prevent crash when an object is destroyed after calling PythonQt::cle…
msmolens Aug 28, 2015
e403085
Update README.md to include description of recent fixes
jcfr Aug 31, 2015
2936746
Enable "name" property support
msmolens Sep 1, 2015
0562458
Update README.md to describe new commits
msmolens Sep 4, 2015
a08c2d0
Prevent crashes during and after cleanup
msmolens Sep 11, 2015
1176466
Fix tests link error on Windows
msmolens Sep 11, 2015
290a5fb
Fix refcount problems seen when re-initializing Python after finalizing
msmolens Sep 11, 2015
9437eb6
Explicitly initialize global storage containers
msmolens Sep 11, 2015
4d2c80b
Add cleanup/finalization tests
msmolens Sep 11, 2015
4d36f86
Fix PythonQtSignalReceiver crash during cleanup
msmolens Sep 15, 2015
7d18114
Fix compilation of test when PythonQt_Wrap_Qtcore option is disabled
jcfr Feb 16, 2016
330a0ed
Remove unused call to qt4_wrap_ui/qt4_add_resources associated with P…
jcfr Feb 18, 2016
9766873
Add macro pythonqt_wrap_cpp removing the need for qt version specific…
jcfr Feb 18, 2016
f09671f
Re-factor code introducing qt_wrapped_libs variable
jcfr Feb 18, 2016
a49ec49
Refactor handling of "generated_cpp_suffix".
jcfr Feb 18, 2016
82ebfa2
Add support for Qt5
jcfr Feb 18, 2016
04b74f4
addDecorators: Check for null object
jcfr May 21, 2016
50d646c
Add missing link to OpenGL library
mwoehlke-kitware May 24, 2016
1a8b9ae
Update README.md to describe the "patched-7" branch
jcfr Jan 17, 2017
1cc9275
README.md: Fix formatting
jcfr Jun 11, 2017
57117bb
Revert "removed enums that have been removed in Qt 5.8"
cwilling Jun 11, 2017
b534dad
Update README.md to describe the "patched-8" branch
cwilling Jun 11, 2017
e39be13
Add MSVC 2017, Qt 5.8, and Qt 5.9 support
kislinsk Jul 4, 2017
3dfe45d
Relax check for MSVC and set minimum required version of CMake to 2.8.12
kislinsk Jul 5, 2017
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
287 changes: 230 additions & 57 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,109 @@
# If you are not a CMake expert, you should better use the provided qmake profiles.
#-----------------------------------------------------------------------------

cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 2.8.12)

#-----------------------------------------------------------------------------
project(PythonQt)
#-----------------------------------------------------------------------------

include(CTestUseLaunchers OPTIONAL)
#----------------------------------------------------------------------------
# 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

find_package(PythonLibs REQUIRED)
include_directories("${PYTHON_INCLUDE_DIR}")
add_definitions(-DPYTHONQT_USE_RELEASE_PYTHON_FALLBACK)
add_definitions(
-DPYTHONQT_USE_RELEASE_PYTHON_FALLBACK
-DPYTHONQT_SUPPORT_NAME_PROPERTY
)

#-----------------------------------------------------------------------------
# Build options

if(NOT DEFINED PythonQt_INSTALL_RUNTIME_DIR)
set(PythonQt_INSTALL_RUNTIME_DIR bin)
endif()

if(NOT DEFINED PythonQt_INSTALL_LIBRARY_DIR)
set(PythonQt_INSTALL_LIBRARY_DIR lib${LIB_SUFFIX})
endif()

if(NOT DEFINED PythonQt_INSTALL_ARCHIVE_DIR)
set(PythonQt_INSTALL_ARCHIVE_DIR lib${LIB_SUFFIX})
endif()

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 @@ -51,38 +125,94 @@ 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)

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

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(QT4_FOUND)
include_directories(${Qt5Core_PRIVATE_INCLUDE_DIRS})

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

if(${found_qt_version} VERSION_LESS ${minimum_required_qt_version})
macro(pythonqt_wrap_cpp)
qt5_wrap_cpp(${ARGV})
endmacro()

else()

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()

# 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}")
endif()
set(QT_USE_QT${qtlib_uppercase} ${PythonQt_Wrap_Qt${qtlib}})
endforeach()

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")

# 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()

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
# 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 All @@ -106,8 +236,10 @@ set(sources
src/PythonQtStdDecorators.cpp
src/PythonQtStdIn.cpp
src/PythonQtStdOut.cpp
src/PythonQtProperty.cpp
src/PythonQtSlotDecorator.cpp
src/gui/PythonQtScriptingConsole.cpp

generated_cpp${generated_cpp_suffix}/PythonQt_QtBindings.cpp

generated_cpp${generated_cpp_suffix}/com_trolltech_qt_core_builtin/com_trolltech_qt_core_builtin0.cpp
Expand Down Expand Up @@ -141,8 +273,11 @@ set(headers
src/PythonQtStdIn.h
src/PythonQtStdOut.h
src/PythonQtSystem.h
src/PythonQtUtils.h
src/PythonQtVariants.h
src/PythonQtPythonInclude.h
src/PythonQtProperty.h
src/PythonQtSlotDecorator.cpp
generated_cpp${generated_cpp_suffix}/PythonQt_QtBindings.h
)

Expand All @@ -161,59 +296,47 @@ 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)
list(APPEND sources ${file_prefix}${index}.cpp)
endif()

# Headers that should run through moc
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file_prefix}${index}.h)
list(APPEND moc_sources ${file_prefix}${index}.h)
endif()

endforeach()

list(APPEND sources ${file_prefix}_init.cpp)

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

include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/src
)

add_library(PythonQt SHARED
${sources}
${gen_moc_sources}
${gen_ui_sources}
${gen_qrc_sources}
)
set_target_properties(PythonQt PROPERTIES DEFINE_SYMBOL PYTHONQT_EXPORTS)

Expand All @@ -225,6 +348,10 @@ set_target_properties(PythonQt PROPERTIES
INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib"
)

target_compile_options(PythonQt PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/bigobj>
)

target_link_libraries(PythonQt
${PYTHON_LIBRARY}
${QT_LIBRARIES}
Expand All @@ -234,7 +361,53 @@ target_link_libraries(PythonQt
# Install library (on windows, put the dll in 'bin' and the archive in 'lib')

install(TARGETS PythonQt
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
install(FILES ${headers} DESTINATION include/PythonQt)
RUNTIME DESTINATION ${PythonQt_INSTALL_RUNTIME_DIR}
LIBRARY DESTINATION ${PythonQt_INSTALL_LIBRARY_DIR}
ARCHIVE DESTINATION ${PythonQt_INSTALL_ARCHIVE_DIR})
install(FILES ${headers} DESTINATION ${PythonQt_INSTALL_INCLUDE_DIR})

#-----------------------------------------------------------------------------
# Testing

option(BUILD_TESTING "Build the testing tree." OFF)
include(CTest)

if(BUILD_TESTING)
create_test_sourcelist(test_sources PythonQtCppTests.cpp
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
)

pythonqt_wrap_cpp(test_sources
tests/PythonQtTests.h
)

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)

add_test(
NAME tests_PythonQtTestMain
COMMAND ${Slicer_LAUNCH_COMMAND} $<TARGET_FILE:PythonQtCppTests> tests/PythonQtTestMain
)
endif()

Loading