Files
shadowsocks-libev/cmake/FindSodium.cmake
Max LvandClaude Opus 4.6 1c404eccf4 Modernize build: switch to CMake, add unit tests, fix man pages
Remove autotools (configure.ac, Makefile.am, m4/, autogen.sh) and make
CMake the sole build system. Enhance CMake with proper Find modules for
MbedTLS, libsodium, PCRE, and c-ares with version/feature detection.
Add support for connmarktos, nftables, stack protector, and MinGW.

Add 10 unit test suites (CTest) covering base64, buffer, cache, crypto,
jconf, json, netutils, ppbloom, rule, and utils modules. Add a Python
stress test measuring bandwidth per cipher with memory leak detection.

Fix man page typos ("Resovle" -> "Resolve"), document missing TCP buffer
options, fix ss-manager duplicate --executable entry, add example section
to ss-tunnel, and document --workdir and --nftables-sets options.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 16:40:27 +08:00

58 lines
1.6 KiB
CMake

# FindSodium.cmake - Find libsodium with version check
#
# Sets:
# SODIUM_FOUND
# SODIUM_INCLUDE_DIRS
# SODIUM_LIBRARIES
find_path(SODIUM_INCLUDE_DIR
NAMES sodium.h
HINTS
/opt/homebrew/include
/usr/local/include
/usr/local/opt/libsodium/include
/opt/homebrew/opt/libsodium/include
/usr/include
$ENV{LIBSODIUM_INCLUDE_DIR}
$ENV{LIBSODIUM_DIR}/include
)
find_library(SODIUM_LIBRARY
NAMES sodium
HINTS
/opt/homebrew/lib
/usr/local/lib
/usr/local/opt/libsodium/lib
/opt/homebrew/opt/libsodium/lib
/usr/lib
)
if(SODIUM_INCLUDE_DIR AND SODIUM_LIBRARY)
set(SODIUM_FOUND TRUE)
set(SODIUM_INCLUDE_DIRS ${SODIUM_INCLUDE_DIR})
set(SODIUM_LIBRARIES ${SODIUM_LIBRARY})
# Version check: require SODIUM_LIBRARY_VERSION_MAJOR >= 7 (libsodium >= 1.0.4)
include(CheckCSourceCompiles)
set(CMAKE_REQUIRED_INCLUDES ${SODIUM_INCLUDE_DIR})
set(CMAKE_REQUIRED_LIBRARIES ${SODIUM_LIBRARY})
check_c_source_compiles("
#include <sodium.h>
#if SODIUM_LIBRARY_VERSION_MAJOR < 7
#error libsodium too old
#endif
int main(void) { return 0; }
" SODIUM_VERSION_OK)
unset(CMAKE_REQUIRED_INCLUDES)
unset(CMAKE_REQUIRED_LIBRARIES)
if(NOT SODIUM_VERSION_OK)
message(FATAL_ERROR "libsodium found but version is too old. Require >= 1.0.4 (SODIUM_LIBRARY_VERSION_MAJOR >= 7)")
endif()
message(STATUS "Found libsodium: ${SODIUM_LIBRARY}")
else()
set(SODIUM_FOUND FALSE)
message(FATAL_ERROR "Could not find libsodium. Install libsodium-dev or equivalent.")
endif()