diff --git a/CMakeLists.txt b/CMakeLists.txt index ec3d3a33..d7bedbbc 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ 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 "beta13") +set(DROGON_VERSION_STRING "${DROGON_VERSION}.beta13") # Offer the user the choice of overriding the installation directories set(INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries") @@ -268,17 +268,12 @@ if(BUILD_ORM) 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 - ${DROGON_MAJOR_VERSION} - ${DROGON_MINOR_VERSION} - ${DROGON_PATCH_VERSION} - ${PRE_RELEASE_STRING} - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} - VERBATIM) +execute_process(COMMAND "git" rev-parse HEAD + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + OUTPUT_VARIABLE GIT_SHA1 + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) +configure_file("${PROJECT_SOURCE_DIR}/cmake/templates/version.h.in" + "${PROJECT_SOURCE_DIR}/lib/inc/drogon/version.h" @ONLY) if(BUILD_EXAMPLES) add_subdirectory(examples) @@ -316,8 +311,6 @@ set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD_REQUIRED ON) set_target_properties(${PROJECT_NAME} PROPERTIES CXX_EXTENSIONS OFF) set_target_properties(${PROJECT_NAME} PROPERTIES EXPORT_NAME Drogon) -add_dependencies(${PROJECT_NAME} makeVersion) - if(PostgreSQL_FOUND OR MYSQL_FOUND OR SQLITE3_FOUND) if(PostgreSQL_FOUND) option(USE_POSTGRESQL "Enable PostgreSQL" ON) diff --git a/cmake/templates/version.h.in b/cmake/templates/version.h.in new file mode 100644 index 00000000..4542ba00 --- /dev/null +++ b/cmake/templates/version.h.in @@ -0,0 +1,5 @@ +#define MAJOR @DROGON_MAJOR_VERSION@ +#define MINOR @DROGON_MINOR_VERSION@ +#define PATCH @DROGON_PATCH_VERSION@ +#define DROGON_VERSION "@DROGON_VERSION_STRING@" +#define DROGON_VERSION_SHA1 "@GIT_SHA1@" \ No newline at end of file diff --git a/drogon_ctl/CMakeLists.txt b/drogon_ctl/CMakeLists.txt index f43895e6..98667a7e 100755 --- a/drogon_ctl/CMakeLists.txt +++ b/drogon_ctl/CMakeLists.txt @@ -37,7 +37,6 @@ target_link_libraries(drogon_ctl PRIVATE ${PROJECT_NAME}) target_include_directories(drogon_ctl PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) add_dependencies(drogon_ctl trantor - makeVersion _drogon_ctl) if(WIN32) target_link_libraries(drogon_ctl PRIVATE ws2_32 Rpcrt4) diff --git a/drogon_ctl/version.cc b/drogon_ctl/version.cc index be9d35d9..d05e2891 100644 --- a/drogon_ctl/version.cc +++ b/drogon_ctl/version.cc @@ -30,8 +30,8 @@ void version::handleCommand(std::vector ¶meters) { std::cout << banner << std::endl; std::cout << "A utility for drogon" << std::endl; - std::cout << "Version:" << VERSION << std::endl; - std::cout << "Git commit:" << VERSION_MD5 << std::endl; - std::cout << "Compile config:" << COMPILATION_FLAGS << " " << INCLUDING_DIRS + std::cout << "Version: " << DROGON_VERSION << std::endl; + std::cout << "Git commit: " << DROGON_VERSION_SHA1 << std::endl; + std::cout << "Compile config: " << COMPILATION_FLAGS << " " << INCLUDING_DIRS << std::endl; } diff --git a/get_version.sh b/get_version.sh deleted file mode 100755 index dfd3f54a..00000000 --- a/get_version.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh - -GIT_VER=$(git log|grep ^commit|wc -l|sed -e "s/^ *//") -MD5=$(git log|head -1|awk '{printf $2}') -TMP_FILE=/tmp/version -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 -else -diff ${TMP_FILE} $1 -if [ $? -eq 1 ];then -mv -f ${TMP_FILE} $1 -else -rm -f ${TMP_FILE} -fi -fi diff --git a/lib/src/HttpAppFrameworkImpl.cc b/lib/src/HttpAppFrameworkImpl.cc index af2f1997..4102f8fc 100644 --- a/lib/src/HttpAppFrameworkImpl.cc +++ b/lib/src/HttpAppFrameworkImpl.cc @@ -98,11 +98,11 @@ namespace drogon { std::string getVersion() { - return VERSION; + return DROGON_VERSION; } std::string getGitCommit() { - return VERSION_MD5; + return DROGON_VERSION_SHA1; } } // namespace drogon static void godaemon(void) diff --git a/lib/src/HttpControllersRouter.cc b/lib/src/HttpControllersRouter.cc index 533cd6e0..8ea90b64 100644 --- a/lib/src/HttpControllersRouter.cc +++ b/lib/src/HttpControllersRouter.cc @@ -20,6 +20,7 @@ #include "HttpAppFrameworkImpl.h" #include "FiltersFunction.h" #include +#include using namespace drogon;