Skip to content

Commit

Permalink
[Sofa.GUI] Clean CMake variables (sofa-framework#2974)
Browse files Browse the repository at this point in the history
Clean all cmake var/options/names to follow the new guidelines and the new SOFA-NG module names
(fulfill some TODO written long ago as well)

+ Fix sofa-framework#2972

Remark/question: should we keep compatibility with all the cmake variables/options and preproc defines?
  • Loading branch information
fredroy authored Jun 1, 2022
1 parent 87e2b62 commit e70cc60
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 70 deletions.
8 changes: 4 additions & 4 deletions Sofa/GUI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ add_subdirectory(Component)
add_subdirectory(Common)
add_subdirectory(Batch)

option(SOFAGUI_QT "Compile the Qt GUI" ON)
if(SOFAGUI_QT)
option(SOFA_GUI_ENABLE_QT "Compile the Qt GUI" ON)
if(SOFA_GUI_ENABLE_QT)
add_subdirectory(Qt)
endif()

option(SOFAGUI_HEADLESS_RECORDER "Compile the headless recorder (Linux only)" OFF)
if(SOFAGUI_HEADLESS_RECORDER)
option(SOFA_GUI_ENABLE_HEADLESSRECORDER "Compile the headless recorder (Linux only)" OFF)
if(SOFA_GUI_ENABLE_HEADLESSRECORDER)
add_subdirectory(HeadlessRecorder)
endif()
64 changes: 28 additions & 36 deletions Sofa/GUI/Qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ if (NOT Qt5Core_FOUND)
endif()

if (Qt5Core_FOUND)
message("SofaGuiQt: will use Qt5")
message("${PROJECT_NAME}: will use Qt5")
sofa_find_package(Qt5 COMPONENTS Core Gui OpenGL REQUIRED)
set(QT_TARGETS ${QT_TARGETS} Qt5::Core Qt5::Gui Qt5::OpenGL)
elseif (Qt6Core_FOUND)
message("SofaGuiQt: will use Qt6 (beta)")
message("${PROJECT_NAME}: will use Qt6 (beta)")
sofa_find_package(Qt6 COMPONENTS Gui GuiTools Widgets WidgetsTools OpenGLWidgets REQUIRED)
set(QT_TARGETS ${QT_TARGETS} Qt::Core Qt::Gui Qt::Widgets Qt::OpenGLWidgets )
else()
message(SEND_ERROR "SofaGuiQt: Could not find either Qt5 or Qt6.")
message(SEND_ERROR "${PROJECT_NAME}: Could not find either Qt5 or Qt6.")
endif()

if (Qt5Core_FOUND)
Expand All @@ -34,13 +34,13 @@ if (Qt5Core_FOUND)
if(Qt5Charts_FOUND)
set(QT_TARGETS ${QT_TARGETS} Qt5::Charts)
else()
message(STATUS "SofaGuiQt: Qt5Charts not found. No chart nor Profile will be compiled")
message(STATUS "${PROJECT_NAME}: Qt5Charts not found. No chart nor Profile will be compiled")
endif()

# QDocBrowser
find_package(Qt5 COMPONENTS WebEngine QUIET) # if found, then QDocBrowser will be ON by default
option(SOFAGUIQT_ENABLE_QDOCBROWSER "Build the QDocBrowser. QtWebEngine is needed." ${Qt5WebEngine_FOUND})
if(SOFAGUIQT_ENABLE_QDOCBROWSER)
option(SOFA_GUI_QT_ENABLE_QDOCBROWSER "Build the QDocBrowser. QtWebEngine is needed." ${Qt5WebEngine_FOUND})
if(SOFA_GUI_QT_ENABLE_QDOCBROWSER)
sofa_find_package(Qt5 COMPONENTS WebEngine WebEngineWidgets REQUIRED BOTH_SCOPES)
set(QT_TARGETS ${QT_TARGETS} Qt5::WebEngine Qt5::WebEngineWidgets)
endif()
Expand All @@ -53,13 +53,13 @@ elseif (Qt6Core_FOUND)
# if(Qt6Charts_FOUND)
# set(QT_TARGETS ${QT_TARGETS} Qt::Charts)
# else()
# message(STATUS "SofaGuiQt: Qt6 Charts not found. No chart nor Profile will be compiled")
# message(STATUS "${PROJECT_NAME}: Qt6 Charts not found. No chart nor Profile will be compiled")
# endif()

# # QDocBrowser
# find_package(Qt6 COMPONENTS WebEngine QUIET) # if found, then QDocBrowser will be ON by default
# option(SOFAGUIQT_ENABLE_QDOCBROWSER "Build the QDocBrowser. QtWebEngine is needed." ${Qt6WebEngine_FOUND})
# if(SOFAGUIQT_ENABLE_QDOCBROWSER)
# option(SOFA_GUI_QT_ENABLE_QDOCBROWSER "Build the QDocBrowser. QtWebEngine is needed." ${Qt6WebEngine_FOUND})
# if(SOFA_GUI_QT_ENABLE_QDOCBROWSER)
# sofa_find_package(Qt6 COMPONENTS WebEngine WebEngineWidgets REQUIRED BOTH_SCOPES)
# set(QT_TARGETS ${QT_TARGETS} Qt::WebEngine Qt::WebEngineWidgets)
# endif()
Expand All @@ -69,47 +69,40 @@ find_package(Sofa.GL QUIET)
# QtViewer and QGLViewer
if(Sofa.GL_FOUND)
# QtViewer
# TODO: rename SOFAGUI_QTVIEWER into SOFAGUIQT_ENABLE_QTVIEWER
option(SOFAGUI_QTVIEWER "Compile the QtViewer for the Qt GUI" ON)
option(SOFA_GUI_QT_ENABLE_QTVIEWER "Compile the QtViewer for the Qt GUI" ON)

# QGLViewer
# TODO: rename SOFAGUI_QGLVIEWER into SOFAGUIQT_ENABLE_QGLVIEWER
option(SOFAGUI_QGLVIEWER "Compile the QGLViewer for the Qt GUI" ON)
option(SOFA_GUI_QT_ENABLE_QGLVIEWER "Compile the QGLViewer for the Qt GUI" ON)
# Remove the discard once qglviewer is compatible with Qt6 (if ever)
if(Qt6Core_FOUND)
message(WARNING "QGLViewer is not (yet?) compatible with Qt6")
set(SOFAGUI_QGLVIEWER OFF)
set(SOFA_GUI_QT_ENABLE_QGLVIEWER OFF)
endif()
if(SOFAGUI_QGLVIEWER)
if(SOFA_GUI_QT_ENABLE_QGLVIEWER)
find_package(QGLViewer QUIET)
if(NOT QGLViewer_FOUND)
add_subdirectory(libQGLViewer-2.7.1/QGLViewer)
endif()
endif()
else()
message(STATUS "Sofa.GL has not been activated, QtViewer/QGLViewer will be disabled.")
set(SOFAGUI_QTVIEWER OFF)
set(SOFAGUI_QGLVIEWER OFF)
set(SOFA_GUI_QT_ENABLE_QTVIEWER OFF)
set(SOFA_GUI_QT_ENABLE_QGLVIEWER OFF)
endif()

sofa_set_01(SOFA_GUI_QT_HAVE_QTVIEWER VALUE ${SOFAGUI_QTVIEWER} BOTH_SCOPES)
sofa_set_01(SOFA_GUI_QT_HAVE_QGLVIEWER VALUE ${SOFAGUI_QGLVIEWER} BOTH_SCOPES)

# VSync
# TODO: rename SOFAGUI_ENABLE_VSYNC into SOFAGUIQT_ENABLE_VSYNC
option(SOFA_GUI_QT_ENABLE_VSYNC "Enable vertical refresh sync" OFF)

# Qt native menu
# TODO: rename SOFAGUI_ENABLE_NATIVE_MENU into SOFAGUIQT_ENABLE_NATIVE_MENU
set(DEFAULT_SOFAGUI_ENABLE_NATIVE_MENU ON)
set(DEFAULT_SOFA_GUI_QT_ENABLE_NATIVE_MENU ON)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(DEFAULT_SOFAGUI_ENABLE_NATIVE_MENU OFF)
set(DEFAULT_SOFA_GUI_QT_ENABLE_NATIVE_MENU OFF)
endif()
option(SOFAGUI_ENABLE_NATIVE_MENU "Enable Qt to use the operating system's native menu for the Qt GUI" ${DEFAULT_SOFAGUI_ENABLE_NATIVE_MENU})
option(SOFA_GUI_QT_ENABLE_NATIVE_MENU "Enable Qt to use the operating system's native menu for the Qt GUI" ${DEFAULT_SOFA_GUI_QT_ENABLE_NATIVE_MENU})

# NodeEditor
option(SOFAGUIQT_ENABLE_NODEGRAPH "Build the Node graph representation. NodeEditor library is needed." OFF)
if(SOFAGUIQT_ENABLE_NODEGRAPH)
option(SOFA_GUI_QT_ENABLE_NODEGRAPH "Build the Node graph representation. NodeEditor library is needed." OFF)
if(SOFA_GUI_QT_ENABLE_NODEGRAPH)
sofa_find_package(NodeEditor REQUIRED BOTH_SCOPES)
endif()

Expand Down Expand Up @@ -255,13 +248,13 @@ if(Sofa.GL_FOUND)
)

