drogon/CMakeLists.txt

139 lines
4.9 KiB
CMake
Raw Normal View History

2018-09-09 14:11:41 +00:00
cmake_minimum_required (VERSION 3.2)
2018-04-27 06:38:27 +00:00
project (DROGON CXX)
2018-07-16 10:58:22 +00:00
IF (CMAKE_SYSTEM_NAME MATCHES "Linux")
2018-08-27 10:36:58 +00: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 10:36:58 +00:00
MESSAGE(STATUS "gcc is too old")
stop()
2018-09-16 07:31:25 +00: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 10:36:58 +00:00
set(CMAKE_CXX_STD_FLAGS c++17)
set(DR_DEFS "USE_STD_ANY")
2018-09-16 07:31:25 +00:00
MESSAGE(STATUS "c++17")
2018-08-27 10:36:58 +00:00
endif()
2018-07-16 10:58:22 +00:00
else()
set(CMAKE_CXX_STD_FLAGS c++11)
endif()
2018-05-03 06:17:04 +00:00
2018-10-07 15:01:43 +00:00
include_directories(${PROJECT_SOURCE_DIR}/trantor ${PROJECT_SOURCE_DIR}/lib/inc)
2018-09-14 15:54:06 +00:00
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake_modules/)
2018-06-26 06:52:41 +00:00
#jsoncpp
find_package (Jsoncpp REQUIRED)
include_directories(${JSONCPP_INCLUDE_DIRS})
2018-06-26 06:52:41 +00:00
#message(STATUS ${JSONCPP_LIBRARIES})
if(NOT EXISTS ${JSONCPP_INCLUDE_DIRS}/json/version.h)
2018-08-27 10:36:58 +00:00
message(STATUS "jsoncpp lib is too old.....stop")
stop()
2018-06-26 06:52:41 +00: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 10:36:58 +00:00
MESSAGE(STATUS "jsoncpp lib is too old,please get new version from https://github.com/open-source-parsers/jsoncpp")
stop()
2018-06-26 06:52:41 +00:00
endif()
2018-05-09 10:11:56 +00:00
find_package (UUID REQUIRED)
2018-09-09 13:38:37 +00:00
include_directories(${UUID_INCLUDE_DIR})
2018-05-03 06:17:04 +00:00
find_package (OpenSSL)
2018-06-14 16:07:43 +00:00
if(OpenSSL_FOUND)
2018-08-27 10:36:58 +00:00
#add_definitions(-DUSE_OPENSSL)
set(DR_DEFS "USE_OPENSSL;${DR_DEFS}")
include_directories(${OPENSSL_INCLUDE_DIR})
2018-06-23 11:22:20 +00:00
endif()
message(STATUS "openssl inc path:" ${OPENSSL_INCLUDE_DIR})
2018-09-03 02:56:11 +00:00
find_package(ZLIB REQUIRED)
include_directories(${ZLIB_INCLUDE_DIR})
2018-05-03 06:17:04 +00:00
find_package(Boost)
2018-05-03 10:28:37 +00:00
if(Boost_FOUND)
2018-08-27 10:36:58 +00:00
# add_definitions(-DUSE_BOOST)
2018-08-21 10:20:06 +00:00
set(DR_DEFS "USE_BOOST;${DR_DEFS}")
2018-05-03 06:17:04 +00:00
include_directories(${Boost_INCLUDE_DIRS})
endif()
2018-05-03 10:28:37 +00:00
2018-09-12 02:17:16 +00:00
if(CMAKE_BUILD_TYPE STREQUAL "")
set(CMAKE_BUILD_TYPE Release)
2018-09-03 06:42:44 +00:00
endif()
2018-09-12 02:17:16 +00: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 10:28:37 +00:00
2018-05-28 06:34:47 +00:00
add_subdirectory(trantor)
2018-04-27 06:38:27 +00:00
2018-05-28 06:34:47 +00: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 06:34:47 +00:00
add_subdirectory(drogon_ctl)
2018-04-27 06:38:27 +00:00
aux_source_directory(${PROJECT_SOURCE_DIR}/lib/src DIR_SRCS)
2018-04-27 06:38:27 +00:00
ADD_LIBRARY(drogon ${DIR_SRCS})
2018-04-27 06:38:27 +00:00
2018-06-28 15:12:44 +00:00
add_dependencies(drogon trantor makeVersion)
2018-04-27 06:38:27 +00:00
SET(CONFIG_HEADER "${PROJECT_SOURCE_DIR}/config.h")
file(WRITE "${CONFIG_HEADER}" "#pragma once\n")
2018-08-21 10:20:06 +00: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 10:20:06 +00: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 02:17:16 +00: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 01:44:40 +00:00
file(APPEND "${CONFIG_HEADER}" "\nconst char includeDirs[]=\"")
foreach(loop_var ${INS})
2018-08-27 10:36:58 +00:00
file(APPEND "${CONFIG_HEADER}" "-I" ${loop_var} " ")
endforeach(loop_var)
2018-06-15 01:44:40 +00: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 01:51:12 +00:00
if (MAKETEST STREQUAL YES)
ADD_SUBDIRECTORY(tests)
endif ()
2018-10-02 13:21:22 +00: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)