diff --git a/CMakeLists.txt b/CMakeLists.txt index 57fc958..50b788c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,10 @@ cmake_minimum_required (VERSION 3.25) set(CMAKE_CXX_STANDARD 20) -set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") +# Allow runtime library to be set externally; default to dynamic if not set +if(NOT CMAKE_MSVC_RUNTIME_LIBRARY) + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") +endif() set(INCLUDES "Include") # Enable Hot Reload for MSVC compilers if supported. @@ -17,6 +20,7 @@ endif() project ("SRAL") option (BUILD_SRAL_TEST "Build SRAL examples/tests" ON) +option (SRAL_DISABLE_UIA "Disable UIA (UI Automation) support" OFF) add_library(${PROJECT_NAME}_obj OBJECT) target_sources(${PROJECT_NAME}_obj PRIVATE "SRC/Encoding.h" "SRC/Encoding.cpp" @@ -29,8 +33,12 @@ if(WIN32) target_sources(${PROJECT_NAME}_obj PRIVATE "SRC/NVDA.h" "SRC/NVDA.cpp" "SRC/SAPI.h" "SRC/SAPI.cpp" "Dep/blastspeak.h" "Dep/blastspeak.c" "Dep/fsapi.h" "Dep/fsapi.c" "Dep/nvda_control.h" "Dep/nvda_control.c" - "SRC/Jaws.h" "SRC/Jaws.cpp" "SRC/UIA.cpp" - "Dep/UIAProvider.h" "Dep/UIAProvider.cpp" "Dep/wasapi.h" "Dep/wasapi.cpp" "SRC/ZDSR.h" "SRC/ZDSR.cpp") + "SRC/Jaws.h" "SRC/Jaws.cpp" + "Dep/wasapi.h" "Dep/wasapi.cpp" "SRC/ZDSR.h" "SRC/ZDSR.cpp") + if(NOT SRAL_DISABLE_UIA) + target_sources(${PROJECT_NAME}_obj PRIVATE + "SRC/UIA.cpp" "Dep/UIAProvider.h" "Dep/UIAProvider.cpp") + endif() elseif(APPLE) target_sources(${PROJECT_NAME}_obj PRIVATE "SRC/AVSpeech.h" "SRC/AVSpeech.mm" "SRC/VoiceOver.h" "SRC/VoiceOver.mm") @@ -43,6 +51,9 @@ set_property(TARGET ${PROJECT_NAME}_obj PROPERTY POSITION_INDEPENDENT_CODE on) # TODO: Probably we shouldn't simply suppress these warnings target_compile_definitions(${PROJECT_NAME}_obj PRIVATE _CRT_SECURE_NO_WARNINGS) +if(SRAL_DISABLE_UIA) + target_compile_definitions(${PROJECT_NAME}_obj PRIVATE SRAL_NO_UIA) +endif() if(BUILD_SHARED_LIBS) add_library(${PROJECT_NAME} SHARED @@ -81,11 +92,13 @@ if (WIN32) if (BUILD_SRAL_TEST) add_executable(${PROJECT_NAME}_NVDAControleExConsole "Examples/C/NVDAControlExConsole.c" "Dep/nvda_control.c") endif() - set(LIBS "uiautomationcore.lib") - if(BUILD_SHARED_LIBS) - target_link_libraries(${PROJECT_NAME} ${LIBS}) - endif() - target_link_libraries(${PROJECT_NAME}_static ${LIBS}) + if(NOT SRAL_DISABLE_UIA) + set(LIBS "uiautomationcore.lib") + if(BUILD_SHARED_LIBS) + target_link_libraries(${PROJECT_NAME} ${LIBS}) + endif() + target_link_libraries(${PROJECT_NAME}_static ${LIBS}) + endif() elseif (APPLE) enable_language(OBJCXX) set(CMAKE_C_COMPILER clang) diff --git a/SRC/SRAL.cpp b/SRC/SRAL.cpp index f1a2455..1a45572 100644 --- a/SRC/SRAL.cpp +++ b/SRC/SRAL.cpp @@ -7,7 +7,9 @@ #include "ZDSR.h" #include "SAPI.h" #include "Jaws.h" +#ifndef SRAL_NO_UIA #include "UIA.h" +#endif #include #include #elif defined(__APPLE__) @@ -219,7 +221,9 @@ extern "C" SRAL_API bool SRAL_Initialize(int engines_exclude) { g_engines[SRAL_ENGINE_NVDA] = std::make_unique(); g_engines[SRAL_ENGINE_JAWS] = std::make_unique(); g_engines[SRAL_ENGINE_ZDSR] = std::make_unique(); +#ifndef SRAL_NO_UIA g_engines[SRAL_ENGINE_UIA] = std::make_unique(); +#endif g_engines[SRAL_ENGINE_SAPI] = std::make_unique(); #elif defined(__APPLE__) g_engines[SRAL_ENGINE_VOICE_OVER] = std::make_unique(); @@ -317,7 +321,7 @@ static BOOL FindProcess(const wchar_t* name) { #endif static void speech_engine_update() { if (!g_currentEngine || !g_currentEngine->GetActive() || g_currentEngine->GetNumber() == SRAL_ENGINE_SAPI || g_currentEngine->GetNumber() == SRAL_ENGINE_UIA || g_currentEngine->GetNumber() == SRAL_ENGINE_AV_SPEECH) { -#ifdef _WIN32 +#if defined(_WIN32) && !defined(SRAL_NO_UIA) if (FindProcess(L"narrator.exe") == TRUE) { g_currentEngine = get_engine(SRAL_ENGINE_UIA); return; @@ -330,10 +334,10 @@ static void speech_engine_update() { break; } } +#if defined(_WIN32) && !defined(SRAL_NO_UIA) } -#ifdef _WIN32 - } #endif + } } extern "C" SRAL_API bool SRAL_Speak(const char* text, bool interrupt) {