Skip to content

Commit

Permalink
Add support for Qt5
Browse files Browse the repository at this point in the history
Todo:
* Test with Qt4
* Make sure ctkMacroWrapPythonQt.cmake works correctly
  • Loading branch information
finetjul committed Sep 20, 2013
1 parent 0036612 commit 47b3421
Show file tree
Hide file tree
Showing 103 changed files with 789 additions and 379 deletions.
1 change: 1 addition & 0 deletions CMake/CTKConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ SET(CTK_QT_RCC_EXECUTABLE "@QT_RCC_EXECUTABLE@")
SET(CTK_QT_MOC_EXECUTABLE "@QT_MOC_EXECUTABLE@")
SET(CTK_QT_UIC_EXECUTABLE "@QT_UIC_EXECUTABLE@")
SET(CTK_QT_QMAKE_EXECUTABLE "@QT_QMAKE_EXECUTABLE@")
SET(CTK_QT_VERSION "@CTK_QT_VERSION@")

# The CTK version number
SET(CTK_MAJOR_VERSION "@CTK_MAJOR_VERSION@")
Expand Down
6 changes: 5 additions & 1 deletion CMake/ctkFunctionGeneratePluginManifest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ function(ctkFunctionGeneratePluginManifest QRC_SRCS)
configure_file("${CTK_CMAKE_DIR}/MANIFEST.MF.in" "${_manifest_filepath}" @ONLY)
configure_file("${CTK_CMAKE_DIR}/plugin_manifest.qrc.in" "${_manifest_qrc_filepath}" @ONLY)

QT4_ADD_RESOURCES(_qrc_src ${_manifest_qrc_filepath})
if (CTK_QT_VERSION VERSION_GREATER "4")
QT5_ADD_RESOURCES(_qrc_src ${_manifest_qrc_filepath})
else()
QT4_ADD_RESOURCES(_qrc_src ${_manifest_qrc_filepath})
endif()

set(${QRC_SRCS} ${${QRC_SRCS}} ${_qrc_src} PARENT_SCOPE)

Expand Down
37 changes: 26 additions & 11 deletions CMake/ctkMacroBuildApp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,32 @@ macro(ctkMacroBuildApp)
set(MY_MOC_CPP)
set(MY_QRC_SRCS)

# Wrap
if(MY_MOC_SRCS)
# this is a workaround for Visual Studio. The relative include paths in the generated
# moc files can get very long and can't be resolved by the MSVC compiler.
foreach(moc_src ${MY_MOC_SRCS})
QT4_WRAP_CPP(MY_MOC_CPP ${moc_src} OPTIONS -f${moc_src})
endforeach()
endif()
QT4_WRAP_UI(MY_UI_CPP ${MY_UI_FORMS})
if(DEFINED MY_RESOURCES)
QT4_ADD_RESOURCES(MY_QRC_SRCS ${MY_RESOURCES})
if (CTK_QT_VERSION VERSION_GREATER "4")
# Wrap
if(MY_MOC_SRCS)
# this is a workaround for Visual Studio. The relative include paths in the generated
# moc files can get very long and can't be resolved by the MSVC compiler.
foreach(moc_src ${MY_MOC_SRCS})
QT5_WRAP_CPP(MY_MOC_CPP ${moc_src} OPTIONS -f${moc_src})
endforeach()
endif()
QT5_WRAP_UI(MY_UI_CPP ${MY_UI_FORMS})
if(DEFINED MY_RESOURCES)
QT5_ADD_RESOURCES(MY_QRC_SRCS ${MY_RESOURCES})
endif()
else()
# Wrap
if(MY_MOC_SRCS)
# this is a workaround for Visual Studio. The relative include paths in the generated
# moc files can get very long and can't be resolved by the MSVC compiler.
foreach(moc_src ${MY_MOC_SRCS})
QT4_WRAP_CPP(MY_MOC_CPP ${moc_src} OPTIONS -f${moc_src})
endforeach()
endif()
QT4_WRAP_UI(MY_UI_CPP ${MY_UI_FORMS})
if(DEFINED MY_RESOURCES)
QT4_ADD_RESOURCES(MY_QRC_SRCS ${MY_RESOURCES})
endif()
endif()

