Skip to content

Commit

Permalink
[CMake] Start finding Qt6 then Qt5 (sofa-framework#4686)
Browse files Browse the repository at this point in the history
* [CMake] Start finding Qt6 then Qt5

* fix various qt6 as default problems

---------

Co-authored-by: Frederick Roy <[email protected]>
Co-authored-by: Paul Baksic <[email protected]>
  • Loading branch information
3 people authored May 13, 2024
1 parent 2124785 commit 755b657
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 37 deletions.
27 changes: 12 additions & 15 deletions Sofa/GUI/Qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()


Expand Down
12 changes: 12 additions & 0 deletions Sofa/GUI/Qt/Sofa.GUI.QtConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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}/..")

Expand All @@ -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)
Expand Down
10 changes: 4 additions & 6 deletions Sofa/GUI/Qt/libQGLViewer/QGLViewer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion Sofa/GUI/Qt/libQGLViewer/QGLViewer/QGLViewerConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
8 changes: 3 additions & 5 deletions applications/plugins/SofaMatrix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
4 changes: 4 additions & 0 deletions applications/plugins/SofaMatrix/SofaMatrixConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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}/@[email protected]")
Expand Down
18 changes: 8 additions & 10 deletions cmake/Modules/FindQGLViewer.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 755b657

Please sign in to comment.