CMakeLists.txt 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. cmake_minimum_required(VERSION 2.8.7)
  2. include(CheckCXXCompilerFlag)
  3. CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
  4. if(NOT COMPILER_SUPPORTS_CXX11)
  5. message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
  6. endif()
  7. if(USE_libstdcpp)
  8. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++")
  9. message("-- Warning: forcing libstdc++ (controlled by USE_libstdcpp option in cmake)")
  10. endif()
  11. set(CNSTREAM_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../)
  12. set(SOURCE_ROOT_DIR ${CNSTREAM_ROOT_DIR}/source)
  13. #message(STATUS "SOURCE: CNSTREAM_ROOT_DIR = ${CNSTREAM_ROOT_DIR}")
  14. #message(STATUS "SOURCE: SOURCE_ROOT_DIR = ${SOURCE_ROOT_DIR}")
  15. # # compile flags
  16. # set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG -O2")
  17. # set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -g")
  18. # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -D_REENTRANT -fPIC -Wall -Werror")
  19. option(build_kafka "build model kafka" ON)
  20. # ---[ 3rdparty
  21. set(3RDPARTY_LIBS "")
  22. # ---[ kafka
  23. if(build_kafka)
  24. find_package(RDKafka REQUIRED)
  25. include_directories(${RDKAFKA_INCLUDE_DIR})
  26. list(APPEND 3RDPARTY_LIBS ${RDKAFKA_LIBRARIES})
  27. #link_directories(${RDKAFKA_LINK_DIR})
  28. message(STATUS "Source: RDKafka include: ${RDKAFKA_INCLUDE_DIR}")
  29. message(STATUS "Source: RDKafka libraries: ${RDKAFKA_LIBRARIES}")
  30. endif()
  31. set(ENABLE_MYSQL ON CACHE BOOL "enable mysql")
  32. #查找mysql是否安装
  33. find_package(MYSQL QUIET)
  34. if(MYSQL_FOUND AND ENABLE_MYSQL)
  35. message(STATUS "找到mysqlclient库:\"${MYSQL_INCLUDE_DIR}\",ENABLE_MYSQL宏已打开")
  36. include_directories(${MYSQL_INCLUDE_DIR})
  37. include_directories(${MYSQL_INCLUDE_DIR}/mysql)
  38. add_definitions(-DENABLE_MYSQL)
  39. list(APPEND 3RDPARTY_LIBS ${MYSQL_LIBRARIES})
  40. endif()
  41. set(CMAKE_MODULE_PATH ${CNSTREAM_ROOT_DIR}/cmake/sanitizers ${CNSTREAM_ROOT_DIR}/cmake)
  42. # ---[ ZLToolKit
  43. find_package(ZLToolKit REQUIRED)
  44. #link_directories(${ZLTOOLKIT_LINK_DIR})
  45. include_directories(${ZLTOOLKIT_INCLUDE_DIR})
  46. list(APPEND 3RDPARTY_LIBS ${ZLTOOLKIT_LIBRARIES})
  47. message(STATUS "Source: ZLToolKit include: ${ZLTOOLKIT_INCLUDE_DIR}")
  48. message(STATUS "Source: ZLToolKit libraries: ${ZLTOOLKIT_LIBRARIES}")
  49. # ---[ rapidjson
  50. include_directories(${CNSTREAM_ROOT_DIR}/3rdparty/)
  51. # ---[ httplib
  52. include_directories(${CNSTREAM_ROOT_DIR}/3rdparty/httplib/)
  53. # ---[ modules include dirs
  54. include_directories(${CNSTREAM_ROOT_DIR}/modules/Expel/include)
  55. include_directories(${CNSTREAM_ROOT_DIR}/modules/HttpClient/include)
  56. include_directories(${CNSTREAM_ROOT_DIR}/modules/HttpServer/include)
  57. include_directories(${CNSTREAM_ROOT_DIR}/modules/InfineFilter/include)
  58. include_directories(${CNSTREAM_ROOT_DIR}/modules/Monitor/include)
  59. include_directories(${CNSTREAM_ROOT_DIR}/modules/TCPClient/include)
  60. include_directories(${CNSTREAM_ROOT_DIR}/modules/config/include)
  61. include_directories(${CNSTREAM_ROOT_DIR}/modules/Hepu/include)
  62. include_directories(${CNSTREAM_ROOT_DIR}/source/UserApp/include)
  63. #include_directories(${CNSTREAM_ROOT_DIR}/source/TestApp/include)
  64. include_directories(${CNSTREAM_ROOT_DIR}/framework/core/include)
  65. include_directories(${CNSTREAM_ROOT_DIR}/framework/request/include)
  66. include_directories(${CNSTREAM_ROOT_DIR}/plugins/ExpelPlugin/include)
  67. include_directories(${CNSTREAM_ROOT_DIR}/plugins/HttpPlugin/include)
  68. include_directories(${CNSTREAM_ROOT_DIR}/plugins/MonitorPlugin/include)
  69. include_directories(${CNSTREAM_ROOT_DIR}/plugins/TcpPlugin/include)
  70. include_directories(${CNSTREAM_ROOT_DIR}/plugins/AuditPlugin/include)
  71. include_directories(${CNSTREAM_ROOT_DIR}/plugins/HepuPlugin/include)
  72. aux_source_directory(${CNSTREAM_ROOT_DIR}/source/src srcs)
  73. aux_source_directory(${CNSTREAM_ROOT_DIR}/source/UserApp/src userApps)
  74. # ---[ add targets
  75. set(EXECUTABLE_OUTPUT_PATH ${SOURCE_ROOT_DIR}/bin)
  76. add_executable(gsd ${srcs} ${userApps} ${3RDPARTY_LIBS})
  77. target_link_libraries(gsd gsd_core gsd_modules gsd_plugins ${3RDPARTY_LIBS} pthread dl)