CMakeLists.txt 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. ##################################
  2. # DEFINITION OF C++ PROJECT
  3. ##################################
  4. project(cpp-pcapreader)
  5. # Define CMake settings
  6. cmake_minimum_required(VERSION 3.2)
  7. IF(NOT CMAKE_BUILD_TYPE)
  8. SET(CMAKE_BUILD_TYPE "Release")
  9. ENDIF()
  10. IF (CMAKE_BUILD_TYPE MATCHES Debug)
  11. MESSAGE(STATUS "Running Debug configuration.")
  12. ELSEIF (CMAKE_BUILD_TYPE MATCHES Release)
  13. MESSAGE(STATUS "Running Release configuration.")
  14. ENDIF()
  15. SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall")
  16. SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall")
  17. SET(CMAKE_CXX_STANDARD 11)
  18. SET(CMAKE_CXX_STANDARD_REQUIRED ON)
  19. # Add the library source files
  20. SET(SOURCE_FILES cxx/pcap_processor.cpp cxx/pcap_processor.h cxx/statistics.cpp cxx/statistics.h cxx/statistics_db.cpp cxx/statistics_db.h cxx/utilities.h cxx/utilities.cpp)
  21. # Add botnet comm processor source files
  22. SET(BOT_COMM_PROC_SOURCE cxx/botnet_comm_processor.h cxx/botnet_comm_processor.cpp)
  23. # Include SQLiteCpp library and build it
  24. option(SQLITECPP_RUN_CPPLINT OFF)
  25. include_directories(SQLiteCpp/include)
  26. add_subdirectory(SQLiteCpp)
  27. # Find libtins library
  28. FIND_LIBRARY(TINS_LIBRARY tins)
  29. IF(TINS_LIBRARY)
  30. MESSAGE(STATUS "Tins library found in ${TINS_LIBRARY}")
  31. ELSE()
  32. MESSAGE(FATAL_ERROR "Tins library not found.")
  33. ENDIF()
  34. FIND_PACKAGE(PythonLibs 3.0 REQUIRED)
  35. IF(PYTHONLIBS_FOUND)
  36. INCLUDE_DIRECTORIES("${PYTHON_INCLUDE_DIRS}")
  37. MESSAGE(STATUS "Python includes found in: " ${PYTHON_INCLUDE_DIRS} )
  38. MESSAGE(STATUS "Python libs found in: " ${PYTHON_LIBRARIES} )
  39. ELSE()
  40. MESSAGE(FATAL_ERROR "Unable to find Python libraries.")
  41. ENDIF()
  42. # Find and configure BOOST library
  43. FIND_PACKAGE(Boost 1.54 QUIET)
  44. IF (Boost_FOUND)
  45. INCLUDE_DIRECTORIES("${Boost_INCLUDE_DIRS}")
  46. MESSAGE(STATUS "Boots includes found in: " ${Boost_INCLUDE_DIRS} )
  47. SET(Boost_USE_STATIC_LIBS OFF)
  48. SET(Boost_USE_MULTITHREADED ON)
  49. SET(Boost_USE_STATIC_RUNTIME OFF)
  50. # Find the boost python 3 component
  51. EXECUTE_PROCESS(COMMAND python3 --version OUTPUT_VARIABLE PY_VERSION)
  52. STRING(REGEX REPLACE "Python ([0-9]+)\.([0-9]+)\.[0-9]+" "python-py\\1\\2" PY_VERSION ${PY_VERSION})
  53. STRING(STRIP ${PY_VERSION} PY_VERSION)
  54. SET(PYTHON_VERSIONS python3 ${PY_VERSION} python-py35 python-py34 python-py33 python-py32)
  55. FOREACH(VERSION ${PYTHON_VERSIONS})
  56. FIND_PACKAGE(Boost COMPONENTS ${VERSION} QUIET)
  57. IF(Boost_FOUND)
  58. MESSAGE(STATUS "Python Boost found as '${VERSION}'.")
  59. BREAK()
  60. ENDIF()
  61. ENDFOREACH(VERSION)
  62. IF(NOT Boost_FOUND)
  63. MESSAGE(FATAL_ERROR "Python Boost component not found.")
  64. ENDIF()
  65. ELSE ()
  66. MESSAGE(FATAL_ERROR "Unable to find the Boost libraries (version 1.54 or higher).")
  67. ENDIF ()
  68. SET_target_properties(sqlite3 PROPERTIES POSITION_INDEPENDENT_CODE ON)
  69. ADD_LIBRARY(pcapreader SHARED ${SOURCE_FILES})
  70. # Libs pthread and dl are prerequisites of SQLiteCpp
  71. TARGET_LINK_LIBRARIES(pcapreader ${Boost_LIBRARIES} "${TINS_LIBRARY}" ${PYTHON_LIBRARIES} SQLiteCpp sqlite3 pthread dl)
  72. ADD_LIBRARY(botnetcomm SHARED ${BOT_COMM_PROC_SOURCE})
  73. TARGET_LINK_LIBRARIES(botnetcomm ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
  74. IF (APPLE)
  75. SET(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
  76. ENDIF ()
  77. # comment this out to build executable (for development)
  78. #ADD_EXECUTABLE(cpp-pcapreader ${SOURCE_FILES})
  79. #TARGET_LINK_LIBRARIES(cpp-pcapreader ${Boost_LIBRARIES} "${TINS_LIBRARY}" SQLiteCpp sqlite3 pthread dl)