Skip to content

Commit ccd3f4e

Browse files
fredroyhugtalbot
andauthored
[Bindings.SofaGui] Fix compilation without compat layer (#331)
* fix config/compile w/o compat layer * add cmake message when searching for guis * remove useless dep sofa.gl * Cosmectic change in bindings/SofaGui/src/SofaPython3/SofaGui/Module_SofaGui.cpp Co-authored-by: Hugo <hugo.talbot@sofa-framework.org>
1 parent 003a68e commit ccd3f4e

3 files changed

Lines changed: 62 additions & 13 deletions

File tree

bindings/SofaGui/Bindings.SofaGuiConfig.cmake.in

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,20 @@
55

66
find_package(SofaPython3 QUIET REQUIRED COMPONENTS Plugin Bindings.Sofa)
77

8-
find_package(Sofa.GL QUIET REQUIRED)
98
find_package(Sofa.Core QUIET REQUIRED)
10-
find_package(SofaGui QUIET REQUIRED)
9+
find_package(Sofa.Gui.Common QUIET REQUIRED)
10+
11+
if(Sofa.GUI.Batch_FOUND)
12+
find_package(Sofa.GUI.Batch QUIET REQUIRED)
13+
endif()
14+
15+
if(Sofa.GUI.Qt_FOUND)
16+
find_package(Sofa.GUI.Qt QUIET REQUIRED)
17+
endif()
18+
19+
if(Sofa.GUI.HeadlessRecorder_FOUND)
20+
find_package(Sofa.GUI.HeadlessRecorder QUIET REQUIRED)
21+
endif()
1122

1223
# If we are importing this config file and the target is not yet there this is indicating that
1324
# target is an imported one. So we include it

bindings/SofaGui/CMakeLists.txt

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,34 @@ set(HEADER_FILES
1313
)
1414

1515
sofa_find_package(Sofa.Core REQUIRED)
16-
sofa_find_package(SofaGui REQUIRED)
17-
sofa_find_package(Sofa.GL REQUIRED)
16+
sofa_find_package(Sofa.GUI.Common REQUIRED) # to get the GUI mechanism
17+
18+
sofa_find_package(Sofa.GUI.Batch QUIET)
19+
if(Sofa.GUI.Batch_FOUND)
20+
list(APPEND SUPPORTED_GUIS Sofa.GUI.Batch)
21+
endif()
22+
sofa_find_package(Sofa.GUI.Qt QUIET)
23+
if(Sofa.GUI.Qt_FOUND)
24+
list(APPEND SUPPORTED_GUIS Sofa.GUI.Qt)
25+
endif()
26+
sofa_find_package(Sofa.GUI.HeadlessRecorder QUIET)
27+
if(Sofa.GUI.HeadlessRecorder_FOUND)
28+
list(APPEND SUPPORTED_GUIS Sofa.GUI.HeadlessRecorder)
29+
endif()
30+
31+
if(SUPPORTED_GUIS)
32+
message(STATUS "SofaPython3: Bindings.SofaGui will support: ${SUPPORTED_GUIS} .")
33+
else()
34+
message(WARNING "SofaPython3: No GUIs detected.")
35+
endif()
1836

1937
SP3_add_python_module(
2038
TARGET ${PROJECT_NAME}
2139
MODULE Gui
2240
DESTINATION Sofa
2341
SOURCES ${SOURCE_FILES}
2442
HEADERS ${HEADER_FILES}
25-
DEPENDS Sofa.Core SofaGui SofaPython3::Plugin SofaPython3::Bindings.Sofa.Core
43+
DEPENDS Sofa.Core Sofa.GUI.Common SofaPython3::Plugin SofaPython3::Bindings.Sofa.Core ${SUPPORTED_GUIS}
2644
)
2745

2846
sofa_create_component_in_package_with_targets(

bindings/SofaGui/src/SofaPython3/SofaGui/Module_SofaGui.cpp

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,28 @@
2020

2121
#include <pybind11/pybind11.h>
2222

23-
#include <SofaGui/initSofaGui.h>
2423
#include <sofa/core/init.h>
2524
#include <sofa/helper/logging/Messaging.h>
2625
#include <sofa/helper/Utils.h>
2726
#include <sofa/helper/system/FileSystem.h>
2827
using sofa::helper::system::FileSystem;
2928

30-
#if SOFAGUI_HAVE_SOFA_GUI_QT
29+
#if __has_include(<sofa/gui/batch/init.h>)
30+
#include <sofa/gui/batch/init.h>
31+
#define HAS_GUI_BATCH
32+
#endif
33+
34+
#if __has_include(<sofa/gui/qt/init.h>)
35+
#include <sofa/gui/qt/init.h>
3136
#include <sofa/gui/qt/qt.conf.h>
32-
#endif // SOFAGUI_HAVE_SOFA_GUI_QT
37+
#define HAS_GUI_QT
38+
#endif
39+
40+
#if __has_include(<sofa/gui/headlessrecorder/init.h>)
41+
#include <sofa/gui/headlessrecorder/init.h>
42+
#define HAS_GUI_HEADLESSRECORDER
43+
#endif
44+
3345

3446
#include "Binding_BaseGui.h"
3547
#include "Binding_GUIManager.h"
@@ -63,7 +75,7 @@ PYBIND11_MODULE(Gui, m) {
6375
:members:
6476
)doc";
6577

66-
#if SOFAGUI_HAVE_SOFA_GUI_QT
78+
#ifdef HAS_GUI_QT
6779
std::string sofaPrefixAbsolute = sofa::helper::Utils::getSofaPathPrefix();
6880
std::string inputFilepath = FileSystem::cleanPath(sofaPrefixAbsolute + "/bin/qt.conf");
6981
bool success = sofa::gui::qt::loadQtConfWithCustomPrefix(inputFilepath, sofaPrefixAbsolute);
@@ -82,11 +94,19 @@ PYBIND11_MODULE(Gui, m) {
8294
}
8395
std::cout << std::endl;
8496
}
85-
#endif // SOFAGUI_HAVE_SOFA_GUI_QT
97+
#endif // HAS_GUI_QT
98+
99+
// forcefullly link libraries at compile-time
100+
#ifdef HAS_GUI_BATCH
101+
sofa::gui::batch::init();
102+
#endif
103+
#ifdef HAS_GUI_QT
104+
sofa::gui::qt::init();
105+
#endif
106+
#ifdef HAS_GUI_HEADLESSRECORDER
107+
sofa::gui::headlessrecorder::init();
108+
#endif
86109

87-
// This is needed to make sure the GuiMain library (libSofaGuiMain.so) is correctly
88-
// linked since the GUIs are statically created during the load of the library.
89-
sofa::gui::initSofaGui();
90110
sofa::core::init();
91111

92112
moduleAddBaseGui(m);

0 commit comments

Comments
 (0)