Compare commits

...

11 Commits

10 changed files with 115 additions and 52 deletions

View File

@ -32,6 +32,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Add helper functions provided by [`cmake-modules`](https://github.com/bilke/cmake-modules) - Add helper functions provided by [`cmake-modules`](https://github.com/bilke/cmake-modules)
manually now. Those should not change too often and only a small subset is needed manually now. Those should not change too often and only a small subset is needed
- Separate folder for easier update and for distinction - Separate folder for easier update and for distinction
- Add helper functions provided by [`cmake-modules`](https://github.com/rpavlik/cmake-modules)
manually now. Those should not change too often and only a small subset is needed
- Separate folder for easier update and for distinction
- LICENSE file included - LICENSE file included
- use `int` for version numbers to allow unset or uninitialized version - use `int` for version numbers to allow unset or uninitialized version
- Initialize Version object with numbers set to -1 - Initialize Version object with numbers set to -1
@ -40,6 +43,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
versions since the last tag versions since the last tag
- Additional information is set to the last part of the git describe output for `FSFW_VERSION` now. - Additional information is set to the last part of the git describe output for `FSFW_VERSION` now.
- Version still need to be hand-updated if the FSFW is not included as a submodule for now. - Version still need to be hand-updated if the FSFW is not included as a submodule for now.
- CMake will auto-generate a file named `versionAutogen.cpp` on each rebuild which contains
the version retrieved with git
- IPC Message Queue Handling: Allow passing an optional `MqArgs` argument into the MessageQueue - IPC Message Queue Handling: Allow passing an optional `MqArgs` argument into the MessageQueue
creation call. It allows passing context information and an arbitrary user argument into creation call. It allows passing context information and an arbitrary user argument into
the message queue. Also streamlined and simplified `MessageQueue` implementation for all OSALs the message queue. Also streamlined and simplified `MessageQueue` implementation for all OSALs

View File

@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.13)
set(MSG_PREFIX "fsfw |") set(MSG_PREFIX "fsfw |")
# Add the cmake folder so the FindSphinx module is found # Add the cmake folder so the FindSphinx module is found
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake-modules/bilke") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake-modules/bilke")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake-modules/rpavlik") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake-modules/rpavlik")
@ -11,44 +11,49 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake-modules/r
# Version file handling # # Version file handling #
########################## ##########################
set(FSFW_VERSION_IF_GIT_FAILS 4) set(FSFW_VERSION_MAJOR_IF_GIT_FAILS 4)
set(FSFW_SUBVERSION_IF_GIT_FAILS 0) set(FSFW_VERSION_MINOR_IF_GIT_FAILS 0)
set(FSFW_REVISION_IF_GIT_FAILS 0) set(FSFW_VERSION_REVISION_IF_GIT_FAILS 0)
set(FSFW_GIT_VER_HANDLING_OK FALSE) set(FSFW_GIT_VER_HANDLING_OK FALSE)
# Version handling # Check whether we got any revision (which isn't
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git) # always the case, e.g. when someone downloaded a zip
message(STATUS "${MSG_PREFIX} Determining version information with git") # file from Github instead of a checkout)
include(FsfwHelpers) message(STATUS "${MSG_PREFIX} Determining version information with git")
determine_version_with_git("--exclude" "docker_*") include(FsfwHelpers)
if(GIT_INFO) determine_version_with_git("--exclude" "docker_*")
set(FSFW_GIT_INFO ${GIT_INFO} CACHE STRING "Version information retrieved with git describe") if(GIT_INFO)
list(GET FSFW_GIT_INFO 1 FSFW_VERSION) set(FSFW_GIT_INFO ${GIT_INFO} CACHE STRING "Version information retrieved with git describe" FORCE)
list(GET FSFW_GIT_INFO 2 FSFW_SUBVERSION) list(GET FSFW_GIT_INFO 1 FSFW_VERSION_MAJOR)
list(GET FSFW_GIT_INFO 3 FSFW_REVISION) list(GET FSFW_GIT_INFO 2 FSFW_VERSION_MINOR)
list(GET FSFW_GIT_INFO 4 FSFW_VCS_INFO) list(GET FSFW_GIT_INFO 3 FSFW_VERSION_REVISION)
if(NOT FSFW_VERSION) list(GET FSFW_GIT_INFO 4 FSFW_VERSION_VCS_INFO)
set(FSFW_VERSION ${FSFW_VERSION_IF_GIT_FAILS}) if(NOT FSFW_VERSION_MAJOR)
endif() set(FSFW_VERSION_MAJOR ${FSFW_VERSION_MAJOR_IF_GIT_FAILS})
if(NOT FSFW_SUBVERSION) endif()
set(FSFW_SUBVERSION ${FSFW_SUBVERSION_IF_GIT_FAILS}) if(NOT FSFW_VERSION_MINOR)
endif() set(FSFW_VERSION_MINOR ${FSFW_VERSION_MINOR_IF_GIT_FAILS})
if(NOT FSFW_REVISION) endif()
set(FSFW_REVISION ${FSFW_REVISION_IF_GIT_FAILS}) if(NOT FSFW_VERSION_REVISION)
endif() set(FSFW_VERSION_REVISION ${FSFW_VERSION_REVISION_IF_GIT_FAILS})
set(FSFW_GIT_VER_HANDLING_OK TRUE) endif()
else() set(FSFW_GIT_VER_HANDLING_OK TRUE)
set(FSFW_GIT_VER_HANDLING_OK FALSE) else()
endif() set(FSFW_GIT_VER_HANDLING_OK FALSE)
endif()
if(NOT FSFW_GIT_VER_HANDLING_OK)
set(FSFW_VERSION ${FSFW_VERSION_IF_GIT_FAILS})
set(FSFW_SUBVERSION ${FSFW_SUBVERSION_IF_GIT_FAILS})
set(FSFW_REVISION ${FSFW_REVISION_IF_GIT_FAILS})
endif() endif()
if(NOT FSFW_GIT_VER_HANDLING_OK)
set(FSFW_VERSION_MAJOR ${FSFW_VERSION_MAJOR_IF_GIT_FAILS})
set(FSFW_VERSION_MINOR ${FSFW_VERSION_MINOR_IF_GIT_FAILS})
set(FSFW_VERSION_REVISION ${FSFW_VERSION_REVISION_IF_GIT_FAILS})
set(GIT_REV "N/A")
set(GIT_DIFF "")
set(GIT_BRANCH "N/A")
endif()
set(LIB_FSFW_NAME fsfw) set(LIB_FSFW_NAME fsfw)
project(${LIB_FSFW_NAME} VERSION ${FSFW_VERSION}.${FSFW_SUBVERSION}.${FSFW_REVISION}) project(${LIB_FSFW_NAME} VERSION ${FSFW_VERSION_MAJOR}.${FSFW_VERSION_MINOR}.${FSFW_VERSION_REVISION})
if(NOT CMAKE_CXX_STANDARD) if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
@ -245,7 +250,7 @@ else()
endif() endif()
configure_file(src/fsfw/FSFW.h.in fsfw/FSFW.h) configure_file(src/fsfw/FSFW.h.in fsfw/FSFW.h)
configure_file(src/fsfw/FSFWVersion.h.in fsfw/FSFWVersion.h) # configure_file(src/fsfw/FSFWVersion.h.in fsfw/FSFWVersion.h)
message(STATUS "${MSG_PREFIX} Compiling FSFW for the ${FSFW_OS_NAME} operating system") message(STATUS "${MSG_PREFIX} Compiling FSFW for the ${FSFW_OS_NAME} operating system")
@ -456,9 +461,17 @@ add_custom_command(
COMMENT ${POST_BUILD_COMMENT} COMMENT ${POST_BUILD_COMMENT}
) )
# Add a custom command that produces version.cpp, plus
# a dummy output that's not actually produced, in order
# to force version.cmake to always be re-run before the build
add_custom_command( add_custom_command(
TARGET ${LIB_FSFW_NAME} TARGET ${LIB_FSFW_NAME}
PRE_BUILD COMMAND ${CMAKE_COMMAND} -DVERSION_DIR=${FSFW_SOURCES_DIR}
COMMAND touch ${FSFW_SOURCES_DIR}/FSFWVersion.h.in -DVERSION_MAJOR=${FSFW_VERSION_MAJOR}
COMMENT "${MSG_PREFIX} Updating FSFWVersion.h" -DVERSION_MINOR=${FSFW_VERSION_MINOR}
-DVERSION_REVISION=${FSFW_VERSION_REVISION}
-DVERSION_VCS_INFO=${FSFW_VERSION_VCS_INFO}
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.cmake
BYPRODUCTS ${FSFW_SOURCES_DIR}/versionAutogen.cpp
COMMENT ""
) )

