drogon/CMakeLists.txt

222 lines
7.4 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-11-21 15:18:41 +08:00
message (STATUS "os:" ${CMAKE_SYSTEM_NAME})
2019-04-26 13:43:59 +08:00
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
#Clang, use c++17
set(CMAKE_CXX_STD_FLAGS c++17)
set(CXX_STD 17)
else()
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})
2018-10-16 10:59:32 +08:00
if(version LESS 5.4.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 7.1.0)
set(CMAKE_CXX_STD_FLAGS c++14)
set(CXX_STD 14)
2018-09-16 15:31:25 +08:00
MESSAGE(STATUS "c++14")
else()
2018-08-27 18:36:58 +08:00
set(CMAKE_CXX_STD_FLAGS c++17)
set(CXX_STD 17)
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
endif()
2018-05-03 14:17:04 +08:00
2018-10-28 16:00:37 +08:00
include_directories(${PROJECT_SOURCE_DIR}/trantor ${PROJECT_SOURCE_DIR}/lib/inc ${PROJECT_SOURCE_DIR}/orm_lib/inc)
2018-09-14 23:54:06 +08:00
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules/)
2018-06-26 14:52:41 +08:00
#jsoncpp
find_package (Jsoncpp REQUIRED)
include_directories(${JSONCPP_INCLUDE_DIRS})
link_libraries(${JSONCPP_LIBRARIES})
2018-10-19 17:24:12 +08:00
message(STATUS "jsoncpp inc path:" ${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-10-19 17:24:12 +08:00
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})
link_libraries(${UUID_LIBRARIES})
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
include_directories(${OPENSSL_INCLUDE_DIR})
link_libraries(${OPENSSL_LIBRARIES})
2018-10-19 17:24:12 +08:00
message(STATUS "openssl inc path:" ${OPENSSL_INCLUDE_DIR})
else()
aux_source_directory(${PROJECT_SOURCE_DIR}/lib/src/ssl_funcs DIR_SRCS)
2018-06-23 19:22:20 +08:00
endif()
2018-10-19 17:24:12 +08:00
2018-09-03 10:56:11 +08:00
find_package(ZLIB REQUIRED)
include_directories(${ZLIB_INCLUDE_DIR})
link_libraries(${ZLIB_LIBRARIES})
2018-10-19 17:24:12 +08:00
message(STATUS "zlib inc path:" ${ZLIB_INCLUDE_DIR})
2018-05-03 18:28:37 +08:00
2018-10-28 16:00:37 +08:00
#find postgres
find_package(PostgreSQL)
if(PostgreSQL_FOUND)
2018-11-21 15:18:41 +08:00
include_directories(${PostgreSQL_INCLUDE_DIR})
message(STATUS "libpq inc path:" ${PostgreSQL_INCLUDE_DIR})
link_libraries(${PostgreSQL_LIBRARIES})
aux_source_directory(${PROJECT_SOURCE_DIR}/orm_lib/src/postgresql_impl DIR_SRCS)
set(USE_ORM TRUE)
2018-10-28 16:00:37 +08:00
endif()
2018-11-21 15:18:41 +08:00
#Find mysql, only mariadb client liberary is supported
find_package(MySQL)
if(MYSQL_FOUND)
message(STATUS "inc:" ${MYSQL_INCLUDE_DIR})
message(STATUS "libs:" ${MYSQL_CLIENT_LIBS})
message(STATUS "version:" ${MYSQL_VERSION_STRING})
if(MYSQL_VERSION_STRING STREQUAL "")
2018-12-03 18:39:44 +08:00
set(MYSQL_FOUND false)
2018-11-21 15:18:41 +08:00
message(STATUS "The mysql in your system is not the mariadb, so we can't use it in drogon")
else()
message(STATUS "Ok! We find the mariadb!")
include_directories(${MYSQL_INCLUDE_DIR})
link_libraries(${MYSQL_CLIENT_LIBS})
aux_source_directory(${PROJECT_SOURCE_DIR}/orm_lib/src/mysql_impl DIR_SRCS)
set(USE_ORM TRUE)
endif()
endif()
2018-12-26 18:37:11 +08:00
#Find sqlite3.
find_package (SQLite3)
if (SQLITE3_FOUND)
include_directories(${SQLITE3_INCLUDE_DIRS})
link_libraries(${SQLITE3_LIBRARIES})
aux_source_directory(${PROJECT_SOURCE_DIR}/orm_lib/src/sqlite3_impl DIR_SRCS)
set(USE_ORM TRUE)
endif()
2018-12-26 18:37:11 +08:00
#message(STATUS ${DIR_SRCS})
2018-11-21 15:18:41 +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)
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
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
2018-05-28 14:34:47 +08:00
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-10-28 16:00:37 +08:00
aux_source_directory(${PROJECT_SOURCE_DIR}/orm_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-10-16 10:59:32 +08:00
file(APPEND "${CONFIG_HEADER}" "#include <trantor/utils/config.h>\n")
file(APPEND "${CONFIG_HEADER}" "#define CXX_STD " ${CXX_STD} "\n")
2018-11-21 15:18:41 +08:00
if(USE_ORM)
file(APPEND "${CONFIG_HEADER}" "#define USE_ORM 1\n")
if(PostgreSQL_FOUND)
file(APPEND "${CONFIG_HEADER}" "#define USE_POSTGRESQL 1\n")
else()
file(APPEND "${CONFIG_HEADER}" "#define USE_POSTGRESQL 0\n")
endif()
if(MYSQL_FOUND)
file(APPEND "${CONFIG_HEADER}" "#define USE_MYSQL 1\n")
else()
file(APPEND "${CONFIG_HEADER}" "#define USE_MYSQL 0\n")
endif()
2018-12-26 18:37:11 +08:00
if(SQLITE3_FOUND)
file(APPEND "${CONFIG_HEADER}" "#define USE_SQLITE3 1\n")
else()
file(APPEND "${CONFIG_HEADER}" "#define USE_SQLITE3 0\n")
endif()
else()
2018-11-21 15:18:41 +08:00
file(APPEND "${CONFIG_HEADER}" "#define USE_ORM 0\n")
endif()
2018-09-12 10:17:16 +08:00
string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_LOWER)
if(CMAKE_BUILD_TYPE_LOWER STREQUAL release)
2019-04-26 13:43:59 +08:00
file(APPEND "${CONFIG_HEADER}" "\n" "const char compileFlags[] = \"" ${CMAKE_CXX_FLAGS_RELEASE} "\";\n")
2018-09-12 10:17:16 +08:00
else()
2019-04-26 13:43:59 +08:00
file(APPEND "${CONFIG_HEADER}" "\n" "const char compileFlags[] = \"" ${CMAKE_CXX_FLAGS_DEBUG} "\";\n")
2018-09-12 10:17:16 +08:00
endif()
2019-04-26 13:43:59 +08:00
file(APPEND "${CONFIG_HEADER}" "const char compilerCommand[] = \"${CMAKE_CXX_COMPILER}\";\n")
file(APPEND "${CONFIG_HEADER}" "const char compilerId[] = \"${CMAKE_CXX_COMPILER_ID}\";\n")
get_target_property(INS drogon INCLUDE_DIRECTORIES)
2018-10-19 18:14:49 +08:00
2018-06-15 09:44:40 +08:00
file(APPEND "${CONFIG_HEADER}" "\nconst char includeDirs[]=\"")
2018-10-19 18:14:49 +08:00
set(TMP_INS,"")
foreach(loop_var ${INS})
2018-10-19 18:14:49 +08:00
if(TMP_INS MATCHES ";${loop_var};")
else()
set(TMP_INS ";${loop_var};${TMP_INS}")
file(APPEND "${CONFIG_HEADER}" "-I" ${loop_var} " ")
endif()
endforeach(loop_var)
2018-10-19 18:14:49 +08:00
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)
2018-11-27 18:29:23 +08:00
ADD_SUBDIRECTORY(lib/tests)
2018-10-28 16:00:37 +08:00
if(PostgreSQL_FOUND)
add_subdirectory(${PROJECT_SOURCE_DIR}/orm_lib/src/postgresql_impl/test)
endif()
2018-11-22 14:55:05 +08:00
if(MYSQL_FOUND)
add_subdirectory(${PROJECT_SOURCE_DIR}/orm_lib/src/mysql_impl/test)
endif()
2018-12-27 17:29:51 +08:00
if(SQLITE3_FOUND)
add_subdirectory(${PROJECT_SOURCE_DIR}/orm_lib/src/sqlite3_impl/test)
endif()
2018-11-27 17:37:41 +08:00
if(USE_ORM)
2018-11-27 18:29:23 +08:00
add_subdirectory(${PROJECT_SOURCE_DIR}/orm_lib/tests)
2018-11-27 17:37:41 +08:00
endif()
2018-05-04 09:51:12 +08:00
endif ()
2018-10-31 19:07:37 +08:00
#Installation
2018-10-02 21:21:22 +08:00
install(TARGETS drogon DESTINATION lib)
file(GLOB drogon_headers "${CMAKE_CURRENT_SOURCE_DIR}/lib/inc/drogon/*.h")
install(FILES ${drogon_headers} DESTINATION include/drogon)
2018-10-31 19:07:37 +08:00
if(USE_ORM)
2018-11-27 17:37:41 +08:00
file(GLOB orm_headers "${CMAKE_CURRENT_SOURCE_DIR}/orm_lib/inc/drogon/orm/*.h")
install(FILES ${orm_headers} DESTINATION include/drogon/orm)
2018-10-31 19:07:37 +08:00
endif()
2018-10-02 21:21:22 +08:00
file(GLOB drogon_util_headers "${CMAKE_CURRENT_SOURCE_DIR}/lib/inc/drogon/utils/*.h")
install(FILES ${drogon_util_headers}
DESTINATION include/drogon/utils)
2019-03-29 15:34:14 +08:00
file(GLOB drogon_plugin_headers "${CMAKE_CURRENT_SOURCE_DIR}/lib/inc/drogon/plugins/*.h")
install(FILES ${drogon_plugin_headers}
DESTINATION include/drogon/plugins)
2018-10-02 21:21:22 +08:00
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/lib/inc/drogon/version.h"
DESTINATION include/drogon)