CMakeLists.txt 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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_WSASENDMSG "mswsock.h" HAVE_MSW_1)
  39. check_symbol_exists(WSAID_WSARECVMSG "mswsock.h" HAVE_MSW_2)
  40. check_symbol_exists(WSAID_ACCEPTEX "mswsock.h" HAVE_MSW_3)
  41. check_symbol_exists(WSAID_GETACCEPTEXSOCKADDRS "mswsock.h" HAVE_MSW_4)
  42. check_symbol_exists(WSAID_CONNECTEX "mswsock.h" HAVE_MSW_5)
  43. set(CMAKE_REQUIRED_DEFINITIONS "")
  44. if (NOT (HAVE_MSW_1 AND HAVE_MSW_2 AND HAVE_MSW_3 AND HAVE_MSW_4 AND HAVE_MSW_5))
  45. add_definitions(-DBADVPN_USE_SHIPPED_MSWSOCK)
  46. check_type_size(WSAMSG HAVE_WSAMSG)
  47. if (NOT HAVE_WSAMSG)
  48. add_definitions(-DBADVPN_SHIPPED_MSWSOCK_DECLARE_WSAMSG)
  49. endif ()
  50. endif ()
  51. else ()
  52. set(BADVPN_THREADWORK_USE_PTHREAD 1)
  53. add_definitions(-DBADVPN_THREADWORK_USE_PTHREAD)
  54. link_libraries(rt)
  55. if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
  56. add_definitions(-DBADVPN_LINUX)
  57. check_include_files(sys/signalfd.h HAVE_SYS_SIGNALFD_H)
  58. if (HAVE_SYS_SIGNALFD_H)
  59. add_definitions(-DBADVPN_USE_SIGNALFD)
  60. else ()
  61. add_definitions(-DBADVPN_USE_SELFPIPE)
  62. endif ()
  63. check_include_files(sys/epoll.h HAVE_SYS_EPOLL_H)
  64. if (HAVE_SYS_EPOLL_H)
  65. add_definitions(-DBADVPN_USE_EPOLL)
  66. else ()
  67. add_definitions(-DBADVPN_USE_POLL)
  68. endif ()
  69. check_include_files(linux/rfkill.h HAVE_LINUX_RFKILL_H)
  70. if (HAVE_LINUX_RFKILL_H)
  71. add_definitions(-DBADVPN_USE_LINUX_RFKILL)
  72. set(BADVPN_USE_LINUX_RFKILL 1)
  73. endif ()
  74. check_include_files(linux/input.h HAVE_LINUX_INPUT_H)
  75. if (HAVE_LINUX_INPUT_H)
  76. add_definitions(-DBADVPN_USE_LINUX_INPUT)
  77. set(BADVPN_USE_LINUX_INPUT 1)
  78. endif ()
  79. check_include_files(sys/inotify.h HAVE_SYS_INOTIFY_H)
  80. if (HAVE_SYS_INOTIFY_H)
  81. add_definitions(-DBADVPN_USE_INOTIFY)
  82. set(BADVPN_USE_INOTIFY 1)
  83. endif ()
  84. elseif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
  85. add_definitions(-DBADVPN_FREEBSD)
  86. check_symbol_exists(kqueue "sys/types.h;sys/event.h;sys/time.h" HAVE_KQUEUE)
  87. if (NOT HAVE_KQUEUE)
  88. message(FATAL_ERROR "kqueue is required")
  89. endif ()
  90. add_definitions(-DBADVPN_USE_KEVENT)
  91. endif ()
  92. if (NOT DEFINED BADVPN_WITHOUT_CRYPTODEV)
  93. check_include_files(crypto/cryptodev.h HAVE_CRYPTO_CRYPTODEV_H)
  94. if (HAVE_CRYPTO_CRYPTODEV_H)
  95. add_definitions(-DBADVPN_USE_CRYPTODEV)
  96. elseif (DEFINED BADVPN_WITH_CRYPTODEV)
  97. message(FATAL_ERROR "crypto/cryptodev.h not found")
  98. endif ()
  99. endif ()
  100. endif ()
  101. # add preprocessor definitions
  102. if (BIG_ENDIAN)
  103. add_definitions(-DBADVPN_BIG_ENDIAN)
  104. else ()
  105. add_definitions(-DBADVPN_LITTLE_ENDIAN)
  106. endif ()
  107. # install man pages
  108. install(
  109. FILES badvpn.7
  110. DESTINATION share/man/man7
  111. )
  112. install(
  113. FILES badvpn-server.8 badvpn-client.8
  114. DESTINATION share/man/man8
  115. )
  116. # internal libraries
  117. add_subdirectory(base)
  118. add_subdirectory(system)
  119. add_subdirectory(flow)
  120. add_subdirectory(flowextra)
  121. add_subdirectory(tuntap)
  122. add_subdirectory(predicate)
  123. add_subdirectory(nspr_support)
  124. add_subdirectory(server_connection)
  125. add_subdirectory(security)
  126. add_subdirectory(socksclient)
  127. add_subdirectory(lwip)
  128. add_subdirectory(dhcpclient)
  129. add_subdirectory(ncdconfig)
  130. add_subdirectory(threadwork)
  131. add_subdirectory(stringmap)
  132. add_subdirectory(udpgw_client)
  133. if (NOT WIN32)
  134. add_subdirectory(process)
  135. add_subdirectory(inputprocess)
  136. add_subdirectory(udevmonitor)
  137. endif ()
  138. # example programs
  139. add_subdirectory(examples)
  140. # tests
  141. add_subdirectory(tests)
  142. # server
  143. add_subdirectory(server)
  144. # client
  145. add_subdirectory(client)
  146. # flooder
  147. add_subdirectory(flooder)
  148. # tun2socks
  149. add_subdirectory(tun2socks)
  150. # udpgw
  151. add_subdirectory(udpgw)
  152. # ncd
  153. if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
  154. add_subdirectory(ncd)
  155. endif ()