From 80ec7d921103b01201a6ea8e0c01338eb88e3f95 Mon Sep 17 00:00:00 2001 From: Omar Mohamed Khallaf <51155980+omarmohamedkh@users.noreply.github.com> Date: Thu, 22 Aug 2024 10:46:47 +0300 Subject: [PATCH] Use correct libraries when compiling statically (#2136) When compiling statically, cmake pulls shared libraries as dependencies for drogon e.g. libpq.so instead of libpq.a. This causes linkage errors when compiling the whole program. The flag USE_STATIC_LIBS_ONLY should set the CMAKE_FIND_LIBRARY_SUFFIXES to the appropriate suffix on different platforms, thus find_* commands find the right library. --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index e5d859e8..804db4b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,7 @@ option(BUILD_DOC "Build Doxygen documentation" OFF) option(BUILD_BROTLI "Build Brotli" ON) option(BUILD_YAML_CONFIG "Build yaml config" ON) option(USE_SUBMODULE "Use trantor as a submodule" ON) +option(USE_STATIC_LIBS_ONLY "Use only static libraries as dependencies" OFF) include(CMakeDependentOption) CMAKE_DEPENDENT_OPTION(BUILD_POSTGRESQL "Build with postgresql support" ON "BUILD_ORM" OFF) @@ -77,6 +78,10 @@ if (BUILD_SHARED_LIBS) endif () endif (BUILD_SHARED_LIBS) +if(USE_STATIC_LIBS_ONLY) + set(CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_STATIC_LIBRARY_SUFFIX}") +endif(USE_STATIC_LIBS_ONLY) + if(USE_SPDLOG) find_package(spdlog CONFIG) if(spdlog_FOUND)