CMakeLists.txt 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. cmake_minimum_required(VERSION 2.8.7)
  2. set(GSD_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..)
  3. #message(STATUS "PLUGIN: GSD_ROOT_DIR = ${GSD_ROOT_DIR}")
  4. include(CheckCXXCompilerFlag)
  5. CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
  6. if(NOT COMPILER_SUPPORTS_CXX11)
  7. message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
  8. endif()
  9. # compile flags
  10. # set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-as-needed")
  11. # set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG -O2")
  12. # set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -g")
  13. # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -D_REENTRANT -fPIC -Wall -Werror")
  14. # ---[ Options
  15. option(build_ExpelPlugin "build module ExpelPlugin" ON)
  16. option(build_HttpPlugin "build module HttpPlugin" ON)
  17. option(build_MonitorPlugin "build module MonitorPlugin" ON)
  18. option(build_TcpPlugin "build module TcpPlugin" ON)
  19. option(build_AuditPlugin "build module AuditPlugin" ON)
  20. option(build_kafka "build module kafka" ON)
  21. option(build_HepuPlugin "build module HepuPlugin" ON)
  22. # ---[ 3rdparty
  23. set(3RDPARTY_LIBS "")
  24. set(CMAKE_MODULE_PATH ${GSD_ROOT_DIR}/cmake)
  25. # ---[ ZLToolKit
  26. find_package(ZLToolKit REQUIRED)
  27. #link_directories(${ZLTOOLKIT_LINK_DIR})
  28. include_directories(${ZLTOOLKIT_INCLUDE_DIR})
  29. list(APPEND 3RDPARTY_LIBS ${ZLTOOLKIT_LIBRARIES})
  30. message(STATUS "ZLToolKit include: ${ZLTOOLKIT_INCLUDE_DIR}")
  31. message(STATUS "ZLToolKit libraries: ${ZLTOOLKIT_LIBRARIES}")
  32. # ---[ rapidjson
  33. include_directories(${GSD_ROOT_DIR}/3rdparty/)
  34. include_directories(${GSD_ROOT_DIR}/3rdparty/httplib/)
  35. include_directories(${GSD_ROOT_DIR}/framework/core/include)
  36. include_directories(${GSD_ROOT_DIR}/framework/request/include)
  37. include_directories(${GSD_ROOT_DIR}/modules/Expel/include)
  38. include_directories(${GSD_ROOT_DIR}/modules/HttpClient/include)
  39. include_directories(${GSD_ROOT_DIR}/modules/InfineFilter/include)
  40. include_directories(${GSD_ROOT_DIR}/modules/Monitor/include)
  41. include_directories(${GSD_ROOT_DIR}/modules/TCPClient/include)
  42. include_directories(${GSD_ROOT_DIR}/modules/HttpServer/include)
  43. include_directories(${GSD_ROOT_DIR}/modules/config/include)
  44. include_directories(${GSD_ROOT_DIR}/modules/Hepu/include)
  45. include_directories(${GSD_ROOT_DIR}/modules/Audit/include)
  46. set(module_list "")
  47. set(srcs "")
  48. if(build_ExpelPlugin)
  49. list(APPEND module_list ExpelPlugin)
  50. include_directories(${PROJECT_SOURCE_DIR}/plugins/ExpelPlugin/src)
  51. install(DIRECTORY ExpelPlugin/include/ DESTINATION include)
  52. endif()
  53. if(build_HttpPlugin)
  54. list(APPEND module_list HttpPlugin)
  55. include_directories(${PROJECT_SOURCE_DIR}/plugins/HttpPlugin/src)
  56. install(DIRECTORY HttpPlugin/include/ DESTINATION include)
  57. endif()
  58. if(build_MonitorPlugin)
  59. list(APPEND module_list MonitorPlugin)
  60. include_directories(${PROJECT_SOURCE_DIR}/plugins/MonitorPlugin/src)
  61. install(DIRECTORY MonitorPlugin/include/ DESTINATION include)
  62. endif()
  63. if(build_TcpPlugin)
  64. list(APPEND module_list TcpPlugin)
  65. include_directories(${PROJECT_SOURCE_DIR}/plugins/TcpPlugin/src)
  66. install(DIRECTORY TcpPlugin/include/ DESTINATION include)
  67. endif()
  68. if(build_HepuPlugin)
  69. list(APPEND module_list HepuPlugin)
  70. include_directories(${PROJECT_SOURCE_DIR}/plugins/HepuPlugin/src)
  71. install(DIRECTORY HepuPlugin/include/ DESTINATION include)
  72. endif()
  73. if(build_AuditPlugin)
  74. list(APPEND module_list AuditPlugin)
  75. include_directories(${PROJECT_SOURCE_DIR}/plugins/AuditPlugin/src)
  76. install(DIRECTORY AuditPlugin/include/ DESTINATION include)
  77. endif()
  78. # ---[ kafka
  79. if(build_kafka)
  80. find_package(RDKafka REQUIRED)
  81. include_directories(${RDKAFKA_INCLUDE_DIR})
  82. list(APPEND 3RDPARTY_LIBS ${RDKAFKA_LIBRARIES})
  83. #link_directories(${RDKAFKA_LINK_DIR})
  84. message(STATUS "RDKafka include: ${RDKAFKA_INCLUDE_DIR}")
  85. message(STATUS "RDKafka libraries: ${RDKAFKA_LIBRARIES}")
  86. endif()
  87. set(ENABLE_MYSQL ON CACHE BOOL "enable mysql")
  88. #查找mysql是否安装
  89. find_package(MYSQL QUIET)
  90. if(MYSQL_FOUND AND ENABLE_MYSQL)
  91. message(STATUS "找到mysqlclient库:\"${MYSQL_INCLUDE_DIR}\",ENABLE_MYSQL宏已打开")
  92. include_directories(${MYSQL_INCLUDE_DIR})
  93. include_directories(${MYSQL_INCLUDE_DIR}/mysql)
  94. add_definitions(-DENABLE_MYSQL)
  95. list(APPEND 3RDPARTY_LIBS ${MYSQL_LIBRARIES})
  96. endif()
  97. include_directories(${CMAKE_CURRENT_SOURCE_DIR})
  98. foreach(module ${module_list})
  99. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/${module}/include)
  100. file(GLOB_RECURSE module_src ${CMAKE_CURRENT_SOURCE_DIR}/${module}/*.cpp)
  101. list(APPEND srcs ${module_src})
  102. endforeach()
  103. set(LIBRARY_OUTPUT_PATH ${GSD_ROOT_DIR}/lib)
  104. add_library(gsd_plugins SHARED ${srcs})
  105. target_link_libraries(gsd_plugins ${3RDPARTY_LIBS} rt dl uuid pthread)