Skip to content
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

[Sofa.GUI.Qt] Add cmake module for QGLViewer #4290

Merged
merged 4 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
2 changes: 1 addition & 1 deletion Sofa/GUI/Qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
69 changes: 69 additions & 0 deletions cmake/Modules/FindQGLViewer.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Find the QGLViewer headers and libraries
# 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.

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(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)
endif()
fredroy marked this conversation as resolved.
Show resolved Hide resolved
Loading