CMakeLists.txt 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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)
  21. # Include SQLiteCpp library and build it
  22. option(SQLITECPP_RUN_CPPLINT OFF)
  23. include_directories(SQLiteCpp/include)
  24. add_subdirectory(SQLiteCpp)
  25. # Find libtins library
  26. FIND_LIBRARY(TINS_LIBRARY tins)
  27. IF(TINS_LIBRARY)
  28. MESSAGE(STATUS "Tins library found in ${TINS_LIBRARY}")
  29. ELSE()
  30. MESSAGE(FATAL_ERROR "Tins library not found.")
  31. ENDIF()
  32. FIND_PACKAGE(PythonLibs 3.0 REQUIRED)
  33. IF(PYTHONLIBS_FOUND)
  34. INCLUDE_DIRECTORIES("${PYTHON_INCLUDE_DIRS}")
  35. ELSE()
  36. MESSAGE(FATAL_ERROR "Unable to find Python libraries.")
  37. ENDIF()
  38. # Find and configure BOOST library
  39. FIND_PACKAGE(Boost 1.54 QUIET)
  40. IF (Boost_FOUND)
  41. INCLUDE_DIRECTORIES("${Boost_INCLUDE_DIRS}")
  42. SET(Boost_USE_STATIC_LIBS OFF)
  43. SET(Boost_USE_MULTITHREADED ON)
  44. SET(Boost_USE_STATIC_RUNTIME OFF)
  45. # Find the boost python 3 component
  46. SET(PYTHON_VERSIONS python3 python-py35 python-py34 python-py33 python-py32)
  47. FOREACH(VERSION ${PYTHON_VERSIONS})
  48. FIND_PACKAGE(Boost COMPONENTS ${VERSION} QUIET)
  49. IF(Boost_FOUND)
  50. MESSAGE(STATUS "Python Boost found as '${VERSION}'.")
  51. BREAK()
  52. ENDIF()
  53. ENDFOREACH(VERSION)
  54. IF(NOT Boost_FOUND)
  55. MESSAGE(FATAL_ERROR "Python Boost component not found.")
  56. ENDIF()
  57. ELSE ()
  58. MESSAGE(FATAL_ERROR "Unable to find the Boost libraries (version 1.54 or higher).")
  59. ENDIF ()
  60. SET_target_properties(sqlite3 PROPERTIES POSITION_INDEPENDENT_CODE ON)
  61. ADD_LIBRARY(pcapreader SHARED ${SOURCE_FILES})
  62. # Libs pthread and dl are prerequisites of SQLiteCpp
  63. TARGET_LINK_LIBRARIES(pcapreader ${Boost_LIBRARIES} "${TINS_LIBRARY}" SQLiteCpp sqlite3 pthread dl)
  64. # comment this out to build executable (for development)
  65. #ADD_EXECUTABLE(cpp-pcapreader ${SOURCE_FILES})
  66. #TARGET_LINK_LIBRARIES(cpp-pcapreader ${Boost_LIBRARIES} "${TINS_LIBRARY}" SQLiteCpp sqlite3 pthread dl)