From c8f4e524ba30f6148c6da83d0f23dd0f3fc68125 Mon Sep 17 00:00:00 2001 From: WarmUpTill <19472752+WarmUpTill@users.noreply.github.com> Date: Fri, 25 Sep 2026 21:00:47 +0200 Subject: [PATCH] Make deps/exprtk dependency optional --- CMakeLists.txt | 14 ++++++++++++-- lib/utils/math-helpers.cpp | 4 ++++ tests/CMakeLists.txt | 7 +++++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index df1e47c3..09c6086a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -383,8 +383,18 @@ target_precompile_headers(${LIB_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/lib/pch.hpp") target_include_directories( - ${LIB_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/deps/obs-websocket/lib" - "${CMAKE_CURRENT_SOURCE_DIR}/deps/exprtk") + ${LIB_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/deps/obs-websocket/lib") + +if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/deps/exprtk/exprtk.hpp") + target_include_directories(${LIB_NAME} + PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/deps/exprtk") + target_compile_definitions(${LIB_NAME} PRIVATE EXPRTK_SUPPORT=1) +else() + message( + STATUS + "${PROJECT_NAME}: deps/exprtk not found - math expression support disabled" + ) +endif() if(NOT nlohmann_json_DIR AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/deps/json/CMakeLists.txt") diff --git a/lib/utils/math-helpers.cpp b/lib/utils/math-helpers.cpp index fc014343..64d15268 100644 --- a/lib/utils/math-helpers.cpp +++ b/lib/utils/math-helpers.cpp @@ -2,13 +2,16 @@ #include "obs-module-helper.hpp" #include +#ifdef EXPRTK_SUPPORT #include #include +#endif namespace advss { std::variant EvalMathExpression(const std::string &expr) { +#ifdef EXPRTK_SUPPORT static auto randomFunc = []() { thread_local std::mt19937 gen(std::random_device{}()); thread_local std::uniform_real_distribution dis(0.0, @@ -26,6 +29,7 @@ std::variant EvalMathExpression(const std::string &expr) if (parser.compile(expr, expression)) { return expression.value(); } +#endif return std::string(obs_module_text( "AdvSceneSwitcher.math.expressionFail")) + " \"" + expr + "\""; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 97165712..e3d2fdcb 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -85,8 +85,11 @@ target_sources( ${PROJECT_NAME} PRIVATE test-math.cpp ${ADVSS_SOURCE_DIR}/lib/utils/math-helpers.cpp ${ADVSS_SOURCE_DIR}/lib/utils/obs-module-helper.cpp) -target_include_directories(${PROJECT_NAME} - PRIVATE ${ADVSS_SOURCE_DIR}/deps/exprtk) +if(EXISTS "${ADVSS_SOURCE_DIR}/deps/exprtk/exprtk.hpp") + target_include_directories(${PROJECT_NAME} + PRIVATE ${ADVSS_SOURCE_DIR}/deps/exprtk) + target_compile_definitions(${PROJECT_NAME} PRIVATE EXPRTK_SUPPORT=1) +endif() if(MSVC) target_compile_options(${PROJECT_NAME} PUBLIC /MP /d2FH4- /wd4267 /bigobj)