Files
shadowsocks-libev/cmake/configure.cmake
Max LvandClaude Opus 4.6 7bb250739e Modernize build: switch to CMake, add unit tests, fix man pages
* 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>

* Migrate from PCRE to PCRE2

Replace legacy PCRE (libpcre3) with PCRE2 (libpcre2-8). PCRE1 has been
end-of-life since 2021.

- src/rule.h: use pcre2_code and pcre2_match_data types
- src/rule.c: pcre_compile -> pcre2_compile, pcre_exec -> pcre2_match,
  pcre_free -> pcre2_code_free, with proper error message retrieval
- cmake/FindPCRE.cmake -> cmake/FindPCRE2.cmake: find libpcre2-8 via
  pkg-config, pcre2-config, or manual search
- Update all CMakeLists.txt, config.h.cmake, configure.cmake, README.md

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Update Dockerfiles: use CMake build and pcre2-dev

The alpine Dockerfile still used autotools (autogen.sh/configure) which
were removed. Switch to cmake build and replace pcre-dev with pcre2-dev.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Fix Docker build: disable tests and remove git dep

The tests/ directory is excluded by .dockerignore, so pass
-DBUILD_TESTING=OFF to cmake. Submodules are already checked out
by actions/checkout, no need for git inside the container.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Fix Docker build: disable static libs (not available in alpine)

Alpine's mbedtls-dev only provides shared libraries. Disable static
build since Docker only needs shared binaries.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Rewrite GitHub Actions: build and test directly on runner

Replace Docker-based CI with direct cmake build on ubuntu-latest and
macos-latest. Install dependencies via apt/brew, build with cmake,
run unit tests with ctest.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Fix CI: use mbedtls@3 on macOS, disable static build

- macOS: brew's mbedtls is now v4 (incompatible), use mbedtls@3
- Disable static build since CI runners lack static lib packages

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Fix test build on Linux: add stdint.h and link libm

- test_ppbloom.c: add missing #include <stdint.h> for uint8_t
- test_json: link against libm for pow() used in json.c

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Fix test_ppbloom link: add libm for bloom's log()

On Linux, libbloom uses log() which requires explicit -lm linkage.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Fix Linux build: link libm for test_buffer and test_crypto, fix warnings

Both test_buffer and test_crypto link libbloom.so which uses log() from
libm. Also fix unused variable warnings in test_json.c that would fail
with -Werror.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Fix Linux build: link libm for test_jconf (json.c uses pow)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* CI: add unit test and stress test steps to GitHub Actions

Split the Test step into separate "Unit tests" (ctest) and "Stress test"
(stress_test.py with 10MB transfer across all AEAD ciphers) steps for
better visibility.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 17:06:47 +08:00

199 lines
5.8 KiB
CMake