# QtViewer
if(SOFAGUI_QTVIEWER)
if(SOFA_GUI_QT_ENABLE_QTVIEWER)
list(APPEND MOC_HEADER_FILES ${SRC_ROOT}/viewer/qt/QtViewer.h)
list(APPEND SOURCE_FILES ${SRC_ROOT}/viewer/qt/QtViewer.cpp)
endif()

# QGLViewer
if(SOFAGUI_QGLVIEWER)
if(SOFA_GUI_QT_ENABLE_QGLVIEWER)
list(APPEND MOC_HEADER_FILES ${SRC_ROOT}/viewer/qgl/QtGLViewer.h)
list(APPEND SOURCE_FILES ${SRC_ROOT}/viewer/qgl/QtGLViewer.cpp)
endif()
Expand All @@ -285,19 +278,19 @@ if(Qt5Charts_FOUND)
)
list(APPEND UI_FILES ${SRC_ROOT}/WindowProfiler.ui)
else()
message(STATUS "SofaGuiQt: QtCharts not found, SofaWindowProfiler will not be built.")
message(STATUS "${PROJECT_NAME}: QtCharts not found, SofaWindowProfiler will not be built.")
endif()

if(SOFAGUIQT_ENABLE_QDOCBROWSER)
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 "SofaGuiQt: Qt5WebEngine not found, QDocBrowser will not be built.")
message(STATUS "${PROJECT_NAME}: Qt5WebEngine not found, QDocBrowser will not be built.")
endif()