source_group("Resources" FILES
Expand Down
37 changes: 26 additions & 11 deletions CMake/ctkMacroBuildLib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,32 @@ macro(ctkMacroBuildLib)
set(MY_UI_CPP)
set(MY_QRC_SRCS)

# Wrap
if(MY_MOC_SRCS)
# this is a workaround for Visual Studio. The relative include paths in the generated
# moc files can get very long and can't be resolved by the MSVC compiler.
foreach(moc_src ${MY_MOC_SRCS})
QT4_WRAP_CPP(MY_MOC_CPP ${moc_src} OPTIONS -f${moc_src})
endforeach()
endif()
QT4_WRAP_UI(MY_UI_CPP ${MY_UI_FORMS})
if(DEFINED MY_RESOURCES)
QT4_ADD_RESOURCES(MY_QRC_SRCS ${MY_RESOURCES})
if (CTK_QT_VERSION VERSION_GREATER "4")
# Wrap
if(MY_MOC_SRCS)
# this is a workaround for Visual Studio. The relative include paths in the generated
# moc files can get very long and can't be resolved by the MSVC compiler.
foreach(moc_src ${MY_MOC_SRCS})
qt5_wrap_cpp(MY_MOC_CPP ${moc_src} OPTIONS -f${moc_src})
endforeach()
endif()
qt5_wrap_ui(MY_UI_CPP ${MY_UI_FORMS})
if(DEFINED MY_RESOURCES)
qt5_add_resources(MY_QRC_SRCS ${MY_RESOURCES})
endif()
else()
# Wrap
if(MY_MOC_SRCS)
# this is a workaround for Visual Studio. The relative include paths in the generated
# moc files can get very long and can't be resolved by the MSVC compiler.
foreach(moc_src ${MY_MOC_SRCS})
QT4_WRAP_CPP(MY_MOC_CPP ${moc_src} OPTIONS -f${moc_src})
endforeach()
endif()
QT4_WRAP_UI(MY_UI_CPP ${MY_UI_FORMS})
if(DEFINED MY_RESOURCES)
QT4_ADD_RESOURCES(MY_QRC_SRCS ${MY_RESOURCES})
endif()
endif()

source_group("Resources" FILES
Expand Down
6 changes: 5 additions & 1 deletion CMake/ctkMacroBuildLibWrapper.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ macro(ctkMacroBuildLibWrapper)
KIT_PYTHONQT_SRCS "${MY_SRCS}" ${CTK_WRAP_PYTHONQT_FULL} ${HAS_DECORATOR})
if(HAS_DECORATOR)
list(APPEND KIT_PYTHONQT_SRCS ${DECORATOR_HEADER})
QT4_WRAP_CPP(KIT_PYTHONQT_SRCS ${DECORATOR_HEADER} OPTIONS -f${DECORATOR_HEADER})
if (CTK_QT_VERSION VERSION_GREATER "4")
qt5_wrap_cpp(KIT_PYTHONQT_SRCS ${DECORATOR_HEADER} OPTIONS -f${DECORATOR_HEADER})
else()
QT4_WRAP_CPP(KIT_PYTHONQT_SRCS ${DECORATOR_HEADER} OPTIONS -f${DECORATOR_HEADER})
endif()
endif()
add_library(${lib_name}PythonQt ${MY_WRAPPER_LIBRARY_TYPE} ${KIT_PYTHONQT_SRCS})
target_link_libraries(${lib_name}PythonQt ${lib_name} ${my_EXTRA_PYTHON_LIBRARIES})
Expand Down
35 changes: 24 additions & 11 deletions CMake/ctkMacroBuildPlugin.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,31 @@ macro(ctkMacroBuildPlugin)
set(MY_QRC_SRCS)

# Wrap
if(MY_MOC_SRCS)
# this is a workaround for Visual Studio. The relative include paths in the generated
# moc files can get very long and can't be resolved by the MSVC compiler.
foreach(moc_src ${MY_MOC_SRCS})
QT4_WRAP_CPP(MY_MOC_CPP ${moc_src} OPTIONS -f${moc_src})
endforeach()
endif()
QT4_WRAP_UI(MY_UI_CPP ${MY_UI_FORMS})
if(DEFINED MY_RESOURCES)
QT4_ADD_RESOURCES(MY_QRC_SRCS ${MY_RESOURCES})
if (CTK_QT_VERSION VERSION_GREATER "4")
if(MY_MOC_SRCS)
# this is a workaround for Visual Studio. The relative include paths in the generated
# moc files can get very long and can't be resolved by the MSVC compiler.
foreach(moc_src ${MY_MOC_SRCS})
QT5_WRAP_CPP(MY_MOC_CPP ${moc_src} OPTIONS -f${moc_src})
endforeach()
endif()
QT5_WRAP_UI(MY_UI_CPP ${MY_UI_FORMS})
if(DEFINED MY_RESOURCES)
QT5_ADD_RESOURCES(MY_QRC_SRCS ${MY_RESOURCES})
endif()
else()
if(MY_MOC_SRCS)
# this is a workaround for Visual Studio. The relative include paths in the generated
# moc files can get very long and can't be resolved by the MSVC compiler.
foreach(moc_src ${MY_MOC_SRCS})
QT4_WRAP_CPP(MY_MOC_CPP ${moc_src} OPTIONS -f${moc_src})
endforeach()
endif()
QT4_WRAP_UI(MY_UI_CPP ${MY_UI_FORMS})
if(DEFINED MY_RESOURCES)
QT4_ADD_RESOURCES(MY_QRC_SRCS ${MY_RESOURCES})
endif()
endif()

# Add the generated manifest qrc file
set(manifest_qrc_src )
ctkFunctionGeneratePluginManifest(manifest_qrc_src
Expand Down
31 changes: 22 additions & 9 deletions CMake/ctkMacroBuildQtPlugin.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,20 @@ macro(ctkMacroBuildQtPlugin)

# --------------------------------------------------------------------------
# Include dirs

set(my_includes
${CTK_BASE_INCLUDE_DIRS}
${QT_QTDESIGNER_INCLUDE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${MY_INCLUDE_DIRECTORIES}
)
include_directories(
${my_includes}
)

if (CTK_QT_VERSION VERSION_GREATER "4")
list(APPEND my_includes ${Qt5Designer_INCLUDE_DIRS})
else()
list(APPEND my_includes ${QT_QTDESIGNER_INCLUDE_DIR})
endif()
include_directories(${my_includes})

set(MY_LIBRARY_EXPORT_DIRECTIVE ${MY_EXPORT_DIRECTIVE})
set(MY_EXPORT_HEADER_PREFIX ${MY_NAME})
Expand All @@ -82,11 +86,20 @@ macro(ctkMacroBuildQtPlugin)
set(MY_QRC_SRCS)

# Wrap
QT4_WRAP_CPP(MY_MOC_CPP ${MY_MOC_SRCS})
QT4_WRAP_UI(MY_UI_CPP ${MY_UI_FORMS})
set(MY_QRC_SRCS "")
if(DEFINED MY_RESOURCES)
QT4_ADD_RESOURCES(MY_QRC_SRCS ${MY_RESOURCES})
if (CTK_QT_VERSION VERSION_GREATER "4")
qt5_wrap_cpp(MY_MOC_CPP ${MY_MOC_SRCS})
qt5_wrap_ui(MY_UI_CPP ${MY_UI_FORMS})
set(MY_QRC_SRCS "")
if(DEFINED MY_RESOURCES)
qt5_add_resources(MY_QRC_SRCS ${MY_RESOURCES})
endif()
else()
QT4_WRAP_CPP(MY_MOC_CPP ${MY_MOC_SRCS})
QT4_WRAP_UI(MY_UI_CPP ${MY_UI_FORMS})
set(MY_QRC_SRCS "")
if(DEFINED MY_RESOURCES)
QT4_ADD_RESOURCES(MY_QRC_SRCS ${MY_RESOURCES})
endif()
endif()

source_group("Resources" FILES
Expand Down
52 changes: 36 additions & 16 deletions CMake/ctkMacroGenerateMocs.cmake
Original file line number Diff line number Diff line change
@@ -1,21 +1,41 @@

# QT4_GENERATE_MOCS(inputfile1 [inputfile2 ...])
if (CTK_QT_VERSION VERSION_GREATER "4")
# QT5_GENERATE_MOCS(inputfile1 [inputfile2 ...])
macro(QT5_GENERATE_MOCS)
foreach(file ${ARGN})
set(moc_file moc_${file})
QT5_GENERATE_MOC(${file} ${moc_file})

macro(QT4_GENERATE_MOCS)
foreach(file ${ARGN})
set(moc_file moc_${file})
QT4_GENERATE_MOC(${file} ${moc_file})

get_filename_component(source_name ${file} NAME_WE)
get_filename_component(source_ext ${file} EXT)
if(${source_ext} MATCHES "\\.[hH]")
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${source_name}.cpp)
set(source_ext .cpp)
elseif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${source_name}.cxx)
set(source_ext .cxx)
get_filename_component(source_name ${file} NAME_WE)
get_filename_component(source_ext ${file} EXT)
if(${source_ext} MATCHES "\\.[hH]")
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${source_name}.cpp)
set(source_ext .cpp)
elseif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${source_name}.cxx)
set(source_ext .cxx)
endif()
endif()
endif()
set_property(SOURCE ${source_name}${source_ext} APPEND PROPERTY OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${moc_file})
endforeach()
set_property(SOURCE ${source_name}${source_ext} APPEND PROPERTY OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${moc_file})
endforeach()
endmacro()

