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.

153 lines
5.0 KiB

5 years ago
5 years ago
  1. cmake_minimum_required(VERSION 3.2)
  2. set(PROJECT_NAME shadowsocks-libev)
  3. set(RELEASE_DATE 2019-10-31)
  4. set(PROJECT_VERSION "3.3.3")
  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(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/out)
  11. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
  12. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
  13. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
  14. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
  15. set(RUNTIME_SHARED_OUTPUT_DIRECTORY ${CMAKE_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(${CMAKE_SOURCE_DIR}/cmake/configure.cmake)
  36. configure_file(${CMAKE_SOURCE_DIR}/cmake/config.h.cmake ${CMAKE_BINARY_DIR}/src/config.h)
  37. add_definitions(-I$(CMAKE_BINARY_DIR)/src)
  38. add_definitions(-DHAVE_CONFIG_H)
  39. # pkg-config
  40. configure_file(
  41. ${CMAKE_SOURCE_DIR}/cmake/shadowsocks-libev.pc.cmake
  42. ${CMAKE_BINARY_DIR}/pkgconfig/shadowsocks-libev.pc
  43. @ONLY
  44. )
  45. install(FILES
  46. ${CMAKE_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/posix/subprocess.c
  81. libcork/src/libcork/pthreads/thread.c
  82. )
  83. if (WITH_STATIC)
  84. add_library(cork STATIC ${LIBCORK_SOURCE})
  85. target_compile_definitions(cork PUBLIC -DCORK_API=CORK_LOCAL)
  86. endif ()
  87. add_library(cork-shared SHARED ${LIBCORK_SOURCE})
  88. target_compile_definitions(cork-shared PUBLIC -DCORK_API=CORK_EXPORT)
  89. set_target_properties(cork-shared PROPERTIES OUTPUT_NAME cork)
  90. set(LIBIPSET_SOURCE
  91. libipset/src/libipset/general.c
  92. libipset/src/libipset/bdd/assignments.c
  93. libipset/src/libipset/bdd/basics.c
  94. libipset/src/libipset/bdd/bdd-iterator.c
  95. libipset/src/libipset/bdd/expanded.c
  96. libipset/src/libipset/bdd/reachable.c
  97. libipset/src/libipset/bdd/read.c
  98. libipset/src/libipset/bdd/write.c
  99. libipset/src/libipset/map/allocation.c
  100. libipset/src/libipset/map/inspection.c
  101. libipset/src/libipset/map/ipv4_map.c
  102. libipset/src/libipset/map/ipv6_map.c
  103. libipset/src/libipset/map/storage.c
  104. libipset/src/libipset/set/allocation.c
  105. libipset/src/libipset/set/inspection.c
  106. libipset/src/libipset/set/ipv4_set.c
  107. libipset/src/libipset/set/ipv6_set.c
  108. libipset/src/libipset/set/iterator.c
  109. libipset/src/libipset/set/storage.c
  110. )
  111. if (WITH_STATIC)
  112. add_library(ipset STATIC ${LIBIPSET_SOURCE})
  113. endif ()
  114. add_library(ipset-shared SHARED ${LIBIPSET_SOURCE})
  115. set_target_properties(ipset-shared PROPERTIES OUTPUT_NAME ipset)
  116. set(LIBBLOOM_SOURCE
  117. libbloom/bloom.c
  118. libbloom/murmur2/MurmurHash2.c
  119. )
  120. if (WITH_STATIC)
  121. add_library(bloom STATIC ${LIBBLOOM_SOURCE})
  122. target_link_libraries(ipset cork bloom)
  123. endif ()
  124. add_library(bloom-shared SHARED ${LIBBLOOM_SOURCE})
  125. target_link_libraries(ipset-shared cork-shared bloom-shared)
  126. set_target_properties(bloom-shared PROPERTIES OUTPUT_NAME bloom)
  127. endif ()
  128. add_subdirectory(src)
  129. add_subdirectory(doc)