CMakeLists.txt 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 (HAVE_SYS_EPOLL_H)
  57. add_definitions(-DBADVPN_USE_EPOLL)
  58. else ()
  59. add_definitions(-DBADVPN_USE_POLL)
  60. endif ()
  61. check_include_files(linux/rfkill.h HAVE_LINUX_RFKILL_H)
  62. if (HAVE_LINUX_RFKILL_H)
  63. add_definitions(-DBADVPN_USE_LINUX_RFKILL)
  64. set(BADVPN_USE_LINUX_RFKILL 1)
  65. endif ()
  66. check_include_files(linux/input.h HAVE_LINUX_INPUT_H)
  67. if (HAVE_LINUX_INPUT_H)
  68. add_definitions(-DBADVPN_USE_LINUX_INPUT)
  69. set(BADVPN_USE_LINUX_INPUT 1)
  70. endif ()
  71. check_include_files(sys/inotify.h HAVE_SYS_INOTIFY_H)
  72. if (HAVE_SYS_INOTIFY_H)
  73. add_definitions(-DBADVPN_USE_INOTIFY)
  74. set(BADVPN_USE_INOTIFY 1)
  75. endif ()
  76. elseif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
  77. add_definitions(-DBADVPN_FREEBSD)
  78. check_symbol_exists(kqueue "sys/types.h;sys/event.h;sys/time.h" HAVE_KQUEUE)
  79. if (NOT HAVE_KQUEUE)
  80. message(FATAL_ERROR "kqueue is required")
  81. endif ()
  82. add_definitions(-DBADVPN_USE_KEVENT)
  83. endif ()
  84. if (NOT DEFINED BADVPN_WITHOUT_CRYPTODEV)
  85. check_include_files(crypto/cryptodev.h HAVE_CRYPTO_CRYPTODEV_H)
  86. if (HAVE_CRYPTO_CRYPTODEV_H)
  87. add_definitions(-DBADVPN_USE_CRYPTODEV)
  88. elseif (DEFINED BADVPN_WITH_CRYPTODEV)
  89. message(FATAL_ERROR "crypto/cryptodev.h not found")
  90. endif ()
  91. endif ()
  92. endif ()
  93. # add preprocessor definitions
  94. if (BIG_ENDIAN)
  95. add_definitions(-DBADVPN_BIG_ENDIAN)
  96. else ()
  97. add_definitions(-DBADVPN_LITTLE_ENDIAN)
  98. endif ()
  99. # install man pages
  100. install(
  101. FILES badvpn.7
  102. DESTINATION share/man/man7
  103. )
  104. install(
  105. FILES badvpn-server.8 badvpn-client.8
  106. DESTINATION share/man/man8
  107. )
  108. # internal libraries
  109. add_subdirectory(system)
  110. add_subdirectory(flow)
  111. add_subdirectory(tuntap)
  112. add_subdirectory(predicate)
  113. add_subdirectory(nspr_support)
  114. add_subdirectory(server_connection)
  115. add_subdirectory(security)
  116. add_subdirectory(socksclient)
  117. add_subdirectory(lwip)
  118. add_subdirectory(dhcpclient)
  119. add_subdirectory(ncdconfig)
  120. add_subdirectory(threadwork)
  121. add_subdirectory(stringmap)
  122. if (NOT WIN32)
  123. add_subdirectory(ipc)
  124. add_subdirectory(process)
  125. add_subdirectory(inputprocess)
  126. endif ()
  127. # example programs
  128. add_subdirectory(examples)
  129. # tests
  130. add_subdirectory(tests)
  131. # server
  132. add_subdirectory(server)
  133. # client
  134. add_subdirectory(client)
  135. # flooder
  136. add_subdirectory(flooder)
  137. # tun2socks
  138. add_subdirectory(tun2socks)
  139. # ncd
  140. if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
  141. add_subdirectory(ncd)
  142. endif ()