From da54d0e31483a45a1dfdfe17a338579a7f9eeaf8 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Sat, 13 Jul 2024 15:18:23 +0900 Subject: [PATCH] Add preference to libsodium static lib --- CMakeLists.txt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b123db4..95e1419 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,7 +50,20 @@ else() pkg_check_modules(LIBSODIUM QUIET libsodium) if(LIBSODIUM_FOUND) target_compile_definitions(UDPC PUBLIC UDPC_LIBSODIUM_ENABLED) - target_link_libraries(UDPC PUBLIC ${LIBSODIUM_LIBRARIES}) + + # Try to link with static lib by default. + foreach(LIB_DIR IN LISTS ${LIBSODIUM_LIBRARY_DIRS}) + if(EXISTS "${LIB_DIR}/libsodium.a") + set(LIBSODIUM_STATIC_LIB "${LIB_DIR}/libsodium.a") + break() + endif() + endforeach() + + if(EXISTS ${LIBSODIUM_STATIC_LIB}) + target_link_libraries(UDPC PUBLIC ${LIBSODIUM_STATIC_LIB}) + else() + target_link_libraries(UDPC PUBLIC ${LIBSODIUM_LIBRARIES}) + endif() target_include_directories(UDPC PUBLIC ${LIBSODIUM_INCLUDE_DIRS}) target_compile_options(UDPC PUBLIC ${LIBSODIUM_CFLAGS_OTHER}) message(STATUS "libsodium enabled")