cmake_minimum_required(VERSION 3.6) set(INS_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..) set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib/) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake") 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() if(USE_libstdcpp) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++") message("-- Warning: forcing libstdc++ (controlled by USE_libstdcpp option in cmake)") 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_UserApp "build module UserApp " ON) option(build_TcpProxySession "build module TcpProxySession" ON) option(build_dataType "build module dataType" ON) option(build_Disposition "build module Disposition" ON) option(build_md5 "build module md5" ON) # ---[ 3rdparty set(3RDPARTY_LIBS "") set(DEPENDENCIES "") set(CMAKE_MODULE_PATH ${CNSTREAM_ROOT_DIR}/cmake) 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() set(module_list "") if(build_UserApp) list(APPEND module_list UserApp) include_directories(${PROJECT_SOURCE_DIR}/modules/UserApp/src) install(DIRECTORY UserApp/include/ DESTINATION include) endif() if(build_TcpProxySession) list(APPEND module_list TcpProxySession) include_directories(${PROJECT_SOURCE_DIR}/modules/TcpProxySession/src) install(DIRECTORY TcpProxySession/include/ DESTINATION include) endif() if(build_dataType) list(APPEND module_list dataType) include_directories(${PROJECT_SOURCE_DIR}/modules/dataType/src) install(DIRECTORY dataType/include/ DESTINATION include) endif() if(build_Disposition) list(APPEND module_list Disposition) include_directories(${PROJECT_SOURCE_DIR}/modules/Disposition/src) install(DIRECTORY Disposition/include/ DESTINATION include) endif() if(build_md5) list(APPEND module_list md5) include_directories(${PROJECT_SOURCE_DIR}/modules/md5/src) install(DIRECTORY md5/include/ DESTINATION include) endif() include_directories(${CMAKE_CURRENT_SOURCE_DIR}) include_directories(/usr/local/include/hv) include_directories(${PROJECT_SOURCE_DIR}/3rdparty/) include_directories(${PROJECT_SOURCE_DIR}/3rdparty/rapidjson/include/) 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() add_library(models SHARED ${srcs}) install(TARGETS models LIBRARY DESTINATION lib) target_link_libraries(models ${3RDPARTY_LIBS} rt dl pthread ZLToolKit hv )