From 66816a697d54b209802437f00c546d66fc1a847c Mon Sep 17 00:00:00 2001 From: Oscar Cowdery Lack Date: Wed, 17 Jan 2024 11:19:02 +1100 Subject: [PATCH] Allow configuring diag font path at build time This allows for better integration with distros that put the system font in a different directory. --- src/CMakeLists.txt | 8 ++++++++ src/CMakeModules/Bootstrap_Linux.cmake | 4 ---- src/core/diagnostics/osd_graph.cpp | 10 ++-------- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1b040081a0..162b49487e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,6 +12,14 @@ set(CASPARCG_DOWNLOAD_CACHE ${CMAKE_CURRENT_BINARY_DIR}/external CACHE STRING "D option(ENABLE_HTML "Enable HTML module, require CEF" ON) +set(DIAG_FONT_PATH "LiberationMono-Regular.ttf" CACHE STRING + "Path to font that will be used to load diag font at runtime. By default + this loads the font distribtued with the application from the working + directory. It can be set to an absolute path to instead load a font from + the system." +) +add_compile_definitions("DIAG_FONT_PATH=\"${DIAG_FONT_PATH}\"") + # Add custom cmake modules path SET (CASPARCG_PATCH_DIR ${CMAKE_SOURCE_DIR}/CMakeModules/patches) LIST (APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMakeModules) diff --git a/src/CMakeModules/Bootstrap_Linux.cmake b/src/CMakeModules/Bootstrap_Linux.cmake index 9c649e6a9a..4425faaed7 100644 --- a/src/CMakeModules/Bootstrap_Linux.cmake +++ b/src/CMakeModules/Bootstrap_Linux.cmake @@ -114,10 +114,6 @@ if (NOT USE_STATIC_BOOST) ADD_DEFINITIONS (-DBOOST_ALL_DYN_LINK) endif() -if (USE_SYSTEM_DIAG_FONT) - ADD_DEFINITIONS(-DUSE_SYSTEM_DIAG_FONT) -endif() - IF (NOT CMAKE_BUILD_TYPE STREQUAL "Debug") ADD_COMPILE_OPTIONS (-O3) # Needed for precompiled headers to work endif() diff --git a/src/core/diagnostics/osd_graph.cpp b/src/core/diagnostics/osd_graph.cpp index b14ceafee9..aac1a46dbf 100644 --- a/src/core/diagnostics/osd_graph.cpp +++ b/src/core/diagnostics/osd_graph.cpp @@ -66,14 +66,8 @@ sf::Font& get_default_font() { static sf::Font DEFAULT_FONT = []() { sf::Font font; -#ifdef USE_SYSTEM_DIAG_FONT - if (!font.loadFromFile("/usr/share/fonts/truetype/liberation/LiberationMono-Regular.ttf")) - CASPAR_THROW_EXCEPTION(file_not_found() << msg_info( - "/usr/share/fonts/truetype/liberation/LiberationMono-Regular.ttf not found")); -#else - if (!font.loadFromFile("LiberationMono-Regular.ttf")) - CASPAR_THROW_EXCEPTION(file_not_found() << msg_info("LiberationMono-Regular.ttf not found")); -#endif + if (!font.loadFromFile(DIAG_FONT_PATH)) + CASPAR_THROW_EXCEPTION(file_not_found() << msg_info(DIAG_FONT_PATH " not found")); return font; }();