CMakeLists.txt 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. cmake_minimum_required(VERSION 2.8.7)
  2. set(GSD_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..)
  3. include(CheckCXXCompilerFlag)
  4. CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
  5. if(NOT COMPILER_SUPPORTS_CXX11)
  6. message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
  7. endif()
  8. # compile flags
  9. # set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-as-needed")
  10. # set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG -O2")
  11. # set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -g")
  12. # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -D_REENTRANT -fPIC -Wall -Werror")
  13. # ---[ Options
  14. option(build_Expel "build module Expel" ON)
  15. option(build_HttpClient "build module HttpClient" ON)
  16. option(build_InfineFilter "build module InfineFilter" ON)
  17. option(build_Monitor "build module Monitor" ON)
  18. option(build_TCPClient "build module TCPClient" ON)
  19. option(build_config "build module config" ON)
  20. option(build_HttpServer "build module HttpServer" ON)
  21. option(build_kafka "build module kafka" ON)
  22. # ---[ 3rdparty
  23. set(3RDPARTY_LIBS "")
  24. set(CMAKE_MODULE_PATH ${GSD_ROOT_DIR}/cmake)
  25. # ---[ rapidjson
  26. include_directories(${GSD_ROOT_DIR}/3rdparty/)
  27. include_directories(${GSD_ROOT_DIR}/3rdparty/httplib)
  28. include_directories(${GSD_ROOT_DIR}/framework/core/include)
  29. include_directories(${GSD_ROOT_DIR}/framework/request/include)
  30. set(module_list "")
  31. set(srcs "")
  32. if(build_Expel)
  33. list(APPEND module_list Expel)
  34. include_directories(${PROJECT_SOURCE_DIR}/modules/Expel/src)
  35. install(DIRECTORY Expel/include/ DESTINATION include)
  36. endif()
  37. if(build_InfineFilter)
  38. list(APPEND module_list InfineFilter)
  39. include_directories(${PROJECT_SOURCE_DIR}/modules/InfineFilter/src)
  40. install(DIRECTORY InfineFilter/include/ DESTINATION include)
  41. endif()
  42. if(build_Monitor)
  43. list(APPEND module_list Monitor)
  44. include_directories(${PROJECT_SOURCE_DIR}/modules/Monitor/src)
  45. install(DIRECTORY Monitor/include/ DESTINATION include)
  46. endif()
  47. if(build_TCPClient)
  48. list(APPEND module_list TCPClient)
  49. include_directories(${PROJECT_SOURCE_DIR}/modules/TCPClient/src)
  50. install(DIRECTORY TCPClient/include/ DESTINATION include)
  51. endif()
  52. if(build_config)
  53. list(APPEND module_list config)
  54. include_directories(${PROJECT_SOURCE_DIR}/modules/config/src)
  55. install(DIRECTORY config/include/ DESTINATION include)
  56. endif()
  57. if(build_HttpClient)
  58. list(APPEND module_list HttpClient)
  59. include_directories(${PROJECT_SOURCE_DIR}/modules/HttpClient/src)
  60. install(DIRECTORY HttpClient/include/ DESTINATION include)
  61. endif()
  62. if(build_HttpServer)
  63. list(APPEND module_list HttpServer)
  64. include_directories(${PROJECT_SOURCE_DIR}/modules/HttpServer/src)
  65. install(DIRECTORY HttpServer/include/ DESTINATION include)
  66. endif()
  67. # ---[ kafka
  68. if(build_kafka)
  69. find_package(LibRDKafka)
  70. if(LIBRDKAFKA_FOUND)
  71. include_directories(${LibRDKafka_INCLUDE_DIR})
  72. list(APPEND 3RDPARTY_LIBS ${LibRDKafka_C_LIBRARIES})
  73. message(STATUS "LibRDKafka include: ${LibRDKafka_INCLUDE_DIR}")
  74. message(STATUS "LibRDKafka libraries: ${LibRDKafka_C_LIBRARIES}")
  75. else()
  76. message(FATAL_ERROR "rdkafka not found!")
  77. endif()
  78. endif()
  79. set(ENABLE_MYSQL ON CACHE BOOL "enable mysql")
  80. #查找mysql是否安装
  81. find_package(MYSQL QUIET)
  82. if(MYSQL_FOUND AND ENABLE_MYSQL)
  83. message(STATUS "找到mysqlclient库:\"${MYSQL_INCLUDE_DIR}\",ENABLE_MYSQL宏已打开")
  84. include_directories(${MYSQL_INCLUDE_DIR})
  85. include_directories(${MYSQL_INCLUDE_DIR}/mysql)
  86. add_definitions(-DENABLE_MYSQL)
  87. list(APPEND 3RDPARTY_LIBS ${MYSQL_LIBRARIES})
  88. endif()
  89. include_directories(${CMAKE_CURRENT_SOURCE_DIR})
  90. foreach(module ${module_list})
  91. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/${module}/include)
  92. file(GLOB_RECURSE module_src ${CMAKE_CURRENT_SOURCE_DIR}/${module}/*.cpp)
  93. list(APPEND srcs ${module_src})
  94. endforeach()
  95. set(LIBRARY_OUTPUT_PATH ${GSD_ROOT_DIR}/lib)
  96. add_library(gsd_modules SHARED ${srcs})
  97. target_link_libraries(gsd_modules ${3RDPARTY_LIBS} rdkafka++ rdkafka rt dl pthread ZLToolKit)