CMakeLists.txt 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. cmake_minimum_required(VERSION 2.6)
  2. project(BADVPN C)
  3. set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
  4. include(TestBigEndian)
  5. include(CheckIncludeFiles)
  6. include(CheckSymbolExists)
  7. include(CheckTypeSize)
  8. find_package(OpenSSL REQUIRED)
  9. set(LIBCRYPTO_INCLUDE_DIRS "${OpenSSL_INCLUDE_DIRS}")
  10. set(LIBCRYPTO_LIBRARY_DIRS "${OpenSSL_LIBRARY_DIRS}")
  11. set(LIBCRYPTO_LIBRARIES "${OpenSSL_LIBRARIES}")
  12. find_package(NSPR REQUIRED)
  13. find_package(NSS REQUIRED)
  14. include_directories(
  15. ${CMAKE_CURRENT_SOURCE_DIR}
  16. ${LIBCRYPTO_INCLUDE_DIRS}
  17. ${NSPR_INCLUDE_DIRS}
  18. ${NSS_INCLUDE_DIRS}
  19. lwip/custom
  20. lwip/src/include
  21. lwip/src/include/ipv4
  22. )
  23. link_directories(
  24. ${LIBCRYPTO_LIBRARY_DIRS}
  25. ${NSPR_LIBRARY_DIRS}
  26. ${NSS_LIBRARY_DIRS}
  27. )
  28. test_big_endian(BIG_ENDIAN)
  29. check_type_size(int INT_SIZE)
  30. if (NOT (INT_SIZE GREATER "3"))
  31. message(FATAL_ERROR "int must be at least 32 bits")
  32. endif ()
  33. add_definitions(-std=gnu99 -Werror=implicit-function-declaration -Wno-unused-value -Wno-parentheses -Wno-switch-enum -Wredundant-decls)
  34. # platform-specific stuff
  35. if (WIN32)
  36. add_definitions(-DBADVPN_USE_WINAPI -D_WIN32_WINNT=0x600 -DWIN32_LEAN_AND_MEAN)
  37. set(CMAKE_REQUIRED_DEFINITIONS "-D_WIN32_WINNT=0x600")
  38. check_symbol_exists(WSAID_WSARECVMSG "mswsock.h" HAVE_WSARECVMSG)
  39. check_symbol_exists(WSAID_WSASENDMSG "mswsock.h" HAVE_WSASENDMSG)
  40. set(CMAKE_REQUIRED_DEFINITIONS "")
  41. if (NOT (HAVE_WSARECVMSG AND HAVE_WSASENDMSG))
  42. add_definitions(-DBADVPN_USE_CUSTOM_MSWSOCK_H)
  43. endif ()
  44. else ()
  45. set(BADVPN_THREADWORK_USE_PTHREAD 1)
  46. add_definitions(-DBADVPN_THREADWORK_USE_PTHREAD)
  47. link_libraries(rt)
  48. if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
  49. add_definitions(-DBADVPN_LINUX)
  50. check_include_files(sys/signalfd.h HAVE_SYS_SIGNALFD_H)
  51. if (NOT HAVE_SYS_SIGNALFD_H)
  52. message(FATAL_ERROR "signalfd is required")
  53. endif ()
  54. add_definitions(-DBADVPN_USE_SIGNALFD)
  55. check_include_files(sys/epoll.h HAVE_SYS_EPOLL_H)
  56. if (NOT HAVE_SYS_EPOLL_H)
  57. message(FATAL_ERROR "epoll is required")
  58. endif ()
  59. add_definitions(-DBADVPN_USE_EPOLL)
  60. check_include_files(linux/rfkill.h HAVE_LINUX_RFKILL_H)
  61. if (HAVE_LINUX_RFKILL_H)
  62. add_definitions(-DBADVPN_USE_LINUX_RFKILL)
  63. set(BADVPN_USE_LINUX_RFKILL 1)
  64. endif ()
  65. check_include_files(linux/input.h HAVE_LINUX_INPUT_H)
  66. if (HAVE_LINUX_INPUT_H)
  67. add_definitions(-DBADVPN_USE_LINUX_INPUT)
  68. set(BADVPN_USE_LINUX_INPUT 1)
  69. endif ()
  70. check_include_files(sys/inotify.h HAVE_SYS_INOTIFY_H)
  71. if (HAVE_SYS_INOTIFY_H)
  72. add_definitions(-DBADVPN_USE_INOTIFY)
  73. set(BADVPN_USE_INOTIFY 1)
  74. endif ()
  75. elseif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
  76. add_definitions(-DBADVPN_FREEBSD)
  77. check_symbol_exists(kqueue "sys/types.h;sys/event.h;sys/time.h" HAVE_KQUEUE)
  78. if (NOT HAVE_KQUEUE)
  79. message(FATAL_ERROR "kqueue is required")
  80. endif ()
  81. add_definitions(-DBADVPN_USE_KEVENT)
  82. endif ()
  83. if (NOT DEFINED BADVPN_WITHOUT_CRYPTODEV)
  84. check_include_files(crypto/cryptodev.h HAVE_CRYPTO_CRYPTODEV_H)
  85. if (HAVE_CRYPTO_CRYPTODEV_H)
  86. add_definitions(-DBADVPN_USE_CRYPTODEV)
  87. elseif (DEFINED BADVPN_WITH_CRYPTODEV)
  88. message(FATAL_ERROR "crypto/cryptodev.h not found")
  89. endif ()
  90. endif ()
  91. endif ()
  92. # add preprocessor definitions
  93. if (BIG_ENDIAN)
  94. add_definitions(-DBADVPN_BIG_ENDIAN)
  95. else ()
  96. add_definitions(-DBADVPN_LITTLE_ENDIAN)
  97. endif ()
  98. # install man pages
  99. install(
  100. FILES badvpn.7
  101. DESTINATION share/man/man7
  102. )
  103. install(
  104. FILES badvpn-server.8 badvpn-client.8
  105. DESTINATION share/man/man8
  106. )
  107. # internal libraries
  108. add_subdirectory(system)
  109. add_subdirectory(flow)
  110. add_subdirectory(tuntap)
  111. add_subdirectory(predicate)
  112. add_subdirectory(nspr_support)
  113. add_subdirectory(server_connection)
  114. add_subdirectory(security)
  115. add_subdirectory(socksclient)
  116. add_subdirectory(lwip)
  117. add_subdirectory(dhcpclient)
  118. add_subdirectory(ncdconfig)
  119. add_subdirectory(threadwork)
  120. if (NOT WIN32)
  121. add_subdirectory(ipc)
  122. add_subdirectory(process)
  123. endif ()
  124. # example programs
  125. add_subdirectory(examples)
  126. # tests
  127. add_subdirectory(tests)
  128. # server
  129. add_subdirectory(server)
  130. # client
  131. add_subdirectory(client)
  132. # flooder
  133. add_subdirectory(flooder)
  134. # tun2socks
  135. add_subdirectory(tun2socks)
  136. # ncd
  137. if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
  138. add_subdirectory(ncd)
  139. endif ()