drogon/CMakeLists.txt

142 lines
4.9 KiB
CMake
Raw Normal View History

2018-09-09 22:11:41 +08:00
cmake_minimum_required (VERSION 3.2)
2018-04-27 14:38:27 +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.9.0)
2018-08-27 18:36:58 +08:00
MESSAGE(STATUS "gcc is too old")
stop()
2018-09-16 15:31:25 +08:00
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()
2018-08-27 18:36:58 +08:00
set(CMAKE_CXX_STD_FLAGS c++17)
set(DR_DEFS "USE_STD_ANY")
2018-09-16 15:31:25 +08:00
MESSAGE(STATUS "c++17")
2018-08-27 18:36:58 +08:00
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-09-14 23:54:06 +08:00
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake_modules/)
2018-06-26 14:52:41 +08:00
#jsoncpp
find_package (Jsoncpp REQUIRED)
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})
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-09-09 21:38:37 +08:00
include_directories(${UUID_INCLUDE_DIR})
2018-05-03 14:17:04 +08:00
find_package (OpenSSL)
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-12 10:17:16 +08:00
if(CMAKE_BUILD_TYPE STREQUAL "")
set(CMAKE_BUILD_TYPE Release)
2018-09-03 14:42:44 +08:00
endif()
2018-09-12 10:17:16 +08:00
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -std=${CMAKE_CXX_STD_FLAGS}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall -std=${CMAKE_CXX_STD_FLAGS}")
2018-05-03 18:28:37 +08:00
2018-05-28 14:34:47 +08:00
add_subdirectory(trantor)
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 )
add_subdirectory(examples)
2018-05-28 14:34:47 +08:00
add_subdirectory(drogon_ctl)
2018-04-27 14:38:27 +08:00
aux_source_directory(${PROJECT_SOURCE_DIR}/lib/src DIR_SRCS)
2018-04-27 14:38:27 +08:00
ADD_LIBRARY(drogon ${DIR_SRCS})
2018-04-27 14:38:27 +08:00
2018-06-28 23:12:44 +08:00
add_dependencies(drogon trantor makeVersion)
2018-04-27 14:38:27 +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})
file(APPEND "${CONFIG_HEADER}" "#define ${loop_var}\n")
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-09-12 10:17:16 +08:00
string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_LOWER)
if(CMAKE_BUILD_TYPE_LOWER STREQUAL release)
file(APPEND "${CONFIG_HEADER}" "\n" "const char compileFlags[]=\"" ${CMAKE_CXX_FLAGS_RELEASE} "\";")
else()
file(APPEND "${CONFIG_HEADER}" "\n" "const char compileFlags[]=\"" ${CMAKE_CXX_FLAGS_DEBUG} "\";")
endif()
get_target_property(INS drogon INCLUDE_DIRECTORIES)
2018-06-15 09:44:40 +08:00
file(APPEND "${CONFIG_HEADER}" "\nconst char includeDirs[]=\"")
foreach(loop_var ${INS})
2018-08-27 18:36:58 +08:00
file(APPEND "${CONFIG_HEADER}" "-I" ${loop_var} " ")
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-05-04 09:51:12 +08:00
if (MAKETEST STREQUAL YES)
ADD_SUBDIRECTORY(tests)
endif ()
2018-10-02 21:21:22 +08:00
SET(CMAKE_INSTALL_PREFIX /usr/local)
install(TARGETS drogon DESTINATION lib)
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}
DESTINATION include/drogon/utils)
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/lib/inc/drogon/version.h"
DESTINATION include/drogon)
#target_link_libraries(drogon trantor pthread)