CMakeLists.txt 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. cmake_minimum_required (VERSION 2.8.12)
  2. project (ZMAP C)
  3. SET (VERSION 2.0.0)
  4. option(WITH_REDIS "Build with support for Redis DB" OFF)
  5. option(WITH_MONGO "Build with support for MongoDB" OFF)
  6. option(WITH_JSON "Build with support for JSON" ON)
  7. option(ENABLE_DEVELOPMENT "Enable development specific compiler and linker flags" OFF)
  8. option(RESPECT_INSTALL_PREFIX_CONFIG "Respect CMAKE_INSTALL_PREFIX for /etc" OFF)
  9. option(WITH_WERROR "Build with -Werror" OFF)
  10. option(WITH_PFRING "Build with PF_RING ZC for send (10 GigE)" OFF)
  11. if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  12. set(USING_CLANG "YES")
  13. else()
  14. set(USING_GCC "YES")
  15. endif()
  16. if ("${CMAKE_SYSTEM_NAME}" MATCHES "FreeBSD" OR "${CMAKE_SYSTEM_NAME}" MATCHES "NetBSD")
  17. set(BSD "YES")
  18. endif()
  19. # Hardening and warnings for building with gcc
  20. # Maybe add -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations
  21. set(GCCWARNINGS
  22. "-Wall -Wformat=2 -Wno-format-nonliteral"
  23. "-pedantic -fno-strict-aliasing"
  24. "-Wextra"
  25. "-Wfloat-equal -Wundef -Wwrite-strings -Wredundant-decls"
  26. "-Wnested-externs -Wbad-function-cast -Winit-self"
  27. "-Wmissing-noreturn"
  28. "-Wstack-protector"
  29. )
  30. # Fix line breaks
  31. string(REPLACE ";" " " GCCWARNINGS "${GCCWARNINGS}")
  32. if(WITH_WERROR)
  33. set(GCCWARNINGS "${GCCWARNINGS} -Werror")
  34. endif()
  35. if(ENABLE_DEVELOPMENT)
  36. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ggdb")
  37. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -g")
  38. else()
  39. # Hardening and optimizations for building with gcc
  40. set(GCCHARDENING "-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fstack-protector-all -fwrapv -fPIC --param ssp-buffer-size=1")
  41. if (NOT APPLE AND NOT BSD)
  42. set(LDHARDENING "-z relro -z now")
  43. else()
  44. set(LDHARDENING "")
  45. endif()
  46. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GCCHARDENING} -O2")
  47. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LDHARDENING}")
  48. endif()
  49. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GCCWARNINGS}")
  50. if(WITH_REDIS)
  51. set(REDIS_LIBS hiredis)
  52. add_definitions("-DREDIS")
  53. endif()
  54. if(WITH_JSON)
  55. include(FindPkgConfig)
  56. pkg_check_modules(JSON json-c)
  57. if(JSON_FOUND)
  58. include_directories(${JSON_INCLUDE_DIRS})
  59. else()
  60. message(FATAL_ERROR "Did not find libjson")
  61. endif()
  62. add_definitions("-DJSON")
  63. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${JSON_CFLAGS}")
  64. endif()
  65. if(WITH_MONGO)
  66. include(FindPkgConfig)
  67. pkg_check_modules(MONGO libmongoc-1.0)
  68. if(MONGO_FOUND)
  69. include_directories(${MONGO_INCLUDE_DIRS})
  70. else()
  71. message(FATAL_ERROR "Did not find libmongoc-1.0")
  72. endif()
  73. add_definitions("-DMONGODB")
  74. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MONGO_CFLAGS_OTHER}")
  75. endif()
  76. if(WITH_PFRING)
  77. add_definitions("-DPFRING")
  78. set(PFRING_LIBRARIES pfring rt numa)
  79. endif()
  80. # Standard FLAGS
  81. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
  82. if (NOT APPLE)
  83. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread")
  84. endif()
  85. # Set up OS-specific include directories
  86. if (APPLE)
  87. if (EXISTS /opt/local/include)
  88. include_directories(/opt/local/include)
  89. endif()
  90. if (EXISTS /opt/local/lib)
  91. link_directories(/opt/local/lib)
  92. endif()
  93. if (EXISTS /usr/local/include)
  94. include_directories(/usr/local/include)
  95. endif()
  96. if (EXISTS /usr/local/lib)
  97. link_directories(/usr/local/lib)
  98. endif()
  99. endif()
  100. if (BSD)
  101. include_directories(/usr/local/include)
  102. link_directories(/usr/local/lib)
  103. endif()
  104. add_subdirectory(lib)
  105. add_subdirectory(src)
  106. # Install conf files
  107. FILE(GLOB CONF_FILES "${PROJECT_SOURCE_DIR}/conf/*")
  108. if (RESPECT_INSTALL_PREFIX_CONFIG)
  109. set(CONFIG_DESTINATION "etc/zmap")
  110. else()
  111. set(CONFIG_DESTINATION "/etc/zmap")
  112. endif()
  113. install(SCRIPT InstallConfFiles.cmake)
  114. # Allow Debian Packaging
  115. INCLUDE (InstallRequiredSystemLibraries)
  116. SET (CPACK_SET_DESTDIR "on")
  117. SET (CPACK_PACKAGING_INSTALL_PREFIX "/tmp")
  118. SET (CPACK_GENERATOR "DEB")
  119. SET (${VERSION} CPACK_DEBIAN_PACKAGE_VERSION)
  120. SET (CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
  121. SET (CPACK_DEBIAN_PACKAGE_SECTION "network")
  122. SET (CPACK_DEBIAN_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR})
  123. SET (CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.1.3), libgmp10, libpcap0.8")
  124. SET (CPACK_PACKAGE_DESCRIPTION "Internet-scale network scanner")
  125. SET (CPACK_PACKAGE_DESCRIPTION_SUMMARY "ZMap is an open-source network scanner that enables researchers to easily perform Internet-wide network studies. With a single machine and a well provisioned network uplink, ZMap is capable of performing a complete scan of the IPv4 address space in under five minutes, approaching the theoretical limit of gigabit Ethernet. ZMap can be used to study protocol adoption over time, monitor service availability, and help us better understand large systems distributed across the Internet.")
  126. SET (CPACK_PACKAGE_CONTACT "Zakir Durumeric <zakird@gmail.com>")
  127. SET (CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}_${VERSION}_${CPACK_DEBIAN_ARCHITECTURE}")
  128. SET (CPACK_COMPONENTS_ALL Libraries ApplicationData)
  129. INCLUDE(CPack)