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.

151 lines
5.0 KiB

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