this compiles
This commit is contained in:
parent
aa4e2d7209
commit
f57bd290d9
@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.13)
|
||||
set(MSG_PREFIX "fsfw |")
|
||||
|
||||
# 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/rpavlik")
|
||||
|
||||
@ -16,17 +16,18 @@ set(FSFW_SUBVERSION_IF_GIT_FAILS 0)
|
||||
set(FSFW_REVISION_IF_GIT_FAILS 0)
|
||||
|
||||
set(FSFW_GIT_VER_HANDLING_OK FALSE)
|
||||
# Version handling
|
||||
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
|
||||
message(STATUS "${MSG_PREFIX} Determining version information with git")
|
||||
include(FsfwHelpers)
|
||||
determine_version_with_git("--exclude" "docker_*")
|
||||
if(GIT_INFO)
|
||||
# Check whether we got any revision (which isn't
|
||||
# always the case, e.g. when someone downloaded a zip
|
||||
# file from Github instead of a checkout)
|
||||
message(STATUS "${MSG_PREFIX} Determining version information with git")
|
||||
include(FsfwHelpers)
|
||||
determine_version_with_git("--exclude" "docker_*")
|
||||
if(GIT_INFO)
|
||||
set(FSFW_GIT_INFO ${GIT_INFO} CACHE STRING "Version information retrieved with git describe" FORCE)
|
||||
list(GET FSFW_GIT_INFO 1 FSFW_VERSION)
|
||||
list(GET FSFW_GIT_INFO 2 FSFW_SUBVERSION)
|
||||
list(GET FSFW_GIT_INFO 3 FSFW_REVISION)
|
||||
list(GET FSFW_GIT_INFO 4 FSFW_VCS_INFO)
|
||||
list(GET FSFW_GIT_INFO 1 FSFW_VERSION_MAJOR)
|
||||
list(GET FSFW_GIT_INFO 2 FSFW_VERSION_MINOR)
|
||||
list(GET FSFW_GIT_INFO 3 FSFW_VERSION_REVISION)
|
||||
list(GET FSFW_GIT_INFO 4 FSFW_VERSION_VCS_INFO)
|
||||
if(NOT FSFW_VERSION)
|
||||
set(FSFW_VERSION ${FSFW_VERSION_IF_GIT_FAILS})
|
||||
endif()
|
||||
@ -37,16 +38,20 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
|
||||
set(FSFW_REVISION ${FSFW_REVISION_IF_GIT_FAILS})
|
||||
endif()
|
||||
set(FSFW_GIT_VER_HANDLING_OK TRUE)
|
||||
else()
|
||||
else()
|
||||
set(FSFW_GIT_VER_HANDLING_OK FALSE)
|
||||
endif()
|
||||
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})
|
||||
set(GIT_REV "N/A")
|
||||
set(GIT_DIFF "")
|
||||
set(GIT_BRANCH "N/A")
|
||||
endif()
|
||||
|
||||
|
||||
set(LIB_FSFW_NAME fsfw)
|
||||
project(${LIB_FSFW_NAME} VERSION ${FSFW_VERSION}.${FSFW_SUBVERSION}.${FSFW_REVISION})
|
||||
|
||||
@ -245,7 +250,7 @@ else()
|
||||
endif()
|
||||
|
||||
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")
|
||||
|
||||
@ -455,3 +460,18 @@ add_custom_command(
|
||||
POST_BUILD
|
||||
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(
|
||||
TARGET ${LIB_FSFW_NAME}
|
||||
COMMAND ${CMAKE_COMMAND} -DVERSION_DIR=${FSFW_SOURCES_DIR}
|
||||
-DVERSION_MAJOR=${FSFW_VERSION_MAJOR}
|
||||
-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 ""
|
||||
)
|
||||
|
@ -8,6 +8,7 @@
|
||||
function(determine_version_with_git)
|
||||
include(GetGitRevisionDescription)
|
||||
git_describe(VERSION ${ARGN})
|
||||
get_git_head_revision(GIT_BRANCH HASH_VAR)
|
||||
string(FIND ${VERSION} "." VALID_VERSION)
|
||||
if(VALID_VERSION EQUAL -1)
|
||||
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]+\\.([0-9]+).*" "\\1" _VERSION_PATCH "${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})
|
||||
list(APPEND GIT_INFO ${_VERSION_MAJOR})
|
||||
list(APPEND GIT_INFO ${_VERSION_MINOR})
|
||||
list(APPEND GIT_INFO ${_VERSION_PATCH})
|
||||
list(APPEND GIT_INFO ${VERSION_SHA1})
|
||||
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}")
|
||||
endfunction()
|
||||
|
38
cmake/version.cmake
Normal file
38
cmake/version.cmake
Normal 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()
|
@ -1,5 +1,6 @@
|
||||
target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||
version.cpp
|
||||
versionAutogen.cpp
|
||||
)
|
||||
|
||||
# Core
|
||||
|
@ -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_ */
|
@ -57,7 +57,12 @@ class Version {
|
||||
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
|
||||
|
||||
|
10
src/fsfw/versionAutogen.cpp
Normal file
10
src/fsfw/versionAutogen.cpp
Normal 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[] = "285-gaa4e2d72";
|
||||
|
||||
};
|
Loading…
Reference in New Issue
Block a user