From 3578674fa59a4c581fa453d59e8524e389b0996b Mon Sep 17 00:00:00 2001 From: an-tao <20741618@qq.com> Date: Mon, 28 May 2018 14:34:47 +0800 Subject: [PATCH] add version --- .gitignore | 1 + CMakeLists.txt | 11 ++++++++++- drogon_ctl/CMakeLists.txt | 4 ++++ drogon_ctl/main.cc | 28 ++++++++++++++++++++++++++++ get_version.sh | 15 +++++++++++++++ lib/inc/drogon/HttpAppFramework.h | 3 ++- lib/src/HttpAppFramework.cc | 10 +++++++++- 7 files changed, 69 insertions(+), 3 deletions(-) create mode 100755 drogon_ctl/CMakeLists.txt create mode 100755 drogon_ctl/main.cc create mode 100755 get_version.sh diff --git a/.gitignore b/.gitignore index 49953a91..2f783ab9 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,4 @@ build cmake-build-debug .idea +version.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 37237fd4..2e8f614b 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,11 +43,19 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=${CMAKE_CXX_STD_FLAGS} -g -ggdb -Wa MESSAGE(STATUS ${CMAKE_CXX_FLAGS}) -add_subdirectory(trantor) + +add_subdirectory(trantor) include_directories(${PROJECT_SOURCE_DIR}/trantor ${PROJECT_SOURCE_DIR}/lib/inc) +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) +add_subdirectory(drogon_ctl) aux_source_directory(${PROJECT_SOURCE_DIR}/lib/src DIR_SRCS) @@ -61,6 +69,7 @@ file(GLOB trantor_net_headers "${CMAKE_CURRENT_SOURCE_DIR}/lib/inc/drogon/*.h") install(FILES ${trantor_net_headers} DESTINATION include/drogon) add_dependencies(drogon trantor) +add_dependencies(drogon makeVersion) if (MAKETEST STREQUAL YES) ADD_SUBDIRECTORY(tests) diff --git a/drogon_ctl/CMakeLists.txt b/drogon_ctl/CMakeLists.txt new file mode 100755 index 00000000..1df71873 --- /dev/null +++ b/drogon_ctl/CMakeLists.txt @@ -0,0 +1,4 @@ +#link_libraries(drogon trantor uuid pthread jsoncpp) +AUX_SOURCE_DIRECTORY(. SRC_DIR) +add_executable(drogon_ctl ${SRC_DIR}) +install(TARGETS drogon_ctl DESTINATION bin) diff --git a/drogon_ctl/main.cc b/drogon_ctl/main.cc new file mode 100755 index 00000000..97314d68 --- /dev/null +++ b/drogon_ctl/main.cc @@ -0,0 +1,28 @@ +#include +#include +#include +#include +static const char banner[]=" _ \n" + " __| |_ __ ___ __ _ ___ _ __ \n" + " / _` | '__/ _ \\ / _` |/ _ \\| '_ \\ \n" + "| (_| | | | (_) | (_| | (_) | | | |\n" + " \\__,_|_| \\___/ \\__, |\\___/|_| |_|\n" + " |___/ \n"; + +int main(int argc, char* argv[]) +{ + if(argc<2) + { + std::cout<<"usage:"< $TMP_FILE +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 +fi +fi \ No newline at end of file diff --git a/lib/inc/drogon/HttpAppFramework.h b/lib/inc/drogon/HttpAppFramework.h index 5763db3f..ee95651b 100755 --- a/lib/inc/drogon/HttpAppFramework.h +++ b/lib/inc/drogon/HttpAppFramework.h @@ -26,7 +26,8 @@ namespace drogon { - + inline std::string getVersion(); + inline std::string getGitCommit(); class HttpAppFramework:public trantor::NonCopyable { public: diff --git a/lib/src/HttpAppFramework.cc b/lib/src/HttpAppFramework.cc index f60d13c6..12a2343a 100755 --- a/lib/src/HttpAppFramework.cc +++ b/lib/src/HttpAppFramework.cc @@ -18,7 +18,7 @@ #include #include #include - +#include namespace drogon { @@ -351,5 +351,13 @@ HttpAppFramework::~HttpAppFramework() } +inline std::string getVersion() +{ + return VERSION; +} +inline std::string getGitCommit() +{ + return VERSION_MD5; +}