CMakeLists.txt 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. # ---[ 3rdparty
  21. set(3RDPARTY_LIBS "")
  22. set(CMAKE_MODULE_PATH ${GSD_ROOT_DIR}/cmake)
  23. # ---[ ZLToolKit
  24. find_package(ZLToolKit REQUIRED)
  25. link_directories(${ZLTOOLKIT_LINK_DIR})
  26. include_directories(${ZLTOOLKIT_INCLUDE_DIR})
  27. list(APPEND 3RDPARTY_LIBS ${ZLTOOLKIT_LIBRARIES})
  28. message(STATUS "ZLToolKit include: ${ZLTOOLKIT_INCLUDE_DIR}")
  29. message(STATUS "ZLToolKit libraries: ${ZLTOOLKIT_LIBRARIES}")
  30. message(STATUS "ZLToolKit link dir: ${ZLTOOLKIT_LINK_DIR}")
  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. set(ENABLE_MYSQL ON CACHE BOOL "enable mysql")
  72. #查找mysql是否安装
  73. find_package(MYSQL QUIET)
  74. if(MYSQL_FOUND AND ENABLE_MYSQL)
  75. message(STATUS "找到mysqlclient库:\"${MYSQL_INCLUDE_DIR}\",ENABLE_MYSQL宏已打开")
  76. include_directories(${MYSQL_INCLUDE_DIR})
  77. include_directories(${MYSQL_INCLUDE_DIR}/mysql)
  78. add_definitions(-DENABLE_MYSQL)
  79. list(APPEND 3RDPARTY_LIBS ${MYSQL_LIBRARIES})
  80. endif()
  81. include_directories(${CMAKE_CURRENT_SOURCE_DIR})
  82. foreach(module ${module_list})
  83. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/${module}/include)
  84. file(GLOB_RECURSE module_src ${CMAKE_CURRENT_SOURCE_DIR}/${module}/*.cpp)
  85. list(APPEND srcs ${module_src})
  86. endforeach()
  87. set(LIBRARY_OUTPUT_PATH ${GSD_ROOT_DIR}/lib)
  88. add_library(gsd_plugins SHARED ${srcs})
  89. target_link_libraries(gsd_plugins ${3RDPARTY_LIBS} rt dl uuid pthread)