Skip to content

Commit

Permalink
Dependencies: Make dmon and tinyfiledialogs optional (#1792)
Browse files Browse the repository at this point in the history
* Dependencies: Make dmon and tinyfiledialogs optional
  • Loading branch information
mwestphal authored Dec 16, 2024
1 parent df62746 commit 93c2a3e
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .github/actions/generic-ci/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ runs:
-DF3D_MODULE_EXR=${{ inputs.optional_deps_label == 'optional-deps' && 'ON' || 'OFF' }}
-DF3D_MODULE_RAYTRACING=${{ inputs.raytracing_label == 'raytracing' && 'ON' || 'OFF' }}
-DF3D_MODULE_UI=${{ inputs.optional_deps_label == 'optional-deps' && 'ON' || 'OFF' }}
-DF3D_MODULE_DMON=${{ inputs.optional_deps_label == 'optional-deps' && 'ON' || 'OFF' }}
-DF3D_MODULE_TINYFILEDIALOGS=${{ inputs.optional_deps_label == 'optional-deps' && 'ON' || 'OFF' }}
-DF3D_PLUGINS_STATIC_BUILD=${{ inputs.bundle_label == 'bundle' && 'ON' || 'OFF' }}
-DF3D_PLUGIN_BUILD_ALEMBIC=${{ inputs.optional_deps_label == 'optional-deps' && 'ON' || 'OFF' }}
-DF3D_PLUGIN_BUILD_ASSIMP=${{ inputs.optional_deps_label == 'optional-deps' && 'ON' || 'OFF' }}
Expand Down
8 changes: 5 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ mark_as_advanced(F3D_EXCLUDE_DEPRECATED)
option(F3D_MODULE_RAYTRACING "Raytracing module" OFF)
option(F3D_MODULE_EXR "OpenEXR images module" OFF)
option(F3D_MODULE_UI "ImGui widgets module" ON)
option(F3D_MODULE_DMON "dmon (watch) module" ON)
option(F3D_MODULE_TINYFILEDIALOGS "tinyfiledialogs module" ON)

# Use externals
option(F3D_USE_EXTERNAL_CXXOPTS "Use external cxxopts dependency" OFF)
option(F3D_USE_EXTERNAL_NLOHMANN_JSON "Use external nlohmann_json dependency" OFF)
option(F3D_USE_EXTERNAL_DMON "Use external dmon dependency" OFF)
option(F3D_USE_EXTERNAL_IMGUI "Use external imgui dependency" OFF)
cmake_dependent_option(F3D_USE_EXTERNAL_DMON "Use external dmon dependency" OFF "F3D_MODULE_DMON" OFF)
cmake_dependent_option(F3D_USE_EXTERNAL_IMGUI "Use external imgui dependency" OFF "F3D_MODULE_UI" OFF)

if (F3D_USE_EXTERNAL_CXXOPTS)
find_package(cxxopts REQUIRED)
Expand All @@ -72,7 +74,7 @@ endif ()
if (F3D_USE_EXTERNAL_DMON)
find_package(dmon REQUIRED)
endif ()
if (F3D_MODULE_UI AND F3D_USE_EXTERNAL_IMGUI)
if (F3D_USE_EXTERNAL_IMGUI)
find_package(imgui REQUIRED)
endif ()

Expand Down
20 changes: 16 additions & 4 deletions application/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ else ()
target_include_directories(f3d PUBLIC $<BUILD_INTERFACE:${F3D_SOURCE_DIR}/external/nlohmann_json>)
endif ()

if (F3D_USE_EXTERNAL_DMON)
target_link_libraries(f3d PRIVATE dmon::dmon)
else ()
target_include_directories(f3d PUBLIC $<BUILD_INTERFACE:${F3D_SOURCE_DIR}/external/dmon>)
if (F3D_MODULE_DMON)
if (F3D_USE_EXTERNAL_DMON)
target_link_libraries(f3d PRIVATE dmon::dmon)
else ()
target_include_directories(f3d PUBLIC $<BUILD_INTERFACE:${F3D_SOURCE_DIR}/external/dmon>)
endif ()
endif ()

target_include_directories(f3d PUBLIC $<BUILD_INTERFACE:${F3D_SOURCE_DIR}/external/tinyfiledialogs>)
Expand Down Expand Up @@ -111,6 +113,16 @@ if (F3D_MODULE_EXR)
target_compile_definitions(f3d PRIVATE F3D_MODULE_EXR)
endif ()

# dmon
if (F3D_MODULE_DMON)
target_compile_definitions(f3d PRIVATE F3D_MODULE_DMON)
endif ()

# tinyfiledialogs
if (F3D_MODULE_TINYFILEDIALOGS)
target_compile_definitions(f3d PRIVATE F3D_MODULE_TINYFILEDIALOGS)
endif ()

if(VTK_VERSION VERSION_LESS 9.3.20240914)
# Headless EGL build
if (VTK_OPENGL_HAS_EGL)
Expand Down
6 changes: 4 additions & 2 deletions application/F3DOptionsTools.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ static inline const std::array<CLIGroup, 8> CLIOptions = {{
{ "no-render", "", "Do not read the configuration file", "<bool>", "1" },
{ "rendering-backend", "", "Backend to use when rendering (auto|glx|wgl|egl|osmesa)", "<string>", "" },
{ "max-size", "", "Maximum size in Mib of a file to load, negative value means unlimited", "<size in Mib>", "" },
#if F3D_MODULE_DMON
{ "watch", "", "Watch current file and automatically reload it whenever it is modified on disk", "<bool>", "1" },
#endif
{ "frame-rate", "", "Frame rate used to refresh animation and other repeated tasks (watch, UI). Does not impact rendering frame rate.", "<fps>", "" },
{ "load-plugins", "", "List of plugins to load separated with a comma", "<paths or names>", "" },
{ "scan-plugins", "", "Scan standard directories for plugins and display available plugins (result can be incomplete)", "", "" },
Expand All @@ -95,8 +97,8 @@ static inline const std::array<CLIGroup, 8> CLIOptions = {{
{ "animation-index", "", "Select animation to show", "<index>", "" },
{ "animation-speed-factor", "", "Set animation speed factor", "<factor>", "" },
{ "animation-time", "", "Set animation time to load", "<time>", "" },
{"font-file", "", "Path to a FreeType compatible font file", "<file_path>", ""},
{"command-script", "", "Path to a script file containing commands to execute", "<file_path>", "" } } },
{"font-file", "", "Path to a FreeType compatible font file", "<file_path>", ""},
{"command-script", "", "Path to a script file containing commands to execute", "<file_path>", "" } } },
{ "Material",
{ {"point-sprites", "o", "Show sphere sprites instead of surfaces", "<bool>", "1" },
{"point-sprites-type", "", "Point sprites type", "<sphere|gaussian>", ""},
Expand Down
25 changes: 23 additions & 2 deletions application/F3DStarter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "F3DPluginsTools.h"
#include "F3DSystemTools.h"

#if F3D_MODULE_DMON
#define DMON_IMPL
#ifdef WIN32
#pragma warning(push)
Expand All @@ -26,8 +27,11 @@
#else
#include "dmon.h"
#endif
#endif

#if F3D_MODULE_TINYFILEDIALOGS
#include "tinyfiledialogs.h"
#endif

#include "engine.h"
#include "interactor.h"
Expand Down Expand Up @@ -218,6 +222,7 @@ class F3DStarter::F3DInternals
}
}

#if F3D_MODULE_DMON
static void dmonFolderChanged(
dmon_watch_id, dmon_action, const char*, const char* filename, const char*, void* userData)
{
Expand All @@ -230,6 +235,7 @@ class F3DStarter::F3DInternals
self->Internals->ReloadFileRequested = true;
}
}
#endif

