diff --git a/Sofa/GUI/Qt/CMakeLists.txt b/Sofa/GUI/Qt/CMakeLists.txt index acc702c7803..588c24d7db7 100644 --- a/Sofa/GUI/Qt/CMakeLists.txt +++ b/Sofa/GUI/Qt/CMakeLists.txt @@ -9,24 +9,21 @@ set(QT5_NO_LINK_QTMAIN 1) -# Will only use Qt6 if Qt6 is found and Qt5 is not found -# if Qt5 and Qt6 are both found, Qt5 will take priority -# Qt6 needs cmake >= 3.16, https://doc.qt.io/qt-6/cmake-get-started.html -find_package(Qt5 COMPONENTS Core QUIET) -if (NOT Qt5Core_FOUND) - if(${CMAKE_VERSION} VERSION_GREATER "3.16.0") - find_package(Qt6 COMPONENTS Core CoreTools QUIET) - endif() +# Will only use Qt5 if Qt5 is found and Qt6 is not found +# if Qt5 and Qt6 are both found, Qt6 will take priority +find_package(Qt6 COMPONENTS Core CoreTools QUIET) +if (NOT Qt6Core_FOUND) + find_package(Qt5 COMPONENTS Core QUIET) endif() -if (Qt5Core_FOUND) - message("${PROJECT_NAME}: will use Qt5") +if (Qt6Core_FOUND) + message("${PROJECT_NAME}: will use Qt6") + sofa_find_package(Qt6 COMPONENTS Gui GuiTools Widgets WidgetsTools OpenGLWidgets REQUIRED) + set(SOFA_GUI_QT_TARETS ${SOFA_GUI_QT_TARGETS} Qt::Core Qt::Gui Qt::Widgets Qt::OpenGLWidgets ) +elseif (Qt5Core_FOUND) + message("${PROJECT_NAME}: will use Qt5 (deprecated)") sofa_find_package(Qt5 COMPONENTS Core Gui OpenGL REQUIRED) set(SOFA_GUI_QT_TARGETS ${SOFA_GUI_QT_TARGETS} Qt5::Core Qt5::Gui Qt5::OpenGL) -elseif (Qt6Core_FOUND) - message("${PROJECT_NAME}: will use Qt6 (beta)") - sofa_find_package(Qt6 COMPONENTS Gui GuiTools Widgets WidgetsTools OpenGLWidgets REQUIRED) - set(SOFA_GUI_QT_TARGETS ${SOFA_GUI_QT_TARGETS} Qt::Core Qt::Gui Qt::Widgets Qt::OpenGLWidgets ) else() message(SEND_ERROR "${PROJECT_NAME}: Could not find either Qt5 or Qt6.") endif() @@ -291,7 +288,7 @@ if(SOFA_GUI_QT_ENABLE_QDOCBROWSER) list(APPEND MOC_HEADER_FILES ${SRC_ROOT}/panels/QDocBrowser.h) list(APPEND SOURCE_FILES ${SRC_ROOT}/panels/QDocBrowser.cpp) else() - message(STATUS "${PROJECT_NAME}: Qt5WebEngine not found, QDocBrowser will not be built.") + message(STATUS "${PROJECT_NAME}: QtWebEngine not found, QDocBrowser will not be built.") endif() diff --git a/Sofa/GUI/Qt/Sofa.GUI.QtConfig.cmake.in b/Sofa/GUI/Qt/Sofa.GUI.QtConfig.cmake.in index e41f4695dd7..f9e7ce28642 100644 --- a/Sofa/GUI/Qt/Sofa.GUI.QtConfig.cmake.in +++ b/Sofa/GUI/Qt/Sofa.GUI.QtConfig.cmake.in @@ -16,6 +16,9 @@ set(SOFA_GUI_QT_HAVE_QT5_WEBENGINE @SOFA_GUI_QT_HAVE_QT5_WEBENGINE@) set(SOFA_GUI_QT_HAVE_NODEEDITOR @SOFA_GUI_QT_HAVE_NODEEDITOR@) set(SOFA_GUI_QT_HAVE_TINYXML @SOFA_GUI_QT_HAVE_TINYXML@) +set(SOFA_GUI_QT_HAVE_QT6_CHARTS @SOFA_GUI_QT_HAVE_QT6_CHARTS@) +set(SOFA_GUI_QT_HAVE_QT6_WEBENGINECORE @SOFA_GUI_QT_HAVE_QT6_WEBENGINECORE@) + # This is needed to be able to find plugins/SofaGuiQt/lib/cmake/QGLViewer list(APPEND CMAKE_PREFIX_PATH "${CMAKE_CURRENT_LIST_DIR}/..") @@ -36,6 +39,15 @@ if(SOFA_GUI_QT_HAVE_QT5) endif() elseif(SOFA_GUI_QT_HAVE_QT6) find_package(Qt6 COMPONENTS Widgets OpenGLWidgets QUIET REQUIRED) + if(SOFA_GUI_QT_HAVE_QT6_CHARTS) + find_package(Qt6 QUIET REQUIRED Charts) + endif() + if(SOFA_GUI_QT_HAVE_QT6_WEBENGINECORE) + find_package(Qt6 QUIET REQUIRED Positioning WebChannel WebEngineCore WebEngineWidgets) + endif() + if(SOFA_GUI_QT_ENABLE_QGLVIEWER) + find_package(QGLViewer QUIET REQUIRED) + endif() endif() if(SOFA_GUI_QT_HAVE_NODEEDITOR) diff --git a/Sofa/GUI/Qt/libQGLViewer/QGLViewer/CMakeLists.txt b/Sofa/GUI/Qt/libQGLViewer/QGLViewer/CMakeLists.txt index 5735302b9b5..83c3c45cd89 100644 --- a/Sofa/GUI/Qt/libQGLViewer/QGLViewer/CMakeLists.txt +++ b/Sofa/GUI/Qt/libQGLViewer/QGLViewer/CMakeLists.txt @@ -2,12 +2,10 @@ cmake_minimum_required(VERSION 3.22) project(QGLViewer VERSION 2.8.0) # Same checks as Sofa.GUI.Qt -# i.e find Qt5, then if not, Qt6, then if not error -find_package(Qt5 COMPONENTS Core QUIET) -if (NOT Qt5Core_FOUND) - if(${CMAKE_VERSION} VERSION_GREATER "3.16.0") - find_package(Qt6 COMPONENTS Core CoreTools QUIET) - endif() +# i.e find Qt6, then if not, Qt5, then if not error +find_package(Qt6 COMPONENTS Core CoreTools QUIET) +if (NOT Qt6Core_FOUND) + find_package(Qt5 COMPONENTS Core QUIET) endif() if (Qt5Core_FOUND) diff --git a/Sofa/GUI/Qt/libQGLViewer/QGLViewer/QGLViewerConfig.cmake.in b/Sofa/GUI/Qt/libQGLViewer/QGLViewer/QGLViewerConfig.cmake.in index 8b2f77d8234..8bceae1ad69 100644 --- a/Sofa/GUI/Qt/libQGLViewer/QGLViewer/QGLViewerConfig.cmake.in +++ b/Sofa/GUI/Qt/libQGLViewer/QGLViewer/QGLViewerConfig.cmake.in @@ -3,8 +3,11 @@ @PACKAGE_INIT@ set(QGLVIEWER_HAVE_QT5_CORE @QGLVIEWER_HAVE_QT5_CORE@) +set(QGLVIEWER_HAVE_QT6_CORE @QGLVIEWER_HAVE_QT6_CORE@) -if(QGLVIEWER_HAVE_QT5_CORE) +if(QGLVIEWER_HAVE_QT6_CORE) + find_package(Qt6 COMPONENTS Widgets OpenGLWidgets QUIET REQUIRED) +elseif(QGLVIEWER_HAVE_QT5_CORE) find_package(Qt5 COMPONENTS Core Gui Xml OpenGL Widgets QUIET REQUIRED) endif() diff --git a/applications/plugins/SofaMatrix/CMakeLists.txt b/applications/plugins/SofaMatrix/CMakeLists.txt index 7e8ed6f0bde..5d8bb8e73dc 100644 --- a/applications/plugins/SofaMatrix/CMakeLists.txt +++ b/applications/plugins/SofaMatrix/CMakeLists.txt @@ -74,11 +74,9 @@ else() Sofa.GUI.Qt ) - find_package(Qt5 COMPONENTS Core QUIET) - if (NOT Qt5Core_FOUND) - if(${CMAKE_VERSION} VERSION_GREATER "3.16.0") - find_package(Qt6 COMPONENTS Core CoreTools QUIET) - endif() + find_package(Qt6 COMPONENTS Core CoreTools QUIET) + if (NOT Qt6Core_FOUND) + find_package(Qt5 COMPONENTS Core QUIET) endif() if(Qt5Core_FOUND) qt5_wrap_cpp(MOC_FILES ${MOC_HEADER_FILES}) diff --git a/applications/plugins/SofaMatrix/SofaMatrixConfig.cmake.in b/applications/plugins/SofaMatrix/SofaMatrixConfig.cmake.in index 652e963f6ef..4d6af409d84 100644 --- a/applications/plugins/SofaMatrix/SofaMatrixConfig.cmake.in +++ b/applications/plugins/SofaMatrix/SofaMatrixConfig.cmake.in @@ -5,6 +5,7 @@ set(SOFAMATRIX_HAVE_SOFA_GUI_QT @SOFAMATRIX_HAVE_SOFA_GUI_QT@) set(SOFAMATRIX_HAVE_QT5CORE @SOFAMATRIX_HAVE_QT5CORE@) +set(SOFAMATRIX_HAVE_QT6CORE @SOFAMATRIX_HAVE_QT6CORE@) find_package(Sofa.Core QUIET REQUIRED) find_package(Sofa.Component.Constraint.Lagrangian.Solver QUIET REQUIRED) @@ -17,6 +18,9 @@ endif() if(SOFAMATRIX_HAVE_QT5CORE) find_package(Qt5 COMPONENTS Core QUIET REQUIRED) endif() +if(SOFAMATRIX_HAVE_QT6CORE) + find_package(Qt6 COMPONENTS Core CoreTools QUIET) +endif() if(NOT TARGET @PROJECT_NAME@) include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") diff --git a/cmake/Modules/FindQGLViewer.cmake b/cmake/Modules/FindQGLViewer.cmake index cbf284d949a..796281298db 100644 --- a/cmake/Modules/FindQGLViewer.cmake +++ b/cmake/Modules/FindQGLViewer.cmake @@ -35,20 +35,18 @@ if(NOT TARGET QGLViewer) endif() # Same checks as Sofa.GUI.Qt - # i.e find Qt5, then if not, Qt6, then if not error - find_package(Qt5 COMPONENTS Core QUIET) - if (NOT Qt5Core_FOUND) - if(${CMAKE_VERSION} VERSION_GREATER "3.16.0") - find_package(Qt6 COMPONENTS Core CoreTools QUIET) - endif() + # i.e find Qt6, then if not, Qt5, then if not error + find_package(Qt6 COMPONENTS Core CoreTools QUIET) + if (NOT Qt6Core_FOUND) + find_package(Qt5 COMPONENTS Core QUIET) endif() if (Qt5Core_FOUND) - find_package(Qt5 COMPONENTS Core Charts Gui Xml OpenGL Widgets REQUIRED) - set(QT_TARGETS Qt5::Core Qt5::Charts Qt5::Gui Qt5::Xml Qt5::OpenGL Qt5::Widgets) + find_package(Qt5 COMPONENTS Core Gui Xml OpenGL Widgets REQUIRED) + set(QT_TARGETS Qt5::Core Qt5::Gui Qt5::Xml Qt5::OpenGL Qt5::Widgets) elseif (Qt6Core_FOUND) - find_package(Qt6 COMPONENTS Gui Charts GuiTools Widgets WidgetsTools OpenGLWidgets Xml REQUIRED) - set(QT_TARGETS ${QT_TARGETS} Qt::Core Qt::Charts Qt::Gui Qt::Widgets Qt::OpenGLWidgets Qt::Xml) + find_package(Qt6 COMPONENTS Gui GuiTools Widgets WidgetsTools OpenGLWidgets Xml REQUIRED) + set(QT_TARGETS ${QT_TARGETS} Qt::Core Qt::Gui Qt::Widgets Qt::OpenGLWidgets Qt::Xml) endif() if(QGLViewer_FOUND)