CMakeLists.txt 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. cmake_minimum_required(VERSION 2.8.7)
  2. set(GSD_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..)
  3. #message(STATUS "MODULES: 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_Expel "build module Expel" OFF)
  16. option(build_HttpClient "build module HttpClient" OFF)
  17. option(build_InfineFilter "build module InfineFilter" OFF)
  18. option(build_Monitor "build module Monitor" OFF)
  19. option(build_TCPClient "build module TCPClient" OFF)
  20. option(build_config "build module config" OFF)
  21. option(build_HttpServer "build module HttpServer" OFF)
  22. option(build_Audit "build module Audit" OFF)
  23. option(build_kafka "build module kafka" OFF)
  24. option(build_Hepu "build module Hepu" ON)
  25. # ---[ 3rdparty
  26. set(3RDPARTY_LIBS "")
  27. set(CMAKE_MODULE_PATH ${GSD_ROOT_DIR}/cmake)
  28. # ---[ ZLToolKit
  29. find_package(ZLToolKit REQUIRED)
  30. #link_directories(${ZLTOOLKIT_LINK_DIR})
  31. include_directories(${ZLTOOLKIT_INCLUDE_DIR})
  32. list(APPEND 3RDPARTY_LIBS ${ZLTOOLKIT_LIBRARIES})
  33. message(STATUS "ZLToolKit include: ${ZLTOOLKIT_INCLUDE_DIR}")
  34. message(STATUS "ZLToolKit libraries: ${ZLTOOLKIT_LIBRARIES}")
  35. # ---[ rapidjson
  36. include_directories(${GSD_ROOT_DIR}/3rdparty/)
  37. include_directories(${GSD_ROOT_DIR}/3rdparty/httplib)
  38. include_directories(${GSD_ROOT_DIR}/framework/core/include)
  39. include_directories(${GSD_ROOT_DIR}/framework/request/include)
  40. set(module_list "")
  41. set(srcs "")
  42. if(build_Expel)
  43. list(APPEND module_list Expel)
  44. include_directories(${PROJECT_SOURCE_DIR}/modules/Expel/src)
  45. install(DIRECTORY Expel/include/ DESTINATION include)
  46. endif()
  47. if(build_InfineFilter)
  48. list(APPEND module_list InfineFilter)
  49. include_directories(${PROJECT_SOURCE_DIR}/modules/InfineFilter/src)
  50. install(DIRECTORY InfineFilter/include/ DESTINATION include)
  51. endif()
  52. if(build_Monitor)
  53. list(APPEND module_list Monitor)
  54. include_directories(${PROJECT_SOURCE_DIR}/modules/Monitor/src)
  55. install(DIRECTORY Monitor/include/ DESTINATION include)
  56. endif()
  57. if(build_TCPClient)
  58. list(APPEND module_list TCPClient)
  59. include_directories(${PROJECT_SOURCE_DIR}/modules/TCPClient/src)
  60. install(DIRECTORY TCPClient/include/ DESTINATION include)
  61. endif()
  62. if(build_config)
  63. list(APPEND module_list config)
  64. include_directories(${PROJECT_SOURCE_DIR}/modules/config/src)
  65. install(DIRECTORY config/include/ DESTINATION include)
  66. endif()
  67. if(build_HttpClient)
  68. list(APPEND module_list HttpClient)
  69. include_directories(${PROJECT_SOURCE_DIR}/modules/HttpClient/src)
  70. install(DIRECTORY HttpClient/include/ DESTINATION include)
  71. endif()
  72. if(build_HttpServer)
  73. list(APPEND module_list HttpServer)
  74. include_directories(${PROJECT_SOURCE_DIR}/modules/HttpServer/src)
  75. install(DIRECTORY HttpServer/include/ DESTINATION include)
  76. endif()
  77. if(build_Hepu)
  78. list(APPEND module_list Hepu)
  79. include_directories(${PROJECT_SOURCE_DIR}/modules/Hepu/src)
  80. install(DIRECTORY Hepu/include/ DESTINATION include)
  81. endif()
  82. if(build_Audit)
  83. list(APPEND module_list Audit)
  84. include_directories(${PROJECT_SOURCE_DIR}/modules/Audit/src)
  85. install(DIRECTORY Audit/include/ DESTINATION include)
  86. endif()
  87. # ---[ kafka
  88. if(build_kafka)
  89. find_package(RDKafka REQUIRED)
  90. include_directories(${RDKAFKA_INCLUDE_DIR})
  91. list(APPEND 3RDPARTY_LIBS ${RDKAFKA_LIBRARIES})
  92. #link_directories(${RDKAFKA_LINK_DIR})
  93. message(STATUS "RDKafka include: ${RDKAFKA_INCLUDE_DIR}")
  94. message(STATUS "RDKafka libraries: ${RDKAFKA_LIBRARIES}")
  95. endif()
  96. set(ENABLE_MYSQL ON CACHE BOOL "enable mysql")
  97. #查找mysql是否安装
  98. find_package(MYSQL QUIET)
  99. if(MYSQL_FOUND AND ENABLE_MYSQL)
  100. message(STATUS "找到mysqlclient库:\"${MYSQL_INCLUDE_DIR}\",ENABLE_MYSQL宏已打开")
  101. include_directories(${MYSQL_INCLUDE_DIR})
  102. include_directories(${MYSQL_INCLUDE_DIR}/mysql)
  103. add_definitions(-DENABLE_MYSQL)
  104. list(APPEND 3RDPARTY_LIBS ${MYSQL_LIBRARIES})
  105. endif()
  106. include_directories(${CMAKE_CURRENT_SOURCE_DIR})
  107. foreach(module ${module_list})
  108. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/${module}/include)
  109. file(GLOB_RECURSE module_src ${CMAKE_CURRENT_SOURCE_DIR}/${module}/*.cpp)
  110. list(APPEND srcs ${module_src})
  111. endforeach()
  112. set(LIBRARY_OUTPUT_PATH ${GSD_ROOT_DIR}/lib)
  113. add_library(gsd_modules SHARED ${srcs})
  114. target_link_libraries(gsd_modules ${3RDPARTY_LIBS} rt dl pthread)