drogon/CMakeLists.txt

224 lines
7.4 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-11-21 07:18:41 +00:00
message (STATUS "os:" ${CMAKE_SYSTEM_NAME})
2019-04-26 05:43:59 +00: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 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})
2018-10-16 02:59:32 +00:00
if(version LESS 5.4.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 7.1.0)
set(CMAKE_CXX_STD_FLAGS c++14)
set(CXX_STD 14)
2018-09-16 07:31:25 +00:00
MESSAGE(STATUS "c++14")
else()
2018-08-27 10:36:58 +00:00
set(CMAKE_CXX_STD_FLAGS c++17)
set(CXX_STD 17)
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
endif()
2018-05-03 06:17:04 +00:00
2018-10-28 08:00:37 +00:00
include_directories(${PROJECT_SOURCE_DIR}/trantor ${PROJECT_SOURCE_DIR}/lib/inc ${PROJECT_SOURCE_DIR}/orm_lib/inc)
2018-09-14 15:54:06 +00:00
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules/)
2018-06-26 06:52:41 +00:00
#jsoncpp
find_package (Jsoncpp REQUIRED)
include_directories(${JSONCPP_INCLUDE_DIRS})
link_libraries(${JSONCPP_LIBRARIES})
2018-10-19 09:24:12 +00:00
message(STATUS "jsoncpp inc path:" ${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-10-19 09:24:12 +00:00
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})
link_libraries(${UUID_LIBRARIES})
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
include_directories(${OPENSSL_INCLUDE_DIR})
link_libraries(${OPENSSL_LIBRARIES})
2018-10-19 09:24:12 +00: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 11:22:20 +00:00
endif()
2018-10-19 09:24:12 +00:00
2018-09-03 02:56:11 +00:00
find_package(ZLIB REQUIRED)
include_directories(${ZLIB_INCLUDE_DIR})
link_libraries(${ZLIB_LIBRARIES})
2018-10-19 09:24:12 +00:00
message(STATUS "zlib inc path:" ${ZLIB_INCLUDE_DIR})
2018-05-03 10:28:37 +00:00
2018-10-28 08:00:37 +00:00
#find postgres
find_package(PostgreSQL)
if(PostgreSQL_FOUND)
2018-11-21 07:18:41 +00: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 08:00:37 +00:00
endif()
2018-11-21 07:18:41 +00: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 10:39:44 +00:00
set(MYSQL_FOUND false)
2018-11-21 07:18:41 +00: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 10:37:11 +00: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 10:37:11 +00:00
#message(STATUS ${DIR_SRCS})
2018-11-21 07:18:41 +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
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
2018-05-28 06:34:47 +00:00
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-10-28 08:00:37 +00:00
aux_source_directory(${PROJECT_SOURCE_DIR}/orm_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-10-16 02:59:32 +00:00
file(APPEND "${CONFIG_HEADER}" "#include <trantor/utils/config.h>\n")
file(APPEND "${CONFIG_HEADER}" "#define CXX_STD " ${CXX_STD} "\n")
2018-11-21 07:18:41 +00: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 10:37:11 +00: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 07:18:41 +00:00
file(APPEND "${CONFIG_HEADER}" "#define USE_ORM 0\n")
endif()
2018-09-12 02:17:16 +00:00
string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_LOWER)
if(CMAKE_BUILD_TYPE_LOWER STREQUAL release)
2019-04-26 05:43:59 +00:00
file(APPEND "${CONFIG_HEADER}" "\n" "const char compileFlags[] = \"" ${CMAKE_CXX_FLAGS_RELEASE} "\";\n")
2018-09-12 02:17:16 +00:00
else()
2019-04-26 05:43:59 +00:00
file(APPEND "${CONFIG_HEADER}" "\n" "const char compileFlags[] = \"" ${CMAKE_CXX_FLAGS_DEBUG} "\";\n")
2018-09-12 02:17:16 +00:00
endif()
2019-04-26 05:43:59 +00: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 10:14:49 +00:00
2018-06-15 01:44:40 +00:00
file(APPEND "${CONFIG_HEADER}" "\nconst char includeDirs[]=\"")
2018-10-19 10:14:49 +00:00
set(TMP_INS,"")
foreach(loop_var ${INS})
2018-10-19 10:14:49 +00: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 10:14:49 +00:00
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)
2018-11-27 10:29:23 +00:00
ADD_SUBDIRECTORY(lib/tests)
2018-10-28 08:00:37 +00:00
if(PostgreSQL_FOUND)
add_subdirectory(${PROJECT_SOURCE_DIR}/orm_lib/src/postgresql_impl/test)
endif()
2018-11-22 06:55:05 +00:00
if(MYSQL_FOUND)
add_subdirectory(${PROJECT_SOURCE_DIR}/orm_lib/src/mysql_impl/test)
endif()
2018-12-27 09:29:51 +00:00
if(SQLITE3_FOUND)
add_subdirectory(${PROJECT_SOURCE_DIR}/orm_lib/src/sqlite3_impl/test)
endif()
2018-11-27 09:37:41 +00:00
if(USE_ORM)
2018-11-27 10:29:23 +00:00
add_subdirectory(${PROJECT_SOURCE_DIR}/orm_lib/tests)
2018-11-27 09:37:41 +00:00
endif()
2018-05-04 01:51:12 +00:00
endif ()
2018-10-02 13:21:22 +00:00
SET(CMAKE_INSTALL_PREFIX /usr/local)
2018-10-31 11:07:37 +00:00
#Installation
2018-10-02 13:21:22 +00: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 11:07:37 +00:00
if(USE_ORM)
2018-11-27 09:37:41 +00: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 11:07:37 +00:00
endif()
2018-10-02 13:21:22 +00: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 07:34:14 +00: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 13:21:22 +00:00
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/lib/inc/drogon/version.h"
DESTINATION include/drogon)