#NodeEditor
if (SOFAGUIQT_ENABLE_NODEGRAPH)
if (SOFA_GUI_QT_ENABLE_NODEGRAPH)
list(APPEND MOC_HEADER_FILES
${SRC_ROOT}/SofaWindowDataGraph.h
${SRC_ROOT}/dataGraph/SofaComponentNodeModel.h
Expand Down Expand Up @@ -338,19 +331,18 @@ if(SOFA_DUMP_VISITOR_INFO)
endif()

if(Sofa.GL_FOUND)
if(SOFAGUI_QGLVIEWER)
if(SOFA_GUI_QT_ENABLE_QGLVIEWER)
target_link_libraries(${PROJECT_NAME} PUBLIC QGLViewer)
endif()
endif()

if(SOFAGUIQT_ENABLE_NODEGRAPH)
if(SOFA_GUI_QT_ENABLE_NODEGRAPH)
target_link_libraries(${PROJECT_NAME} PUBLIC NodeEditor::nodes)
if (SOFA_BUILD_RELEASE_PACKAGE OR CMAKE_SYSTEM_NAME STREQUAL Windows)
sofa_install_libraries(TARGETS NodeEditor::nodes)
endif()
endif()


# FFMPEG
if(FFMPEG_EXEC_FOUND)
install(PROGRAMS "${FFMPEG_EXEC_FILE}" DESTINATION bin COMPONENT applications)
Expand Down
33 changes: 18 additions & 15 deletions Sofa/GUI/Qt/Sofa.GUI.QtConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
@PACKAGE_GUARD@
@PACKAGE_INIT@

set(SOFAGUIQT_HAVE_QT5 @SOFAGUIQT_HAVE_QT5@)
set(SOFAGUIQT_HAVE_QT6 @SOFAGUIQT_HAVE_QT6@)
set(SOFA_GUI_QT_HAVE_QT5 @SOFA_GUI_QT_HAVE_QT5@)
set(SOFA_GUI_QT_HAVE_QT6 @SOFA_GUI_QT_HAVE_QT6@)

set(SOFAGUIQT_HAVE_QTVIEWER @SOFAGUIQT_HAVE_QTVIEWER@)
set(SOFAGUIQT_HAVE_QGLVIEWER @SOFAGUIQT_HAVE_QGLVIEWER@)
set(SOFAGUIQT_HAVE_QT5_CHARTS @SOFAGUIQT_HAVE_QT5_CHARTS@)
set(SOFAGUIQT_HAVE_QT5_WEBENGINE @SOFAGUIQT_HAVE_QT5_WEBENGINE@)
set(SOFAGUIQT_HAVE_NODEEDITOR @SOFAGUIQT_HAVE_NODEEDITOR@)
set(SOFAGUIQT_HAVE_TINYXML @SOFAGUIQT_HAVE_TINYXML@)
set(SOFA_GUI_QT_ENABLE_QTVIEWER @SOFA_GUI_QT_ENABLE_QTVIEWER@)
set(SOFA_GUI_QT_ENABLE_QGLVIEWER @SOFA_GUI_QT_ENABLE_QGLVIEWER@)
set(SOFA_GUI_QT_ENABLE_NATIVE_MENU @SOFA_GUI_QT_ENABLE_NATIVE_MENU@)
set(SOFA_GUI_QT_ENABLE_VSYNC @SOFA_GUI_QT_ENABLE_VSYNC@)

set(SOFA_GUI_QT_HAVE_QT5_CHARTS @SOFA_GUI_QT_HAVE_QT5_CHARTS@)
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@)

