diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 39cf8888aa..954ff43cdd 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -781,6 +781,34 @@ INSTALL(TARGETS IfcGeomServer endif() +find_package (Git) +if (GIT_FOUND) + message("git found: ${GIT_EXECUTABLE} with version ${GIT_VERSION_STRING}") + execute_process( + COMMAND ${GIT_EXECUTABLE} show -s --pretty=%D HEAD + OUTPUT_VARIABLE git_branches + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + string(REPLACE ", " ";" git_branch_list "${git_branches}") + string(REPLACE " -> " ";" git_branch_list "${git_branch_list}") + foreach(git_branch_candidate IN ITEMS ${git_branch_list}) + if (NOT git_branch_candidate MATCHES "/") + if (NOT git_branch_candidate MATCHES "^HEAD$") + set(git_branch ${git_branch_candidate}) + endif() + endif() + endforeach() + execute_process( + COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD + OUTPUT_VARIABLE git_sha + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + message(STATUS "IfcOpenShell branch ${git_branch}") + message(STATUS "IfcOpenShell commit ${git_sha}") + add_definitions(-DIFCOPENSHELL_BRANCH=${git_branch}) + add_definitions(-DIFCOPENSHELL_COMMIT=${git_sha}) +endif() + # Documentation IF(BUILD_DOCUMENTATION) set(CMAKE_MODULE_PATH "../docs/cmake") diff --git a/src/ifcparse/IfcParse.h b/src/ifcparse/IfcParse.h index 33e6e83bdc..8b0edf4880 100644 --- a/src/ifcparse/IfcParse.h +++ b/src/ifcparse/IfcParse.h @@ -27,7 +27,13 @@ #ifndef IFCPARSE_H #define IFCPARSE_H -#define IFCOPENSHELL_VERSION "0.6.0b0" +#include "../ifcparse/macros.h" + +#if defined(IFCOPENSHELL_BRANCH) && defined(IFCOPENSHELL_COMMIT) +#define IFCOPENSHELL_VERSION STRINGIFY(IFCOPENSHELL_BRANCH) "-" STRINGIFY(IFCOPENSHELL_COMMIT) +#else +#define IFCOPENSHELL_VERSION "0.7.0" +#endif #include #include