else()
# QT4_GENERATE_MOCS(inputfile1 [inputfile2 ...])
macro(QT4_GENERATE_MOCS)
foreach(file ${ARGN})
set(moc_file moc_${file})
QT4_GENERATE_MOC(${file} ${moc_file})
get_filename_component(source_name ${file} NAME_WE)
get_filename_component(source_ext ${file} EXT)
if(${source_ext} MATCHES "\\.[hH]")
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${source_name}.cpp)
set(source_ext .cpp)
elseif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${source_name}.cxx)
set(source_ext .cxx)
endif()
endif()
set_property(SOURCE ${source_name}${source_ext} APPEND PROPERTY OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${moc_file})
endforeach()
endmacro()
endif()

6 changes: 5 additions & 1 deletion CMake/ctkMacroGeneratePluginResourceFile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ macro(ctkMacroGeneratePluginResourceFile QRC_SRCS)
")
configure_file("${CTK_CMAKE_DIR}/plugin_resources_cached.qrc.in" "${_qrc_filepath}" @ONLY)

QT4_ADD_RESOURCES(${QRC_SRCS} ${_qrc_filepath})
if (CTK_QT_VERSION VERSION_GREATER "4")
QT5_ADD_RESOURCES(${QRC_SRCS} ${_qrc_filepath})
else()
QT4_ADD_RESOURCES(${QRC_SRCS} ${_qrc_filepath})
endif()

