diff options
author | Simon Rettberg | 2014-01-13 12:22:03 +0100 |
---|---|---|
committer | Simon Rettberg | 2014-01-13 12:22:03 +0100 |
commit | d2adcf51505484efd164d6c867a8157061d1ff29 (patch) | |
tree | 73a8dba7435b7b3019e03384c0a2b5dd787aefc0 | |
parent | [SERVER] Add example config (diff) | |
download | dnbd3-2.0.tar.gz dnbd3-2.0.tar.xz dnbd3-2.0.zip |
[*] Add automatic version string generationv2.0
-rw-r--r-- | CMakeLists.txt | 20 | ||||
-rwxr-xr-x | get-version.sh | 6 | ||||
-rw-r--r-- | src/client/client.c | 1 | ||||
-rw-r--r-- | src/server/server.c | 1 | ||||
-rw-r--r-- | src/version.c.in | 4 | ||||
-rw-r--r-- | src/version.h | 7 |
6 files changed, 37 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 0dd9a37..e04416d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,25 @@ FIND_PACKAGE(ZLIB REQUIRED) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${ZLIB_INCLUDE_DIR}) +################################################################################ +# VERSION HEADER # +################################################################################ +FILE(WRITE ${CMAKE_BINARY_DIR}/version.cmake +"EXECUTE_PROCESS( + COMMAND \${CMD} + OUTPUT_VARIABLE VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + CONFIGURE_FILE(\${SRC} \${DST} @ONLY) +") +ADD_CUSTOM_TARGET( + version + ${CMAKE_COMMAND} -D SRC=${CMAKE_SOURCE_DIR}/src/version.c.in + -D DST=${CMAKE_BINARY_DIR}/version.c + -D CMD=${CMAKE_SOURCE_DIR}/get-version.sh + -P ${CMAKE_BINARY_DIR}/version.cmake +) ################################################################################ # CLIENT # @@ -45,6 +63,7 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${ZLIB_INCLUDE_DIR}) FILE(GLOB_RECURSE CLIENT_SRCS src/client/*.c) ADD_EXECUTABLE(dnbd3-client ${CLIENT_SRCS}) TARGET_LINK_LIBRARIES(dnbd3-client) +ADD_DEPENDENCIES(dnbd3-client version) @@ -58,6 +77,7 @@ TARGET_LINK_LIBRARIES(dnbd3-server ${CMAKE_THREAD_LIBS_INIT} ${ZLIB_LIBRARIES}) if(UNIX AND NOT APPLE) target_link_libraries(dnbd3-server rt) endif() +ADD_DEPENDENCIES(dnbd3-server version) diff --git a/get-version.sh b/get-version.sh new file mode 100755 index 0000000..d0a095c --- /dev/null +++ b/get-version.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +[ -n "$(git diff)" ] && MODDED='+MOD' + +echo $(git describe)$MODDED, branch $(git rev-parse --abbrev-ref HEAD), built "$(date +%Y-%m-%d)" + diff --git a/src/client/client.c b/src/client/client.c index c0d316b..bb5683b 100644 --- a/src/client/client.c +++ b/src/client/client.c @@ -638,6 +638,7 @@ static int dnbd3_daemon_send(int argc, char **argv) static void dnbd3_print_help(char *argv_0) { + printf( "Version: %s\n\n", VERSION_STRING ); printf( "\nUsage: %s\n" "\t-h <host> -i <image name> [-r <rid>] -d <device> [-a <KB>] || -c <device>\n\n", argv_0 ); printf( "Start the DNBD3 client.\n" ); diff --git a/src/server/server.c b/src/server/server.c index eef9fdc..968d59f 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -71,6 +71,7 @@ static void dnbd3_printClients(); */ void dnbd3_print_help(char *argv_0) { + printf( "Version: %s\n\n", VERSION_STRING ); printf( "Usage: %s [OPTIONS]...\n", argv_0 ); printf( "Start the DNBD3 server\n" ); printf( "-c or --config Configuration file (default /etc/dnbd3-server.conf)\n" ); diff --git a/src/version.c.in b/src/version.c.in new file mode 100644 index 0000000..54854c9 --- /dev/null +++ b/src/version.c.in @@ -0,0 +1,4 @@ +#include "version.h" + +const char * VERSION_STRING = "@VERSION@"; + diff --git a/src/version.h b/src/version.h index 60246b7..0c4a66b 100644 --- a/src/version.h +++ b/src/version.h @@ -21,7 +21,10 @@ #ifndef VERSION_H_ #define VERSION_H_ -#define VERSION_STRING "1.0.0" -#define VERSION_NUMBER 100 +extern const char *VERSION_STRING; + +// This is done in a little weird way but otherwise eclipse complains about +// unresolvable symbols etc... +#include "version.c" #endif /* VERSION_H_ */ |