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")