123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- cmake_minimum_required(VERSION 2.8.7)
- set(GSD_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..)
- #message(STATUS "MODULES: GSD_ROOT_DIR = ${GSD_ROOT_DIR}")
- include(CheckCXXCompilerFlag)
- CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
- if(NOT COMPILER_SUPPORTS_CXX11)
- message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
- endif()
- # compile flags
- # set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-as-needed")
- # set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG -O2")
- # set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -g")
- # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -D_REENTRANT -fPIC -Wall -Werror")
- # ---[ Options
- option(build_Expel "build module Expel" ON)
- option(build_HttpClient "build module HttpClient" ON)
- option(build_InfineFilter "build module InfineFilter" ON)
- option(build_Monitor "build module Monitor" ON)
- option(build_TCPClient "build module TCPClient" ON)
- option(build_config "build module config" ON)
- option(build_HttpServer "build module HttpServer" ON)
- option(build_Audit "build module Audit" ON)
- option(build_kafka "build module kafka" ON)
- # ---[ 3rdparty
- set(3RDPARTY_LIBS "")
- set(CMAKE_MODULE_PATH ${GSD_ROOT_DIR}/cmake)
- # ---[ ZLToolKit
- find_package(ZLToolKit REQUIRED)
- link_directories(${ZLTOOLKIT_LINK_DIR})
- include_directories(${ZLTOOLKIT_INCLUDE_DIR})
- list(APPEND 3RDPARTY_LIBS ${ZLTOOLKIT_LIBRARIES})
- message(STATUS "ZLToolKit include: ${ZLTOOLKIT_INCLUDE_DIR}")
- message(STATUS "ZLToolKit libraries: ${ZLTOOLKIT_LIBRARIES}")
- message(STATUS "ZLToolKit link dir: ${ZLTOOLKIT_LINK_DIR}")
- # ---[ rapidjson
- include_directories(${GSD_ROOT_DIR}/3rdparty/)
- include_directories(${GSD_ROOT_DIR}/3rdparty/httplib)
- include_directories(${GSD_ROOT_DIR}/framework/core/include)
- include_directories(${GSD_ROOT_DIR}/framework/request/include)
- set(module_list "")
- set(srcs "")
- if(build_Expel)
- list(APPEND module_list Expel)
- include_directories(${PROJECT_SOURCE_DIR}/modules/Expel/src)
- install(DIRECTORY Expel/include/ DESTINATION include)
- endif()
- if(build_InfineFilter)
- list(APPEND module_list InfineFilter)
- include_directories(${PROJECT_SOURCE_DIR}/modules/InfineFilter/src)
- install(DIRECTORY InfineFilter/include/ DESTINATION include)
- endif()
- if(build_Monitor)
- list(APPEND module_list Monitor)
- include_directories(${PROJECT_SOURCE_DIR}/modules/Monitor/src)
- install(DIRECTORY Monitor/include/ DESTINATION include)
- endif()
- if(build_TCPClient)
- list(APPEND module_list TCPClient)
- include_directories(${PROJECT_SOURCE_DIR}/modules/TCPClient/src)
- install(DIRECTORY TCPClient/include/ DESTINATION include)
- endif()
- if(build_config)
- list(APPEND module_list config)
- include_directories(${PROJECT_SOURCE_DIR}/modules/config/src)
- install(DIRECTORY config/include/ DESTINATION include)
- endif()
- if(build_HttpClient)
- list(APPEND module_list HttpClient)
- include_directories(${PROJECT_SOURCE_DIR}/modules/HttpClient/src)
- install(DIRECTORY HttpClient/include/ DESTINATION include)
- endif()
- if(build_HttpServer)
- list(APPEND module_list HttpServer)
- include_directories(${PROJECT_SOURCE_DIR}/modules/HttpServer/src)
- install(DIRECTORY HttpServer/include/ DESTINATION include)
- endif()
- if(build_Audit)
- list(APPEND module_list Audit)
- include_directories(${PROJECT_SOURCE_DIR}/modules/Audit/src)
- install(DIRECTORY Audit/include/ DESTINATION include)
- endif()
- # ---[ kafka
- if(build_kafka)
- find_package(RDKafka REQUIRED)
- include_directories(${RDKAFKA_INCLUDE_DIR})
- list(APPEND 3RDPARTY_LIBS ${RDKAFKA_LIBRARIES})
- link_directories(${RDKAFKA_LINK_DIR})
- message(STATUS "RDKafka include: ${RDKAFKA_INCLUDE_DIR}")
- message(STATUS "RDKafka libraries: ${RDKAFKA_LIBRARIES}")
- message(STATUS "RDKafka link dir: ${RDKAFKA_LINK_DIR}")
- endif()
- set(ENABLE_MYSQL ON CACHE BOOL "enable mysql")
- #查找mysql是否安装
- find_package(MYSQL QUIET)
- if(MYSQL_FOUND AND ENABLE_MYSQL)
- message(STATUS "找到mysqlclient库:\"${MYSQL_INCLUDE_DIR}\",ENABLE_MYSQL宏已打开")
- include_directories(${MYSQL_INCLUDE_DIR})
- include_directories(${MYSQL_INCLUDE_DIR}/mysql)
- add_definitions(-DENABLE_MYSQL)
- list(APPEND 3RDPARTY_LIBS ${MYSQL_LIBRARIES})
- endif()
- include_directories(${CMAKE_CURRENT_SOURCE_DIR})
- foreach(module ${module_list})
- include_directories(${CMAKE_CURRENT_SOURCE_DIR}/${module}/include)
- file(GLOB_RECURSE module_src ${CMAKE_CURRENT_SOURCE_DIR}/${module}/*.cpp)
- list(APPEND srcs ${module_src})
- endforeach()
- set(LIBRARY_OUTPUT_PATH ${GSD_ROOT_DIR}/lib)
- add_library(gsd_modules SHARED ${srcs})
- target_link_libraries(gsd_modules ${3RDPARTY_LIBS} rt dl pthread)
|