Skip to content

Commit

Permalink
add version info to cucumber-cpp-main
Browse files Browse the repository at this point in the history
  • Loading branch information
ursfassler committed Dec 28, 2023
1 parent ddc4bd6 commit 8a0d16b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
29 changes: 29 additions & 0 deletions cmake/modules/GitVersion.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function(git_get_version VERSION_VARIABLE)
find_program(GIT_EXECUTABLE git)

if(NOT GIT_EXECUTABLE)
message(FATAL_ERROR "Git not found. Please install Git and make sure it is in your system's PATH.")
endif()

execute_process(
COMMAND ${GIT_EXECUTABLE} describe --always --dirty
OUTPUT_VARIABLE VERSION_STRING
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
ERROR_VARIABLE GIT_DESCRIBE_ERROR
RESULT_VARIABLE GIT_DESCRIBE_RESULT
)

if(NOT GIT_DESCRIBE_RESULT EQUAL 0)
message(FATAL_ERROR "Error running 'git describe': ${GIT_DESCRIBE_ERROR}")
endif()

string(LENGTH "${VERSION_STRING}" VERSION_STRING_LENGTH)
string(SUBSTRING "${VERSION_STRING}" 0 1 FIRST_CHARACTER)

if("${FIRST_CHARACTER}" STREQUAL "v")
string(SUBSTRING "${VERSION_STRING}" 1 ${VERSION_STRING_LENGTH} VERSION_STRING)
endif()

set(${VERSION_VARIABLE} ${VERSION_STRING} PARENT_SCOPE)
endfunction()
7 changes: 7 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
include(GenerateExportHeader)

find_package(nlohmann_json 3.10.5 REQUIRED)
include(../cmake/modules/GitVersion.cmake)

set(CUKE_SOURCES
drivers/GenericDriver.cpp
Expand Down Expand Up @@ -123,6 +124,12 @@ foreach(TARGET
endif(MINGW)
endforeach()

git_get_version(CUKE_VERSION)
message(STATUS "Version: ${CUKE_VERSION}")
target_compile_definitions(cucumber-cpp PRIVATE
CUKE_VERSION="${CUKE_VERSION}"
)

target_link_libraries(cucumber-cpp
PRIVATE
Boost::program_options
Expand Down
6 changes: 6 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ int CUCUMBER_CPP_EXPORT main(int argc, char** argv) {
boost::program_options::options_description optionDescription("Allowed options");
optionDescription.add_options()("help,h", "help for cucumber-cpp")(
"verbose,v", "verbose output"
)("version", "version of cucumber-cpp"
)("listen,l", value<std::string>(), "listening address of wireserver"
)("port,p",
value<int>(),
Expand All @@ -68,6 +69,11 @@ int CUCUMBER_CPP_EXPORT main(int argc, char** argv) {
exit(1);
}

if (optionVariableMap.count("version")) {
std::cout << CUKE_VERSION << std::endl;
exit(0);
}

std::string listenHost("127.0.0.1");
if (optionVariableMap.count("listen")) {
listenHost = optionVariableMap["listen"].as<std::string>();
Expand Down

0 comments on commit 8a0d16b

Please sign in to comment.