diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | CMakeLists.txt | 30 | ||||
-rw-r--r-- | include/mscp_version.h.in | 7 | ||||
-rw-r--r-- | src/main.c | 10 |
4 files changed, 39 insertions, 10 deletions
@@ -4,6 +4,8 @@ compile_commands.json CMakeUserPresets.json .*.swp +include/mscp_version.h + dist *.egg-info __pycache__ diff --git a/CMakeLists.txt b/CMakeLists.txt index d1418b8..dedc0c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,26 @@ project(mscp VERSION ${MSCP_VERSION} LANGUAGES C) + +find_package(Git) +if (Git_FOUND) + # based on https://github.com/nocnokneo/cmake-git-versioning-example + execute_process( + COMMAND ${GIT_EXECUTABLE} describe --tags --dirty --match "v*" + OUTPUT_VARIABLE GIT_DESCRIBE_VERSION + RESULT_VARIABLE GIT_DESCRIBE_ERROR_CODE + OUTPUT_STRIP_TRAILING_WHITESPACE) + if(NOT GIT_DESCRIBE_ERROR_CODE) + set(MSCP_BUILD_VERSION ${GIT_DESCRIBE_VERSION}) + endif() +endif() + +if (NOT MSCP_BUILD_VERSION) + message(STATUS "Failed to determine version via Git. Use VERSION file instead.") + set(MSCP_BUILD_VERSION v${MSCP_VERSION}) +endif() + + include(GNUInstallDirs) set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG") @@ -62,9 +82,16 @@ if(BUILD_CONAN) list(APPEND MSCP_LINK_LIBS OpenSSL::Crypto) endif() -set(LIBMSCP_SRC src/mscp.c src/ssh.c src/fileops.c src/path.c src/platform.c src/message.c) + +# generate version header file +configure_file( + ${mscp_SOURCE_DIR}/include/mscp_version.h.in + ${mscp_SOURCE_DIR}/include/mscp_version.h) + # libmscp.so +set(LIBMSCP_SRC + src/mscp.c src/ssh.c src/fileops.c src/path.c src/platform.c src/message.c) add_library(mscp-shared SHARED ${LIBMSCP_SRC}) target_include_directories(mscp-shared PUBLIC $<BUILD_INTERFACE:${mscp_SOURCE_DIR}/include> @@ -104,7 +131,6 @@ if (BUILD_STATIC) target_link_options(mscp PRIVATE -static) endif() target_compile_options(mscp PRIVATE ${MSCP_COMPILE_OPTS}) -target_compile_definitions(mscp PUBLIC _VERSION="${PROJECT_VERSION}") install(TARGETS mscp RUNTIME DESTINATION bin) diff --git a/include/mscp_version.h.in b/include/mscp_version.h.in new file mode 100644 index 0000000..7fcaa58 --- /dev/null +++ b/include/mscp_version.h.in @@ -0,0 +1,7 @@ +#ifndef _MSCP_VERSION_H_ +#define _MSCP_VERSION_H_ + +#define MSCP_VERSION "@MSCP_VERSION@" +#define MSCP_BUILD_VERSION "@MSCP_BUILD_VERSION@" + +#endif /* _MSCP_VERSION_H_ */ @@ -11,18 +11,12 @@ #include <pthread.h> #include <mscp.h> +#include <mscp_version.h> #include <util.h> -#ifndef _VERSION /* passed through cmake */ -#define VERSION "(unknown)" -#else -#define VERSION _VERSION -#endif - - void usage(bool print_help) { - printf("mscp v" VERSION ": copy files over multiple ssh connections\n" + printf("mscp " MSCP_BUILD_VERSION ": copy files over multiple ssh connections\n" "\n" "Usage: mscp [vqDHdNh] [-n nr_conns] [-m coremask] [-u max_startups]\n" " [-s min_chunk_sz] [-S max_chunk_sz] [-a nr_ahead] [-b buf_sz]\n" |