endmacro()
16 changes: 8 additions & 8 deletions CMake/ctkMacroSetupPlugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ macro(ctkMacroSetupPlugins )
endif()

# Set up Qt, if not already done
if(NOT QT4_FOUND)
set(minimum_required_qt_version "4.6")
find_package(Qt4 REQUIRED)

if("${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}" VERSION_LESS "${minimum_required_qt_version}")
message(FATAL_ERROR "error: CTK requires Qt >= ${minimum_required_qt_version} -- you cannot use Qt ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH}.")
endif()
endif()
#if(NOT QT4_FOUND)
# set(minimum_required_qt_version "4.6")
# find_package(Qt4 REQUIRED)

# if("${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}" VERSION_LESS "${minimum_required_qt_version}")
# message(FATAL_ERROR "error: CTK requires Qt >= ${minimum_required_qt_version} -- you cannot use Qt ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH}.")
# endif()
#endif()

# Set the variable QT_INSTALLED_LIBRARY_DIR that contains all
# Qt shared libraries
Expand Down
60 changes: 37 additions & 23 deletions CMake/ctkMacroSetupQt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,48 @@

#! \ingroup CMakeUtilities
macro(ctkMacroSetupQt)
include(ctkQt)

set(minimum_required_qt_version "4.6")
if (CTK_QT_VERSION VERSION_GREATER "4")
set(qt_modules Core Sql WebKit Widgets Xml)
list(APPEND qt_modules Designer ) # plugins
list(APPEND qt_modules Network) # Visualization/VTK
list(APPEND qt_modules OpenGL) # Widgets/ctkWidgetsUtils and Visualization/VTK
if (${BUILD_TESTING})
list(APPEND qt_modules Test)
endif()
foreach(qt_module ${qt_modules})
find_package(Qt5${qt_module} REQUIRED)
endforeach()
else()
set(minimum_required_qt_version "4.6")

