From 1376180b6acd2964cc60e12ac5080728de4499c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna=20=E2=80=9CCyberTailor=E2=80=9D?= Date: Sat, 27 Jan 2024 05:26:24 +0500 Subject: [PATCH] build: CMake: Add option to prefer static libs Enabled by default on Windows. --- CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c8ba57859..7d0b606562 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,6 +84,7 @@ option(ENABLE_GUI "Enable Qt-based GUI" OFF) option(ENABLE_DOCS "Build Doxygen documentation" OFF) option(ENABLE_TESTS "Build tests" OFF) option(LUPDATE "Update translation files" OFF) +option(STATIC_LIBS "Prefer static variants of system libraries" ${WIN32}) option(STATIC_RUNTIME "Link runtime statically" ${WIN32}) # CPU-dependent options @@ -251,6 +252,11 @@ if(APPLE) add_compile_options(-Wno-error=thread-safety-reference) endif() +if(STATIC_LIBS) + set(CMAKE_LINK_SEARCH_START_STATIC ON) + set(CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_STATIC_LIBRARY_SUFFIX}") +endif() + if(STATIC_RUNTIME) if(CMAKE_CXX_COMPILER_ID MATCHES "^(GNU|Clang)\$") list(APPEND RUNTIME_LIBS -static-libgcc -static-libstdc++)