CMakeLists.txt 4.4 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_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. # ---[ rapidjson
  35. include_directories(${GSD_ROOT_DIR}/3rdparty/)
  36. include_directories(${GSD_ROOT_DIR}/3rdparty/httplib)
  37. include_directories(${GSD_ROOT_DIR}/framework/core/include)
  38. include_directories(${GSD_ROOT_DIR}/framework/request/include)
  39. set(module_list "")
  40. set(srcs "")
  41. if(build_Expel)
  42. list(APPEND module_list Expel)
  43. include_directories(${PROJECT_SOURCE_DIR}/modules/Expel/src)
  44. install(DIRECTORY Expel/include/ DESTINATION include)
  45. endif()
  46. if(build_InfineFilter)
  47. list(APPEND module_list InfineFilter)
  48. include_directories(${PROJECT_SOURCE_DIR}/modules/InfineFilter/src)
  49. install(DIRECTORY InfineFilter/include/ DESTINATION include)
  50. endif()
  51. if(build_Monitor)
  52. list(APPEND module_list Monitor)
  53. include_directories(${PROJECT_SOURCE_DIR}/modules/Monitor/src)
  54. install(DIRECTORY Monitor/include/ DESTINATION include)
  55. endif()
  56. if(build_TCPClient)
  57. list(APPEND module_list TCPClient)
  58. include_directories(${PROJECT_SOURCE_DIR}/modules/TCPClient/src)
  59. install(DIRECTORY TCPClient/include/ DESTINATION include)
  60. endif()
  61. if(build_config)
  62. list(APPEND module_list config)
  63. include_directories(${PROJECT_SOURCE_DIR}/modules/config/src)
  64. install(DIRECTORY config/include/ DESTINATION include)
  65. endif()
  66. if(build_HttpClient)
  67. list(APPEND module_list HttpClient)
  68. include_directories(${PROJECT_SOURCE_DIR}/modules/HttpClient/src)
  69. install(DIRECTORY HttpClient/include/ DESTINATION include)
  70. endif()
  71. if(build_HttpServer)
  72. list(APPEND module_list HttpServer)
  73. include_directories(${PROJECT_SOURCE_DIR}/modules/HttpServer/src)
  74. install(DIRECTORY HttpServer/include/ DESTINATION include)
  75. endif()
  76. if(build_Audit)
  77. list(APPEND module_list Audit)
  78. include_directories(${PROJECT_SOURCE_DIR}/modules/Audit/src)
  79. install(DIRECTORY Audit/include/ DESTINATION include)
  80. endif()
  81. # ---[ kafka
  82. if(build_kafka)
  83. find_package(RDKafka REQUIRED)
  84. include_directories(${RDKAFKA_INCLUDE_DIR})
  85. list(APPEND 3RDPARTY_LIBS ${RDKAFKA_LIBRARIES})
  86. #link_directories(${RDKAFKA_LINK_DIR})
  87. message(STATUS "RDKafka include: ${RDKAFKA_INCLUDE_DIR}")
  88. message(STATUS "RDKafka libraries: ${RDKAFKA_LIBRARIES}")
  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} rt dl pthread)