CMakeLists.txt 4.3 KB

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