find_package(Qt4)

if(QT4_FOUND)
find_package(Qt4)

if("${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}" VERSION_LESS "${minimum_required_qt_version}")
message(FATAL_ERROR "error: CTK requires Qt >= ${minimum_required_qt_version} -- you cannot use Qt ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH}.")
endif()
if(QT4_FOUND)

set(QT_USE_QTNETWORK ON)
set(QT_USE_QTSQL ON)
set(QT_USE_QTOPENGL ON)
set(QT_USE_QTXML ON)
set(QT_USE_QTXMLPATTERNS ON)
set(QT_USE_QTTEST ${BUILD_TESTING})
include(${QT_USE_FILE})

# Set variable QT_INSTALLED_LIBRARY_DIR that will contains
# Qt shared library
set(QT_INSTALLED_LIBRARY_DIR ${QT_LIBRARY_DIR})
if(WIN32)
get_filename_component(QT_INSTALLED_LIBRARY_DIR ${QT_QMAKE_EXECUTABLE} PATH)
endif()
if("${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}" VERSION_LESS "${minimum_required_qt_version}")
message(FATAL_ERROR "error: CTK requires Qt >= ${minimum_required_qt_version} -- you cannot use Qt ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH}.")
endif()

else()
message(FATAL_ERROR "error: Qt4 was not found on your system. You probably need to set the QT_QMAKE_EXECUTABLE variable")
set(QT_USE_QTNETWORK ON)
set(QT_USE_QTSQL ON)
set(QT_USE_QTOPENGL ON)
set(QT_USE_QTXML ON)
set(QT_USE_QTXMLPATTERNS ON)
set(QT_USE_QTTEST ${BUILD_TESTING})
include(${QT_USE_FILE})

# Set variable QT_INSTALLED_LIBRARY_DIR that will contains
# Qt shared library
set(QT_INSTALLED_LIBRARY_DIR ${QT_LIBRARY_DIR})
if(WIN32)
get_filename_component(QT_INSTALLED_LIBRARY_DIR ${QT_QMAKE_EXECUTABLE} PATH)
endif()

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

endmacro()
4 changes: 3 additions & 1 deletion CMake/ctkMacroWrapPythonQt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,9 @@ macro(ctkMacroWrapPythonQt WRAPPING_NAMESPACE TARGET SRCS_LIST_NAME SOURCES IS_W
set(moc_flags)

# Grab moc flags
QT4_GET_MOC_FLAGS(moc_flags)
if (CTK_QT_VERSION VERSION_EQUAL "4")
QT4_GET_MOC_FLAGS(moc_flags)
endif()

# Prepare custom_command argument
set(moc_flags_arg)
Expand Down
Loading

0 comments on commit 47b3421

Please sign in to comment.