void addOutputImageMetadata(f3d::image& image)
{
Expand Down Expand Up @@ -672,7 +678,9 @@ class F3DStarter::F3DInternals
interactor.addBinding({ mod_t::NONE, "Up" }, "reload_current_file_group", "Others", std::bind(docString, "Reload current file group"));
interactor.addBinding({ mod_t::NONE, "Down" }, "add_current_directories", "Others", std::bind(docString, "Add files from dir of current file"));
interactor.addBinding({ mod_t::NONE, "F12" }, "take_screenshot", "Others", std::bind(docString, "Take a screenshot"));
#if F3D_MODULE_TINYFILEDIALOGS
interactor.addBinding({ mod_t::CTRL, "O" }, "open_file_dialog", "Others", std::bind(docString, "Open File Dialog"));
#endif
interactor.addBinding({ mod_t::CTRL, "F12" }, "take_minimal_screenshot", "Others", std::bind(docString, "Take a minimal screenshot"));

// This replace an existing default binding command in the libf3d
Expand Down Expand Up @@ -756,11 +764,13 @@ class F3DStarter::F3DInternals
std::unique_ptr<f3d::engine> Engine;
std::vector<std::vector<fs::path>> FilesGroups;
std::vector<fs::path> LoadedFiles;
std::vector<dmon_watch_id> FolderWatchIds;
int CurrentFilesGroupIndex = -1;

// dmon used atomic and mutex
#if F3D_MODULE_DMON
// dmon related
std::mutex LoadedFilesMutex;
std::vector<dmon_watch_id> FolderWatchIds;
#endif

// Event loop atomics
std::atomic<bool> ReloadFileRequested = false;
Expand All @@ -770,15 +780,19 @@ class F3DStarter::F3DInternals
F3DStarter::F3DStarter()
: Internals(std::make_unique<F3DStarter::F3DInternals>())
{
#if F3D_MODULE_DMON
// Initialize dmon
dmon_init();
#endif
}

//----------------------------------------------------------------------------
F3DStarter::~F3DStarter()
{
#if F3D_MODULE_DMON
// deinit dmon
dmon_deinit();
#endif
}

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -1180,8 +1194,10 @@ void F3DStarter::LoadFileGroup(
std::vector<fs::path> localPaths;
try
{
#if F3D_MODULE_DMON
// In the main thread, we only need to guard writing
const std::lock_guard<std::mutex> lock(this->Internals->LoadedFilesMutex);
#endif

if (clear)
{
Expand Down Expand Up @@ -1280,6 +1296,7 @@ void F3DStarter::LoadFileGroup(
filenameInfo += " [+UNSUPPORTED]";
}

#if F3D_MODULE_DMON
// Update dmon watch logic
if (this->Internals->AppOptions.Watch)
{
Expand All @@ -1299,6 +1316,7 @@ void F3DStarter::LoadFileGroup(
dmon_watch(parentPath.string().c_str(), &F3DInternals::dmonFolderChanged, 0, this));
}
}
#endif
}
else
{
Expand Down Expand Up @@ -1625,6 +1643,8 @@ void F3DStarter::AddCommands()
this->LoadFileGroup(index);
}
});