# This is needed to be able to find plugins/SofaGuiQt/lib/cmake/QGLViewer
list(APPEND CMAKE_PREFIX_PATH "${CMAKE_CURRENT_LIST_DIR}/..")
Expand All @@ -20,25 +23,25 @@ find_package(Sofa.GUI.Common QUIET REQUIRED)
find_package(Sofa.Component.Visual QUIET REQUIRED)
find_package(Sofa.Component.SceneUtility QUIET REQUIRED)

if(SOFAGUIQT_HAVE_QT5)
if(SOFA_GUI_QT_HAVE_QT5)
find_package(Qt5 QUIET REQUIRED Core Gui OpenGL)
if(SOFAGUIQT_HAVE_QT5_CHARTS)
if(SOFA_GUI_QT_HAVE_QT5_CHARTS)
find_package(Qt5 QUIET REQUIRED Charts)
endif()
if(SOFAGUIQT_HAVE_QT5_WEBENGINE)
if(SOFA_GUI_QT_HAVE_QT5_WEBENGINE)
find_package(Qt5 QUIET REQUIRED WebEngine WebEngineWidgets)
endif()
if(SOFAGUIQT_HAVE_QGLVIEWER)
if(SOFA_GUI_QT_HAVE_QGLVIEWER)
find_package(QGLViewer QUIET REQUIRED)
endif()
elseif(SOFAGUIQT_HAVE_QT6)
elseif(SOFA_GUI_QT_HAVE_QT6)
find_package(Qt6 COMPONENTS Widgets OpenGLWidgets QUIET REQUIRED)
endif()

if(SOFAGUIQT_HAVE_NODEEDITOR)
if(SOFA_GUI_QT_HAVE_NODEEDITOR)
find_package(NodeEditor QUIET REQUIRED)
endif()
if(SOFAGUIQT_HAVE_TINYXML)
if(SOFA_GUI_QT_HAVE_TINYXML)
find_package(TinyXML QUIET REQUIRED)
endif()

Expand Down
2 changes: 1 addition & 1 deletion Sofa/GUI/Qt/src/sofa/gui/qt/DataWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ typedef sofa::helper::Factory<std::string, DataWidget, DataWidget::CreatorArgume
} //namespace sofa::gui::qt

