Files
shadowsocks-libev/third_party/CMakeLists.txt
Max Lv bdc77408cb Rename to shadowsocks-c with libuv, async DNS and CI lint (#3051)
Rename the project to shadowsocks-c while retaining ss-* commands, the embedding ABI, and legacy library/package lookup compatibility.

Replace libev with bundled libuv for IOCP/kqueue event backends, expand asynchronous runtime DNS coverage, and add actionlint/Ruff with strict clang-tidy failure handling. Validate native platforms, static builds, packaging, interoperability, sanitizers, and canonical/legacy consumers.

All 22 hosted checks pass at reviewed head a8493250eb.
2026-09-11 14:18:37 +08:00

83 lines
3.6 KiB
CMake

# Sources are included in the checkout/release archive. Configuration never
# accesses the network. Extract into the build tree, verified before use.
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/manifest.json" manifest)
string(JSON count LENGTH "${manifest}")
math(EXPR last "${count} - 1")
foreach(i RANGE ${last})
foreach(field name archive sha256)
string(JSON ${field} GET "${manifest}" ${i} ${field})
endforeach()
if(name STREQUAL "pcre2" AND NOT SS_ENABLE_REGEX)
continue()
endif()
set(archive_path "${CMAKE_CURRENT_SOURCE_DIR}/dist/${archive}")
file(SHA256 "${archive_path}" actual)
if(NOT actual STREQUAL sha256)
message(FATAL_ERROR "Bundled ${name}: archive checksum mismatch")
endif()
set(destination "${CMAKE_CURRENT_BINARY_DIR}/${name}-${sha256}")
if(NOT EXISTS "${destination}/.extracted")
file(MAKE_DIRECTORY "${destination}")
file(ARCHIVE_EXTRACT INPUT "${archive_path}" DESTINATION "${destination}")
file(WRITE "${destination}/.extracted" "${sha256}\n")
endif()
file(GLOB children LIST_DIRECTORIES TRUE "${destination}/*")
list(FILTER children EXCLUDE REGEX "/\\.extracted$")
list(GET children 0 source)
set(${name}_SOURCE "${source}")
endforeach()
set(ENABLE_PROGRAMS OFF CACHE BOOL "" FORCE)
set(ENABLE_TESTING OFF CACHE BOOL "" FORCE)
set(USE_SHARED_MBEDTLS_LIBRARY OFF CACHE BOOL "" FORCE)
set(USE_STATIC_MBEDTLS_LIBRARY ON CACHE BOOL "" FORCE)
set(DISABLE_PACKAGE_CONFIG_AND_INSTALL ON CACHE BOOL "" FORCE)
set(MBEDTLS_CONFIG_FILE "${CMAKE_CURRENT_SOURCE_DIR}/mbedtls_config.h" CACHE FILEPATH "Crypto-only configuration" FORCE)
add_subdirectory("${mbedtls_SOURCE}" mbedtls EXCLUDE_FROM_ALL)
add_library(ss_mbedcrypto ALIAS mbedcrypto)
set(MBEDTLS_INCLUDE_DIRS "${mbedtls_SOURCE}/include" PARENT_SCOPE)
set(CARES_STATIC ON CACHE BOOL "" FORCE)
set(CARES_SHARED OFF CACHE BOOL "" FORCE)
set(CARES_STATIC_PIC ON CACHE BOOL "" FORCE)
set(CARES_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(CARES_BUILD_TOOLS OFF CACHE BOOL "" FORCE)
set(CARES_INSTALL OFF CACHE BOOL "" FORCE)
add_subdirectory("${cares_SOURCE}" cares EXCLUDE_FROM_ALL)
get_target_property(cares_target c-ares::cares ALIASED_TARGET)
add_library(ss_cares ALIAS ${cares_target})
set(CARES_INCLUDE_DIRS "${cares_SOURCE}/include;${CMAKE_CURRENT_BINARY_DIR}/cares" PARENT_SCOPE)
if(SS_ENABLE_REGEX)
set(BUILD_SHARED_LIBS OFF)
set(PCRE2_BUILD_PCRE2_8 ON CACHE BOOL "" FORCE)
set(PCRE2_BUILD_PCRE2_16 OFF CACHE BOOL "" FORCE)
set(PCRE2_BUILD_PCRE2_32 OFF CACHE BOOL "" FORCE)
set(PCRE2_BUILD_PCRE2GREP OFF CACHE BOOL "" FORCE)
set(PCRE2_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(PCRE2_SUPPORT_JIT OFF CACHE BOOL "" FORCE)
set(PCRE2_INSTALL OFF CACHE BOOL "" FORCE)
add_subdirectory("${pcre2_SOURCE}" pcre2 EXCLUDE_FROM_ALL)
add_library(ss_pcre2 ALIAS pcre2-8-static)
set(PCRE2_INCLUDE_DIRS "${CMAKE_CURRENT_BINARY_DIR}/pcre2" PARENT_SCOPE)
endif()
set(LIBUV_BUILD_SHARED OFF CACHE BOOL "" FORCE)
set(LIBUV_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(LIBUV_BUILD_BENCH OFF CACHE BOOL "" FORCE)
include(LibuvWindows.cmake)
add_subdirectory("${uv_SOURCE}" uv EXCLUDE_FROM_ALL)
add_library(ss_uv ALIAS uv_a)
include(${PROJECT_SOURCE_DIR}/cmake/EventLoop.cmake)
include(Sodium.cmake)
foreach(name sodium uv mbedtls)
install(FILES "${${name}_SOURCE}/LICENSE" DESTINATION "${CMAKE_INSTALL_DATADIR}/licenses/shadowsocks-c/${name}")
endforeach()
install(FILES "${cares_SOURCE}/LICENSE.md" DESTINATION "${CMAKE_INSTALL_DATADIR}/licenses/shadowsocks-c/cares")
if(SS_ENABLE_REGEX)
install(FILES "${pcre2_SOURCE}/LICENCE.md" DESTINATION "${CMAKE_INSTALL_DATADIR}/licenses/shadowsocks-c/pcre2")
endif()