View File

View File

@ -8,6 +8,7 @@
function(determine_version_with_git) function(determine_version_with_git)
include(GetGitRevisionDescription) include(GetGitRevisionDescription)
git_describe(VERSION ${ARGN}) git_describe(VERSION ${ARGN})
get_git_head_revision(GIT_BRANCH HASH_VAR)
string(FIND ${VERSION} "." VALID_VERSION) string(FIND ${VERSION} "." VALID_VERSION)
if(VALID_VERSION EQUAL -1) if(VALID_VERSION EQUAL -1)
message(WARNING "Version string ${VERSION} retrieved with git describe is invalid") message(WARNING "Version string ${VERSION} retrieved with git describe is invalid")
@ -18,11 +19,14 @@ function(determine_version_with_git)
string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" _VERSION_MINOR "${VERSION}") string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" _VERSION_MINOR "${VERSION}")
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" _VERSION_PATCH "${VERSION}") string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" _VERSION_PATCH "${VERSION}")
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+-(.*)" "\\1" VERSION_SHA1 "${VERSION}") string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+-(.*)" "\\1" VERSION_SHA1 "${VERSION}")
string(STRIP "${GIT_BRANCH}" GIT_BRANCH)
set(GIT_INFO ${VERSION}) set(GIT_INFO ${VERSION})
list(APPEND GIT_INFO ${_VERSION_MAJOR}) list(APPEND GIT_INFO ${_VERSION_MAJOR})
list(APPEND GIT_INFO ${_VERSION_MINOR}) list(APPEND GIT_INFO ${_VERSION_MINOR})
list(APPEND GIT_INFO ${_VERSION_PATCH}) list(APPEND GIT_INFO ${_VERSION_PATCH})
list(APPEND GIT_INFO ${VERSION_SHA1}) list(APPEND GIT_INFO ${VERSION_SHA1})
set(GIT_INFO ${GIT_INFO} PARENT_SCOPE) set(GIT_INFO ${GIT_INFO} PARENT_SCOPE)
set(GIT_BRANCH ${GIT_BRANCH} PARENT_SCOPE)
message(STATUS "${MSG_PREFIX} git branch ${GIT_BRANCH}")
message(STATUS "${MSG_PREFIX} Set git version info into GIT_INFO from the git tag ${VERSION}") message(STATUS "${MSG_PREFIX} Set git version info into GIT_INFO from the git tag ${VERSION}")
endfunction() endfunction()