//MOC_SKIP_BEGIN
#if !defined(SOFA_BUILD_SOFAGUIQT)
#if !defined(SOFA_BUILD_SOFA_GUI_QT)
namespace sofa::helper
{
//delay load of the specialized Factory class. unique definition reside in the cpp file
Expand Down
2 changes: 1 addition & 1 deletion Sofa/GUI/Qt/src/sofa/gui/qt/RealGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ void RealGUI::InitApplication( RealGUI* _gui)
QString pathIcon=(DataRepository.getFirstPath() + std::string( "/icons/SOFA.png" )).c_str();
application->setWindowIcon(QIcon(pathIcon));

if(SOFAGUI_ENABLE_NATIVE_MENU)
if(SOFA_GUI_QT_ENABLE_NATIVE_MENU)
{
// Use the OS'native menu instead of the Qt one
_gui->menubar->setNativeMenuBar(true);
Expand Down
15 changes: 9 additions & 6 deletions Sofa/GUI/Qt/src/sofa/gui/qt/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@

#include <sofa/config.h>

#cmakedefine01 SOFA_GUI_QT_HAVE_QTVIEWER
#cmakedefine01 SOFA_GUI_QT_HAVE_QGLVIEWER
#cmakedefine01 SOFA_GUI_QT_HAVE_QT5_CHARTS
#cmakedefine01 SOFA_GUI_QT_HAVE_QT5_WEBENGINE
#cmakedefine01 SOFA_GUI_QT_HAVE_NODEEDITOR
#cmakedefine01 SOFAGUI_ENABLE_NATIVE_MENU
#cmakedefine01 SOFA_GUI_QT_ENABLE_QTVIEWER
#cmakedefine01 SOFA_GUI_QT_ENABLE_QGLVIEWER
#cmakedefine01 SOFA_GUI_QT_ENABLE_NATIVE_MENU
#cmakedefine01 SOFA_GUI_QT_ENABLE_VSYNC

#cmakedefine01 SOFA_GUI_QT_HAVE_QT5_CHARTS
#cmakedefine01 SOFA_GUI_QT_HAVE_QT5_WEBENGINE

// Equals to SOFA_GUI_QT_ENABLE_NODEGRAPH
#cmakedefine01 SOFA_GUI_QT_HAVE_NODEEDITOR

#ifdef SOFA_BUILD_SOFA_GUI_QT
# define SOFA_GUI_QT_API SOFA_EXPORT_DYNAMIC_LIBRARY
#else
Expand Down
2 changes: 1 addition & 1 deletion Sofa/GUI/Qt/src/sofa/gui/qt/viewer/qgl/QtGLViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ QGLFormat QtGLViewer::setupGLFormat(const unsigned int nbMSAASamples)
f.setSamples(nbMSAASamples);
}

if(!SOFAGUI_ENABLE_NATIVE_MENU)
if(!SOFA_GUI_QT_ENABLE_VSYNC)
{
QSurfaceFormat format;
format.setSwapInterval(0);
Expand Down
2 changes: 1 addition & 1 deletion Sofa/GUI/Qt/src/sofa/gui/qt/viewer/qt/QtViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ QSurfaceFormat QtViewer::setupGLFormat(const unsigned int nbMSAASamples)
f.setSamples(static_cast<int>(nbMSAASamples));
}

if(!SOFAGUI_ENABLE_NATIVE_MENU)
if(!SOFA_GUI_QT_ENABLE_VSYNC)
{
f.setSwapInterval(0); // disable vertical refresh sync
}
Expand Down
5 changes: 1 addition & 4 deletions SofaGui/src/SofaGui/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
* *
* Contact information: [email protected] *
******************************************************************************/
#ifndef SOFAGUI_CONFIG_H
#define SOFAGUI_CONFIG_H
#pragma once

#include <sofa/config.h>

Expand All @@ -33,5 +32,3 @@
#else
# define SOFA_SOFAGUI_API SOFA_IMPORT_DYNAMIC_LIBRARY
#endif

#endif
2 changes: 1 addition & 1 deletion custom.cmake.example
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ endmacro()
# setSofaOption(APPLICATION_MODELER OFF)

# ON
# setSofaOption(SOFAGUI_QGLVIEWER ON)
# setSofaOption(SOFA_GUI_QT_ENABLE_QGLVIEWER ON)

0 comments on commit e70cc60

Please sign in to comment.