From 98d956275af26bb93481e434f82ac5a34eebbc40 Mon Sep 17 00:00:00 2001 From: dehnert Date: Fri, 10 Mar 2017 21:56:00 +0100 Subject: [PATCH] reworked version detection via git/defaults if not available --- CMakeLists.txt | 94 +++++++++++++------------------ src/storm/cli/cli.cpp | 2 +- src/storm/utility/storm-version.h | 24 +++++--- storm-version.cpp.in | 8 +-- 4 files changed, 60 insertions(+), 68 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 02e32c8ad..294328776 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ include(imported) ############################################################# ## -## CMake options of storm +## CMake options of Storm ## ############################################################# option(STORM_DEVELOPER "Sets whether the development mode is used." OFF) @@ -44,7 +44,7 @@ option(STORM_COMPILE_WITH_CCACHE "Compile using CCache [if found]" ON) mark_as_advanced(STORM_COMPILE_WITH_CCACHE) option(STORM_LOG_DISABLE_DEBUG "Disable log and trace message support" OFF) option(STORM_USE_CLN_NUMBERS "Sets whether CLN or GMP numbers should be used" ON) -option(BUILD_SHARED_LIBS "Build the storm library dynamically" OFF) +option(BUILD_SHARED_LIBS "Build the Storm library dynamically" OFF) set(BOOST_ROOT "" CACHE STRING "A hint to the root directory of Boost (optional).") set(GUROBI_ROOT "" CACHE STRING "A hint to the root directory of Gurobi (optional).") set(Z3_ROOT "" CACHE STRING "A hint to the root directory of Z3 (optional).") @@ -55,11 +55,6 @@ set(ADDITIONAL_LINK_DIRS "" CACHE STRING "Additional directories added to the li set(USE_XERCESC ${XML_SUPPORT}) mark_as_advanced(USE_XERCESC) -# Sets the source from which storm is obtained. Can be either "git" or "archive". This -# influences, among other things, the version information. -set(STORM_SOURCE "git" CACHE STRING "The source from which storm is obtained: either 'git' or 'archive'.") -mark_as_advanced(STORM_SOURCE) - # Set some CMAKE Variables as advanced mark_as_advanced(CMAKE_OSX_ARCHITECTURES) mark_as_advanced(CMAKE_OSX_SYSROOT) @@ -72,7 +67,7 @@ set(LIB_INSTALL_DIR lib/ CACHE PATH "Installation directory for libraries") set(BIN_INSTALL_DIR lib/ CACHE PATH "Installation directory for executables") -# Install dir for cmake files (info for other libraries that include storm) +# Install dir for cmake files (info for other libraries that include Storm) set(DEF_INSTALL_CMAKE_DIR "lib/CMake/storm") set(CMAKE_INSTALL_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files") @@ -91,17 +86,17 @@ else() endif() endif() -message(STATUS "storm - Building ${CMAKE_BUILD_TYPE} version.") +message(STATUS "Storm - Building ${CMAKE_BUILD_TYPE} version.") if(STORM_COMPILE_WITH_CCACHE) find_program(CCACHE_FOUND ccache) mark_as_advanced(CCACHE_FOUND) if(CCACHE_FOUND) - message(STATUS "storm - Using ccache") + message(STATUS "Storm - Using ccache") set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) else() - message(STATUS "storm - Could not find ccache.") + message(STATUS "Storm - Could not find ccache.") endif() endif() @@ -127,7 +122,7 @@ else() set(OPERATING_SYSTEM "Linux") set(LINUX 1) ENDIF() -message(STATUS "storm - Detected operating system ${OPERATING_SYSTEM}.") +message(STATUS "Storm - Detected operating system ${OPERATING_SYSTEM}.") set(DYNAMIC_EXT ".so") set(STATIC_EXT ".a") @@ -305,12 +300,12 @@ if ("${CMAKE_GENERATOR}" STREQUAL "Xcode") endif() # Display information about build configuration. -message(STATUS "storm - Using compiler configuration ${STORM_COMPILER_ID} ${STORM_COMPILER_VERSION}.") +message(STATUS "Storm - Using compiler configuration ${STORM_COMPILER_ID} ${STORM_COMPILER_VERSION}.") if (STORM_DEVELOPER) - message(STATUS "storm - CXX Flags: ${CMAKE_CXX_FLAGS}") - message(STATUS "storm - CXX Debug Flags: ${CMAKE_CXX_FLAGS_DEBUG}") - message(STATUS "storm - CXX Release Flags: ${CMAKE_CXX_FLAGS_RELEASE}") - message(STATUS "storm - Build type: ${CMAKE_BUILD_TYPE}") + message(STATUS "Storm - CXX Flags: ${CMAKE_CXX_FLAGS}") + message(STATUS "Storm - CXX Debug Flags: ${CMAKE_CXX_FLAGS_DEBUG}") + message(STATUS "Storm - CXX Release Flags: ${CMAKE_CXX_FLAGS_RELEASE}") + message(STATUS "Storm - Build type: ${CMAKE_BUILD_TYPE}") endif() ############################################################# @@ -350,50 +345,41 @@ endif(DOXYGEN_FOUND) ############################################################# ## -## CMake-generated Config File for storm +## CMake-generated Config File for Storm ## ############################################################# -# If storm is built from an archive, we need to skip the version detection based on git. -if (STORM_SOURCE STREQUAL "archive") - if (NOT DEFINED STORM_VERSION_MAJOR OR NOT DEFINED STORM_VERSION_MINOR OR NOT DEFINED STORM_VERSION_PATCH) - message(FATAL_ERROR "storm - building from archive requires setting a version via cmake.") - endif() - message(STATUS "storm - version is ${STORM_VERSION_MAJOR}.${STORM_VERSION_MINOR}.${STORM_VERSION_PATCH} (building from archive).") - set(STORM_VERSION_COMMITS_AHEAD boost::none) - set(STORM_VERSION_GIT_HASH boost::none) +# try to obtain the current version from git. +include(GetGitRevisionDescription) +get_git_head_revision(STORM_VERSION_REFSPEC STORM_VERSION_GIT_HASH) +git_describe_checkout(STORM_GIT_VERSION_STRING) + +# parse the git tag into variables +string(REGEX REPLACE "^([0-9]+)\\..*" "\\1" STORM_VERSION_MAJOR "${STORM_GIT_VERSION_STRING}") +string(REGEX REPLACE "^[0-9]+\\.([0-9]+).*" "\\1" STORM_VERSION_MINOR "${STORM_GIT_VERSION_STRING}") +string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" STORM_VERSION_PATCH "${STORM_GIT_VERSION_STRING}") +string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.[0-9]+\\-([0-9]+)\\-.*" "\\1" STORM_VERSION_COMMITS_AHEAD "${STORM_GIT_VERSION_STRING}") +string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.[0-9]+\\-[0-9]+\\-([a-z0-9]+).*" "\\1" STORM_VERSION_TAG_HASH "${STORM_GIT_VERSION_STRING}") +string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.[0-9]+\\-[0-9]+\\-[a-z0-9]+\\-(.*)" "\\1" STORM_VERSION_APPENDIX "${STORM_GIT_VERSION_STRING}") + +# now check whether the git version lookup failed +if (STORM_VERSION_MAJOR STREQUAL "HEAD-HASH-NOTFOUND") + set(STORM_VERSION_MAJOR 1) + set(STORM_VERSION_MINOR 0) + set(STORM_VERSION_PATCH 0) + set(STORM_VERSION_GIT_HASH "") + set(STORM_VERSION_COMMITS_AHEAD 0) set(STORM_VERSION_DIRTY boost::none) + + message(WARN "Storm - git version information not available.") + message(STATUS "Storm - version is ${STORM_VERSION_MAJOR}.${STORM_VERSION_MINOR}.${STORM_VERSION_PATCH}.") else() - if (DEFINED STORM_VERSION_MAJOR OR DEFINED STORM_VERSION_MINOR OR DEFINED STORM_VERSION_PATCH) - message(FATAL_ERROR "storm - building from git does not support setting a version via cmake.") - endif() - - # Make a version file containing the current version from git. - include(GetGitRevisionDescription) - get_git_head_revision(STORM_VERSION_REFSPEC STORM_VERSION_GIT_HASH) - - git_describe_checkout(STORM_GIT_VERSION_STRING) - # Parse the git Tag into variables - string(REGEX REPLACE "^([0-9]+)\\..*" "\\1" STORM_VERSION_MAJOR "${STORM_GIT_VERSION_STRING}") - string(REGEX REPLACE "^[0-9]+\\.([0-9]+).*" "\\1" STORM_VERSION_MINOR "${STORM_GIT_VERSION_STRING}") - string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" STORM_VERSION_PATCH "${STORM_GIT_VERSION_STRING}") - string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.[0-9]+\\-([0-9]+)\\-.*" "\\1" STORM_VERSION_COMMITS_AHEAD "${STORM_GIT_VERSION_STRING}") - string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.[0-9]+\\-[0-9]+\\-([a-z0-9]+).*" "\\1" STORM_VERSION_TAG_HASH "${STORM_GIT_VERSION_STRING}") - string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.[0-9]+\\-[0-9]+\\-[a-z0-9]+\\-(.*)" "\\1" STORM_VERSION_APPENDIX "${STORM_GIT_VERSION_STRING}") if ("${STORM_VERSION_APPENDIX}" MATCHES "^.*dirty.*$") - set(STORM_VERSION_DIRTY 1) - else() - set(STORM_VERSION_DIRTY 0) - endif() - if (STORM_VERSION_DIRTY) - set(STORM_VERSION_DIRTY_STR "yes") + set(STORM_VERSION_DIRTY "true") else() - set(STORM_VERSION_DIRTY_STR "no") + set(STORM_VERSION_DIRTY "false") endif() - message(STATUS "storm - version is ${STORM_VERSION_MAJOR}.${STORM_VERSION_MINOR}.${STORM_VERSION_PATCH} (${STORM_VERSION_COMMITS_AHEAD} commits ahead of tag), building from git: ${STORM_VERSION_GIT_HASH} (dirty: ${STORM_VERSION_DIRTY_STR}).") - - # proper type conversion so we can assign it to an optional - set(STORM_VERSION_GIT_HASH "std::string(\"${STORM_VERSION_GIT_HASH}\")") + message(STATUS "Storm - version is ${STORM_VERSION_MAJOR}.${STORM_VERSION_MINOR}.${STORM_VERSION_PATCH} (${STORM_VERSION_COMMITS_AHEAD} commits ahead of tag), building from git: ${STORM_VERSION_GIT_HASH} (dirty: ${STORM_VERSION_DIRTY}).") endif() # Configure a header file to pass some of the CMake settings to the source code @@ -402,7 +388,7 @@ configure_file ( "${PROJECT_BINARY_DIR}/include/storm-config.h" ) -# Configure a source file to pass the storm version to the source code +# Configure a source file to pass the Storm version to the source code configure_file ( "${PROJECT_SOURCE_DIR}/storm-version.cpp.in" "${PROJECT_SOURCE_DIR}/src/storm/utility/storm-version.cpp" diff --git a/src/storm/cli/cli.cpp b/src/storm/cli/cli.cpp index efdb54d42..314afa700 100644 --- a/src/storm/cli/cli.cpp +++ b/src/storm/cli/cli.cpp @@ -93,7 +93,7 @@ namespace storm { #endif #ifdef STORM_HAVE_CARL // TODO get version string - STORM_PRINT("Linked with CARL." << std::endl); + STORM_PRINT("Linked with CArL." << std::endl); #endif #ifdef STORM_HAVE_CUDA diff --git a/src/storm/utility/storm-version.h b/src/storm/utility/storm-version.h index 2cd72c00b..24cf9a36f 100644 --- a/src/storm/utility/storm-version.h +++ b/src/storm/utility/storm-version.h @@ -19,13 +19,13 @@ namespace storm { const static unsigned versionPatch; /// The short hash of the git commit this build is based on - const static boost::optional gitRevisionHash; + const static std::string gitRevisionHash; /// How many commits passed since the tag was last set. - const static boost::optional commitsAhead; + const static unsigned commitsAhead; /// 0 iff there no files were modified in the checkout, 1 otherwise. - const static boost::optional dirty; + const static boost::optional dirty; /// The system which has compiled Storm. const static std::string systemName; @@ -48,14 +48,20 @@ namespace storm { static std::string longVersionString() { std::stringstream sstream; sstream << "Version " << versionMajor << "." << versionMinor << "." << versionPatch; - if (commitsAhead && commitsAhead.get() > 0) { - sstream << " (+" << commitsAhead.get() << " commits)"; + if (commitsAhead) { + sstream << " (+ " << commitsAhead << " commits)"; } - if (gitRevisionHash) { - sstream << " build from revision " << gitRevisionHash.get(); + if (!gitRevisionHash.empty()) { + sstream << " build from revision " << gitRevisionHash; } - if (dirty && dirty.get() == 1) { - sstream << " (dirty)"; + if (dirty) { + if (dirty.get()) { + sstream << " (dirty)"; + } else { + sstream << " (clean)"; + } + } else { + sstream << " (potentially dirty)"; } return sstream.str(); } diff --git a/storm-version.cpp.in b/storm-version.cpp.in index 23a993169..61d9b4bc5 100644 --- a/storm-version.cpp.in +++ b/storm-version.cpp.in @@ -1,4 +1,4 @@ -//AUTO GENERATED -- DO NOT CHANGE +//AUTO GENERATED -- DO NOT CHANGE // TODO resolve issues when placing this in the build order directly. #include "storm/utility/storm-version.h" @@ -8,9 +8,9 @@ namespace storm { const unsigned StormVersion::versionMajor = @STORM_VERSION_MAJOR@; const unsigned StormVersion::versionMinor = @STORM_VERSION_MINOR@; const unsigned StormVersion::versionPatch = @STORM_VERSION_PATCH@; - const boost::optional StormVersion::gitRevisionHash = @STORM_VERSION_GIT_HASH@; - const boost::optional StormVersion::commitsAhead = @STORM_VERSION_COMMITS_AHEAD@; - const boost::optional StormVersion::dirty = @STORM_VERSION_DIRTY@; + const std::string StormVersion::gitRevisionHash = "@STORM_VERSION_GIT_HASH@"; + const unsigned StormVersion::commitsAhead = @STORM_VERSION_COMMITS_AHEAD@; + const boost::optional StormVersion::dirty = @STORM_VERSION_DIRTY@; const std::string StormVersion::systemName = "@CMAKE_SYSTEM_NAME@"; const std::string StormVersion::systemVersion = "@CMAKE_SYSTEM_VERSION@"; const std::string StormVersion::cxxCompiler = "@STORM_COMPILER_ID@ @CMAKE_CXX_COMPILER_VERSION@";