CMakeLists.txt 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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_DIR})
  30. include_directories(${ZLTOOLKIT_INCLUDE_DIR})
  31. list(APPEND 3RDPARTY_LIBS ${ZLTOOLKIT_LIBRARIES})
  32. message(STATUS "ZLToolKit include: ${ZLTOOLKIT_INCLUDE_DIR}")
  33. message(STATUS "ZLToolKit libraries: ${ZLTOOLKIT_LIBRARIES}")
  34. message(STATUS "ZLToolKit link dir: ${ZLTOOLKIT_LINK_DIR}")
  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_Audit)
  78. list(APPEND module_list Audit)
  79. include_directories(${PROJECT_SOURCE_DIR}/modules/Audit/src)
  80. install(DIRECTORY Audit/include/ DESTINATION include)
  81. endif()
  82. # ---[ kafka
  83. if(build_kafka)
  84. find_package(RDKafka REQUIRED)
  85. include_directories(${RDKAFKA_INCLUDE_DIR})
  86. list(APPEND 3RDPARTY_LIBS ${RDKAFKA_LIBRARIES})
  87. link_directories(${RDKAFKA_LINK_DIR})
  88. message(STATUS "RDKafka include: ${RDKAFKA_INCLUDE_DIR}")
  89. message(STATUS "RDKafka libraries: ${RDKAFKA_LIBRARIES}")
  90. message(STATUS "RDKafka link dir: ${RDKAFKA_LINK_DIR}")
  91. endif()
  92. set(ENABLE_MYSQL ON CACHE BOOL "enable mysql")
  93. #查找mysql是否安装
  94. find_package(MYSQL QUIET)
  95. if(MYSQL_FOUND AND ENABLE_MYSQL)
  96. message(STATUS "找到mysqlclient库:\"${MYSQL_INCLUDE_DIR}\",ENABLE_MYSQL宏已打开")
  97. include_directories(${MYSQL_INCLUDE_DIR})
  98. include_directories(${MYSQL_INCLUDE_DIR}/mysql)
  99. add_definitions(-DENABLE_MYSQL)
  100. list(APPEND 3RDPARTY_LIBS ${MYSQL_LIBRARIES})
  101. endif()
  102. include_directories(${CMAKE_CURRENT_SOURCE_DIR})
  103. foreach(module ${module_list})
  104. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/${module}/include)
  105. file(GLOB_RECURSE module_src ${CMAKE_CURRENT_SOURCE_DIR}/${module}/*.cpp)
  106. list(APPEND srcs ${module_src})
  107. endforeach()
  108. set(LIBRARY_OUTPUT_PATH ${GSD_ROOT_DIR}/lib)
  109. add_library(gsd_modules SHARED ${srcs})
  110. target_link_libraries(gsd_modules ${3RDPARTY_LIBS} rt dl pthread)