#if F3D_MODULE_TINYFILEDIALOGS
interactor.addCommand("open_file_dialog",
[this](const std::vector<std::string>&)
{
Expand Down Expand Up @@ -1660,5 +1680,6 @@ void F3DStarter::AddCommands()
}
}
});
#endif
interactor.addCommand("exit", [&](const std::vector<std::string>&) { interactor.stop(); });
}
7 changes: 5 additions & 2 deletions application/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,6 @@ f3d_test(NAME TestInteractionZoomToggleOrthographicProjection DATA cow.vtp INTER
f3d_test(NAME TestInteractionRotateCameraMinus90 DATA f3d.glb INTERACTION)
f3d_test(NAME TestInteractionRotateCamera90 DATA f3d.glb INTERACTION)
f3d_test(NAME TestInteractionPanWithShift DATA f3d.glb INTERACTION) #Shift;LeftMouse;MouseMovements
f3d_test(NAME TestInteractionFileOpen INTERACTION NO_BASELINE ENV CTEST_OPEN_DIALOG_FILE=${F3D_SOURCE_DIR}/testing/data/cow.vtp)
f3d_test(NAME TestInteractionConsoleOpen DATA f3d.glb INTERACTION UI) #Escape
f3d_test(NAME TestInteractionConsoleOpenExit DATA f3d.glb REGEXP "Interactor has been stopped" INTERACTION NO_BASELINE UI) #Escape;exit;Return
f3d_test(NAME TestInteractionConsoleOpenWarningKeyboard DATA f3d.glb ARGS --position=0 INTERACTION UI) #Escape
Expand All @@ -817,6 +816,10 @@ f3d_test(NAME TestInteractionConsoleInvalidCommand DATA f3d.glb INTERACTION UI)
f3d_test(NAME TestInteractionConsoleInvalidOption DATA f3d.glb INTERACTION UI) #Escape;toggle foo;Return
f3d_test(NAME TestInteractionConsoleTypingSceneInfo DATA f3d.glb INTERACTION UI) #Escape;e;Escape;printt;BackSpace;_scee;Left;Right;_info;Return

if (F3D_MODULE_TINYFILEDIALOGS)
f3d_test(NAME TestInteractionFileOpen INTERACTION NO_BASELINE ENV CTEST_OPEN_DIALOG_FILE=${F3D_SOURCE_DIR}/testing/data/cow.vtp)
endif ()

# Progress test
f3d_test(NAME TestProgress DATA cow.vtp ARGS --progress NO_BASELINE)
f3d_test(NAME TestProgressScene DATA WaterBottle.glb ARGS --progress NO_BASELINE)
Expand Down Expand Up @@ -1152,7 +1155,7 @@ endif()

# Watch testing require GLX rendering on Linux
# SIGTERM is not caught with VTK 9.2.6 for some reason
if(WIN32 OR APPLE OR (F3D_TESTING_ENABLE_GLX_TESTS AND VTK_VERSION VERSION_GREATER_EQUAL 9.3.0))
if(F3D_MODULE_DMON AND (WIN32 OR APPLE OR (F3D_TESTING_ENABLE_GLX_TESTS AND VTK_VERSION VERSION_GREATER_EQUAL 9.3.0)))
if(UNIX)
set(_f3d_os_script_ext "sh")
set(_f3d_os_script_exec "")
Expand Down
5 changes: 3 additions & 2 deletions doc/dev/BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ please take a look at our [getting started guide](GETTING_STARTED.md).
* [VTK](https://vtk.org) >= 9.2.6 (9.3.1 recommended).
* A C++17 compiler.
* A CMake-compatible build system (Visual Studio, XCode, Ninja, Make, etc.).
* Optionally (but recommended), [ImGui](https://github.com/ocornut/imgui/) >= 1.91.5.
* Optionally, [Assimp](https://www.assimp.org/) >= 5.0.
* Optionally, Open CASCADE [OCCT](https://dev.opencascade.org/) >= 7.5.2.
* Optionally, [Alembic](http://www.alembic.io/) >= 1.7.
Expand Down Expand Up @@ -43,7 +42,7 @@ Some modules, plugins and language bindings depending on external libraries can

* `F3D_MODULE_RAYTRACING`: Support for raytracing rendering. Requires that VTK has been built with `OSPRay` and `VTK_MODULE_ENABLE_VTK_RenderingRayTracing` turned on. Disabled by default.
* `F3D_MODULE_EXR`: Support for OpenEXR images. Requires `OpenEXR`. Disabled by default.
* `F3D_MODULE_UI`: Support for ImGui widgets. Requires `ImGui`. Enabled by default.
* `F3D_MODULE_UI`: Support for ImGui widgets. Uses provided ImGui. Enabled by default.
* `F3D_PLUGIN_BUILD_EXODUS`: Support for ExodusII (.ex2) file format. Requires that VTK has been built with `IOExodus` module (and `hdf5`). Enabled by default.
* `F3D_PLUGIN_BUILD_OCCT`: Support for STEP, IGES, BREP, and XBF file formats. Requires `OpenCASCADE`. Disabled by default.
* `F3D_PLUGIN_BUILD_ASSIMP`: Support for FBX, DAE, OFF, DXF, X and 3MF file formats. Requires `Assimp`. Disabled by default.
Expand All @@ -54,6 +53,8 @@ Some modules, plugins and language bindings depending on external libraries can
* `F3D_BINDINGS_PYTHON`: Generate python bindings (requires `Python` and `pybind11`). Disabled by default.
* `F3D_BINDINGS_JAVA`: Generate java bindings (requires `Java` and `JNI`). Disabled by default.

Some dependencies are provided internally, eg: ImGui, dmon and others. Use `F3D_USE_EXTERNAL_*` to use an external version of these libraries.

## VCPKG

It's possible to use VCPKG to automatically build dependencies. A manifest file `vcpkg.json` is available at your convenience. Please read [VCPKG documentation](https://vcpkg.io/en/getting-started.html).
Expand Down

0 comments on commit 93c2a3e

Please sign in to comment.