mirror of
https://github.com/upa/mscp.git
synced 2026-02-04 11:34:44 +08:00
introduce git-based versioning
MSCP_BUILD_VERSION (`git describe --tags --dirty --match "v*"`) is passed through include/mscp_version.h.in and cmake. When git is failed, use VERSION file instead (for building from source tar balls that excludes .git).
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -4,6 +4,8 @@ compile_commands.json
|
||||
CMakeUserPresets.json
|
||||
.*.swp
|
||||
|
||||
include/mscp_version.h
|
||||
|
||||
dist
|
||||
*.egg-info
|
||||
__pycache__
|
||||
|
||||
@@ -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)
|
||||
|
||||
7
include/mscp_version.h.in
Normal file
7
include/mscp_version.h.in
Normal file
@@ -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_ */
|
||||
10
src/main.c
10
src/main.c
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user