# -------------------------------------------------------------
# config.h
# Use cmake to generate config.h
include(CheckIncludeFiles)
include(CheckFunctionExists)
include(CheckSymbolExists)
include(CheckLibraryExists)
include(CheckTypeSize)
include(CheckCSourceCompiles)
include(CheckCCompilerFlag)
# Define if building universal (internal helper macro)
# AC_APPLE_UNIVERSAL_BUILD
# Set CONNECT_IN_PROGRESS based on platform
if(MINGW)
set(CONNECT_IN_PROGRESS "WSAEWOULDBLOCK")
else()
set(CONNECT_IN_PROGRESS "EINPROGRESS")
endif()
if (CMAKE_SYSTEM_NAME STREQUAL Darwin)
set(CMAKE_REQUIRED_INCLUDES "/usr/local/include" "/usr/include" "/opt/homebrew/include")
endif ()
check_include_files(dlfcn.h HAVE_DLFCN_H)
check_include_files(ev.h HAVE_EV_H)
check_include_files(fcntl.h HAVE_FCNTL_H)
check_function_exists(fork HAVE_FORK)
check_function_exists(getpwnam_r HAVE_GETPWNAM_R)
check_function_exists(inet_ntop HAVE_INET_NTOP)
check_include_files(inttypes.h HAVE_INTTYPES_H)
set(HAVE_IPv6 1)
check_include_files(langinfo.h HAVE_LANGINFO_H)
set(HAVE_LIBPCRE 1)
check_library_exists(socket socket "" HAVE_LIBSOCKET)
check_include_files(limits.h HAVE_LIMITS_H)
check_include_files(linux/if.h HAVE_LINUX_IF_H)
check_include_files(linux/netfilter_ipv4.h HAVE_LINUX_NETFILTER_IPV4_H)
check_include_files(linux/netfilter_ipv6/ip6_tables.h HAVE_LINUX_NETFILTER_IPV6_IP6_TABLES_H)
check_include_files(locale.h HAVE_LOCALE_H)
check_function_exists(malloc HAVE_MALLOC)
check_include_files(memory.h HAVE_MEMORY_H)
check_function_exists(memset HAVE_MEMSET)
check_include_files(netdb.h HAVE_NETDB_H)
check_include_files(netinet/in.h HAVE_NETINET_IN_H)
if (CYGWIN)
check_include_files("sys/types.h;netinet/tcp.h" HAVE_NETINET_TCP_H)
else ()
check_include_files(netinet/tcp.h HAVE_NETINET_TCP_H)
endif ()
check_include_files(linux/tcp.h HAVE_LINUX_TCP_H)
check_include_files(net/if.h HAVE_NET_IF_H)
set(CMAKE_REQUIRED_DEFINITIONS_SAVE ${CMAKE_REQUIRED_DEFINITIONS})
set(CMAKE_REQUIRED_DEFINITIONS "-DPCRE2_CODE_UNIT_WIDTH=8")
check_include_files(pcre2.h HAVE_PCRE2_H)
set(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS_SAVE})
check_symbol_exists(PTHREAD_PRIO_INHERIT pthread.h HAVE_PTHREAD_PRIO_INHERIT)
check_function_exists(select HAVE_SELECT)
check_function_exists(setresuid HAVE_SETRESUID)
check_function_exists(setreuid HAVE_SETREUID)
check_function_exists(setrlimit HAVE_SETRLIMIT)
check_function_exists(socket HAVE_SOCKET)
check_include_files(stdint.h HAVE_STDINT_H)
check_include_files(stdlib.h HAVE_STDLIB_H)
check_function_exists(strerror HAVE_STRERROR)
check_include_files(strings.h HAVE_STRINGS_H)
check_include_files(string.h HAVE_STRING_H)
check_include_files(sys/ioctl.h HAVE_SYS_IOCTL_H)
check_include_files(sys/select.h HAVE_SYS_SELECT_H)
check_include_files(sys/socket.h HAVE_SYS_SOCKET_H)
check_include_files(sys/stat.h HAVE_SYS_STAT_H)
check_include_files(sys/types.h HAVE_SYS_TYPES_H)
check_include_files(sys/wait.h HAVE_SYS_WAIT_H)
check_include_files(ares.h HAVE_ARES_H)
check_include_files(unistd.h HAVE_UNISTD_H)
check_include_files(arpa/inet.h HAVE_ARPA_INET_H)
check_include_files(linux/random.h HAVE_LINUX_RANDOM_H)
check_function_exists(fork HAVE_FORK)
check_function_exists(vfork HAVE_VFORK)
check_include_files(vfork.h HAVE_VFORK_H)
if (HAVE_VFORK)
set(HAVE_WORKING_VFORK 1)
endif ()
if (HAVE_FORK)
set(HAVE_WORKING_FORK 1)
endif ()
# Additional function checks
check_function_exists(get_current_dir_name HAVE_GET_CURRENT_DIR_NAME)
check_function_exists(posix_memalign HAVE_POSIX_MEMALIGN)
# Define to the sub-directory where libtool stores uninstalled libraries.
set(LT_OBJDIR ".libs/")
set(NDEBUG 1)
set(PACKAGE ${PROJECT_NAME})
set(PACKAGE_BUGREPORT max.c.lv@gmail.com)
set(PACKAGE_NAME ${PROJECT_NAME})
set(PACKAGE_VERSION ${PROJECT_VERSION})
set(PACKAGE_STRING "${PROJECT_NAME} ${PACKAGE_VERSION}")
set(PACKAGE_TARNAME ${PROJECT_NAME})
set(PACKAGE_URL "")
# PTHREAD_CREATE_JOINABLE
# Define as the return type of signal handlers (`int' or `void').
set(RETSIGTYPE void)
# Define to the type of arg 1 for `select'.
set(SELECT_TYPE_ARG1 int)
# Define to the type of args 2, 3 and 4 for `select'.
set(SELECT_TYPE_ARG234 "(fd_set *)")
# Define to the type of arg 5 for `select'.
set(SELECT_TYPE_ARG5 "(struct timeval *)")
# Define to 1 if you have the ANSI C header files.
set(STDC_HEADERS 1)
check_include_files("sys/time.h;time.h" TIME_WITH_SYS_TIME)
# If the compiler supports a TLS storage class define it to that here
check_c_source_compiles("
__thread int tls;
int main(void) { return 0; }"
HAVE_GCC_THREAD_LOCAL_STORAGE)
if (HAVE_GCC_THREAD_LOCAL_STORAGE)
set(TLS __thread)
endif ()
set(_ALL_SOURCE 1)
set(_GNU_SOURCE 1)
set(_POSIX_PTHREAD_SEMANTICS 1)
set(_TANDEM_SOURCE 1)
set(__EXTENSIONS__ 1)
# USE_SYSTEM_SHARED_LIB
set(VERSION ${PACKAGE_VERSION})
set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h)
check_type_size(pid_t PID_T)
check_type_size(size_t SIZE_T)
check_type_size(ssize_t SSIZE_T)
set(CMAKE_EXTRA_INCLUDE_FILES)
check_type_size(uint16_t UINT16_T)
check_type_size(uint8_t UINT8_T)
## Inverse
if (NOT HAVE_PID_T)
set(pid_t int)
endif ()
if (NOT HAVE_SIZE_T)
set(size_t "unsigned int")
endif ()
if (NOT HAVE_SSIZE_T)
set(ssize_t int)
endif ()
if (NOT HAVE_UINT8_T)
set(uint8_t "unsigned char")
endif ()
if (NOT HAVE_UINT16_T)
set(uint16_t "unsigned short")
endif ()
# Define as `fork' if `vfork' does not work.
if (NOT HAVE_WORKING_VFORK)
set(vfork fork)
endif ()
# Stack protector detection
option(DISABLE_SSP "Disable -fstack-protector" OFF)
if(NOT DISABLE_SSP)
check_c_compiler_flag(-fstack-protector HAS_STACK_PROTECTOR)
if(HAS_STACK_PROTECTOR)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector")
message(STATUS "Stack protector enabled")
endif()
endif()
# MinGW/Cygwin compiler flags
if(MINGW OR CYGWIN)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mno-ms-bitfields")
endif()