2018-04-27 11:00:24 +08:00
|
|
|
cmake_minimum_required (VERSION 2.6)
|
2018-04-27 14:38:27 +08:00
|
|
|
|
2018-05-02 17:45:10 +08:00
|
|
|
project (DROGON CXX)
|
2018-07-16 18:58:22 +08:00
|
|
|
IF (CMAKE_SYSTEM_NAME MATCHES "Linux")
|
2018-08-27 18:36:58 +08:00
|
|
|
EXEC_PROGRAM (gcc ARGS "--version | grep '^gcc'|awk '{print $3}' | sed s'/)//g' | sed s'/-.*//g'" OUTPUT_VARIABLE version)
|
|
|
|
MESSAGE(STATUS "This is gcc version:: " ${version})
|
|
|
|
if(version LESS 4.8.5)
|
|
|
|
MESSAGE(STATUS "gcc is too old")
|
|
|
|
stop()
|
|
|
|
elseif (version LESS 6.1.0)
|
|
|
|
MESSAGE(STATUS "c++11")
|
|
|
|
set(CMAKE_CXX_STD_FLAGS c++11)
|
|
|
|
elseif(version LESS 7.1.0)
|
|
|
|
set(CMAKE_CXX_STD_FLAGS c++14)
|
|
|
|
MESSAGE(STATUS "c++14")
|
|
|
|
else()
|
|
|
|
set(CMAKE_CXX_STD_FLAGS c++17)
|
|
|
|
#add_definitions(-DUSE_STD_ANY)
|
|
|
|
set(DR_DEFS "USE_STD_ANY")
|
|
|
|
MESSAGE(STATUS "c++17")
|
|
|
|
|
|
|
|
endif()
|
2018-07-16 18:58:22 +08:00
|
|
|
else()
|
|
|
|
set(CMAKE_CXX_STD_FLAGS c++11)
|
|
|
|
endif()
|
2018-05-03 14:17:04 +08:00
|
|
|
|
2018-05-02 17:45:10 +08:00
|
|
|
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake_modules/)
|
2018-06-26 14:52:41 +08:00
|
|
|
#jsoncpp
|
2018-06-03 21:29:45 +08:00
|
|
|
find_package (Jsoncpp REQUIRED)
|
2018-05-02 17:45:10 +08:00
|
|
|
include_directories(${JSONCPP_INCLUDE_DIRS})
|
2018-06-26 14:52:41 +08:00
|
|
|
#message(STATUS ${JSONCPP_LIBRARIES})
|
|
|
|
if(NOT EXISTS ${JSONCPP_INCLUDE_DIRS}/json/version.h)
|
2018-08-27 18:36:58 +08:00
|
|
|
message(STATUS "jsoncpp lib is too old.....stop")
|
|
|
|
stop()
|
2018-06-26 14:52:41 +08:00
|
|
|
endif()
|
|
|
|
EXEC_PROGRAM(cat ARGS "${JSONCPP_INCLUDE_DIRS}/json/version.h |grep JSONCPP_VERSION_STRING|sed s'/.*define/define/'|awk '{printf $3}'|sed s'/\"//g'" OUTPUT_VARIABLE jsoncpp_ver)
|
|
|
|
message(STATUS "jsoncpp verson:" ${jsoncpp_ver})
|
2018-06-26 21:18:32 +08:00
|
|
|
if(jsoncpp_ver LESS 1.7)
|
2018-08-27 18:36:58 +08:00
|
|
|
MESSAGE(STATUS "jsoncpp lib is too old,please get new version from https://github.com/open-source-parsers/jsoncpp")
|
|
|
|
stop()
|
2018-06-26 14:52:41 +08:00
|
|
|
endif()
|
2018-05-09 18:11:56 +08:00
|
|
|
find_package (UUID REQUIRED)
|
2018-05-03 14:17:04 +08:00
|
|
|
|
2018-08-21 16:02:43 +08:00
|
|
|
find_package (OpenSSL REQUIRED)
|
2018-06-15 00:07:43 +08:00
|
|
|
if(OpenSSL_FOUND)
|
2018-08-27 18:36:58 +08:00
|
|
|
#add_definitions(-DUSE_OPENSSL)
|
|
|
|
set(DR_DEFS "USE_OPENSSL;${DR_DEFS}")
|
|
|
|
include_directories(${OPENSSL_INCLUDE_DIR})
|
2018-06-23 19:22:20 +08:00
|
|
|
endif()
|
|
|
|
message(STATUS "openssl inc path:" ${OPENSSL_INCLUDE_DIR})
|
2018-09-03 10:56:11 +08:00
|
|
|
find_package(ZLIB REQUIRED)
|
|
|
|
include_directories(${ZLIB_INCLUDE_DIR})
|
2018-05-03 14:17:04 +08:00
|
|
|
find_package(Boost)
|
2018-05-03 18:28:37 +08:00
|
|
|
if(Boost_FOUND)
|
2018-08-27 18:36:58 +08:00
|
|
|
# add_definitions(-DUSE_BOOST)
|
2018-08-21 18:20:06 +08:00
|
|
|
set(DR_DEFS "USE_BOOST;${DR_DEFS}")
|
2018-05-03 14:17:04 +08:00
|
|
|
include_directories(${Boost_INCLUDE_DIRS})
|
|
|
|
endif()
|
2018-05-03 18:28:37 +08:00
|
|
|
|
2018-09-03 14:42:44 +08:00
|
|
|
if (RELEASE STREQUAL YES)
|
|
|
|
set(CMAKE_CXX_FLAGS "-std=${CMAKE_CXX_STD_FLAGS} -O2 -Wall -fpermissive ${CMAKE_CXX_FLAGS}")
|
|
|
|
else()
|
|
|
|
set(CMAKE_CXX_FLAGS "-std=${CMAKE_CXX_STD_FLAGS} -g -Wall -fpermissive ${CMAKE_CXX_FLAGS}")
|
|
|
|
endif()
|
2018-05-03 18:28:37 +08:00
|
|
|
#string(REPLACE ";" " " CMAKE_CXX_FLAGS "${CXX_FLAGS}")
|
|
|
|
|
|
|
|
MESSAGE(STATUS ${CMAKE_CXX_FLAGS})
|
|
|
|
|
2018-04-27 14:38:27 +08:00
|
|
|
|
2018-05-28 14:34:47 +08:00
|
|
|
|
|
|
|
add_subdirectory(trantor)
|
2018-05-02 17:45:10 +08:00
|
|
|
include_directories(${PROJECT_SOURCE_DIR}/trantor ${PROJECT_SOURCE_DIR}/lib/inc)
|
2018-04-27 14:38:27 +08:00
|
|
|
|
2018-05-28 14:34:47 +08:00
|
|
|
add_custom_target(makeVersion)
|
|
|
|
add_custom_command(TARGET makeVersion
|
|
|
|
COMMAND ${PROJECT_SOURCE_DIR}/get_version.sh
|
|
|
|
ARGS ${PROJECT_SOURCE_DIR}/lib/inc/drogon/version.h
|
|
|
|
VERBATIM )
|
|
|
|
|
2018-05-02 17:45:10 +08:00
|
|
|
add_subdirectory(examples)
|
2018-05-28 14:34:47 +08:00
|
|
|
add_subdirectory(drogon_ctl)
|
2018-04-27 14:38:27 +08:00
|
|
|
|
2018-05-02 17:45:10 +08:00
|
|
|
aux_source_directory(${PROJECT_SOURCE_DIR}/lib/src DIR_SRCS)
|
2018-04-27 14:38:27 +08:00
|
|
|
|
2018-05-02 17:45:10 +08:00
|
|
|
ADD_LIBRARY(drogon ${DIR_SRCS})
|
2018-04-27 14:38:27 +08:00
|
|
|
|
2018-05-02 17:45:10 +08:00
|
|
|
SET(CMAKE_INSTALL_PREFIX /usr/local)
|
|
|
|
|
|
|
|
install(TARGETS drogon DESTINATION lib)
|
|
|
|
|
2018-08-09 16:43:45 +08:00
|
|
|
file(GLOB drogon_headers "${CMAKE_CURRENT_SOURCE_DIR}/lib/inc/drogon/*.h")
|
|
|
|
install(FILES ${drogon_headers} DESTINATION include/drogon)
|
|
|
|
file(GLOB drogon_util_headers "${CMAKE_CURRENT_SOURCE_DIR}/lib/inc/drogon/utils/*.h")
|
|
|
|
install(FILES ${drogon_util_headers}
|
2018-08-08 16:26:26 +08:00
|
|
|
DESTINATION include/drogon/utils)
|
2018-06-28 23:12:44 +08:00
|
|
|
add_dependencies(drogon trantor makeVersion)
|
2018-04-27 14:38:27 +08:00
|
|
|
|
2018-06-15 15:58:54 +08:00
|
|
|
|
|
|
|
SET(CONFIG_HEADER "${PROJECT_SOURCE_DIR}/config.h")
|
|
|
|
file(WRITE "${CONFIG_HEADER}" "#pragma once\n")
|
|
|
|
|
2018-08-21 18:20:06 +08:00
|
|
|
#get_directory_property(DR_DEFS COMPILE_DEFINITIONS)
|
|
|
|
foreach(loop_var ${DR_DEFS})
|
2018-06-15 15:58:54 +08:00
|
|
|
file(APPEND "${CONFIG_HEADER}" "#define ${loop_var}\n")
|
2018-06-14 14:25:57 +08:00
|
|
|
endforeach(loop_var)
|
2018-08-21 18:20:06 +08:00
|
|
|
file(APPEND "${CONFIG_HEADER}" "#ifdef USE_STD_ANY\n")
|
|
|
|
|
|
|
|
file(APPEND "${CONFIG_HEADER}" "#include <any>\n")
|
|
|
|
file(APPEND "${CONFIG_HEADER}" "using std::any;\n")
|
|
|
|
file(APPEND "${CONFIG_HEADER}" "using std::any_cast;\n")
|
|
|
|
|
|
|
|
file(APPEND "${CONFIG_HEADER}" "#else \n")
|
|
|
|
file(APPEND "${CONFIG_HEADER}" "#ifdef USE_BOOST\n")
|
|
|
|
|
|
|
|
file(APPEND "${CONFIG_HEADER}" "#include <boost/any.hpp>\n")
|
|
|
|
file(APPEND "${CONFIG_HEADER}" "using boost::any;\n")
|
|
|
|
file(APPEND "${CONFIG_HEADER}" "using boost::any_cast;\n")
|
|
|
|
|
|
|
|
file(APPEND "${CONFIG_HEADER}" "#else\n")
|
|
|
|
file(APPEND "${CONFIG_HEADER}" "#error,must use c++17 or boost to support any\n")
|
|
|
|
file(APPEND "${CONFIG_HEADER}" "#endif\n")
|
|
|
|
file(APPEND "${CONFIG_HEADER}" "#endif\n")
|
|
|
|
|
2018-06-15 09:44:40 +08:00
|
|
|
file(APPEND "${CONFIG_HEADER}" "\n" "const char compileFlags[]=\"" ${CMAKE_CXX_FLAGS} "\";")
|
2018-06-14 14:25:57 +08:00
|
|
|
|
|
|
|
get_target_property(INS drogon INCLUDE_DIRECTORIES)
|
2018-06-15 09:44:40 +08:00
|
|
|
file(APPEND "${CONFIG_HEADER}" "\nconst char includeDirs[]=\"")
|
2018-06-14 14:25:57 +08:00
|
|
|
foreach(loop_var ${INS})
|
2018-08-27 18:36:58 +08:00
|
|
|
file(APPEND "${CONFIG_HEADER}" "-I" ${loop_var} " ")
|
2018-06-14 14:25:57 +08:00
|
|
|
endforeach(loop_var)
|
2018-06-15 09:44:40 +08:00
|
|
|
file(APPEND "${CONFIG_HEADER}" "\";\n")
|
|
|
|
EXEC_PROGRAM(${PROJECT_SOURCE_DIR}/update_config.sh ARGS "${CONFIG_HEADER} ${PROJECT_SOURCE_DIR}/lib/inc/drogon/config.h")
|
2018-06-14 14:25:57 +08:00
|
|
|
|
2018-05-04 09:51:12 +08:00
|
|
|
if (MAKETEST STREQUAL YES)
|
|
|
|
ADD_SUBDIRECTORY(tests)
|
|
|
|
endif ()
|
|
|
|
|
2018-05-02 17:45:10 +08:00
|
|
|
#target_link_libraries(drogon trantor pthread)
|