CMakeLists.txt 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. # ---[ 3rdparty
  22. set(3RDPARTY_LIBS "")
  23. set(CMAKE_MODULE_PATH ${GSD_ROOT_DIR}/cmake)
  24. # ---[ ZLToolKit
  25. find_package(ZLToolKit REQUIRED)
  26. #link_directories(${ZLTOOLKIT_LINK_DIR})
  27. include_directories(${ZLTOOLKIT_INCLUDE_DIR})
  28. list(APPEND 3RDPARTY_LIBS ${ZLTOOLKIT_LIBRARIES})
  29. message(STATUS "ZLToolKit include: ${ZLTOOLKIT_INCLUDE_DIR}")
  30. message(STATUS "ZLToolKit libraries: ${ZLTOOLKIT_LIBRARIES}")
  31. # ---[ rapidjson
  32. include_directories(${GSD_ROOT_DIR}/3rdparty/)
  33. include_directories(${GSD_ROOT_DIR}/3rdparty/httplib/)
  34. include_directories(${GSD_ROOT_DIR}/framework/core/include)
  35. include_directories(${GSD_ROOT_DIR}/framework/request/include)
  36. include_directories(${GSD_ROOT_DIR}/modules/Expel/include)
  37. include_directories(${GSD_ROOT_DIR}/modules/HttpClient/include)
  38. include_directories(${GSD_ROOT_DIR}/modules/InfineFilter/include)
  39. include_directories(${GSD_ROOT_DIR}/modules/Monitor/include)
  40. include_directories(${GSD_ROOT_DIR}/modules/TCPClient/include)
  41. include_directories(${GSD_ROOT_DIR}/modules/HttpServer/include)
  42. include_directories(${GSD_ROOT_DIR}/modules/config/include)
  43. include_directories(${GSD_ROOT_DIR}/modules/Audit/include)
  44. set(module_list "")
  45. set(srcs "")
  46. if(build_ExpelPlugin)
  47. list(APPEND module_list ExpelPlugin)
  48. include_directories(${PROJECT_SOURCE_DIR}/modules/ExpelPlugin/src)
  49. install(DIRECTORY ExpelPlugin/include/ DESTINATION include)
  50. endif()
  51. if(build_HttpPlugin)
  52. list(APPEND module_list HttpPlugin)
  53. include_directories(${PROJECT_SOURCE_DIR}/modules/HttpPlugin/src)
  54. install(DIRECTORY HttpPlugin/include/ DESTINATION include)
  55. endif()
  56. if(build_MonitorPlugin)
  57. list(APPEND module_list MonitorPlugin)
  58. include_directories(${PROJECT_SOURCE_DIR}/modules/MonitorPlugin/src)
  59. install(DIRECTORY MonitorPlugin/include/ DESTINATION include)
  60. endif()
  61. if(build_TcpPlugin)
  62. list(APPEND module_list TcpPlugin)
  63. include_directories(${PROJECT_SOURCE_DIR}/modules/TcpPlugin/src)
  64. install(DIRECTORY TcpPlugin/include/ DESTINATION include)
  65. endif()
  66. if(build_AuditPlugin)
  67. list(APPEND module_list AuditPlugin)
  68. include_directories(${PROJECT_SOURCE_DIR}/modules/AuditPlugin/src)
  69. install(DIRECTORY AuditPlugin/include/ DESTINATION include)
  70. endif()
  71. # ---[ kafka
  72. if(build_kafka)
  73. find_package(RDKafka REQUIRED)
  74. include_directories(${RDKAFKA_INCLUDE_DIR})
  75. list(APPEND 3RDPARTY_LIBS ${RDKAFKA_LIBRARIES})
  76. #link_directories(${RDKAFKA_LINK_DIR})
  77. message(STATUS "RDKafka include: ${RDKAFKA_INCLUDE_DIR}")
  78. message(STATUS "RDKafka libraries: ${RDKAFKA_LIBRARIES}")
  79. endif()
  80. set(ENABLE_MYSQL ON CACHE BOOL "enable mysql")
  81. #查找mysql是否安装
  82. find_package(MYSQL QUIET)
  83. if(MYSQL_FOUND AND ENABLE_MYSQL)
  84. message(STATUS "找到mysqlclient库:\"${MYSQL_INCLUDE_DIR}\",ENABLE_MYSQL宏已打开")
  85. include_directories(${MYSQL_INCLUDE_DIR})
  86. include_directories(${MYSQL_INCLUDE_DIR}/mysql)
  87. add_definitions(-DENABLE_MYSQL)
  88. list(APPEND 3RDPARTY_LIBS ${MYSQL_LIBRARIES})
  89. endif()
  90. include_directories(${CMAKE_CURRENT_SOURCE_DIR})
  91. foreach(module ${module_list})
  92. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/${module}/include)
  93. file(GLOB_RECURSE module_src ${CMAKE_CURRENT_SOURCE_DIR}/${module}/*.cpp)
  94. list(APPEND srcs ${module_src})
  95. endforeach()
  96. set(LIBRARY_OUTPUT_PATH ${GSD_ROOT_DIR}/lib)
  97. add_library(gsd_plugins SHARED ${srcs})
  98. target_link_libraries(gsd_plugins ${3RDPARTY_LIBS} rt dl uuid pthread)