diff --git a/CMakeLists.txt b/CMakeLists.txt index 46dcaef6..f1379748 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,62 +1,92 @@ -CMAKE_MINIMUM_REQUIRED (VERSION 3.2) +cmake_minimum_required (VERSION 3.2) -PROJECT (DROGON CXX) -MESSAGE (STATUS "os:" ${CMAKE_SYSTEM_NAME}) +project (DROGON CXX) + +set(DROGON_MAJOR_VERSION 1) +set(DROGON_MINOR_VERSION 0) +set(DROGON_PATCH_VERSION 0) +set(DROGON_VERSION + ${DROGON_MAJOR_VERSION}.${DROGON_MINOR_VERSION}.${DROGON_PATCH_VERSION}) +set(PRE_RELEASE_STRING "beta5") + +# Offer the user the choice of overriding the installation directories +set(INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries") +set(INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables") +set(INSTALL_INCLUDE_DIR include CACHE PATH + "Installation directory for header files") +if(WIN32 AND NOT CYGWIN) + set(DEF_INSTALL_DROGON_CMAKE_DIR cmake) +else() + set(DEF_INSTALL_DROGON_CMAKE_DIR lib/cmake/Drogon) +endif() +set(INSTALL_DROGON_CMAKE_DIR ${DEF_INSTALL_DROGON_CMAKE_DIR} CACHE PATH + "Installation directory for cmake files") +# Make relative paths absolute (needed later on) +foreach(p LIB BIN INCLUDE DROGON_CMAKE) + set(var INSTALL_${p}_DIR) + if(NOT IS_ABSOLUTE "${${var}}") + set(${var} "${CMAKE_INSTALL_PREFIX}/${${var}}") + endif() +endforeach() include(CheckIncludeFileCXX) CHECK_INCLUDE_FILE_CXX(any HAS_ANY) CHECK_INCLUDE_FILE_CXX(string_view HAS_STRING_VIEW) -IF(HAS_ANY AND HAS_STRING_VIEW) - SET(DROGON_CXX_STANDARD 17) -ELSE() - SET(DROGON_CXX_STANDARD 14) -ENDIF() +if(HAS_ANY AND HAS_STRING_VIEW) + set(DROGON_CXX_STANDARD 17) +else() + set(DROGON_CXX_STANDARD 14) +endif() -IF(DROGON_CXX_STANDARD LESS 17) +add_subdirectory(trantor) +set(Trantor_DIR ${PROJECT_BINARY_DIR}/trantor) +find_package(Trantor CONFIG REQUIRED NO_DEFAULT_PATH) +message(STATUS "trantor inc:" ${TRANTOR_INCLUDE_DIRS}) +include_directories(${TRANTOR_INCLUDE_DIRS}) +link_libraries(${TRANTOR_LIBRARIES}) + +if(DROGON_CXX_STANDARD LESS 17) #With C++14, use boost to support any and string_view - MESSAGE(STATUS "use c++14") - FIND_PACKAGE(Boost 1.61.0 REQUIRED) - IF(Boost_FOUND) - INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS}) - ENDIF() -ELSE() - MESSAGE(STATUS "use c++17") -ENDIF() + message(STATUS "use c++14") + find_package(Boost 1.61.0 REQUIRED) + include_directories(${Boost_INCLUDE_DIRS}) +else() + message(STATUS "use c++17") +endif() -INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/trantor - ${PROJECT_SOURCE_DIR}/lib/inc - ${PROJECT_SOURCE_DIR}/orm_lib/inc) +include_directories(${PROJECT_SOURCE_DIR}/lib/inc + ${PROJECT_SOURCE_DIR}/orm_lib/inc + ${PROJECT_BINARY_DIR}) -SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules/) +set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules/) #jsoncpp -FIND_PACKAGE (Jsoncpp REQUIRED) -INCLUDE_DIRECTORIES(${JSONCPP_INCLUDE_DIRS}) -LINK_LIBRARIES(${JSONCPP_LIBRARIES}) +find_package (Jsoncpp REQUIRED) +include_directories(${JSONCPP_INCLUDE_DIRS}) +link_libraries(${JSONCPP_LIBRARIES}) +message(STATUS "jsoncpp inc path:" ${JSONCPP_INCLUDE_DIRS}) -MESSAGE(STATUS "jsoncpp inc path:" ${JSONCPP_INCLUDE_DIRS}) +#message(STATUS ${JSONCPP_LIBRARIES}) +if(NOT EXISTS ${JSONCPP_INCLUDE_DIRS}/json/version.h) + message(FATAL_ERROR "Error: jsoncpp lib is too old.....stop") +endif() -#MESSAGE(STATUS ${JSONCPP_LIBRARIES}) -IF(NOT EXISTS ${JSONCPP_INCLUDE_DIRS}/json/version.h) - MESSAGE(FATAL_ERROR "Error: jsoncpp lib is too old.....stop") -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) + message(FATAL_ERROR "jsoncpp lib is too old,please get new version from https://github.com/open-source-parsers/jsoncpp") +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) - MESSAGE(FATAL_ERROR "jsoncpp lib is too old,please get new version from https://github.com/open-source-parsers/jsoncpp") -ENDIF() +find_package (UUID REQUIRED) +include_directories(${UUID_INCLUDE_DIR}) +link_libraries(${UUID_LIBRARIES}) -FIND_PACKAGE (UUID REQUIRED) -INCLUDE_DIRECTORIES(${UUID_INCLUDE_DIR}) -LINK_LIBRARIES(${UUID_LIBRARIES}) +find_package(ZLIB REQUIRED) +include_directories(${ZLIB_INCLUDE_DIR}) +link_libraries(${ZLIB_LIBRARIES}) -FIND_PACKAGE(ZLIB REQUIRED) -INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR}) -LINK_LIBRARIES(${ZLIB_LIBRARIES}) - -SET(drogon_sources lib/src/AOPAdvice.cc +set(DROGON_SOURCES lib/src/AOPAdvice.cc lib/src/CacheFile.cc lib/src/ConfigLoader.cc lib/src/Cookie.cc @@ -90,115 +120,117 @@ SET(drogon_sources lib/src/AOPAdvice.cc lib/src/WebSocketConnectionImpl.cc lib/src/WebsocketControllersRouter.cc) -FIND_PACKAGE (OpenSSL) -IF(OpenSSL_FOUND) - INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR}) - LINK_LIBRARIES(${OPENSSL_LIBRARIES}) - MESSAGE(STATUS "openssl inc path:" ${OPENSSL_INCLUDE_DIR}) -ELSE() - SET(drogon_sources ${drogon_sources} lib/src/ssl_funcs/Md5.cc +find_package (OpenSSL) +if(OpenSSL_FOUND) + include_directories(${OPENSSL_INCLUDE_DIR}) + link_libraries(${OPENSSL_LIBRARIES}) + message(STATUS "openssl inc path:" ${OPENSSL_INCLUDE_DIR}) +else() + set(DROGON_SOURCES ${DROGON_SOURCES} lib/src/ssl_funcs/Md5.cc lib/src/ssl_funcs/Sha1.cc) -ENDIF() +endif() -IF(NOT BUILD_ORM) - SET(BUILD_ORM TRUE CACHE BOOL INTERNAL) -ENDIF() +if(NOT BUILD_ORM) + set(BUILD_ORM TRUE CACHE BOOL INTERNAL) +endif() -IF(NOT LIBPQ_BATCH_MODE) - SET(LIBPQ_BATCH_MODE TRUE CACHE BOOL INTERNAL) -ENDIF() +if(NOT LIBPQ_BATCH_MODE) + set(LIBPQ_BATCH_MODE TRUE CACHE BOOL INTERNAL) +endif() -IF(BUILD_ORM) +if(BUILD_ORM) #find postgres - FIND_PACKAGE(PostgreSQL) - IF(PostgreSQL_FOUND) - MESSAGE(STATUS "libpq inc path:" ${PostgreSQL_INCLUDE_DIR}) - MESSAGE(STATUS "libpq lib:" ${PostgreSQL_LIBRARIES}) - INCLUDE_DIRECTORIES(${PostgreSQL_INCLUDE_DIR}) - LINK_LIBRARIES(${PostgreSQL_LIBRARIES}) - SET(drogon_sources ${drogon_sources} + find_package(PostgreSQL) + if(PostgreSQL_FOUND) + message(STATUS "libpq inc path:" ${PostgreSQL_INCLUDE_DIR}) + message(STATUS "libpq lib:" ${PostgreSQL_LIBRARIES}) + include_directories(${PostgreSQL_INCLUDE_DIR}) + link_libraries(${PostgreSQL_LIBRARIES}) + set(DROGON_SOURCES ${DROGON_SOURCES} orm_lib/src/postgresql_impl/PostgreSQLResultImpl.cc) - IF(LIBPQ_BATCH_MODE) - TRY_COMPILE(libpq_supports_batch + if(LIBPQ_BATCH_MODE) + try_compile(libpq_supports_batch ${CMAKE_BINARY_DIR}/cmaketest ${PROJECT_SOURCE_DIR}/cmake/tests/test_libpq_batch_mode.cc LINK_LIBRARIES ${PostgreSQL_LIBRARIES} - CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${PostgreSQL_INCLUDE_DIR}") - ENDIF() - IF(libpq_supports_batch) - MESSAGE(STATUS "The libpq supports fatch mode") + CMAKE_FLAGS "-Dinclude_directories=${PostgreSQL_INCLUDE_DIR}") + endif() + if(libpq_supports_batch) + message(STATUS "The libpq supports fatch mode") OPTION(LIBPQ_SUPPORTS_BATCH_MODE "ibpq fatch mode" ON) - SET(drogon_sources ${drogon_sources} + set(DROGON_SOURCES ${DROGON_SOURCES} orm_lib/src/postgresql_impl/PgBatchConnection.cc) - ELSE() + else() OPTION(LIBPQ_SUPPORTS_BATCH_MODE "ibpq fatch mode" OFF) - SET(drogon_sources ${drogon_sources} + set(DROGON_SOURCES ${DROGON_SOURCES} orm_lib/src/postgresql_impl/PgConnection.cc) - ENDIF() - ENDIF() + endif() + endif() #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 "") - SET(MYSQL_FOUND false) - 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}) - SET(drogon_sources ${drogon_sources} + 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 "") + set(MYSQL_FOUND false) + 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}) + set(DROGON_SOURCES ${DROGON_SOURCES} orm_lib/src/mysql_impl/MysqlConnection.cc orm_lib/src/mysql_impl/MysqlResultImpl.cc) - ENDIF() - ENDIF() + endif() + endif() #Find sqlite3. - FIND_PACKAGE (SQLite3) + find_package (SQLite3) if (SQLITE3_FOUND) - MESSAGE(STATUS "SQLite3 inc:" ${SQLITE3_INCLUDE_DIRS}) - INCLUDE_DIRECTORIES(${SQLITE3_INCLUDE_DIRS}) - LINK_LIBRARIES(${SQLITE3_LIBRARIES}) - SET(drogon_sources ${drogon_sources} + message(STATUS "SQLite3 inc:" ${SQLITE3_INCLUDE_DIRS}) + include_directories(${SQLITE3_INCLUDE_DIRS}) + link_libraries(${SQLITE3_LIBRARIES}) + set(DROGON_SOURCES ${DROGON_SOURCES} orm_lib/src/sqlite3_impl/Sqlite3Connection.cc orm_lib/src/sqlite3_impl/Sqlite3ResultImpl.cc) - ENDIF() -ENDIF() - -ADD_SUBDIRECTORY(trantor) + endif() +endif() 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 + ARGS ${PROJECT_SOURCE_DIR}/lib/inc/drogon/version.h + ${DROGON_MAJOR_VERSION} + ${DROGON_MINOR_VERSION} + ${DROGON_PATCH_VERSION} + ${PRE_RELEASE_STRING} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} VERBATIM ) -IF(NOT BUILD_EXAMPLES) - SET(BUILD_EXAMPLES TRUE CACHE BOOL INTERNAL) -ENDIF() +if(NOT BUILD_EXAMPLES) + set(BUILD_EXAMPLES TRUE CACHE BOOL INTERNAL) +endif() -IF(BUILD_EXAMPLES) - ADD_SUBDIRECTORY(examples) -ENDIF() +if(BUILD_EXAMPLES) + add_subdirectory(examples) +endif() -IF(NOT BUILD_CTL) - SET(BUILD_CTL TRUE CACHE BOOL INTERNAL) -ENDIF() +if(NOT BUILD_CTL) + set(BUILD_CTL TRUE CACHE BOOL INTERNAL) +endif() -IF(BUILD_CTL) - ADD_SUBDIRECTORY(drogon_ctl) -ENDIF() +if(BUILD_CTL) + add_subdirectory(drogon_ctl) +endif() -IF(PostgreSQL_FOUND OR MYSQL_FOUND OR SQLITE3_FOUND) - SET(drogon_sources ${drogon_sources} +if(PostgreSQL_FOUND OR MYSQL_FOUND OR SQLITE3_FOUND) + set(DROGON_SOURCES ${DROGON_SOURCES} orm_lib/src/ArrayParser.cc orm_lib/src/Criteria.cc orm_lib/src/DbClient.cc @@ -211,89 +243,91 @@ IF(PostgreSQL_FOUND OR MYSQL_FOUND OR SQLITE3_FOUND) orm_lib/src/Row.cc orm_lib/src/SqlBinder.cc orm_lib/src/TransactionImpl.cc) -ELSE() - SET(drogon_sources ${drogon_sources} lib/src/DbClientManagerSkipped.cc) -ENDIF() +else() + set(DROGON_SOURCES ${DROGON_SOURCES} lib/src/DbClientManagerSkipped.cc) +endif() -ADD_LIBRARY(drogon ${drogon_sources}) +add_library(drogon ${DROGON_SOURCES}) -SET_PROPERTY(TARGET drogon PROPERTY CXX_STANDARD ${DROGON_CXX_STANDARD}) -SET_PROPERTY(TARGET drogon PROPERTY CXX_STANDARD_REQUIRED ON) -SET_PROPERTY(TARGET drogon PROPERTY CXX_EXTENSIONS OFF) +set_property(TARGET drogon PROPERTY CXX_STANDARD ${DROGON_CXX_STANDARD}) +set_property(TARGET drogon PROPERTY CXX_STANDARD_REQUIRED ON) +set_property(TARGET drogon PROPERTY CXX_EXTENSIONS OFF) -ADD_DEPENDENCIES(drogon trantor makeVersion) +add_dependencies(drogon makeVersion) -IF(PostgreSQL_FOUND OR MYSQL_FOUND OR SQLITE3_FOUND) - IF(PostgreSQL_FOUND) +if(PostgreSQL_FOUND OR MYSQL_FOUND OR SQLITE3_FOUND) + if(PostgreSQL_FOUND) OPTION(USE_POSTGRESQL "Enable PostgreSQL" ON) - ELSE() + else() OPTION(USE_POSTGRESQL "Disable PostgreSQL" OFF) - ENDIF() + endif() - IF(MYSQL_FOUND) + if(MYSQL_FOUND) OPTION(USE_MYSQL "Enable Mysql" ON) - ELSE() + else() OPTION(USE_MYSQL "DisableMysql" OFF) - ENDIF() + endif() - IF(SQLITE3_FOUND) + if(SQLITE3_FOUND) OPTION(USE_SQLITE3 "Enable Sqlite3" ON) - ELSE() + else() OPTION(USE_SQLITE3 "Disable Sqlite3" OFF) - ENDIF() -ENDIF() + endif() +endif() -SET(COMPILER_COMMAND ${CMAKE_CXX_COMPILER}) -SET(COMPILER_ID ${CMAKE_CXX_COMPILER_ID}) +set(COMPILER_COMMAND ${CMAKE_CXX_COMPILER}) +set(COMPILER_ID ${CMAKE_CXX_COMPILER_ID}) -IF(CMAKE_BUILD_TYPE) +if(CMAKE_BUILD_TYPE) string(TOLOWER ${CMAKE_BUILD_TYPE} _type) - IF(_type STREQUAL release) - SET(COMPILATION_FLAGS "${CMAKE_CXX_FLAGS_RELEASE} -std=c++") - ELSEIF(_type STREQUAL debug) - SET(COMPILATION_FLAGS "${CMAKE_CXX_FLAGS_DEBUG} -std=c++") - ELSE() - SET(COMPILATION_FLAGS "-std=c++") - ENDIF() -ELSE() - SET(COMPILATION_FLAGS "-std=c++") -ENDIF() + if(_type STREQUAL release) + set(COMPILATION_FLAGS "${CMAKE_CXX_FLAGS_RELEASE} -std=c++") + ELSEif(_type STREQUAL debug) + set(COMPILATION_FLAGS "${CMAKE_CXX_FLAGS_DEBUG} -std=c++") + else() + set(COMPILATION_FLAGS "-std=c++") + endif() +else() + set(COMPILATION_FLAGS "-std=c++") +endif() -GET_TARGET_PROPERTY(INS drogon INCLUDE_DIRECTORIES) -SET(TMP_INS "") -SET(INS_STRING "") -FOREACH(loop_var ${INS}) - IF(TMP_INS MATCHES ";${loop_var};") - ELSE() - SET(TMP_INS ";${loop_var};${TMP_INS}") - SET(INS_STRING "${INS_STRING} -I${loop_var}") - ENDIF() -ENDFOREACH(loop_var) +get_target_property(INS drogon INCLUDE_DIRECTORIES) +set(TMP_INS "") +set(INS_STRING "") +foreach(loop_var ${INS}) + if(TMP_INS MATCHES ";${loop_var};") + else() + set(TMP_INS ";${loop_var};${TMP_INS}") + set(INS_STRING "${INS_STRING} -I${loop_var}") + endif() +endforeach(loop_var) -SET(INCLUDING_DIRS ${INS_STRING}) +set(INCLUDING_DIRS ${INS_STRING}) -configure_file(${PROJECT_SOURCE_DIR}/lib/inc/drogon/config.h.in - ${PROJECT_SOURCE_DIR}/lib/inc/drogon/config.h @ONLY) +configure_file(${PROJECT_SOURCE_DIR}/cmake/templates/config.h.in + ${PROJECT_BINARY_DIR}/drogon/config.h @ONLY) if (MAKETEST STREQUAL YES) - ADD_SUBDIRECTORY(lib/tests) - IF(PostgreSQL_FOUND) - ADD_SUBDIRECTORY(${PROJECT_SOURCE_DIR}/orm_lib/src/postgresql_impl/test) - ADD_SUBDIRECTORY(${PROJECT_SOURCE_DIR}/orm_lib/tests) - ENDIF() - IF(MYSQL_FOUND) - ADD_SUBDIRECTORY(${PROJECT_SOURCE_DIR}/orm_lib/src/mysql_impl/test) - ENDIF() - IF(SQLITE3_FOUND) - ADD_SUBDIRECTORY(${PROJECT_SOURCE_DIR}/orm_lib/src/sqlite3_impl/test) - ENDIF() + add_subdirectory(lib/tests) + if(PostgreSQL_FOUND) + add_subdirectory(${PROJECT_SOURCE_DIR}/orm_lib/src/postgresql_impl/test) + add_subdirectory(${PROJECT_SOURCE_DIR}/orm_lib/tests) + endif() + if(MYSQL_FOUND) + add_subdirectory(${PROJECT_SOURCE_DIR}/orm_lib/src/mysql_impl/test) + endif() + if(SQLITE3_FOUND) + add_subdirectory(${PROJECT_SOURCE_DIR}/orm_lib/src/sqlite3_impl/test) + endif() endif () #Installation -INSTALL(TARGETS drogon DESTINATION lib) -SET(drogon_headers +install(TARGETS drogon EXPORT DrogonTargets + ARCHIVE DESTINATION "${INSTALL_LIB_DIR}" COMPONENT lib) + +set(DROGON_HEADERS lib/inc/drogon/CacheMap.h lib/inc/drogon/Cookie.h lib/inc/drogon/DrClassMap.h @@ -322,9 +356,9 @@ SET(drogon_headers lib/inc/drogon/WebSocketController.h lib/inc/drogon/drogon.h lib/inc/drogon/version.h) -INSTALL(FILES ${drogon_headers} DESTINATION include/drogon) +install(FILES ${DROGON_HEADERS} DESTINATION ${INSTALL_INCLUDE_DIR}/drogon) -SET(orm_headers +set(ORM_HEADERS orm_lib/inc/drogon/orm/ArrayParser.h orm_lib/inc/drogon/orm/Criteria.h orm_lib/inc/drogon/orm/DbClient.h @@ -337,23 +371,74 @@ SET(orm_headers orm_lib/inc/drogon/orm/Row.h orm_lib/inc/drogon/orm/RowIterator.h orm_lib/inc/drogon/orm/SqlBinder.h) -INSTALL(FILES ${orm_headers} DESTINATION include/drogon/orm) +install(FILES ${ORM_HEADERS} DESTINATION ${INSTALL_INCLUDE_DIR}/drogon/orm) -SET(drogon_util_headers +set(DROGON_UTIL_HEADERS lib/inc/drogon/utils/ClassTraits.h lib/inc/drogon/utils/FunctionTraits.h lib/inc/drogon/utils/Utilities.h lib/inc/drogon/utils/any.h lib/inc/drogon/utils/string_view.h lib/inc/drogon/utils/HttpConstraint.h) -INSTALL(FILES ${drogon_util_headers} - DESTINATION include/drogon/utils) +install(FILES ${DROGON_UTIL_HEADERS} + DESTINATION ${INSTALL_INCLUDE_DIR}/drogon/utils) -SET(drogon_plugin_headers lib/inc/drogon/plugins/Plugin.h) -INSTALL(FILES ${drogon_plugin_headers} - DESTINATION include/drogon/plugins) +set(DROGON_PLUGIN_HEADERS lib/inc/drogon/plugins/Plugin.h) +install(FILES ${DROGON_PLUGIN_HEADERS} + DESTINATION ${INSTALL_INCLUDE_DIR}/drogon/plugins) -SOURCE_GROUP( "Public API" FILES ${drogon_headers} - ${orm_headers} - ${drogon_util_headers} - ${drogon_plugin_headers}) +source_group( "Public API" FILES ${DROGON_HEADERS} + ${ORM_HEADERS} + ${DROGON_UTIL_HEADERS} + ${DROGON_PLUGIN_HEADERS}) + + + +# Add all targets to the build-tree export set +export(TARGETS drogon + FILE "${PROJECT_BINARY_DIR}/DrogonTargets.cmake") + +# Export the package for use from the build-tree +# (this registers the build-tree with a global cmake-registry) +# export(PACKAGE Drogon) + +include(CMakePackageConfigHelpers) +# ... for the build tree(locally included) +set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/lib/inc" + "${PROJECT_SOURCE_DIR}/orm_lib/inc" + "${PROJECT_SOURCE_DIR}/trantor" + "${JSONCPP_INCLUDE_DIRS}") +set(TRANTOR_CMAKE_DIR "${CMAKE_CURRENT_BINARY_DIR}/trantor") +configure_package_config_file(cmake/templates/DrogonConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/DrogonConfig.cmake + INSTALL_DESTINATION ${CMAKE_CURRENT_BINARY_DIR} + PATH_VARS CONF_INCLUDE_DIRS TRANTOR_CMAKE_DIR) +# ... for the install tree +if(JSONCPP_INCLUDE_DIRS STREQUAL INSTALL_INCLUDE_DIR) + set(CONF_INCLUDE_DIRS "${INSTALL_INCLUDE_DIR}") +else() + set(CONF_INCLUDE_DIRS "${JSONCPP_INCLUDE_DIRS}" + "${INSTALL_INCLUDE_DIR}") +endif() +set(TRANTOR_CMAKE_DIR "${INSTALL_LIB_DIR}/cmake/Trantor") +configure_package_config_file(cmake/templates/DrogonConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/DrogonConfig.cmake + INSTALL_DESTINATION ${INSTALL_DROGON_CMAKE_DIR} + PATH_VARS CONF_INCLUDE_DIRS TRANTOR_CMAKE_DIR) + +# version +write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/DrogonConfigVersion.cmake + VERSION ${DROGON_VERSION} + COMPATIBILITY SameMajorVersion) + +# Install the DrogonConfig.cmake and DrogonConfigVersion.cmake +install(FILES + "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/DrogonConfig.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/DrogonConfigVersion.cmake" + DESTINATION "${INSTALL_DROGON_CMAKE_DIR}" + COMPONENT dev) + +# Install the export set for use with the install-tree +install(EXPORT DrogonTargets + DESTINATION "${INSTALL_DROGON_CMAKE_DIR}" + COMPONENT dev) diff --git a/cmake/templates/DrogonConfig.cmake.in b/cmake/templates/DrogonConfig.cmake.in new file mode 100644 index 00000000..bfe1c996 --- /dev/null +++ b/cmake/templates/DrogonConfig.cmake.in @@ -0,0 +1,24 @@ +# - Config file for the Drogon package +# It defines the following variables +# DROGON_INCLUDE_DIRS - include directories for Drogon +# DROGON_LIBRARIES - libraries to link against +# DROGON_EXECUTABLE - the drogon_ctl executable + +@PACKAGE_INIT@ + +set(DROGON_INCLUDE_DIRS "@PACKAGE_CONF_INCLUDE_DIRS@") + +# find trantor +set(Trantor_DIR "@PACKAGE_TRANTOR_CMAKE_DIR@") +find_package(Trantor REQUIRED NO_DEFAULT_PATH) + +# Our library dependencies (contains definitions for IMPORTED targets) + +get_filename_component(DROGON_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) +if(NOT TARGET drogon AND NOT Drogon_BINARY_DIR) + include("${DROGON_CMAKE_DIR}/DrogonTargets.cmake") +endif() + +# These are IMPORTED targets created by DrogonTargets.cmake +set(DROGON_LIBRARIES drogon dl) +set(DROGON_EXECUTABLE drogon_ctl) diff --git a/lib/inc/drogon/config.h.in b/cmake/templates/config.h.in similarity index 100% rename from lib/inc/drogon/config.h.in rename to cmake/templates/config.h.in diff --git a/drogon_ctl/CMakeLists.txt b/drogon_ctl/CMakeLists.txt index 4a30aadb..2eeb9bc1 100755 --- a/drogon_ctl/CMakeLists.txt +++ b/drogon_ctl/CMakeLists.txt @@ -28,8 +28,9 @@ ENDFOREACH() INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) ADD_EXECUTABLE(drogon_ctl ${ctl_sources} ${TEMPL_SRC}) ADD_DEPENDENCIES(drogon_ctl trantor makeVersion _drogon_ctl) -INSTALL(TARGETS drogon_ctl DESTINATION bin) -INSTALL(PROGRAMS $/drogon_ctl DESTINATION bin RENAME dg_ctl) +message(STATUS "bin:" ${INSTALL_BIN_DIR}) +INSTALL(TARGETS drogon_ctl RUNTIME DESTINATION ${INSTALL_BIN_DIR}) +INSTALL(PROGRAMS $/drogon_ctl DESTINATION ${INSTALL_BIN_DIR} RENAME dg_ctl) SET(ctl_targets _drogon_ctl drogon_ctl) SET_PROPERTY(TARGET ${ctl_targets} PROPERTY CXX_STANDARD ${DROGON_CXX_STANDARD}) SET_PROPERTY(TARGET ${ctl_targets} PROPERTY CXX_STANDARD_REQUIRED ON) diff --git a/drogon_ctl/create_project.cc b/drogon_ctl/create_project.cc index 83b2a1c4..3a6389ce 100644 --- a/drogon_ctl/create_project.cc +++ b/drogon_ctl/create_project.cc @@ -51,30 +51,6 @@ static void newGitIgFile(std::ofstream &gitFile) gitFile << templ->genText(); } -static void newUuidFindFile(std::ofstream &uuidFile) -{ - auto templ = DrTemplateBase::newTemplate("FindUUID.csp"); - uuidFile << templ->genText(); -} - -static void newJsonFindFile(std::ofstream &jsonFile) -{ - auto templ = DrTemplateBase::newTemplate("FindJsoncpp.csp"); - jsonFile << templ->genText(); -} - -static void newMySQLFindFile(std::ofstream &mysqlFile) -{ - auto templ = DrTemplateBase::newTemplate("FindMySQL.csp"); - mysqlFile << templ->genText(); -} - -static void newSQLite3FindFile(std::ofstream &sqlite3File) -{ - auto templ = DrTemplateBase::newTemplate("FindSQLite3.csp"); - sqlite3File << templ->genText(); -} - static void newConfigFile(std::ofstream &configFile) { auto templ = DrTemplateBase::newTemplate("config"); @@ -109,18 +85,6 @@ void create_project::createProject(const std::string &projectName) mkdir("plugins", 0755); mkdir("build", 0755); mkdir("models", 0755); - mkdir("cmake_modules", 0755); - std::ofstream jsonFile("cmake_modules/FindJsoncpp.cmake", - std::ofstream::out); - newJsonFindFile(jsonFile); - std::ofstream uuidFile("cmake_modules/FindUUID.cmake", std::ofstream::out); - newUuidFindFile(uuidFile); - std::ofstream mysqlFile("cmake_modules/FindMySQL.cmake", - std::ofstream::out); - newMySQLFindFile(mysqlFile); - std::ofstream sqlite3File("cmake_modules/FindSQLite3.cmake", - std::ofstream::out); - newSQLite3FindFile(sqlite3File); std::ofstream gitFile(".gitignore", std::ofstream::out); newGitIgFile(gitFile); diff --git a/drogon_ctl/templates/FindJsoncpp.csp b/drogon_ctl/templates/FindJsoncpp.csp deleted file mode 100644 index 8c69d14f..00000000 --- a/drogon_ctl/templates/FindJsoncpp.csp +++ /dev/null @@ -1,63 +0,0 @@ -# Find jsoncpp -# -# Find the jsoncpp includes and library -# -# if you nee to add a custom library search path, do it via via CMAKE_PREFIX_PATH -# -# This module defines -# JSONCPP_INCLUDE_DIRS, where to find header, etc. -# JSONCPP_LIBRARIES, the libraries needed to use jsoncpp. -# JSONCPP_FOUND, If false, do not try to use jsoncpp. -# JSONCPP_INCLUDE_PREFIX, include prefix for jsoncpp - -# only look in default directories -find_path( - JSONCPP_INCLUDE_DIR - NAMES jsoncpp/json/json.h json/json.h - DOC "jsoncpp include dir" -) - -find_library( - JSONCPP_LIBRARY - NAMES jsoncpp - DOC "jsoncpp library" -) - -set(JSONCPP_INCLUDE_DIRS ${JSONCPP_INCLUDE_DIR}) -set(JSONCPP_LIBRARIES ${JSONCPP_LIBRARY}) - -# debug library on windows -# same naming convention as in qt (appending debug library with d) -# boost is using the same "hack" as us with "optimized" and "debug" -if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") - find_library( - JSONCPP_LIBRARY_DEBUG - NAMES jsoncppd - DOC "jsoncpp debug library" - ) - - set(JSONCPP_LIBRARIES optimized ${JSONCPP_LIBRARIES} debug ${JSONCPP_LIBRARY_DEBUG}) - -endif() - -# find JSONCPP_INCLUDE_PREFIX -find_path( - JSONCPP_INCLUDE_PREFIX - NAMES json.h - PATH_SUFFIXES jsoncpp/json json -) - -if (${JSONCPP_INCLUDE_PREFIX} MATCHES "jsoncpp") - set(JSONCPP_INCLUDE_PREFIX "jsoncpp") - set(JSONCPP_INCLUDE_DIRS "${JSONCPP_INCLUDE_DIRS}/jsoncpp") -else() - set(JSONCPP_INCLUDE_PREFIX "") -endif() - - -# handle the QUIETLY and REQUIRED arguments and set JSONCPP_FOUND to TRUE -# if all listed variables are TRUE, hide their existence from configuration view -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(jsoncpp DEFAULT_MSG - JSONCPP_INCLUDE_DIR JSONCPP_LIBRARY) -mark_as_advanced (JSONCPP_INCLUDE_DIR JSONCPP_LIBRARY) diff --git a/drogon_ctl/templates/FindMySQL.csp b/drogon_ctl/templates/FindMySQL.csp deleted file mode 100644 index 98fa5d3e..00000000 --- a/drogon_ctl/templates/FindMySQL.csp +++ /dev/null @@ -1,114 +0,0 @@ -#-------------------------------------------------------- -# Copyright (C) 1995-2007 MySQL AB -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of version 2 of the GNU General Public License as -# published by the Free Software Foundation. -# -# There are special exceptions to the terms and conditions of the GPL -# as it is applied to this software. View the full text of the exception -# in file LICENSE.exceptions in the top-level directory of this software -# distribution. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA -# -# The MySQL Connector/ODBC is licensed under the terms of the -# GPL, like most MySQL Connectors. There are special exceptions -# to the terms and conditions of the GPL as it is applied to -# this software, see the FLOSS License Exception available on -# mysql.com. - -########################################################################## - - -#-------------- FIND MYSQL_INCLUDE_DIR ------------------ -FIND_PATH(MYSQL_INCLUDE_DIR mysql.h - /usr/include/mysql - /usr/local/include/mysql - /opt/mysql/mysql/include - /opt/mysql/mysql/include/mysql - /opt/mysql/include - /opt/local/include/mysql5 - /usr/local/mysql/include - /usr/local/mysql/include/mysql - $ENV{ProgramFiles}/MySQL/*/include - $ENV{SystemDrive}/MySQL/*/include) - -#----------------- FIND MYSQL_LIB_DIR ------------------- -IF (WIN32) - # Set lib path suffixes - # dist = for mysql binary distributions - # build = for custom built tree - IF (CMAKE_BUILD_TYPE STREQUAL Debug) - SET(libsuffixDist debug) - SET(libsuffixBuild Debug) - ELSE (CMAKE_BUILD_TYPE STREQUAL Debug) - SET(libsuffixDist opt) - SET(libsuffixBuild Release) - ADD_DEFINITIONS(-DDBUG_OFF) - ENDIF (CMAKE_BUILD_TYPE STREQUAL Debug) - - FIND_LIBRARY(MYSQL_LIB NAMES mysqlclient - PATHS - $ENV{MYSQL_DIR}/lib/${libsuffixDist} - $ENV{MYSQL_DIR}/libmysql - $ENV{MYSQL_DIR}/libmysql/${libsuffixBuild} - $ENV{MYSQL_DIR}/client/${libsuffixBuild} - $ENV{MYSQL_DIR}/libmysql/${libsuffixBuild} - $ENV{ProgramFiles}/MySQL/*/lib/${libsuffixDist} - $ENV{SystemDrive}/MySQL/*/lib/${libsuffixDist}) -ELSE (WIN32) - FIND_LIBRARY(MYSQL_LIB NAMES mysqlclient_r mariadbclient - PATHS - /usr/lib/mysql - /usr/local/lib/mysql - /usr/local/mysql/lib - /usr/local/mysql/lib/mysql - /opt/local/mysql5/lib - /opt/local/lib/mysql5/mysql - /opt/mysql/mysql/lib/mysql - /opt/mysql/lib/mysql) -ENDIF (WIN32) - -IF(MYSQL_LIB) - GET_FILENAME_COMPONENT(MYSQL_LIB_DIR ${MYSQL_LIB} PATH) -ENDIF(MYSQL_LIB) - -set(MYSQL_VERSION_STRING "") - -EXEC_PROGRAM (grep ARGS "MARIADB_BASE_VERSION ${MYSQL_INCLUDE_DIR}/*.h|awk '{print $3}'" OUTPUT_VARIABLE MYSQL_VERSION_STRING) - -IF (MYSQL_INCLUDE_DIR AND MYSQL_LIB_DIR) - SET(MYSQL_FOUND TRUE) - - FIND_LIBRARY(MYSQL_ZLIB zlib PATHS ${MYSQL_LIB_DIR}) - FIND_LIBRARY(MYSQL_TAOCRYPT taocrypt PATHS ${MYSQL_LIB_DIR}) - IF (MYSQL_LIB) - SET(MYSQL_CLIENT_LIBS ${MYSQL_LIB}) - ELSE() - SET(MYSQL_CLIENT_LIBS mysqlclient_r) - ENDIF() - IF (MYSQL_ZLIB) - SET(MYSQL_CLIENT_LIBS ${MYSQL_CLIENT_LIBS} zlib) - ENDIF (MYSQL_ZLIB) - IF (MYSQL_TAOCRYPT) - SET(MYSQL_CLIENT_LIBS ${MYSQL_CLIENT_LIBS} taocrypt) - ENDIF (MYSQL_TAOCRYPT) - # Added needed mysqlclient dependencies on Windows - IF (WIN32) - SET(MYSQL_CLIENT_LIBS ${MYSQL_CLIENT_LIBS} ws2_32) - ENDIF (WIN32) - - MESSAGE(STATUS "MySQL Include dir: ${MYSQL_INCLUDE_DIR} library dir: ${MYSQL_LIB_DIR}") - MESSAGE(STATUS "MySQL client libraries: ${MYSQL_CLIENT_LIBS}") -ELSEIF (MySQL_FIND_REQUIRED) - MESSAGE(FATAL_ERROR "Cannot find MySQL. Include dir: ${MYSQL_INCLUDE_DIR} library dir: ${MYSQL_LIB_DIR}") -ENDIF (MYSQL_INCLUDE_DIR AND MYSQL_LIB_DIR) diff --git a/drogon_ctl/templates/FindSQLite3.csp b/drogon_ctl/templates/FindSQLite3.csp deleted file mode 100644 index 9c99ae5c..00000000 --- a/drogon_ctl/templates/FindSQLite3.csp +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright (C) 2007-2009 LuaDist. -# Created by Peter Kapec -# Redistribution and use of this file is allowed according to the terms of the MIT license. -# For details see the COPYRIGHT file distributed with LuaDist. -# Note: -# Searching headers and libraries is very simple and is NOT as powerful as scripts -# distributed with CMake, because LuaDist defines directories to search for. -# Everyone is encouraged to contact the author with improvements. Maybe this file -# becomes part of CMake distribution sometimes. - -# - Find sqlite3 -# Find the native SQLITE3 headers and libraries. -# -# SQLITE3_INCLUDE_DIRS - where to find sqlite3.h, etc. -# SQLITE3_LIBRARIES - List of libraries when using sqlite. -# SQLITE3_FOUND - True if sqlite found. - -# Look for the header file. -FIND_PATH(SQLITE3_INCLUDE_DIR NAMES sqlite3.h) - -# Look for the library. -FIND_LIBRARY(SQLITE3_LIBRARY NAMES sqlite3) - -# Handle the QUIETLY and REQUIRED arguments and set SQLITE3_FOUND to TRUE if all listed variables are TRUE. -INCLUDE(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(SQLITE3 DEFAULT_MSG SQLITE3_LIBRARY SQLITE3_INCLUDE_DIR) - -# Copy the results to the output variables. -IF(SQLITE3_FOUND) - SET(SQLITE3_LIBRARIES ${SQLITE3_LIBRARY}) - SET(SQLITE3_INCLUDE_DIRS ${SQLITE3_INCLUDE_DIR}) -ELSE(SQLITE3_FOUND) - SET(SQLITE3_LIBRARIES) - SET(SQLITE3_INCLUDE_DIRS) -ENDIF(SQLITE3_FOUND) - -MARK_AS_ADVANCED(SQLITE3_INCLUDE_DIRS SQLITE3_LIBRARIES) diff --git a/drogon_ctl/templates/FindUUID.csp b/drogon_ctl/templates/FindUUID.csp deleted file mode 100755 index f41d2ed2..00000000 --- a/drogon_ctl/templates/FindUUID.csp +++ /dev/null @@ -1,119 +0,0 @@ -# - Try to find UUID -# Once done this will define -# -# UUID_FOUND - system has UUID -# UUID_INCLUDE_DIRS - the UUID include directory -# UUID_LIBRARIES - Link these to use UUID -# UUID_DEFINITIONS - Compiler switches required for using UUID -# -# Copyright (c) 2006 Andreas Schneider -# -# Redistribution and use is allowed according to the terms of the New -# BSD license. -# For details see the accompanying COPYING-CMAKE-SCRIPTS file. -# - - -if (UUID_LIBRARIES AND UUID_INCLUDE_DIRS) - # in cache already - set(UUID_FOUND TRUE) -else (UUID_LIBRARIES AND UUID_INCLUDE_DIRS) - find_path(UUID_INCLUDE_DIR - NAMES - uuid.h - PATH_SUFFIXES - uuid - HINTS - ${UUID_DIR}/include - $ENV{UUID_DIR}/include - $ENV{UUID_DIR} - ${DELTA3D_EXT_DIR}/inc - $ENV{DELTA_ROOT}/ext/inc - $ENV{DELTA_ROOT} - PATHS - ~/Library/Frameworks - /Library/Frameworks - /usr/local/include - /usr/include - /usr/include/gdal - /sw/include # Fink - /opt/local/include # DarwinPorts - /opt/csw/include # Blastwave - /opt/include - [HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;OSG_ROOT]/include - /usr/freeware/include - ) - - find_library(UUID_LIBRARY - NAMES - uuid ossp-uuid - HINTS - ${UUID_DIR}/lib - $ENV{UUID_DIR}/lib - $ENV{UUID_DIR} - ${DELTA3D_EXT_DIR}/lib - $ENV{DELTA_ROOT}/ext/lib - $ENV{DELTA_ROOT} - $ENV{OSG_ROOT}/lib - PATHS - ~/Library/Frameworks - /Library/Frameworks - /usr/local/lib - /usr/lib - /sw/lib - /opt/local/lib - /opt/csw/lib - /opt/lib - /usr/freeware/lib64 - ) - - find_library(UUID_LIBRARY_DEBUG - NAMES - uuidd - HINTS - ${UUID_DIR}/lib - $ENV{UUID_DIR}/lib - $ENV{UUID_DIR} - ${DELTA3D_EXT_DIR}/lib - $ENV{DELTA_ROOT}/ext/lib - $ENV{DELTA_ROOT} - $ENV{OSG_ROOT}/lib - PATHS - ~/Library/Frameworks - /Library/Frameworks - /usr/local/lib - /usr/lib - /sw/lib - /opt/local/lib - /opt/csw/lib - /opt/lib - /usr/freeware/lib64 - ) - - if (NOT UUID_LIBRARY AND BSD) - set(UUID_LIBRARY "") - endif(NOT UUID_LIBRARY AND BSD) - - set(UUID_INCLUDE_DIRS ${UUID_INCLUDE_DIR}) - set(UUID_LIBRARIES ${UUID_LIBRARY}) - - if (UUID_INCLUDE_DIRS) - if (BSD OR UUID_LIBRARIES) - set(UUID_FOUND TRUE) - endif (BSD OR UUID_LIBRARIES) - endif (UUID_INCLUDE_DIRS) - - if (UUID_FOUND) - if (NOT UUID_FIND_QUIETLY) - message(STATUS "Found UUID: ${UUID_LIBRARIES}") - endif (NOT UUID_FIND_QUIETLY) - else (UUID_FOUND) - if (UUID_FIND_REQUIRED) - message(FATAL_ERROR "Could not find UUID") - endif (UUID_FIND_REQUIRED) - endif (UUID_FOUND) - - # show the UUID_INCLUDE_DIRS and UUID_LIBRARIES variables only in the advanced view - mark_as_advanced(UUID_INCLUDE_DIRS UUID_LIBRARIES) - -endif (UUID_LIBRARIES AND UUID_INCLUDE_DIRS) diff --git a/drogon_ctl/templates/cmake.csp b/drogon_ctl/templates/cmake.csp index 4eff0014..ac29758f 100644 --- a/drogon_ctl/templates/cmake.csp +++ b/drogon_ctl/templates/cmake.csp @@ -1,106 +1,52 @@ cmake_minimum_required (VERSION 3.2) -PROJECT([[ProjectName]]) +project([[ProjectName]]) -LINK_DIRECTORIES(/usr/local/lib) -LINK_LIBRARIES(drogon trantor pthread dl) +include(CheckIncludeFileCXX) -INCLUDE(CheckIncludeFileCXX) +check_include_file_cxx(any HAS_ANY) +check_include_file_cxx(string_view HAS_STRING_VIEW) +if(HAS_ANY AND HAS_STRING_VIEW) + set(CMAKE_CXX_STANDARD 17) +else() + set(CMAKE_CXX_STANDARD 14) +endif() -CHECK_INCLUDE_FILE_CXX(any HAS_ANY) -CHECK_INCLUDE_FILE_CXX(string_view HAS_STRING_VIEW) -IF(HAS_ANY AND HAS_STRING_VIEW) - SET(CMAKE_CXX_STANDARD 17) -ELSE() - SET(CMAKE_CXX_STANDARD 14) -ENDIF() +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) -SET(CMAKE_CXX_STANDARD_REQUIRED ON) -SET(CMAKE_CXX_EXTENSIONS OFF) +find_package(Drogon CONFIG REQUIRED) +include_directories(${DROGON_INCLUDE_DIRS}) +link_libraries(${DROGON_LIBRARIES}) -IF(CMAKE_CXX_STANDARD LESS 17) +if(CMAKE_CXX_STANDARD LESS 17) #With C++14, use boost to support any and string_view - MESSAGE(STATUS "use c++14") - FIND_PACKAGE(Boost REQUIRED) - IF(Boost_FOUND) - INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS}) - ENDIF() -ELSE() - MESSAGE(STATUS "use c++17") -ENDIF() + message(STATUS "use c++14") + find_package(Boost 1.61.0 REQUIRED) + include_directories(${Boost_INCLUDE_DIRS}) +else() + message(STATUS "use c++17") +endif() -SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules/) +aux_source_directory(./ SRC_DIR) +aux_source_directory(controllers CTL_SRC) +aux_source_directory(filters FILTER_SRC) +aux_source_directory(plugins PLUGIN_SRC) +aux_source_directory(models MODEL_SRC) -#jsoncpp -FIND_PACKAGE (Jsoncpp REQUIRED) -INCLUDE_DIRECTORIES(${JSONCPP_INCLUDE_DIRS}) -LINK_LIBRARIES(${JSONCPP_LIBRARIES}) +include_directories(/usr/local/include) -#uuid -FIND_PACKAGE (UUID REQUIRED) -INCLUDE_DIRECTORIES(${UUID_INCLUDE_DIR}) -LINK_LIBRARIES(${UUID_LIBRARIES}) - -#OpenSSL -FIND_PACKAGE (OpenSSL) -IF(OpenSSL_FOUND) - INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR}) - LINK_LIBRARIES(${OPENSSL_LIBRARIES}) -ENDIF() - -#zlib -FIND_PACKAGE(ZLIB REQUIRED) -INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR}) -LINK_LIBRARIES(${ZLIB_LIBRARIES}) - -#find postgres -FIND_PACKAGE(PostgreSQL) -IF(PostgreSQL_FOUND) -INCLUDE_DIRECTORIES(${PostgreSQL_INCLUDE_DIR}) -LINK_LIBRARIES(${PostgreSQL_LIBRARIES}) -ENDIF() - -#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 "") - 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}) - ENDIF() -ENDIF() - -#Find sqlite3. -FIND_PACKAGE (SQLite3) -if (SQLITE3_FOUND) - INCLUDE_DIRECTORIES(${SQLITE3_INCLUDE_DIRS}) - LINK_LIBRARIES(${SQLITE3_LIBRARIES}) -ENDIF() - -AUX_SOURCE_DIRECTORY(./ SRC_DIR) -AUX_SOURCE_DIRECTORY(controllers CTL_SRC) -AUX_SOURCE_DIRECTORY(filters FILTER_SRC) -AUX_SOURCE_DIRECTORY(plugins PLUGIN_SRC) -AUX_SOURCE_DIRECTORY(models MODEL_SRC) - -INCLUDE_DIRECTORIES(/usr/local/include) - -FILE(GLOB SCP_LIST ${CMAKE_CURRENT_SOURCE_DIR}/views/*.csp) -FOREACH(cspFile ${SCP_LIST}) - MESSAGE(STATUS "cspFile:" ${cspFile}) +file(GLOB SCP_LIST ${CMAKE_CURRENT_SOURCE_DIR}/views/*.csp) +foreach(cspFile ${SCP_LIST}) + message(STATUS "cspFile:" ${cspFile}) EXEC_PROGRAM(basename ARGS "${cspFile} .csp" OUTPUT_VARIABLE classname) - MESSAGE(STATUS "view classname:" ${classname}) + message(STATUS "view classname:" ${classname}) ADD_CUSTOM_COMMAND(OUTPUT ${classname}.h ${classname}.cc COMMAND drogon_ctl ARGS create view ${cspFile} DEPENDS ${cspFile} VERBATIM ) - SET(VIEWSRC ${VIEWSRC} ${classname}.cc) -ENDFOREACH() + set(VIEWSRC ${VIEWSRC} ${classname}.cc) +endforeach() -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) -ADD_EXECUTABLE([[ProjectName]] ${SRC_DIR} ${CTL_SRC} ${FILTER_SRC} ${VIEWSRC} ${PLUGIN_SRC} ${MODEL_SRC}) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +add_executable([[ProjectName]] ${SRC_DIR} ${CTL_SRC} ${FILTER_SRC} ${VIEWSRC} ${PLUGIN_SRC} ${MODEL_SRC}) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 1804b78f..354f2254 100755 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,20 +1,20 @@ -LINK_LIBRARIES(drogon trantor pthread dl) +link_libraries(drogon trantor pthread dl) -FILE(GLOB SCP_LIST ${CMAKE_CURRENT_SOURCE_DIR}/simple_example/*.csp) -FOREACH(cspFile ${SCP_LIST}) - MESSAGE(STATUS "cspFile:" ${cspFile}) - EXEC_PROGRAM(basename ARGS "${cspFile} .csp" OUTPUT_VARIABLE classname) - MESSAGE(STATUS "view classname:" ${classname}) - ADD_CUSTOM_COMMAND(OUTPUT ${classname}.h ${classname}.cc +file(GLOB SCP_LIST ${CMAKE_CURRENT_SOURCE_DIR}/simple_example/*.csp) +foreach(cspFile ${SCP_LIST}) + message(STATUS "cspFile:" ${cspFile}) + exec_program(basename ARGS "${cspFile} .csp" OUTPUT_VARIABLE classname) + message(STATUS "view classname:" ${classname}) + add_custom_command(OUTPUT ${classname}.h ${classname}.cc COMMAND drogon_ctl ARGS create view ${cspFile} DEPENDS ${cspFile} VERBATIM ) - SET(VIEWSRC ${VIEWSRC} ${classname}.cc) -ENDFOREACH() + set(VIEWSRC ${VIEWSRC} ${classname}.cc) +endforeach() -SET(simple_example_sources simple_example/CustomCtrl.cc +set(simple_example_sources simple_example/CustomCtrl.cc simple_example/CustomHeaderFilter.cc simple_example/DoNothingPlugin.cc simple_example/ForwardCtrl.cc @@ -30,33 +30,33 @@ SET(simple_example_sources simple_example/CustomCtrl.cc simple_example/TimeFilter.cc simple_example/main.cc) -ADD_EXECUTABLE(webapp ${simple_example_sources} ${VIEWSRC}) -ADD_DEPENDENCIES(webapp drogon_ctl) +add_executable(webapp ${simple_example_sources} ${VIEWSRC}) +add_dependencies(webapp drogon_ctl) -SET(client_example_sources client_example/main.cc) -SET(benchmark_sources benchmark/BenchmarkCtrl.cc +set(client_example_sources client_example/main.cc) +set(benchmark_sources benchmark/BenchmarkCtrl.cc benchmark/JsonCtrl.cc benchmark/main.cc) #AUX_SOURCE_DIRECTORY(simple_example_test DIR_TEST) -ADD_EXECUTABLE(client ${client_example_sources}) -ADD_EXECUTABLE(benchmark ${benchmark_sources}) -ADD_EXECUTABLE(webapp_test simple_example_test/main.cc) -ADD_EXECUTABLE(pipelining_test simple_example_test/HttpPipeliningTest.cc) -ADD_EXECUTABLE(websocket_test simple_example_test/WebSocketTest.cc) +add_executable(client ${client_example_sources}) +add_executable(benchmark ${benchmark_sources}) +add_executable(webapp_test simple_example_test/main.cc) +add_executable(pipelining_test simple_example_test/HttpPipeliningTest.cc) +add_executable(websocket_test simple_example_test/WebSocketTest.cc) -ADD_CUSTOM_COMMAND(TARGET webapp POST_BUILD +add_custom_command(TARGET webapp POST_BUILD COMMAND gzip ARGS -c ${CMAKE_CURRENT_SOURCE_DIR}/simple_example/index.html > ${CMAKE_CURRENT_BINARY_DIR}/index.html.gz VERBATIM) -ADD_CUSTOM_COMMAND(TARGET webapp POST_BUILD +add_custom_command(TARGET webapp POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PROJECT_SOURCE_DIR}/config.example.json ${PROJECT_SOURCE_DIR}/drogon.jpg ${CMAKE_CURRENT_SOURCE_DIR}/simple_example/index.html ${PROJECT_SOURCE_DIR}/trantor/trantor/tests/server.pem $) -SET(example_targets webapp webapp_test client benchmark pipelining_test websocket_test) +set(example_targets webapp webapp_test client benchmark pipelining_test websocket_test) -SET_PROPERTY(TARGET ${example_targets} PROPERTY CXX_STANDARD ${DROGON_CXX_STANDARD}) -SET_PROPERTY(TARGET ${example_targets} PROPERTY CXX_STANDARD_REQUIRED ON) -SET_PROPERTY(TARGET ${example_targets} PROPERTY CXX_EXTENSIONS OFF) +set_property(TARGET ${example_targets} PROPERTY CXX_STANDARD ${DROGON_CXX_STANDARD}) +set_property(TARGET ${example_targets} PROPERTY CXX_STANDARD_REQUIRED ON) +set_property(TARGET ${example_targets} PROPERTY CXX_EXTENSIONS OFF) diff --git a/get_version.sh b/get_version.sh index c60d01c8..dfd3f54a 100755 --- a/get_version.sh +++ b/get_version.sh @@ -2,16 +2,15 @@ GIT_VER=$(git log|grep ^commit|wc -l|sed -e "s/^ *//") MD5=$(git log|head -1|awk '{printf $2}') -MAJOR=1 -MINOR=0 -PATCH=0 -PRE_RELEASE_STRING="beta5" TMP_FILE=/tmp/version -echo "#define MAJOR ${MAJOR}" > ${TMP_FILE} -echo "#define MINOR ${MINOR}" >> ${TMP_FILE} -echo "#define PATCH ${PATCH}" >> ${TMP_FILE} -echo "#define PRE_RELEASE_STRING \"${PRE_RELEASE_STRING}\"" >> ${TMP_FILE} -echo "#define VERSION \"${MAJOR}.${MINOR}.${PATCH}.${PRE_RELEASE_STRING}.$GIT_VER\"" >> ${TMP_FILE} +echo "#define MAJOR $2" > ${TMP_FILE} +echo "#define MINOR $3" >> ${TMP_FILE} +echo "#define PATCH $4" >> ${TMP_FILE} +if [ $# -gt 4 ];then +echo "#define VERSION \"$2.$3.$4.$5.$GIT_VER\"" >> ${TMP_FILE} +else +echo "#define VERSION \"$2.$3.$4.$GIT_VER\"" >> ${TMP_FILE} +fi echo "#define VERSION_MD5 \"$MD5\"" >> ${TMP_FILE} if [ ! -f $1 ];then mv -f ${TMP_FILE} $1 diff --git a/trantor b/trantor index 17a128ab..60097fe9 160000 --- a/trantor +++ b/trantor @@ -1 +1 @@ -Subproject commit 17a128ab007b21d7a5342b658faacadd66e9c3ab +Subproject commit 60097fe979d4319ac53068ae9b18ff47d61f05b8