From 80fb4c8cc5d79ea8e9bed0a6c79eaa6e304a2e49 Mon Sep 17 00:00:00 2001 From: Olivier Roussel Date: Thu, 9 Nov 2023 14:10:36 +0100 Subject: [PATCH 1/4] Add cmake module for QGLViewer --- Sofa/GUI/Qt/CMakeLists.txt | 2 +- cmake/Modules/FindQGLViewer.cmake | 62 +++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 cmake/Modules/FindQGLViewer.cmake diff --git a/Sofa/GUI/Qt/CMakeLists.txt b/Sofa/GUI/Qt/CMakeLists.txt index 56256c3694d..8de94a80a93 100644 --- a/Sofa/GUI/Qt/CMakeLists.txt +++ b/Sofa/GUI/Qt/CMakeLists.txt @@ -74,7 +74,7 @@ if(Sofa.GL_FOUND) option(SOFA_GUI_QT_ENABLE_QGLVIEWER "Compile the QGLViewer for the Qt GUI" ON) if(SOFA_GUI_QT_ENABLE_QGLVIEWER) - find_package(QGLViewer QUIET) + find_package(QGLViewer) if(NOT QGLViewer_FOUND) add_subdirectory(libQGLViewer/QGLViewer) endif() diff --git a/cmake/Modules/FindQGLViewer.cmake b/cmake/Modules/FindQGLViewer.cmake new file mode 100644 index 00000000000..9dea2cbfa6b --- /dev/null +++ b/cmake/Modules/FindQGLViewer.cmake @@ -0,0 +1,62 @@ +# Find the QGLViewer headers and libraries +# Tries to find the library by looking at headers / lib file. +# +# Defines: +# QGLViewer_FOUND : True if QGLViewer is found +# +# Provides target QGLViewer. + +if(NOT QGLViewer_INCLUDE_DIR) + find_path(QGLViewer_INCLUDE_DIR + NAMES qglviewer.h + PATH_SUFFIXES include/QGLViewer + ) +endif() + +if(NOT QGLViewer_LIBRARY) +find_library(QGLViewer_LIBRARY + NAMES QGLViewer + PATH_SUFFIXES lib +) +endif() + +if(QGLViewer_INCLUDE_DIR AND QGLViewer_LIBRARY) + set(QGLViewer_FOUND TRUE) +else() + if(QGLViewer_FIND_REQUIRED) + message(FATAL_ERROR "Cannot find QGLViewer") + endif() +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() +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) +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) +endif() + +if(QGLViewer_FOUND) + set(QGLViewer_LIBRARIES ${QGLViewer_LIBRARY}) + set(QGLViewer_INCLUDE_DIRS ${QGLViewer_INCLUDE_DIR}) + + if(NOT QGLViewer_FIND_QUIETLY) + message(STATUS "Found QGLViewer: ${QGLVIEWER_LIBRARIES}") + endif(NOT QGLViewer_FIND_QUIETLY) + + if(NOT TARGET QGLViewer) + add_library(QGLViewer INTERFACE IMPORTED) + set_property(TARGET QGLViewer PROPERTY INTERFACE_LINK_LIBRARIES "${QGLViewer_LIBRARIES}" ${QT_TARGETS}) + set_property(TARGET QGLViewer PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${QGLViewer_INCLUDE_DIR}") + endif() +endif() +mark_as_advanced(QGLViewer_INCLUDE_DIR QGLViewer_LIBRARY) From 84edaa0123e36739077fe1c42efff71e240b5ab1 Mon Sep 17 00:00:00 2001 From: Olivier Roussel Date: Thu, 9 Nov 2023 15:12:12 +0100 Subject: [PATCH 2/4] Support library name for apt packages --- cmake/Modules/FindQGLViewer.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Modules/FindQGLViewer.cmake b/cmake/Modules/FindQGLViewer.cmake index 9dea2cbfa6b..0e1157379f3 100644 --- a/cmake/Modules/FindQGLViewer.cmake +++ b/cmake/Modules/FindQGLViewer.cmake @@ -15,7 +15,7 @@ endif() if(NOT QGLViewer_LIBRARY) find_library(QGLViewer_LIBRARY - NAMES QGLViewer + NAMES QGLViewer QGLViewer-qt5 PATH_SUFFIXES lib ) endif() From 719827d692ab885d8bfeba51136d257c46ad20a9 Mon Sep 17 00:00:00 2001 From: Olivier Roussel Date: Fri, 24 Nov 2023 16:05:10 +0100 Subject: [PATCH 3/4] Fix qglviewer cmake finder module to first seach for a config cmake file. --- cmake/Modules/FindQGLViewer.cmake | 109 ++++++++++++++++-------------- 1 file changed, 58 insertions(+), 51 deletions(-) diff --git a/cmake/Modules/FindQGLViewer.cmake b/cmake/Modules/FindQGLViewer.cmake index 0e1157379f3..166903d1cd9 100644 --- a/cmake/Modules/FindQGLViewer.cmake +++ b/cmake/Modules/FindQGLViewer.cmake @@ -1,62 +1,69 @@ # Find the QGLViewer headers and libraries -# Tries to find the library by looking at headers / lib file. +# Behavior is to first look for config files. +# If no config files were found, tries to find +# the library by looking at headers / lib file. # # Defines: # QGLViewer_FOUND : True if QGLViewer is found # # Provides target QGLViewer. -if(NOT QGLViewer_INCLUDE_DIR) - find_path(QGLViewer_INCLUDE_DIR - NAMES qglviewer.h - PATH_SUFFIXES include/QGLViewer +find_package(QGLViewer NO_MODULE QUIET) + +if(NOT TARGET QGLViewer) + + if(NOT QGLViewer_INCLUDE_DIR) + find_path(QGLViewer_INCLUDE_DIR + NAMES qglviewer.h + PATH_SUFFIXES include/QGLViewer + ) + endif() + + if(NOT QGLViewer_LIBRARY) + find_library(QGLViewer_LIBRARY + NAMES QGLViewer QGLViewer-qt5 + PATH_SUFFIXES lib ) -endif() - -if(NOT QGLViewer_LIBRARY) -find_library(QGLViewer_LIBRARY - NAMES QGLViewer QGLViewer-qt5 - PATH_SUFFIXES lib -) -endif() - -if(QGLViewer_INCLUDE_DIR AND QGLViewer_LIBRARY) - set(QGLViewer_FOUND TRUE) -else() - if(QGLViewer_FIND_REQUIRED) - message(FATAL_ERROR "Cannot find QGLViewer") endif() -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) + + if(QGLViewer_INCLUDE_DIR AND QGLViewer_LIBRARY) + set(QGLViewer_FOUND TRUE) + else() + if(QGLViewer_FIND_REQUIRED) + message(FATAL_ERROR "Cannot find QGLViewer") + endif() + 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() + 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) + 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) + endif() + + if(QGLViewer_FOUND) + set(QGLViewer_LIBRARIES ${QGLViewer_LIBRARY}) + set(QGLViewer_INCLUDE_DIRS ${QGLViewer_INCLUDE_DIR}) + + if(NOT QGLViewer_FIND_QUIETLY) + message(STATUS "Found QGLViewer: ${QGLVIEWER_LIBRARIES}") + endif(NOT QGLViewer_FIND_QUIETLY) + + if(NOT TARGET QGLViewer) + add_library(QGLViewer INTERFACE IMPORTED) + set_property(TARGET QGLViewer PROPERTY INTERFACE_LINK_LIBRARIES "${QGLViewer_LIBRARIES}" ${QT_TARGETS}) + set_property(TARGET QGLViewer PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${QGLViewer_INCLUDE_DIR}") endif() -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) -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) -endif() - -if(QGLViewer_FOUND) - set(QGLViewer_LIBRARIES ${QGLViewer_LIBRARY}) - set(QGLViewer_INCLUDE_DIRS ${QGLViewer_INCLUDE_DIR}) - - if(NOT QGLViewer_FIND_QUIETLY) - message(STATUS "Found QGLViewer: ${QGLVIEWER_LIBRARIES}") - endif(NOT QGLViewer_FIND_QUIETLY) - - if(NOT TARGET QGLViewer) - add_library(QGLViewer INTERFACE IMPORTED) - set_property(TARGET QGLViewer PROPERTY INTERFACE_LINK_LIBRARIES "${QGLViewer_LIBRARIES}" ${QT_TARGETS}) - set_property(TARGET QGLViewer PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${QGLViewer_INCLUDE_DIR}") endif() -endif() -mark_as_advanced(QGLViewer_INCLUDE_DIR QGLViewer_LIBRARY) + mark_as_advanced(QGLViewer_INCLUDE_DIR QGLViewer_LIBRARY) +endif() \ No newline at end of file From e505cf5c66a985143ca6547c4b48b4ff9dd3c14c Mon Sep 17 00:00:00 2001 From: Frederick Roy Date: Wed, 29 Nov 2023 18:29:17 +0900 Subject: [PATCH 4/4] Update cmake/Modules/FindQGLViewer.cmake Co-authored-by: Hugo --- cmake/Modules/FindQGLViewer.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Modules/FindQGLViewer.cmake b/cmake/Modules/FindQGLViewer.cmake index 166903d1cd9..cbf284d949a 100644 --- a/cmake/Modules/FindQGLViewer.cmake +++ b/cmake/Modules/FindQGLViewer.cmake @@ -66,4 +66,4 @@ if(NOT TARGET QGLViewer) endif() endif() mark_as_advanced(QGLViewer_INCLUDE_DIR QGLViewer_LIBRARY) -endif() \ No newline at end of file +endif()