mirror of
https://github.com/shadowsocks/shadowsocks-libev.git
synced 2026-10-25 18:23:42 +00:00
Build shared and static shadowsock-libev and executable.
This commit is contained in:
+36
-374
@@ -2,23 +2,22 @@ cmake_minimum_required(VERSION 3.6)
|
||||
|
||||
set(PROJECT_NAME shadowsocks-libev)
|
||||
set(RELEASE_DATE 2017-2-17)
|
||||
set(PROJECT_VERSION 3.0.2)
|
||||
set(PROJECT_VERSION "3.0.2")
|
||||
set(PROJECT_DESC "a lightweight secured socks5 proxy")
|
||||
set(PROJECT_URL "https://shadowsocks.org")
|
||||
set(PROJECT_ISSUES_URL "https://github.com/shadowsocks/shadowsocks-libev")
|
||||
project(${PROJECT_NAME})
|
||||
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c11")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -c")
|
||||
|
||||
#set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/out)
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
#set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
|
||||
#set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||||
|
||||
# -------------------------------------------------------------
|
||||
# Options
|
||||
option(BUILD_STATIC "Static link library to executable" ON)
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
|
||||
set(CMAKE_MACOSX_RPATH TRUE)
|
||||
|
||||
if (NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE Debug)
|
||||
@@ -28,315 +27,32 @@ if (UNIX AND NOT APPLE)
|
||||
set(LINUX TRUE)
|
||||
endif ()
|
||||
|
||||
message(STATUS "Running cmake version ${CMAKE_VERSION}")
|
||||
|
||||
# -------------------------------------------------------------
|
||||
# config.h
|
||||
|
||||
# If we generate config.h by automake
|
||||
#include_directories(.)
|
||||
|
||||
# Use cmake to generate config.h
|
||||
include(CheckIncludeFiles)
|
||||
include(CheckFunctionExists)
|
||||
include(CheckSymbolExists)
|
||||
include(CheckLibraryExists)
|
||||
include(CheckTypeSize)
|
||||
include(CheckCSourceCompiles)
|
||||
|
||||
# Define if building universal (internal helper macro)
|
||||
# AC_APPLE_UNIVERSAL_BUILD
|
||||
set(CONNECT_IN_PROGRESS "EINPROGRESS")
|
||||
set(CONNECT_IN_PROGRESS "EINPROGRESS" CACHE STRING "")
|
||||
|
||||
|
||||
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)
|
||||
check_include_files(net/if.h HAVE_NET_IF_H)
|
||||
check_include_files(pcre.h HAVE_PCRE_H)
|
||||
check_include_files(pcre/pcre.h HAVE_PCRE_PCRE_H)
|
||||
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(udns.h HAVE_UDNS_H)
|
||||
check_include_files(unistd.h HAVE_UNISTD_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 ()
|
||||
|
||||
|
||||
# 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_VERSION 3.0.2)
|
||||
set(PACKAGE_STRING "${PROJECT_NAME} ${PACKAGE_VERSION}")
|
||||
set(PACKAGE_TARNAME ${PROJECT_NAME})
|
||||
set(PACKAGE_URL "")
|
||||
|
||||
#message(${PACKAGE_NAME} - v${PACKAGE_VERSION} - v${PROJECT_VERSION})
|
||||
|
||||
# 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})
|
||||
# TODO WORDS_BIGENDIAN
|
||||
# _MINIX
|
||||
# _POSIX_1_SOURCE
|
||||
# _POSIX_SOURCE
|
||||
# _UINT8_T
|
||||
|
||||
# Define to empty if `const' does not conform to ANSI C.
|
||||
# undef const
|
||||
|
||||
# Define to `__inline__' or `__inline' if that's what the C compiler
|
||||
# calls it, or to nothing if 'inline' is not supported under any name.
|
||||
#ifndef __cplusplus
|
||||
#undef inline
|
||||
#endif
|
||||
# TODO Assume we got inline support
|
||||
# https://cmake.org/Wiki/CMakeTestInline
|
||||
|
||||
# Define to the equivalent of the C99 'restrict' keyword, or to
|
||||
# nothing if this is not supported. Do not define if restrict is
|
||||
# supported directly.
|
||||
#define restrict __restrict
|
||||
if (NOT "c_restrict" IN_LIST CMAKE_C_COMPILE_FEATURES)
|
||||
message("No restrict")
|
||||
set(restrict __restrict)
|
||||
endif ()
|
||||
|
||||
# Define to `int' if <sys/types.h> does not define.
|
||||
# undef pid_t
|
||||
# Define to the type of an unsigned integer type of width exactly 16 bits if
|
||||
# such a type exists and the standard includes do not define it.
|
||||
# undef uint16_t
|
||||
# Define to the type of an unsigned integer type of width exactly 8 bits if
|
||||
# such a type exists and the standard includes do not define it.
|
||||
# undef uint8_t
|
||||
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 ()
|
||||
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/src/config.h)
|
||||
# Will set GIT_EXECUTABLE and GIT_FOUND
|
||||
# find_package(Git)
|
||||
|
||||
# Run platform tests
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/configure.cmake)
|
||||
configure_file(${CMAKE_SOURCE_DIR}/cmake/config.h.cmake ${CMAKE_SOURCE_DIR}/src/config.h)
|
||||
add_definitions(-DHAVE_CONFIG_H)
|
||||
|
||||
# -------------------------------------------------------------
|
||||
# Source
|
||||
|
||||
set(SNI_SOURCE
|
||||
src/http.c
|
||||
src/tls.c
|
||||
src/rule.c
|
||||
# pkg-config
|
||||
configure_file(
|
||||
"${CMAKE_SOURCE_DIR}/cmake/shadowsocks-libev.pc.cmake"
|
||||
"${CMAKE_BINARY_DIR}/pkgconfig/shadowsocks-libev.pc"
|
||||
@ONLY
|
||||
)
|
||||
install(FILES
|
||||
"${CMAKE_BINARY_DIR}/pkgconfig/shadowsocks-libev.pc"
|
||||
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
|
||||
)
|
||||
|
||||
set(CRYPTO_SOURCE
|
||||
src/crypto.c
|
||||
src/aead.c
|
||||
src/stream.c
|
||||
src/base64.c
|
||||
)
|
||||
|
||||
set(PLUGIN_SOURCE
|
||||
src/plugin.c
|
||||
)
|
||||
|
||||
set(SS_LOCAL_SOURCE
|
||||
src/utils.c
|
||||
src/jconf.c
|
||||
src/json.c
|
||||
src/netutils.c
|
||||
src/udprelay.c
|
||||
src/cache.c
|
||||
src/acl.c
|
||||
src/local.c
|
||||
${CRYPTO_SOURCE}
|
||||
${PLUGIN_SOURCE}
|
||||
${SNI_SOURCE}
|
||||
)
|
||||
|
||||
set(SS_TUNNEL_SOURCE
|
||||
src/utils.c
|
||||
src/jconf.c
|
||||
src/json.c
|
||||
src/netutils.c
|
||||
src/udprelay.c
|
||||
src/cache.c
|
||||
src/tunnel.c
|
||||
${CRYPTO_SOURCE}
|
||||
${PLUGIN_SOURCE}
|
||||
)
|
||||
|
||||
set(SS_SERVER_SOURCE
|
||||
src/utils.c
|
||||
src/jconf.c
|
||||
src/json.c
|
||||
src/netutils.c
|
||||
src/udprelay.c
|
||||
src/cache.c
|
||||
src/acl.c
|
||||
src/resolv.c
|
||||
src/server.c
|
||||
${CRYPTO_SOURCE}
|
||||
${PLUGIN_SOURCE}
|
||||
${SNI_SOURCE}
|
||||
)
|
||||
|
||||
set(SS_MANAGER_SOURCE
|
||||
src/utils.c
|
||||
src/jconf.c
|
||||
src/json.c
|
||||
src/netutils.c
|
||||
src/manager.c
|
||||
)
|
||||
|
||||
set(SS_REDIR_SOURCE
|
||||
src/utils.c
|
||||
src/jconf.c
|
||||
src/json.c
|
||||
src/netutils.c
|
||||
src/udprelay.c
|
||||
src/cache.c
|
||||
src/redir.c
|
||||
${CRYPTO_SOURCE}
|
||||
${PLUGIN_SOURCE}
|
||||
${SNI_SOURCE}
|
||||
)
|
||||
|
||||
# We don't care about shared
|
||||
set(ENABLE_SHARED OFF)
|
||||
set(ENABLE_SHARED_EXECUTABLES OFF)
|
||||
set(ENABLE_STATIC ON)
|
||||
set(ENABLE_STATIC_EXECUTABLES ON)
|
||||
#set(CMAKE_MACOSX_RPATH TRUE)
|
||||
|
||||
# We need libcork,libipset headers
|
||||
include_directories(libcork/include)
|
||||
include_directories(libipset/include)
|
||||
|
||||
# Things we need to build libcork,libipset
|
||||
#link_directories(libcork/src)
|
||||
#link_directories(libipset/src)
|
||||
|
||||
#add_subdirectory(libcork EXCLUDE_FROM_ALL)
|
||||
# So libipset can find cork
|
||||
#set( ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:libcork/src" )
|
||||
#add_subdirectory(libipset EXCLUDE_FROM_ALL)
|
||||
|
||||
add_library(
|
||||
libcork STATIC
|
||||
set(LIBCORK_SOURCE
|
||||
libcork/src/libcork/cli/commands.c
|
||||
libcork/src/libcork/core/allocator.c
|
||||
libcork/src/libcork/core/error.c
|
||||
@@ -363,12 +79,16 @@ add_library(
|
||||
libcork/src/libcork/posix/process.c
|
||||
libcork/src/libcork/posix/subprocess.c
|
||||
libcork/src/libcork/pthreads/thread.c
|
||||
)
|
||||
)
|
||||
|
||||
target_compile_definitions(libcork PUBLIC -DCORK_API=CORK_LOCAL)
|
||||
add_library(cork STATIC ${LIBCORK_SOURCE})
|
||||
target_compile_definitions(cork PUBLIC -DCORK_API=CORK_LOCAL)
|
||||
|
||||
add_library(cork-shared SHARED ${LIBCORK_SOURCE})
|
||||
target_compile_definitions(cork-shared PUBLIC -DCORK_API=CORK_EXPORT)
|
||||
set_target_properties(cork-shared PROPERTIES OUTPUT_NAME cork)
|
||||
|
||||
set(LIBIPSET_SRC
|
||||
set(LIBIPSET_SOURCE
|
||||
libipset/src/libipset/general.c
|
||||
libipset/src/libipset/bdd/assignments.c
|
||||
libipset/src/libipset/bdd/basics.c
|
||||
@@ -390,70 +110,12 @@ set(LIBIPSET_SRC
|
||||
libipset/src/libipset/set/storage.c
|
||||
)
|
||||
|
||||
add_library(libipset STATIC ${LIBIPSET_SRC})
|
||||
set_target_properties(libipset PROPERTIES
|
||||
OUTPUT_NAME ipset
|
||||
VERSION 1.1.0
|
||||
SOVERSION 1)
|
||||
target_link_libraries(libipset libcork)
|
||||
add_library(ipset STATIC ${LIBIPSET_SOURCE})
|
||||
target_link_libraries(ipset cork)
|
||||
|
||||
# Add our targets
|
||||
add_executable(ss-server ${SS_SERVER_SOURCE})
|
||||
add_executable(ss-tunnel ${SS_TUNNEL_SOURCE})
|
||||
add_executable(ss-manager ${SS_MANAGER_SOURCE})
|
||||
add_executable(ss-local ${SS_LOCAL_SOURCE})
|
||||
add_library(ipset-shared SHARED ${LIBIPSET_SOURCE})
|
||||
target_link_libraries(ipset-shared cork-shared)
|
||||
set_target_properties(ipset-shared PROPERTIES OUTPUT_NAME ipset)
|
||||
|
||||
target_compile_definitions(ss-server PUBLIC -DMODULE_REMOTE)
|
||||
target_compile_definitions(ss-tunnel PUBLIC -DMODULE_TUNNEL)
|
||||
target_compile_definitions(ss-manager PUBLIC -DMODULE_MANAGER)
|
||||
target_compile_definitions(ss-local PUBLIC -DMODULE_LOCAL)
|
||||
add_subdirectory(src)
|
||||
|
||||
|
||||
if (BUILD_STATIC)
|
||||
message("Build static linked executable")
|
||||
set(BUILD_SHARED_LIBS OFF)
|
||||
find_library(LIBSODIUM libsodium.a)
|
||||
find_library(LIBMBEDTLS libmbedtls.a)
|
||||
find_library(LIBMBEDCRYPTO libmbedcrypto.a)
|
||||
find_library(LIBEV libev.a)
|
||||
find_library(LIBUDNS libudns.a)
|
||||
find_library(LIBPCRE libpcre.a)
|
||||
|
||||
# Clang crt0 issues
|
||||
# https://github.com/skaht/Csu-85
|
||||
# https://bugs.llvm.org//show_bug.cgi?id=17801
|
||||
# set(CMAKE_EXE_LINKER_FLAGS "-static")
|
||||
else ()
|
||||
message("Build shared linked executable")
|
||||
|
||||
find_library(LIBSODIUM sodium)
|
||||
find_library(LIBMBEDTLS mbedtls)
|
||||
find_library(LIBMBEDCRYPTO mbedcrypto)
|
||||
find_library(LIBEV ev)
|
||||
find_library(LIBUDNS udns)
|
||||
find_library(LIBPCRE pcre)
|
||||
endif ()
|
||||
|
||||
list(APPEND DEPS ${LIBEV} ${LIBUDNS} ${LIBPCRE} ${LIBSODIUM} ${LIBMBEDTLS} ${LIBMBEDCRYPTO})
|
||||
|
||||
target_link_libraries(ss-server libcork libipset ${DEPS})
|
||||
target_link_libraries(ss-tunnel libcork ${DEPS})
|
||||
target_link_libraries(ss-manager libcork ${LIBEV} ${LIBUDNS})
|
||||
target_link_libraries(ss-local libcork libipset ${DEPS})
|
||||
|
||||
# redir need linux/* stuff
|
||||
if (LINUX)
|
||||
add_executable(ss-redir ${SS_REDIR_SOURCE})
|
||||
target_compile_definitions(ss-redir PUBLIC -DMODULE_REDIR)
|
||||
target_link_libraries(ss-redir libcork libipset ${DEPS})
|
||||
endif (LINUX)
|
||||
|
||||
install(DIRECTORY DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
||||
install(TARGETS ss-server RUNTIME DESTINATION bin)
|
||||
install(TARGETS ss-tunnel RUNTIME DESTINATION bin)
|
||||
install(TARGETS ss-manager RUNTIME DESTINATION bin)
|
||||
install(TARGETS ss-local RUNTIME DESTINATION bin)
|
||||
|
||||
if (LINUX)
|
||||
install(TARGETS ss-redir RUNTIME DESTINATION bin)
|
||||
endif (LINUX)
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#ifndef _SHADOWSOCKS_CONFIG_H
|
||||
#define _SHADOWSOCKS_CONFIG_H
|
||||
|
||||
/* Define if building universal (internal helper macro) */
|
||||
#cmakedefine AC_APPLE_UNIVERSAL_BUILD
|
||||
|
||||
@@ -160,25 +163,25 @@
|
||||
#cmakedefine NDEBUG 1
|
||||
|
||||
/* Name of package */
|
||||
#define PACKAGE "@PACKAGE@"
|
||||
#define PACKAGE "@PROJECT_NAME@"
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#define PACKAGE_BUGREPORT "@PACKAGE_BUGREPORT@"
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#define PACKAGE_NAME "@PACKAGE_NAME@"
|
||||
#define PACKAGE_NAME "@PROJECT_NAME@"
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING "@PACKAGE_STRING@"
|
||||
#define PACKAGE_STRING "@PROJECT_NAME@ @PROJECT_VERSION@"
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#define PACKAGE_TARNAME "@PACKAGE_TARNAME@"
|
||||
#define PACKAGE_TARNAME "@PROJECT_NAME@"
|
||||
|
||||
/* Define to the home page for this package. */
|
||||
#define PACKAGE_URL "@PACKAGE_URL@"
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION "@PACKAGE_VERSION@"
|
||||
#define PACKAGE_VERSION "@PROJECT_VERSION@"
|
||||
|
||||
/* Define to necessary symbol if this constant uses a non-standard name on
|
||||
your system. */
|
||||
@@ -231,7 +234,7 @@
|
||||
#cmakedefine USE_SYSTEM_SHARED_LIB 1
|
||||
|
||||
/* Version number of package */
|
||||
#define VERSION "@VERSION@"
|
||||
#define VERSION "@PROJECT_VERSION@"
|
||||
|
||||
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
|
||||
significant byte first (like Motorola and SPARC, unlike Intel). */
|
||||
@@ -302,3 +305,5 @@
|
||||
|
||||
/* Define as `fork' if `vfork' does not work. */
|
||||
#cmakedefine vfork
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,200 @@
|
||||
|
||||
# -------------------------------------------------------------
|
||||
# config.h
|
||||
|
||||
# If we generate config.h by automake
|
||||
#include_directories(.)
|
||||
|
||||
# Use cmake to generate config.h
|
||||
include(CheckIncludeFiles)
|
||||
include(CheckFunctionExists)
|
||||
include(CheckSymbolExists)
|
||||
include(CheckLibraryExists)
|
||||
include(CheckTypeSize)
|
||||
include(CheckCSourceCompiles)
|
||||
|
||||
# Define if building universal (internal helper macro)
|
||||
# AC_APPLE_UNIVERSAL_BUILD
|
||||
set(CONNECT_IN_PROGRESS "EINPROGRESS")
|
||||
set(CONNECT_IN_PROGRESS "EINPROGRESS" CACHE STRING "")
|
||||
|
||||
|
||||
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)
|
||||
check_include_files(net/if.h HAVE_NET_IF_H)
|
||||
check_include_files(pcre.h HAVE_PCRE_H)
|
||||
check_include_files(pcre/pcre.h HAVE_PCRE_PCRE_H)
|
||||
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(udns.h HAVE_UDNS_H)
|
||||
check_include_files(unistd.h HAVE_UNISTD_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 ()
|
||||
|
||||
|
||||
# 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_VERSION 3.0.2)
|
||||
set(PACKAGE_STRING "${PROJECT_NAME} ${PACKAGE_VERSION}")
|
||||
set(PACKAGE_TARNAME ${PROJECT_NAME})
|
||||
set(PACKAGE_URL "")
|
||||
|
||||
#message(${PACKAGE_NAME} - v${PACKAGE_VERSION} - v${PROJECT_VERSION})
|
||||
|
||||
# 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})
|
||||
# TODO WORDS_BIGENDIAN
|
||||
# _MINIX
|
||||
# _POSIX_1_SOURCE
|
||||
# _POSIX_SOURCE
|
||||
# _UINT8_T
|
||||
|
||||
# Define to empty if `const' does not conform to ANSI C.
|
||||
# undef const
|
||||
|
||||
# Define to `__inline__' or `__inline' if that's what the C compiler
|
||||
# calls it, or to nothing if 'inline' is not supported under any name.
|
||||
#ifndef __cplusplus
|
||||
#undef inline
|
||||
#endif
|
||||
# TODO Assume we got inline support
|
||||
# https://cmake.org/Wiki/CMakeTestInline
|
||||
|
||||
# Define to the equivalent of the C99 'restrict' keyword, or to
|
||||
# nothing if this is not supported. Do not define if restrict is
|
||||
# supported directly.
|
||||
#define restrict __restrict
|
||||
if (NOT "c_restrict" IN_LIST CMAKE_C_COMPILE_FEATURES)
|
||||
message("No restrict")
|
||||
set(restrict __restrict)
|
||||
endif ()
|
||||
|
||||
# Define to `int' if <sys/types.h> does not define.
|
||||
# undef pid_t
|
||||
# Define to the type of an unsigned integer type of width exactly 16 bits if
|
||||
# such a type exists and the standard includes do not define it.
|
||||
# undef uint16_t
|
||||
# Define to the type of an unsigned integer type of width exactly 8 bits if
|
||||
# such a type exists and the standard includes do not define it.
|
||||
# undef uint8_t
|
||||
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 ()
|
||||
@@ -0,0 +1,14 @@
|
||||
prefix=@prefix@
|
||||
exec_prefix=${prefix}/@CMAKE_INSTALL_BINDIR@
|
||||
libdir=${exec_prefix}/@CMAKE_INSTALL_FULL_LIBDIR@
|
||||
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
|
||||
sharedir=${prefix}/@CMAKE_INSTALL_DATAROOTDIR@
|
||||
mandir=${prefix}/@CMAKE_INSTALL_MANDIR@
|
||||
|
||||
Name: @PROJECT_NAME@
|
||||
Description: @PROJECT_DESC@
|
||||
URL: @PROJECT_URL@
|
||||
Version: @PROJECT_VERSION@
|
||||
Requires:
|
||||
Cflags: -I${includedir}
|
||||
Libs: -L${libdir} -lshadowsocks-libev -lcrypto
|
||||
@@ -0,0 +1,188 @@
|
||||
# redir need linux/* stuff
|
||||
if (LINUX)
|
||||
option(WITH_SS_REDIR "Build ss-redir" ON)
|
||||
else ()
|
||||
option(WITH_SS_REDIR "Build ss-redir" OFF)
|
||||
endif ()
|
||||
|
||||
|
||||
set(SS_SNI_SOURCE
|
||||
http.c
|
||||
tls.c
|
||||
rule.c
|
||||
)
|
||||
|
||||
set(SS_CRYPTO_SOURCE
|
||||
crypto.c
|
||||
aead.c
|
||||
stream.c
|
||||
base64.c
|
||||
)
|
||||
|
||||
set(SS_PLUGIN_SOURCE
|
||||
plugin.c
|
||||
)
|
||||
|
||||
set(SS_SHARED_SOURCES
|
||||
utils.c
|
||||
jconf.c
|
||||
json.c
|
||||
netutils.c
|
||||
)
|
||||
|
||||
set(LIBSHADOWSOCKS_LIBEV_SOURCE
|
||||
${SS_SHARED_SOURCES}
|
||||
udprelay.c
|
||||
cache.c
|
||||
acl.c
|
||||
local.c
|
||||
${SS_CRYPTO_SOURCE}
|
||||
${SS_PLUGIN_SOURCE}
|
||||
${SS_SNI_SOURCE})
|
||||
|
||||
set(SS_LOCAL_SOURCE
|
||||
${LIBSHADOWSOCKS_LIBEV_SOURCE}
|
||||
|
||||
)
|
||||
|
||||
set(SS_TUNNEL_SOURCE
|
||||
${SS_SHARED_SOURCES}
|
||||
udprelay.c
|
||||
cache.c
|
||||
tunnel.c
|
||||
${SS_CRYPTO_SOURCE}
|
||||
${SS_PLUGIN_SOURCE}
|
||||
)
|
||||
|
||||
set(SS_SERVER_SOURCE
|
||||
${SS_SHARED_SOURCES}
|
||||
udprelay.c
|
||||
cache.c
|
||||
acl.c
|
||||
resolv.c
|
||||
server.c
|
||||
${SS_CRYPTO_SOURCE}
|
||||
${SS_PLUGIN_SOURCE}
|
||||
${SS_SNI_SOURCE}
|
||||
)
|
||||
|
||||
set(SS_MANAGER_SOURCE
|
||||
${SS_SHARED_SOURCES}
|
||||
manager.c
|
||||
)
|
||||
|
||||
set(SS_REDIR_SOURCE
|
||||
${SS_SHARED_SOURCES}
|
||||
udprelay.c
|
||||
cache.c
|
||||
redir.c
|
||||
${SS_CRYPTO_SOURCE}
|
||||
${SS_PLUGIN_SOURCE}
|
||||
${SS_SNI_SOURCE}
|
||||
)
|
||||
|
||||
|
||||
find_library(LIBSODIUM libsodium.a)
|
||||
find_library(LIBMBEDTLS libmbedtls.a)
|
||||
find_library(LIBMBEDCRYPTO libmbedcrypto.a)
|
||||
find_library(LIBEV libev.a)
|
||||
find_library(LIBUDNS libudns.a)
|
||||
find_library(LIBPCRE libpcre.a)
|
||||
|
||||
find_library(LIBSODIUM_SHARED sodium)
|
||||
find_library(LIBMBEDTLS_SHARED mbedtls)
|
||||
find_library(LIBMBEDCRYPTO_SHARED mbedcrypto)
|
||||
find_library(LIBEV_SHARED ev)
|
||||
find_library(LIBUDNS_SHARED udns)
|
||||
find_library(LIBPCRE_SHARED pcre)
|
||||
|
||||
list(APPEND DEPS ${LIBEV} ${LIBUDNS} ${LIBPCRE} ${LIBSODIUM} ${LIBMBEDTLS} ${LIBMBEDCRYPTO})
|
||||
list(APPEND DEPS_SHARED ${LIBEV_SHARED} ${LIBUDNS_SHARED} ${LIBPCRE_SHARED} ${LIBSODIUM_SHARED} ${LIBMBEDTLS_SHARED} ${LIBMBEDCRYPTO_SHARED})
|
||||
|
||||
# Add our targets
|
||||
add_executable(ss-server ${SS_SERVER_SOURCE})
|
||||
add_executable(ss-tunnel ${SS_TUNNEL_SOURCE})
|
||||
add_executable(ss-manager ${SS_MANAGER_SOURCE})
|
||||
add_executable(ss-local ${SS_LOCAL_SOURCE})
|
||||
if (WITH_SS_REDIR)
|
||||
add_executable(ss-redir ${SS_REDIR_SOURCE})
|
||||
else ()
|
||||
add_executable(ss-redir EXCLUDE_FROM_ALL ${SS_REDIR_SOURCE})
|
||||
endif ()
|
||||
add_library(shadowsocks-libev STATIC ${LIBSHADOWSOCKS_LIBEV_SOURCE})
|
||||
|
||||
|
||||
target_compile_definitions(ss-server PUBLIC -DMODULE_REMOTE)
|
||||
target_compile_definitions(ss-tunnel PUBLIC -DMODULE_TUNNEL)
|
||||
target_compile_definitions(ss-manager PUBLIC -DMODULE_MANAGER)
|
||||
target_compile_definitions(ss-local PUBLIC -DMODULE_LOCAL)
|
||||
target_compile_definitions(ss-redir PUBLIC -DMODULE_REDIR)
|
||||
target_compile_definitions(shadowsocks-libev PUBLIC -DMODULE_LOCAL)
|
||||
|
||||
target_link_libraries(ss-server cork ipset ${DEPS})
|
||||
target_link_libraries(ss-tunnel cork ${DEPS})
|
||||
target_link_libraries(ss-manager cork ${LIBEV} ${LIBUDNS})
|
||||
target_link_libraries(ss-local cork ipset ${DEPS})
|
||||
target_link_libraries(ss-redir cork ipset ${DEPS})
|
||||
target_link_libraries(shadowsocks-libev cork ipset ${DEPS})
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Shared
|
||||
add_executable(ss-server-shared ${SS_SERVER_SOURCE})
|
||||
add_executable(ss-tunnel-shared ${SS_TUNNEL_SOURCE})
|
||||
add_executable(ss-manager-shared ${SS_MANAGER_SOURCE})
|
||||
add_executable(ss-local-shared ${SS_LOCAL_SOURCE})
|
||||
if (WITH_SS_REDIR)
|
||||
add_executable(ss-redir-shared ${SS_REDIR_SOURCE})
|
||||
else ()
|
||||
add_executable(ss-redir-shared EXCLUDE_FROM_ALL ${SS_REDIR_SOURCE})
|
||||
endif ()
|
||||
add_library(shadowsocks-libev-shared SHARED ${LIBSHADOWSOCKS_LIBEV_SOURCE})
|
||||
|
||||
target_compile_definitions(ss-server-shared PUBLIC -DMODULE_REMOTE)
|
||||
target_compile_definitions(ss-tunnel-shared PUBLIC -DMODULE_TUNNEL)
|
||||
target_compile_definitions(ss-manager-shared PUBLIC -DMODULE_MANAGER)
|
||||
target_compile_definitions(ss-local-shared PUBLIC -DMODULE_LOCAL)
|
||||
target_compile_definitions(ss-redir-shared PUBLIC -DMODULE_REDIR)
|
||||
target_compile_definitions(shadowsocks-libev-shared PUBLIC -DMODULE_LOCAL)
|
||||
|
||||
target_link_libraries(ss-server-shared cork-shared ipset-shared ${DEPS_SHARED})
|
||||
target_link_libraries(ss-tunnel-shared cork-shared ${DEPS_SHARED})
|
||||
target_link_libraries(ss-manager-shared cork-shared ${LIBEV_SHARED} ${LIBUDNS_SHARED})
|
||||
target_link_libraries(ss-local-shared cork-shared ipset-shared ${DEPS_SHARED})
|
||||
target_link_libraries(ss-redir-shared cork-shared ipset-shared ${DEPS_SHARED})
|
||||
target_link_libraries(shadowsocks-libev-shared cork-shared ipset-shared ${DEPS_SHARED})
|
||||
|
||||
|
||||
set_target_properties(ss-server-shared PROPERTIES OUTPUT_NAME ss-server)
|
||||
set_target_properties(ss-tunnel-shared PROPERTIES OUTPUT_NAME ss-tunnel)
|
||||
set_target_properties(ss-manager-shared PROPERTIES OUTPUT_NAME ss-manager)
|
||||
set_target_properties(ss-local-shared PROPERTIES OUTPUT_NAME ss-local)
|
||||
set_target_properties(ss-redir-shared PROPERTIES OUTPUT_NAME ss-redir)
|
||||
|
||||
set_target_properties(ss-server-shared ss-tunnel-shared ss-manager-shared ss-local-shared ss-redir-shared
|
||||
PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/shared/bin"
|
||||
)
|
||||
|
||||
set_target_properties(shadowsocks-libev-shared PROPERTIES OUTPUT_NAME shadowsocks-libev)
|
||||
target_compile_definitions(shadowsocks-libev-shared PUBLIC -DMODULE_LOCAL)
|
||||
target_link_libraries(shadowsocks-libev-shared cork-shared ipset-shared ${DEPS_SHARED})
|
||||
|
||||
|
||||
#install(DIRECTORY DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
||||
#install(TARGETS ss-server RUNTIME DESTINATION bin)
|
||||
#install(TARGETS ss-tunnel RUNTIME DESTINATION bin)
|
||||
#install(TARGETS ss-manager RUNTIME DESTINATION bin)
|
||||
#install(TARGETS ss-local RUNTIME DESTINATION bin)
|
||||
|
||||
install(DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
|
||||
DESTINATION bin
|
||||
FILES_MATCHING PATTERN "ss-*")
|
||||
|
||||
|
||||
add_custom_target(distclean
|
||||
COMMAND ${CMAKE_COMMAND} -E echo WARNING: distclean target is not functional
|
||||
COMMAND ${CMAKE_COMMAND} -E echo Use 'git clean -fdx' instead
|
||||
VERBATIM
|
||||
)
|
||||
Reference in New Issue
Block a user