You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
5.2 KiB

4 years ago
5 years ago
  1. cmake_minimum_required(VERSION 3.2)
  2. set(PROJECT_NAME shadowsocks-libev)
  3. set(RELEASE_DATE 2020-01-10)
  4. set(PROJECT_VERSION "3.3.4")
  5. set(PROJECT_DESC "a lightweight secured socks5 proxy")
  6. set(PROJECT_URL "https://shadowsocks.org")
  7. set(PROJECT_ISSUES_URL "https://github.com/shadowsocks/shadowsocks-libev")
  8. project(${PROJECT_NAME} VERSION ${PROJECT_VERSION})
  9. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
  10. #set(PROJECT_BINARY_DIR ${PROJECT_SOURCE_DIR}/out)
  11. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
  12. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
  13. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
  14. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake)
  15. set(RUNTIME_SHARED_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/shared/bin)
  16. set(CMAKE_MACOSX_RPATH TRUE)
  17. set(CMAKE_POSITION_INDEPENDENT_CODE ON)
  18. if (NOT CMAKE_BUILD_TYPE)
  19. set(CMAKE_BUILD_TYPE Debug)
  20. endif ()
  21. # Detect linux
  22. if (UNIX AND NOT APPLE)
  23. set(LINUX TRUE)
  24. endif ()
  25. message(STATUS "Running cmake version ${CMAKE_VERSION}")
  26. option(WITH_STATIC "build with static libraries." ON)
  27. option(WITH_EMBEDDED_SRC "build with embedded libcork, libipset, and libbloom source." ON)
  28. # Will set GIT_EXECUTABLE and GIT_FOUND
  29. # find_package(Git)
  30. # When choose to not use embedded libcork, libipset and libbloom, use libs shipped by system
  31. if (NOT WITH_EMBEDDED_SRC)
  32. set(USE_SYSTEM_SHARED_LIB TRUE)
  33. endif ()
  34. # Run platform tests
  35. include(${PROJECT_SOURCE_DIR}/cmake/configure.cmake)
  36. configure_file(${PROJECT_SOURCE_DIR}/cmake/config.h.cmake ${PROJECT_BINARY_DIR}/src/config.h)
  37. add_definitions(-I${PROJECT_BINARY_DIR}/src)
  38. add_definitions(-DHAVE_CONFIG_H)
  39. # pkg-config
  40. configure_file(
  41. ${PROJECT_SOURCE_DIR}/cmake/shadowsocks-libev.pc.cmake
  42. ${PROJECT_BINARY_DIR}/pkgconfig/shadowsocks-libev.pc
  43. @ONLY
  44. )
  45. install(FILES
  46. ${PROJECT_BINARY_DIR}/pkgconfig/shadowsocks-libev.pc
  47. DESTINATION lib/pkgconfig
  48. )
  49. if (WITH_EMBEDDED_SRC)
  50. # We need libcork,libipset headers
  51. include_directories(libcork/include)
  52. include_directories(libipset/include)
  53. include_directories(libbloom/murmur2)
  54. include_directories(libbloom)
  55. set(LIBCORK_SOURCE
  56. libcork/src/libcork/cli/commands.c
  57. libcork/src/libcork/core/allocator.c
  58. libcork/src/libcork/core/error.c
  59. libcork/src/libcork/core/gc.c
  60. libcork/src/libcork/core/hash.c
  61. libcork/src/libcork/core/ip-address.c
  62. libcork/src/libcork/core/mempool.c
  63. libcork/src/libcork/core/timestamp.c
  64. libcork/src/libcork/core/u128.c
  65. libcork/src/libcork/core/version.c
  66. libcork/src/libcork/ds/array.c
  67. libcork/src/libcork/ds/bitset.c
  68. libcork/src/libcork/ds/buffer.c
  69. libcork/src/libcork/ds/dllist.c
  70. libcork/src/libcork/ds/file-stream.c
  71. libcork/src/libcork/ds/hash-table.c
  72. libcork/src/libcork/ds/managed-buffer.c
  73. libcork/src/libcork/ds/ring-buffer.c
  74. libcork/src/libcork/ds/slice.c
  75. libcork/src/libcork/posix/directory-walker.c
  76. libcork/src/libcork/posix/env.c
  77. libcork/src/libcork/posix/exec.c
  78. libcork/src/libcork/posix/files.c
  79. libcork/src/libcork/posix/process.c
  80. libcork/src/libcork/pthreads/thread.c
  81. )
  82. if (NOT MINGW)
  83. set(LIBCORK_SOURCE ${LIBCORK_SOURCE} libcork/src/libcork/posix/subprocess.c)
  84. else ()
  85. set(LIBCORK_SOURCE ${LIBCORK_SOURCE} libcork/src/libcork/posix/mingw.c)
  86. endif ()
  87. if (WITH_STATIC)
  88. add_library(cork STATIC ${LIBCORK_SOURCE})
  89. target_compile_definitions(cork PUBLIC -DCORK_API=CORK_LOCAL)
  90. endif ()
  91. add_library(cork-shared SHARED ${LIBCORK_SOURCE})
  92. target_compile_definitions(cork-shared PUBLIC -DCORK_API=CORK_EXPORT)
  93. set_target_properties(cork-shared PROPERTIES OUTPUT_NAME cork)
  94. if (MINGW)
  95. target_link_libraries(cork-shared ws2_32)
  96. endif ()
  97. set(LIBIPSET_SOURCE
  98. libipset/src/libipset/general.c
  99. libipset/src/libipset/bdd/assignments.c
  100. libipset/src/libipset/bdd/basics.c
  101. libipset/src/libipset/bdd/bdd-iterator.c
  102. libipset/src/libipset/bdd/expanded.c
  103. libipset/src/libipset/bdd/reachable.c
  104. libipset/src/libipset/bdd/read.c
  105. libipset/src/libipset/bdd/write.c
  106. libipset/src/libipset/map/allocation.c
  107. libipset/src/libipset/map/inspection.c
  108. libipset/src/libipset/map/ipv4_map.c
  109. libipset/src/libipset/map/ipv6_map.c
  110. libipset/src/libipset/map/storage.c
  111. libipset/src/libipset/set/allocation.c
  112. libipset/src/libipset/set/inspection.c
  113. libipset/src/libipset/set/ipv4_set.c
  114. libipset/src/libipset/set/ipv6_set.c
  115. libipset/src/libipset/set/iterator.c
  116. libipset/src/libipset/set/storage.c
  117. )
  118. if (WITH_STATIC)
  119. add_library(ipset STATIC ${LIBIPSET_SOURCE})
  120. endif ()
  121. add_library(ipset-shared SHARED ${LIBIPSET_SOURCE})
  122. set_target_properties(ipset-shared PROPERTIES OUTPUT_NAME ipset)
  123. set(LIBBLOOM_SOURCE
  124. libbloom/bloom.c
  125. libbloom/murmur2/MurmurHash2.c
  126. )
  127. if (WITH_STATIC)
  128. add_library(bloom STATIC ${LIBBLOOM_SOURCE})
  129. target_link_libraries(ipset cork bloom)
  130. endif ()
  131. add_library(bloom-shared SHARED ${LIBBLOOM_SOURCE})
  132. target_link_libraries(ipset-shared cork-shared bloom-shared)
  133. set_target_properties(bloom-shared PROPERTIES OUTPUT_NAME bloom)
  134. endif ()
  135. add_subdirectory(src)
  136. add_subdirectory(doc)