From c5ac1316aadc2bd15816c8a2abfc764baa9e0b41 Mon Sep 17 00:00:00 2001 From: wener Date: Fri, 17 Feb 2017 18:58:32 +0800 Subject: [PATCH] Use cmake to generate config.h --- CMakeLists.txt | 211 ++++++++++++++++++++++++++++++++- src/config.h.in | 306 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 514 insertions(+), 3 deletions(-) create mode 100644 src/config.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt index f49f23ce..13d053b1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,11 @@ cmake_minimum_required(VERSION 3.6) -set(PROJECT_NAME shadowsocks_libev) +set(PROJECT_NAME shadowsocks-libev) set(RELEASE_DATE 2017-2-17) +set(PROJECT_VERSION 3.0.2) project(${PROJECT_NAME}) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c11") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -c") @@ -22,10 +24,213 @@ if (UNIX AND NOT APPLE) endif () -# for config.h -include_directories(.) +# ------------------------------------------------------------- +# 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 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}/src/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/src/config.h) + add_definitions(-DHAVE_CONFIG_H) +# ------------------------------------------------------------- +# Source + set(SNI_SOURCE src/http.c src/tls.c diff --git a/src/config.h.in b/src/config.h.in new file mode 100644 index 00000000..bfe86a18 --- /dev/null +++ b/src/config.h.in @@ -0,0 +1,306 @@ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define if building universal (internal helper macro) */ +#cmakedefine AC_APPLE_UNIVERSAL_BUILD + +/* errno for incomplete non-blocking connect(2) */ +#cmakedefine CONNECT_IN_PROGRESS @CONNECT_IN_PROGRESS@ + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_ARPA_INET_H 1 + +/* Define to 1 if you have the declaration of `inet_ntop', and to 0 if you + don't. */ +#cmakedefine HAVE_DECL_INET_NTOP 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_DLFCN_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_EV_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_FCNTL_H 1 + +/* Define to 1 if you have the `fork' function. */ +#cmakedefine HAVE_FORK 1 + +/* Define to 1 if you have the `getpwnam_r' function. */ +#cmakedefine HAVE_GETPWNAM_R 1 + +/* Define to 1 if you have the `inet_ntop' function. */ +#cmakedefine HAVE_INET_NTOP 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_INTTYPES_H 1 + +/* Enable IPv6 support in libudns */ +#cmakedefine HAVE_IPv6 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LANGINFO_H 1 + +/* Compiling with pcre support */ +#cmakedefine HAVE_LIBPCRE 1 + +/* Define to 1 if you have the `socket' library (-lsocket). */ +#cmakedefine HAVE_LIBSOCKET 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LIMITS_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LINUX_IF_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LINUX_NETFILTER_IPV4_H 1 + +/* Define to 1 if you have the header + file. */ +#cmakedefine HAVE_LINUX_NETFILTER_IPV6_IP6_TABLES_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LOCALE_H 1 + +/* Define to 1 if you have the `malloc' function. */ +#cmakedefine HAVE_MALLOC 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_MEMORY_H 1 + +/* Define to 1 if you have the `memset' function. */ +#cmakedefine HAVE_MEMSET 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_NETDB_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_NETINET_IN_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_NET_IF_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_PCRE_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_PCRE_PCRE_H 1 + +/* Have PTHREAD_PRIO_INHERIT. */ +#cmakedefine HAVE_PTHREAD_PRIO_INHERIT 1 + +/* Define to 1 if you have the `select' function. */ +#cmakedefine HAVE_SELECT 1 + +/* Define to 1 if you have the `setresuid' function. */ +#cmakedefine HAVE_SETRESUID 1 + +/* Define to 1 if you have the `setreuid' function. */ +#cmakedefine HAVE_SETREUID 1 + +/* Define to 1 if you have the `setrlimit' function. */ +#cmakedefine HAVE_SETRLIMIT 1 + +/* Define to 1 if you have the `socket' function. */ +#cmakedefine HAVE_SOCKET 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STDLIB_H 1 + +/* Define to 1 if you have the `strerror' function. */ +#cmakedefine HAVE_STRERROR 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STRING_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_IOCTL_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_SELECT_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_SOCKET_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have that is POSIX.1 compatible. */ +#cmakedefine HAVE_SYS_WAIT_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_UDNS_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_UNISTD_H 1 + +/* Define to 1 if you have the `vfork' function. */ +#cmakedefine HAVE_VFORK 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_VFORK_H 1 + +/* Define to 1 if `fork' works. */ +#cmakedefine HAVE_WORKING_FORK 1 + +/* Define to 1 if `vfork' works. */ +#cmakedefine HAVE_WORKING_VFORK 1 + +/* Define to the sub-directory where libtool stores uninstalled libraries. */ +#cmakedefine LT_OBJDIR "@LT_OBJDIR@" + +/* Define to 1 if assertions should be disabled. */ +#cmakedefine NDEBUG 1 + +/* Name of package */ +#define PACKAGE "@PACKAGE@" + +/* 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 to the full name and version of this package. */ +#define PACKAGE_STRING "@PACKAGE_STRING@" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "@PACKAGE_TARNAME@" + +/* 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 to necessary symbol if this constant uses a non-standard name on + your system. */ +#cmakedefine PTHREAD_CREATE_JOINABLE 1 + +/* Define as the return type of signal handlers (`int' or `void'). */ +#cmakedefine RETSIGTYPE @RETSIGTYPE@ + +/* Define to the type of arg 1 for `select'. */ +#cmakedefine SELECT_TYPE_ARG1 @SELECT_TYPE_ARG1@ + +/* Define to the type of args 2, 3 and 4 for `select'. */ +#cmakedefine SELECT_TYPE_ARG234 @SELECT_TYPE_ARG234@ + +/* Define to the type of arg 5 for `select'. */ +#cmakedefine SELECT_TYPE_ARG5 @SELECT_TYPE_ARG5@ + +/* Define to 1 if you have the ANSI C header files. */ +#cmakedefine STDC_HEADERS 1 + +/* Define to 1 if you can safely include both and . */ +#cmakedefine TIME_WITH_SYS_TIME 1 + +/* If the compiler supports a TLS storage class define it to that here */ +#cmakedefine TLS @TLS@ + +/* Enable extensions on AIX 3, Interix. */ +#ifndef _ALL_SOURCE +#cmakedefine _ALL_SOURCE 1 +#endif +/* Enable GNU extensions on systems that have them. */ +#ifndef _GNU_SOURCE +#cmakedefine _GNU_SOURCE 1 +#endif +/* Enable threading extensions on Solaris. */ +#ifndef _POSIX_PTHREAD_SEMANTICS +#cmakedefine _POSIX_PTHREAD_SEMANTICS 1 +#endif +/* Enable extensions on HP NonStop. */ +#ifndef _TANDEM_SOURCE +#cmakedefine _TANDEM_SOURCE 1 +#endif +/* Enable general extensions on Solaris. */ +#ifndef __EXTENSIONS__ +#cmakedefine __EXTENSIONS__ 1 +#endif + + +/* Define if use system shared lib. */ +#cmakedefine USE_SYSTEM_SHARED_LIB 1 + +/* Version number of package */ +#define VERSION "@VERSION@" + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +#cmakedefine WORDS_BIGENDIAN 1 +# endif +#endif + +/* Define to 1 if on MINIX. */ +#cmakedefine _MINIX 1 + +/* Define to 2 if the system does not provide POSIX.1 features except with + this defined. */ +#cmakedefine _POSIX_1_SOURCE 1 + +/* Define to 1 if you need to in order for `stat' and other things to work. */ +#cmakedefine _POSIX_SOURCE 1 + +/* Define for Solaris 2.5.1 so the uint8_t typedef from , + , or is not used. If the typedef were allowed, the + #define below would cause a syntax error. */ +#cmakedefine _UINT8_T 1 + +/* Define to empty if `const' does not conform to ANSI C. */ +#cmakedefine const 1 + +/* 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 +#cmakedefine inline 1 +#endif + +/* Define to `int' if does not define. */ +#cmakedefine pid_t @pid_t@ + +/* 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. */ +#cmakedefine restrict @restrict@ +/* Work around a bug in Sun C++: it does not support _Restrict or + __restrict__, even though the corresponding Sun C compiler ends up with + "#define restrict _Restrict" or "#define restrict __restrict__" in the + previous line. Perhaps some future version of Sun C++ will work with + restrict; if so, hopefully it defines __RESTRICT like Sun C does. */ +#if defined __SUNPRO_CC && !defined __RESTRICT +# define _Restrict +# define __restrict__ +#endif + +/* Define to `unsigned int' if does not define. */ +#cmakedefine size_t unsigned int + +/* Define to `int' if does not define. */ +#cmakedefine ssize_t int + +/* 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. */ +#cmakedefine uint16_t @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. */ +#cmakedefine uint8_t @uint8_t@ + +/* Define as `fork' if `vfork' does not work. */ +#cmakedefine vfork