38
cmake/version.cmake Normal file
View File

@ -0,0 +1,38 @@
if(NOT DEFINED VERSION_MAJOR)
message(WARNING "version.cmake | No VERSION_MAJOR variable passed. Setting to 0")
set(VERSION_MAJOR 0)
endif()
if(NOT DEFINED VERSION_MINOR)
message(WARNING "version.cmake | No VERSION_MINOR variable passed. Setting to 0")
set(VERSION_MINOR 0)
endif()
if(NOT DEFINED VERSION_REVISION)
message(WARNING "version.cmake | No VERSION_REVISION variable passed. Setting to 0")
set(VERSION_REVISION 0)
endif()
if(NOT DEFINED VERSION_VCS_INFO)
set(VERSION_VCS_INFO "")
endif()
set(VERSION_TO_SET "#include \"version.h\"
namespace fsfw {
const int FSFW_VERSION_MAJOR = ${VERSION_MAJOR};
const int FSFW_VERSION_MINOR = ${VERSION_MINOR};
const int FSFW_VERSION_REVISION = ${VERSION_MINOR};
const char FSFW_VCS_INFO[] = \"${VERSION_VCS_INFO}\";
};
")
if(EXISTS ${VERSION_DIR}/versionAutogen.cpp)
file(READ ${VERSION_DIR}/versionAutogen.cpp OLD_VERSION)
else()
set(OLD_VERSION "")
endif()
if (NOT "${VERSION_TO_SET}" STREQUAL "${OLD_VERSION}")
message(STATUS "Updating versionAutogen.cpp file")
file(WRITE ${VERSION_DIR}/versionAutogen.cpp "${VERSION_TO_SET}")
endif()

View File

@ -1,5 +1,6 @@
target_sources(${LIB_FSFW_NAME} PRIVATE target_sources(${LIB_FSFW_NAME} PRIVATE
version.cpp version.cpp
versionAutogen.cpp
) )
# Core # Core

View File

@ -1,11 +0,0 @@
#ifndef FSFW_VERSION_H_
#define FSFW_VERSION_H_
// Versioning is managed in project CMakeLists.txt file
static constexpr int FSFW_VERSION_MAJOR = @FSFW_VERSION@;
static constexpr int FSFW_VERSION_MINOR = @FSFW_SUBVERSION@;
static constexpr int FSFW_VERSION_REVISION = @FSFW_REVISION@;
// Also contains CST (Commits since tag) information
static const char FSFW_VCS_INFO[] = "@FSFW_VCS_INFO@";
#endif /* FSFW_VERSION_H_ */

View File

@ -2,8 +2,6 @@
#include <cstdio> #include <cstdio>
#include "fsfw/FSFWVersion.h"
#ifdef major #ifdef major
#undef major #undef major
#endif #endif

View File

@ -57,7 +57,12 @@ class Version {
void getVersion(char* str, size_t maxLen) const; void getVersion(char* str, size_t maxLen) const;
}; };
extern const Version FSFW_VERSION; extern const int FSFW_VERSION_MAJOR;
extern const int FSFW_VERSION_MINOR;
extern const int FSFW_VERSION_REVISION;
extern const char FSFW_VCS_INFO[];
extern const fsfw::Version FSFW_VERSION;
} // namespace fsfw } // namespace fsfw

View File

@ -0,0 +1,10 @@
#include "version.h"
namespace fsfw {
const int FSFW_VERSION_MAJOR = 4;
const int FSFW_VERSION_MINOR = 0;
const int FSFW_VERSION_REVISION = 0;
const char FSFW_VCS_INFO[] = "292-g42ac1af4";
};