From b9e58a3aae7ee845e9f6f047c0302459c40320c1 Mon Sep 17 00:00:00 2001 From: johndebord Date: Wed, 5 Jun 2019 18:00:28 -0400 Subject: [PATCH 01/28] Update `version` lib --- libraries/CMakeLists.txt | 1 + libraries/version/CMakeLists.txt | 29 +++++++++++++++++++ libraries/version/include/version/version.hpp | 18 ++++++++++++ libraries/version/src/version.cpp | 21 ++++++++++++++ libraries/version/src/version_impl.cpp.in | 28 ++++++++++++++++++ libraries/version/src/version_impl.hpp | 25 ++++++++++++++++ 6 files changed, 122 insertions(+) create mode 100644 libraries/version/CMakeLists.txt create mode 100644 libraries/version/include/version/version.hpp create mode 100644 libraries/version/src/version.cpp create mode 100644 libraries/version/src/version_impl.cpp.in create mode 100644 libraries/version/src/version_impl.hpp diff --git a/libraries/CMakeLists.txt b/libraries/CMakeLists.txt index 54bb2f80e09..c639743f317 100644 --- a/libraries/CMakeLists.txt +++ b/libraries/CMakeLists.txt @@ -6,6 +6,7 @@ add_subdirectory( wasm-jit ) add_subdirectory( appbase ) add_subdirectory( chain ) add_subdirectory( testing ) +add_subdirectory( version ) #turn tools&tests off; not needed for library build set(BUILD_TESTS OFF CACHE BOOL "Build GTest-based tests") diff --git a/libraries/version/CMakeLists.txt b/libraries/version/CMakeLists.txt new file mode 100644 index 00000000000..303b92faa72 --- /dev/null +++ b/libraries/version/CMakeLists.txt @@ -0,0 +1,29 @@ +cmake_minimum_required( + VERSION 2.8.12 ) # What should the version actually be? + +project( + Version ) + +add_library( + version + "./src/version.cpp" + "./include/eosio/version/version.hpp" ) + +target_include_directories( + version + PUBLIC + "${CMAKE_CURRENT_SOURCE_DIR}/include/" ) + +install( + TARGETS + version + RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR} # Is it needed as a RUNTIME? It' just a library? + ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} ## Is it needed as both a static and dynamic lib? + LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} ) ## ... + +install( + DIRECTORY + ${CMAKE_CURRENT_SOURCE_DIR}/include/eosio/version + DESTINATION + ${CMAKE_INSTALL_FULL_INCLUDEDIR}/eosio/version + "./include/eosio/version/version.hpp" ) diff --git a/libraries/version/include/version/version.hpp b/libraries/version/include/version/version.hpp new file mode 100644 index 00000000000..b714e2c588f --- /dev/null +++ b/libraries/version/include/version/version.hpp @@ -0,0 +1,18 @@ +/** + * @file version.hpp + * @copyright defined in eos/LICENSE + */ + +#pragma once + +#include // std::string_view + +namespace eosio { namespace version { + + ///< Grab the version of the client in the form of: `v1.8.0-rc1` + const std::string_view& version_client(); + + ///< Grab the version of the client in the form of: `v1.8.0-rc1-7de458254[-dirty]` + const std::string_view& version_full(); + +} } diff --git a/libraries/version/src/version.cpp b/libraries/version/src/version.cpp new file mode 100644 index 00000000000..e2b8618118e --- /dev/null +++ b/libraries/version/src/version.cpp @@ -0,0 +1,21 @@ +/** + * @file version.cpp + * @copyright defined in eos/LICENSE + */ + +#pragma once + +#include +#include + +namespace eosio { namespace version { + + const std::string_view& version_client() { + return static const std::string{_version_client()}; + } + + const std::string_view& version_full() { + return static const std::string{_version_full()}; + } + +} } diff --git a/libraries/version/src/version_impl.cpp.in b/libraries/version/src/version_impl.cpp.in new file mode 100644 index 00000000000..62fbea6d431 --- /dev/null +++ b/libraries/version/src/version_impl.cpp.in @@ -0,0 +1,28 @@ +/** + * @file version_impl.cpp.in + * @copyright defined in eos/LICENSE + * \warning This file is machine generated. DO NOT EDIT. See version_impl.cpp.in for changes. + */ + +#pragma once + +#include + +namespace eosio { namespace version { + + constexpr std::string_view version_major {"@_VERSION_MAJOR_@"}; + constexpr std::string_view version_minor {"@_VERSION_MINOR_@"}; + constexpr std::string_view version_patch {"@_VERSION_PATCH_@"}; + constexpr std::string_view version_suffix{"@_VERSION_SUFFIX_@"}; + constexpr std::string_view version_hash {"@_VERSION_HASH_@"}; + constexpr std::string_view version_dirty {"@_VERSION_DIRTY_@"}; + + const std::string_view& _version_client() { + return std::string{"v"+version_major+'.'+version_minor+'.'+version_patch+'-'+version_suffix}; + } + + const std::string_view& _version_full() { + return std::string{"v"+version_major+'.'+version_minor+'.'+version_patch+'-'+version_suffix+'-'+version_hash+version_dirty}; + } + +} } diff --git a/libraries/version/src/version_impl.hpp b/libraries/version/src/version_impl.hpp new file mode 100644 index 00000000000..ee946df1804 --- /dev/null +++ b/libraries/version/src/version_impl.hpp @@ -0,0 +1,25 @@ +/** + * @file version_impl.hpp + * @copyright defined in eos/LICENSE + */ + +#pragma once + +#include // std::string_view + +namespace eosio { namespace version { + + constexpr std::string_view version_major; + constexpr std::string_view version_minor; + constexpr std::string_view version_patch; + constexpr std::string_view version_suffix; + constexpr std::string_view version_hash; + constexpr std::string_view version_dirty; + + ///< Helper function `version_client()` + const std::string_view& _version_client(); + + ///< Helper function `version_full()` + const std::string_view& _version_full(); + +} } From 16259e6b1ed18d0e4d7449d056326ce051bdb204 Mon Sep 17 00:00:00 2001 From: johndebord Date: Thu, 6 Jun 2019 13:40:34 -0400 Subject: [PATCH 02/28] Continuation --- CMakeModules/VersionUtils.cmake | 24 +++++++++++++++++++ libraries/version/CMakeLists.txt | 24 +++++++++++++++---- .../include/{ => eosio}/version/version.hpp | 6 ++--- libraries/version/src/version.cpp | 15 ++++++------ libraries/version/src/version_impl.cpp.in | 24 +++++++++---------- libraries/version/src/version_impl.hpp | 17 ++++--------- 6 files changed, 70 insertions(+), 40 deletions(-) create mode 100644 CMakeModules/VersionUtils.cmake rename libraries/version/include/{ => eosio}/version/version.hpp (70%) diff --git a/CMakeModules/VersionUtils.cmake b/CMakeModules/VersionUtils.cmake new file mode 100644 index 00000000000..42020038b59 --- /dev/null +++ b/CMakeModules/VersionUtils.cmake @@ -0,0 +1,24 @@ +function(GENERATE_VERSION_METADATA) + set(_VERSION_MAJOR_ ${VERSION_MAJOR}) + set(_VERSION_MINOR_ ${VERSION_MINOR}) + set(_VERSION_PATCH_ ${VERSION_PATCH}) + set(_VERSION_SUFFIX_ ${VERSION_SUFFIX}) + set(_VERSION_HASH_ ${}) + set(_VERSION_DIRTY_ ${}) + + find_package(Git) + if(EXISTS ${CMAKE_SOURCE_DIR}/.git AND GIT_FOUND) + execute_process( + COMMAND ${GIT_EXECUTABLE} rev-parse --short=8 HEAD + OUTPUT_VARIABLE _VERSION_HASH_ + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE ) + execute_process( + COMMAND ${GIT_EXECUTABLE} describe --tags --dirty + OUTPUT_VARIABLE _VERSION_DIRTY_ + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE ) + string(REGEX MATCH "-dirty$" _VERSION_DIRTY_ ${_VERSION_DIRTY_}) + # configure_file(${CMAKE_CURRENT_SOURCE_DIR}/version.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/version.hpp @ONLY) + endif() +endfunction() diff --git a/libraries/version/CMakeLists.txt b/libraries/version/CMakeLists.txt index 303b92faa72..567ae840f57 100644 --- a/libraries/version/CMakeLists.txt +++ b/libraries/version/CMakeLists.txt @@ -4,16 +4,25 @@ cmake_minimum_required( project( Version ) +# Found in directory `eos/CMakeModules/`. +include( + VersionUtils ) + +# Generate the most up-to-date metadata of the repository. +GENERATE_VERSION_METADATA() + +# Construct the library. add_library( version - "./src/version.cpp" - "./include/eosio/version/version.hpp" ) + "${CMAKE_CURRENT_SOURCE_DIR}/src/version.cpp" ) +# Make dependencies visible. target_include_directories( version PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include/" ) +# Install the library in the appropriate places. install( TARGETS version @@ -21,9 +30,16 @@ install( ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} ## Is it needed as both a static and dynamic lib? LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} ) ## ... +# Install the header file in the appropriate place. install( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/eosio/version DESTINATION - ${CMAKE_INSTALL_FULL_INCLUDEDIR}/eosio/version - "./include/eosio/version/version.hpp" ) + ${CMAKE_INSTALL_FULL_INCLUDEDIR}/eosio/ + FILES_MATCHING PATTERN "*.hpp" ) + +# Modify and substitute the `.cpp.in` file for a `.cpp` in the build directory. +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/src/version_impl.cpp.in + ${CMAKE_CURRENT_BINARY_DIR}/src/version_impl.cpp + @ONLY ) diff --git a/libraries/version/include/version/version.hpp b/libraries/version/include/eosio/version/version.hpp similarity index 70% rename from libraries/version/include/version/version.hpp rename to libraries/version/include/eosio/version/version.hpp index b714e2c588f..a2c1c887fd8 100644 --- a/libraries/version/include/version/version.hpp +++ b/libraries/version/include/eosio/version/version.hpp @@ -5,14 +5,14 @@ #pragma once -#include // std::string_view +#include // std::string namespace eosio { namespace version { ///< Grab the version of the client in the form of: `v1.8.0-rc1` - const std::string_view& version_client(); + const std::string& version_client(); ///< Grab the version of the client in the form of: `v1.8.0-rc1-7de458254[-dirty]` - const std::string_view& version_full(); + const std::string& version_full(); } } diff --git a/libraries/version/src/version.cpp b/libraries/version/src/version.cpp index e2b8618118e..fee2aaff479 100644 --- a/libraries/version/src/version.cpp +++ b/libraries/version/src/version.cpp @@ -3,19 +3,18 @@ * @copyright defined in eos/LICENSE */ -#pragma once - -#include -#include +#include "version_impl.hpp" namespace eosio { namespace version { - const std::string_view& version_client() { - return static const std::string{_version_client()}; + const std::string& version_client() { + static const std::string version{_version_client()}; + return version; } - const std::string_view& version_full() { - return static const std::string{_version_full()}; + const std::string& version_full() { + static const std::string version{_version_full()}; + return version; } } } diff --git a/libraries/version/src/version_impl.cpp.in b/libraries/version/src/version_impl.cpp.in index 62fbea6d431..65ca7c52442 100644 --- a/libraries/version/src/version_impl.cpp.in +++ b/libraries/version/src/version_impl.cpp.in @@ -4,25 +4,23 @@ * \warning This file is machine generated. DO NOT EDIT. See version_impl.cpp.in for changes. */ -#pragma once - -#include +#include "version_impl.hpp" namespace eosio { namespace version { - constexpr std::string_view version_major {"@_VERSION_MAJOR_@"}; - constexpr std::string_view version_minor {"@_VERSION_MINOR_@"}; - constexpr std::string_view version_patch {"@_VERSION_PATCH_@"}; - constexpr std::string_view version_suffix{"@_VERSION_SUFFIX_@"}; - constexpr std::string_view version_hash {"@_VERSION_HASH_@"}; - constexpr std::string_view version_dirty {"@_VERSION_DIRTY_@"}; + const std::string version_major {"@_VERSION_MAJOR_@"}; + const std::string version_minor {"@_VERSION_MINOR_@"}; + const std::string version_patch {"@_VERSION_PATCH_@"}; + const std::string version_suffix{"@_VERSION_SUFFIX_@"}; + const std::string version_hash {"@_VERSION_HASH_@"}; + const std::string version_dirty {"@_VERSION_DIRTY_@"}; - const std::string_view& _version_client() { - return std::string{"v"+version_major+'.'+version_minor+'.'+version_patch+'-'+version_suffix}; + const std::string& _version_client() { + return std::string{'v'+version_major+'.'+version_minor+'.'+version_patch+'-'+version_suffix}; } - const std::string_view& _version_full() { - return std::string{"v"+version_major+'.'+version_minor+'.'+version_patch+'-'+version_suffix+'-'+version_hash+version_dirty}; + const std::string& _version_full() { + return std::string{'v'+version_major+'.'+version_minor+'.'+version_patch+'-'+version_suffix+'-'+version_hash+version_dirty}; } } } diff --git a/libraries/version/src/version_impl.hpp b/libraries/version/src/version_impl.hpp index ee946df1804..1af4460b18a 100644 --- a/libraries/version/src/version_impl.hpp +++ b/libraries/version/src/version_impl.hpp @@ -5,21 +5,14 @@ #pragma once -#include // std::string_view +#include // std::string namespace eosio { namespace version { - - constexpr std::string_view version_major; - constexpr std::string_view version_minor; - constexpr std::string_view version_patch; - constexpr std::string_view version_suffix; - constexpr std::string_view version_hash; - constexpr std::string_view version_dirty; - ///< Helper function `version_client()` - const std::string_view& _version_client(); + ///< Helper function for `version_client()` + const std::string& _version_client(); - ///< Helper function `version_full()` - const std::string_view& _version_full(); + ///< Helper function for `version_full()` + const std::string& _version_full(); } } From c9725cf46fff019379a952de2224899cb3108368 Mon Sep 17 00:00:00 2001 From: johndebord Date: Thu, 6 Jun 2019 14:42:38 -0400 Subject: [PATCH 03/28] Library is now functional --- CMakeModules/VersionUtils.cmake | 28 +++++++++++++------ libraries/version/CMakeLists.txt | 5 ++-- .../version/include/eosio/version/version.hpp | 4 +-- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/CMakeModules/VersionUtils.cmake b/CMakeModules/VersionUtils.cmake index 42020038b59..e29fdc1f93b 100644 --- a/CMakeModules/VersionUtils.cmake +++ b/CMakeModules/VersionUtils.cmake @@ -1,15 +1,13 @@ function(GENERATE_VERSION_METADATA) - set(_VERSION_MAJOR_ ${VERSION_MAJOR}) - set(_VERSION_MINOR_ ${VERSION_MINOR}) - set(_VERSION_PATCH_ ${VERSION_PATCH}) - set(_VERSION_SUFFIX_ ${VERSION_SUFFIX}) - set(_VERSION_HASH_ ${}) - set(_VERSION_DIRTY_ ${}) + set(_VERSION_MAJOR_ ${VERSION_MAJOR} PARENT_SCOPE) + set(_VERSION_MINOR_ ${VERSION_MINOR} PARENT_SCOPE) + set(_VERSION_PATCH_ ${VERSION_PATCH} PARENT_SCOPE) + set(_VERSION_SUFFIX_ ${VERSION_SUFFIX} PARENT_SCOPE) find_package(Git) if(EXISTS ${CMAKE_SOURCE_DIR}/.git AND GIT_FOUND) execute_process( - COMMAND ${GIT_EXECUTABLE} rev-parse --short=8 HEAD + COMMAND ${GIT_EXECUTABLE} rev-parse HEAD OUTPUT_VARIABLE _VERSION_HASH_ ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE ) @@ -18,7 +16,19 @@ function(GENERATE_VERSION_METADATA) OUTPUT_VARIABLE _VERSION_DIRTY_ ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE ) - string(REGEX MATCH "-dirty$" _VERSION_DIRTY_ ${_VERSION_DIRTY_}) - # configure_file(${CMAKE_CURRENT_SOURCE_DIR}/version.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/version.hpp @ONLY) + string(REGEX MATCH "-dirty$" _VERSION_DIRTY_ ${_VERSION_DIRTY_}) + # if dirty empty -> false + # else -> true + # endif() + set(_VERSION_HASH_ ${_VERSION_HASH_} PARENT_SCOPE) + set(_VERSION_DIRTY_ ${_VERSION_DIRTY_} PARENT_SCOPE) + message(STATUS "-------begin-------") + message(STATUS ${_VERSION_MAJOR_}) + message(STATUS ${_VERSION_MINOR_}) + message(STATUS ${_VERSION_PATCH_}) + message(STATUS ${_VERSION_SUFFIX_}) + message(STATUS ${_VERSION_HASH_}) + message(STATUS ${_VERSION_DIRTY_}) + message(STATUS "-------end-------") endfunction() diff --git a/libraries/version/CMakeLists.txt b/libraries/version/CMakeLists.txt index 567ae840f57..3aeb418170c 100644 --- a/libraries/version/CMakeLists.txt +++ b/libraries/version/CMakeLists.txt @@ -14,13 +14,14 @@ GENERATE_VERSION_METADATA() # Construct the library. add_library( version - "${CMAKE_CURRENT_SOURCE_DIR}/src/version.cpp" ) + "${CMAKE_CURRENT_SOURCE_DIR}/src/version.cpp" + "${CMAKE_CURRENT_BINARY_DIR}/src/version_impl.cpp" ) # Make dependencies visible. target_include_directories( version PUBLIC - "${CMAKE_CURRENT_SOURCE_DIR}/include/" ) + "${CMAKE_CURRENT_SOURCE_DIR}/src" ) # Install the library in the appropriate places. install( diff --git a/libraries/version/include/eosio/version/version.hpp b/libraries/version/include/eosio/version/version.hpp index a2c1c887fd8..64c356a492f 100644 --- a/libraries/version/include/eosio/version/version.hpp +++ b/libraries/version/include/eosio/version/version.hpp @@ -9,10 +9,10 @@ namespace eosio { namespace version { - ///< Grab the version of the client in the form of: `v1.8.0-rc1` + ///< Grab the basic version of the client; example: `v1.8.0-rc1` const std::string& version_client(); - ///< Grab the version of the client in the form of: `v1.8.0-rc1-7de458254[-dirty]` + ///< Grab the full version of the client; example: `v1.8.0-rc1-7de458254[-dirty]` const std::string& version_full(); } } From 18c66eb96e845cb972772c3259059cde99569536 Mon Sep 17 00:00:00 2001 From: johndebord Date: Thu, 6 Jun 2019 15:15:56 -0400 Subject: [PATCH 04/28] Change `version_dirty` to type `bool` --- CMakeModules/VersionUtils.cmake | 14 ++++++++------ libraries/version/src/version_impl.cpp.in | 6 ++++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CMakeModules/VersionUtils.cmake b/CMakeModules/VersionUtils.cmake index e29fdc1f93b..abeb9b85b12 100644 --- a/CMakeModules/VersionUtils.cmake +++ b/CMakeModules/VersionUtils.cmake @@ -16,13 +16,15 @@ function(GENERATE_VERSION_METADATA) OUTPUT_VARIABLE _VERSION_DIRTY_ ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE ) - string(REGEX MATCH "-dirty$" _VERSION_DIRTY_ ${_VERSION_DIRTY_}) - # if dirty empty -> false - # else -> true - # + string(REGEX MATCH "-dirty$" _VERSION_DIRTY_ ${_VERSION_DIRTY_}) + if(${_VERSION_DIRTY_} STREQUAL "") + set(_VERSION_DIRTY_ "false") + else() + set(_VERSION_DIRTY_ "true") + endif() endif() - set(_VERSION_HASH_ ${_VERSION_HASH_} PARENT_SCOPE) - set(_VERSION_DIRTY_ ${_VERSION_DIRTY_} PARENT_SCOPE) + set(_VERSION_HASH_ ${_VERSION_HASH_} PARENT_SCOPE) + set(_VERSION_DIRTY_ ${_VERSION_DIRTY_} PARENT_SCOPE) message(STATUS "-------begin-------") message(STATUS ${_VERSION_MAJOR_}) message(STATUS ${_VERSION_MINOR_}) diff --git a/libraries/version/src/version_impl.cpp.in b/libraries/version/src/version_impl.cpp.in index 65ca7c52442..961c6550eef 100644 --- a/libraries/version/src/version_impl.cpp.in +++ b/libraries/version/src/version_impl.cpp.in @@ -16,11 +16,13 @@ namespace eosio { namespace version { const std::string version_dirty {"@_VERSION_DIRTY_@"}; const std::string& _version_client() { - return std::string{'v'+version_major+'.'+version_minor+'.'+version_patch+'-'+version_suffix}; + static const std::string version{'v'+version_major+'.'+version_minor+'.'+version_patch+'-'+version_suffix}; + return version; } const std::string& _version_full() { - return std::string{'v'+version_major+'.'+version_minor+'.'+version_patch+'-'+version_suffix+'-'+version_hash+version_dirty}; + static const std::string version{'v'+version_major+'.'+version_minor+'.'+version_patch+'-'+version_suffix+'-'+version_hash+version_dirty}; + return version; } } } From 84be49c99227110e1cc01f34f22f586858e19e29 Mon Sep 17 00:00:00 2001 From: johndebord Date: Thu, 6 Jun 2019 16:29:39 -0400 Subject: [PATCH 05/28] Library fully functional --- CMakeModules/VersionUtils.cmake | 12 ++-------- libraries/version/CMakeLists.txt | 10 ++++---- .../version/include/eosio/version/version.hpp | 4 ++-- libraries/version/src/version.cpp | 4 ++-- libraries/version/src/version_impl.cpp.in | 24 ++++++++++++------- libraries/version/src/version_impl.hpp | 2 +- programs/cleos/CMakeLists.txt | 19 +-------------- programs/cleos/config.hpp.in | 11 ++++----- programs/cleos/main.cpp | 10 ++++++-- 9 files changed, 43 insertions(+), 53 deletions(-) diff --git a/CMakeModules/VersionUtils.cmake b/CMakeModules/VersionUtils.cmake index abeb9b85b12..b3fed7a6214 100644 --- a/CMakeModules/VersionUtils.cmake +++ b/CMakeModules/VersionUtils.cmake @@ -18,19 +18,11 @@ function(GENERATE_VERSION_METADATA) OUTPUT_STRIP_TRAILING_WHITESPACE ) string(REGEX MATCH "-dirty$" _VERSION_DIRTY_ ${_VERSION_DIRTY_}) if(${_VERSION_DIRTY_} STREQUAL "") - set(_VERSION_DIRTY_ "false") + set(_VERSION_DIRTY_ "false") else() - set(_VERSION_DIRTY_ "true") + set(_VERSION_DIRTY_ "true") endif() endif() set(_VERSION_HASH_ ${_VERSION_HASH_} PARENT_SCOPE) set(_VERSION_DIRTY_ ${_VERSION_DIRTY_} PARENT_SCOPE) - message(STATUS "-------begin-------") - message(STATUS ${_VERSION_MAJOR_}) - message(STATUS ${_VERSION_MINOR_}) - message(STATUS ${_VERSION_PATCH_}) - message(STATUS ${_VERSION_SUFFIX_}) - message(STATUS ${_VERSION_HASH_}) - message(STATUS ${_VERSION_DIRTY_}) - message(STATUS "-------end-------") endfunction() diff --git a/libraries/version/CMakeLists.txt b/libraries/version/CMakeLists.txt index 3aeb418170c..3db82f0b275 100644 --- a/libraries/version/CMakeLists.txt +++ b/libraries/version/CMakeLists.txt @@ -21,15 +21,17 @@ add_library( target_include_directories( version PUBLIC - "${CMAKE_CURRENT_SOURCE_DIR}/src" ) + "${CMAKE_CURRENT_SOURCE_DIR}/include/" + PRIVATE + "${CMAKE_CURRENT_SOURCE_DIR}/src/" ) # Install the library in the appropriate places. install( TARGETS version - RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR} # Is it needed as a RUNTIME? It' just a library? - ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} ## Is it needed as both a static and dynamic lib? - LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} ) ## ... + RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR} # Is it needed as a RUNTIME? It' just a library? + ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} ## Is it needed as both a static and dynamic lib? + LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} ) ## ... # Install the header file in the appropriate place. install( diff --git a/libraries/version/include/eosio/version/version.hpp b/libraries/version/include/eosio/version/version.hpp index 64c356a492f..58f27f411e9 100644 --- a/libraries/version/include/eosio/version/version.hpp +++ b/libraries/version/include/eosio/version/version.hpp @@ -11,8 +11,8 @@ namespace eosio { namespace version { ///< Grab the basic version of the client; example: `v1.8.0-rc1` const std::string& version_client(); - + ///< Grab the full version of the client; example: `v1.8.0-rc1-7de458254[-dirty]` const std::string& version_full(); - + } } diff --git a/libraries/version/src/version.cpp b/libraries/version/src/version.cpp index fee2aaff479..16a23995969 100644 --- a/libraries/version/src/version.cpp +++ b/libraries/version/src/version.cpp @@ -11,10 +11,10 @@ namespace eosio { namespace version { static const std::string version{_version_client()}; return version; } - + const std::string& version_full() { static const std::string version{_version_full()}; return version; } - + } } diff --git a/libraries/version/src/version_impl.cpp.in b/libraries/version/src/version_impl.cpp.in index 961c6550eef..5d73457a7f4 100644 --- a/libraries/version/src/version_impl.cpp.in +++ b/libraries/version/src/version_impl.cpp.in @@ -8,21 +8,29 @@ namespace eosio { namespace version { - const std::string version_major {"@_VERSION_MAJOR_@"}; - const std::string version_minor {"@_VERSION_MINOR_@"}; - const std::string version_patch {"@_VERSION_PATCH_@"}; + const std::string version_major {"@_VERSION_MAJOR_@" }; + const std::string version_minor {"@_VERSION_MINOR_@" }; + const std::string version_patch {"@_VERSION_PATCH_@" }; const std::string version_suffix{"@_VERSION_SUFFIX_@"}; - const std::string version_hash {"@_VERSION_HASH_@"}; - const std::string version_dirty {"@_VERSION_DIRTY_@"}; + const std::string version_hash {"@_VERSION_HASH_@" }; + const bool version_dirty { @_VERSION_DIRTY_@ }; const std::string& _version_client() { - static const std::string version{'v'+version_major+'.'+version_minor+'.'+version_patch+'-'+version_suffix}; + static const std::string version{'v' + version_major + + '.' + version_minor + + '.' + version_patch + + '-' + version_suffix}; return version; } const std::string& _version_full() { - static const std::string version{'v'+version_major+'.'+version_minor+'.'+version_patch+'-'+version_suffix+'-'+version_hash+version_dirty}; + static const std::string version{'v' + version_major + + '.' + version_minor + + '.' + version_patch + + '-' + version_suffix + + '-' + version_hash + + '-' + ((version_dirty == true) ? ("true") : ("false"))}; return version; } - + } } diff --git a/libraries/version/src/version_impl.hpp b/libraries/version/src/version_impl.hpp index 1af4460b18a..40997ce6d37 100644 --- a/libraries/version/src/version_impl.hpp +++ b/libraries/version/src/version_impl.hpp @@ -14,5 +14,5 @@ namespace eosio { namespace version { ///< Helper function for `version_full()` const std::string& _version_full(); - + } } diff --git a/programs/cleos/CMakeLists.txt b/programs/cleos/CMakeLists.txt index 0787c5fe937..cc7cf865680 100644 --- a/programs/cleos/CMakeLists.txt +++ b/programs/cleos/CMakeLists.txt @@ -10,23 +10,6 @@ if( GPERFTOOLS_FOUND ) list( APPEND PLATFORM_SPECIFIC_LIBS tcmalloc ) endif() -if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../../.git) - find_package(Git) - if(GIT_FOUND) - execute_process( - COMMAND ${GIT_EXECUTABLE} rev-parse --short=8 HEAD - WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../.." - OUTPUT_VARIABLE "cleos_BUILD_VERSION" - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) - message(STATUS "Git commit revision: ${cleos_BUILD_VERSION}") - else() - set(cleos_BUILD_VERSION 0) - endif() -else() - set(cleos_BUILD_VERSION 0) -endif() - find_package(Intl REQUIRED) set(LOCALEDIR ${CMAKE_INSTALL_PREFIX}/share/locale) @@ -36,7 +19,7 @@ configure_file(config.hpp.in config.hpp ESCAPE_QUOTES) target_include_directories(${CLI_CLIENT_EXECUTABLE_NAME} PUBLIC ${Intl_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries( ${CLI_CLIENT_EXECUTABLE_NAME} - PRIVATE appbase chain_api_plugin producer_plugin chain_plugin http_plugin eosio_chain fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ${Intl_LIBRARIES} ) + PRIVATE appbase version chain_api_plugin producer_plugin chain_plugin http_plugin eosio_chain fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ${Intl_LIBRARIES} ) copy_bin( ${CLI_CLIENT_EXECUTABLE_NAME} ) diff --git a/programs/cleos/config.hpp.in b/programs/cleos/config.hpp.in index d9d5f45b1de..b49466f3101 100644 --- a/programs/cleos/config.hpp.in +++ b/programs/cleos/config.hpp.in @@ -6,9 +6,8 @@ #pragma once namespace eosio { namespace client { namespace config { - constexpr char version_str[] = "${cleos_BUILD_VERSION}"; - constexpr char locale_path[] = "${LOCALEDIR}"; - constexpr char locale_domain[] = "${LOCALEDOMAIN}"; - constexpr char key_store_executable_name[] = "${KEY_STORE_EXECUTABLE_NAME}"; - constexpr char node_executable_name[] = "${NODE_EXECUTABLE_NAME}"; -}}} + constexpr char locale_path[] {"${LOCALEDIR}"}; + constexpr char locale_domain[] {"${LOCALEDOMAIN}"}; + constexpr char key_store_executable_name[]{"${KEY_STORE_EXECUTABLE_NAME}"}; + constexpr char node_executable_name[] {"${NODE_EXECUTABLE_NAME}"}; +} } } diff --git a/programs/cleos/main.cpp b/programs/cleos/main.cpp index 36c3be1900a..03c8917ffce 100644 --- a/programs/cleos/main.cpp +++ b/programs/cleos/main.cpp @@ -93,6 +93,8 @@ Usage: ./cleos create account [OPTIONS] creator name OwnerKey ActiveKey #include #include +#include + #pragma push_macro("N") #undef N @@ -2402,8 +2404,12 @@ int main( int argc, char** argv ) { auto version = app.add_subcommand("version", localized("Retrieve version information"), false); version->require_subcommand(); - version->add_subcommand("client", localized("Retrieve version information of the client"))->set_callback([] { - std::cout << localized("Build version: ${ver}", ("ver", eosio::client::config::version_str)) << std::endl; + version->add_subcommand("client", localized("Retrieve basic version information of the client"))->set_callback([] { + std::cout << eosio::version::version_client() << '\n'; + }); + + version->add_subcommand("full", localized("Retrieve full version information of the client"))->set_callback([] { + std::cout << eosio::version::version_full() << '\n'; }); // Create subcommand From 49fd6054592defa1e9c2746e01d938e458b73c38 Mon Sep 17 00:00:00 2001 From: johndebord Date: Thu, 6 Jun 2019 16:38:25 -0400 Subject: [PATCH 06/28] Polish --- CMakeModules/VersionUtils.cmake | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/CMakeModules/VersionUtils.cmake b/CMakeModules/VersionUtils.cmake index b3fed7a6214..bf98eec77f9 100644 --- a/CMakeModules/VersionUtils.cmake +++ b/CMakeModules/VersionUtils.cmake @@ -1,9 +1,4 @@ function(GENERATE_VERSION_METADATA) - set(_VERSION_MAJOR_ ${VERSION_MAJOR} PARENT_SCOPE) - set(_VERSION_MINOR_ ${VERSION_MINOR} PARENT_SCOPE) - set(_VERSION_PATCH_ ${VERSION_PATCH} PARENT_SCOPE) - set(_VERSION_SUFFIX_ ${VERSION_SUFFIX} PARENT_SCOPE) - find_package(Git) if(EXISTS ${CMAKE_SOURCE_DIR}/.git AND GIT_FOUND) execute_process( @@ -19,10 +14,21 @@ function(GENERATE_VERSION_METADATA) string(REGEX MATCH "-dirty$" _VERSION_DIRTY_ ${_VERSION_DIRTY_}) if(${_VERSION_DIRTY_} STREQUAL "") set(_VERSION_DIRTY_ "false") - else() + else() set(_VERSION_DIRTY_ "true") endif() + set(_VERSION_MAJOR_ ${VERSION_MAJOR} PARENT_SCOPE) + set(_VERSION_MINOR_ ${VERSION_MINOR} PARENT_SCOPE) + set(_VERSION_PATCH_ ${VERSION_PATCH} PARENT_SCOPE) + set(_VERSION_SUFFIX_ ${VERSION_SUFFIX} PARENT_SCOPE) + set(_VERSION_HASH_ ${_VERSION_HASH_} PARENT_SCOPE) + set(_VERSION_DIRTY_ ${_VERSION_DIRTY_} PARENT_SCOPE) + else() + set(_VERSION_MAJOR_ "unknown" PARENT_SCOPE) + set(_VERSION_MINOR_ "" PARENT_SCOPE) + set(_VERSION_PATCH_ "" PARENT_SCOPE) + set(_VERSION_SUFFIX_ "" PARENT_SCOPE) + set(_VERSION_HASH_ "" PARENT_SCOPE) + set(_VERSION_DIRTY_ "" PARENT_SCOPE) endif() - set(_VERSION_HASH_ ${_VERSION_HASH_} PARENT_SCOPE) - set(_VERSION_DIRTY_ ${_VERSION_DIRTY_} PARENT_SCOPE) endfunction() From 641ed80da8a8f36417eb8e525db5b558a35173db Mon Sep 17 00:00:00 2001 From: John DeBord Date: Thu, 6 Jun 2019 16:42:19 -0400 Subject: [PATCH 07/28] Polish --- libraries/version/CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libraries/version/CMakeLists.txt b/libraries/version/CMakeLists.txt index 3db82f0b275..036bc066f86 100644 --- a/libraries/version/CMakeLists.txt +++ b/libraries/version/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required( - VERSION 2.8.12 ) # What should the version actually be? + VERSION 2.8.12 ) ### What should the version actually be? project( Version ) @@ -8,7 +8,7 @@ project( include( VersionUtils ) -# Generate the most up-to-date metadata of the repository. +# Generate the most up-to-date version metadata of the repository. GENERATE_VERSION_METADATA() # Construct the library. @@ -29,9 +29,9 @@ target_include_directories( install( TARGETS version - RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR} # Is it needed as a RUNTIME? It' just a library? - ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} ## Is it needed as both a static and dynamic lib? - LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} ) ## ... + RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR} ### Is this needed? It's just a library? + ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} ### Is this needed as both a static and dynamic lib? + LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} ) ### ... # Install the header file in the appropriate place. install( From 1ba5fde04c567cb06c3e57e1b8ee1982c08ef62b Mon Sep 17 00:00:00 2001 From: John DeBord Date: Thu, 6 Jun 2019 16:43:15 -0400 Subject: [PATCH 08/28] Polish --- libraries/version/include/eosio/version/version.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/version/include/eosio/version/version.hpp b/libraries/version/include/eosio/version/version.hpp index 58f27f411e9..d9bf85f709d 100644 --- a/libraries/version/include/eosio/version/version.hpp +++ b/libraries/version/include/eosio/version/version.hpp @@ -9,10 +9,10 @@ namespace eosio { namespace version { - ///< Grab the basic version of the client; example: `v1.8.0-rc1` + ///< Grab the basic version information of the client; example: `v1.8.0-rc1` const std::string& version_client(); - ///< Grab the full version of the client; example: `v1.8.0-rc1-7de458254[-dirty]` + ///< Grab the full version information of the client; example: `v1.8.0-rc1-7de458254[-dirty]` const std::string& version_full(); } } From 0ce696635b4b98c512eb8003f2110f9289598180 Mon Sep 17 00:00:00 2001 From: John DeBord Date: Thu, 6 Jun 2019 16:44:42 -0400 Subject: [PATCH 09/28] Polish --- programs/cleos/config.hpp.in | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/programs/cleos/config.hpp.in b/programs/cleos/config.hpp.in index b49466f3101..3441d9cd42d 100644 --- a/programs/cleos/config.hpp.in +++ b/programs/cleos/config.hpp.in @@ -6,8 +6,8 @@ #pragma once namespace eosio { namespace client { namespace config { - constexpr char locale_path[] {"${LOCALEDIR}"}; - constexpr char locale_domain[] {"${LOCALEDOMAIN}"}; + constexpr char locale_path[] {"${LOCALEDIR}" }; + constexpr char locale_domain[] {"${LOCALEDOMAIN}" }; constexpr char key_store_executable_name[]{"${KEY_STORE_EXECUTABLE_NAME}"}; - constexpr char node_executable_name[] {"${NODE_EXECUTABLE_NAME}"}; + constexpr char node_executable_name[] {"${NODE_EXECUTABLE_NAME}" }; } } } From 5cac5b3123860597ad623e54dd83e3b05eb1ca0b Mon Sep 17 00:00:00 2001 From: John DeBord Date: Thu, 6 Jun 2019 16:45:33 -0400 Subject: [PATCH 10/28] Polish --- libraries/version/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/version/CMakeLists.txt b/libraries/version/CMakeLists.txt index 036bc066f86..165a004833f 100644 --- a/libraries/version/CMakeLists.txt +++ b/libraries/version/CMakeLists.txt @@ -29,9 +29,9 @@ target_include_directories( install( TARGETS version - RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR} ### Is this needed? It's just a library? - ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} ### Is this needed as both a static and dynamic lib? - LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} ) ### ... + RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR} ### Is this needed? It's just a library? + ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} ### Is this needed as both a static and dynamic lib? + LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} ) ### ... # Install the header file in the appropriate place. install( From 2b611745e4ce662a0bedd8844e99b8cfc5f53096 Mon Sep 17 00:00:00 2001 From: johndebord Date: Tue, 11 Jun 2019 10:13:03 -0400 Subject: [PATCH 11/28] `CMakeModules/VersionUtils.cmake` quick fix --- CMakeModules/VersionUtils.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeModules/VersionUtils.cmake b/CMakeModules/VersionUtils.cmake index bf98eec77f9..0d511ab2dfc 100644 --- a/CMakeModules/VersionUtils.cmake +++ b/CMakeModules/VersionUtils.cmake @@ -12,7 +12,7 @@ function(GENERATE_VERSION_METADATA) ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE ) string(REGEX MATCH "-dirty$" _VERSION_DIRTY_ ${_VERSION_DIRTY_}) - if(${_VERSION_DIRTY_} STREQUAL "") + if(_VERSION_DIRTY_ STREQUAL "") set(_VERSION_DIRTY_ "false") else() set(_VERSION_DIRTY_ "true") From fe6067e3ff1b8f5fc5aeb82e2d6043e82299926f Mon Sep 17 00:00:00 2001 From: johndebord Date: Tue, 11 Jun 2019 10:25:33 -0400 Subject: [PATCH 12/28] `CMakeModules/VersionUtils.cmake` quick fix --- CMakeModules/VersionUtils.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeModules/VersionUtils.cmake b/CMakeModules/VersionUtils.cmake index 0d511ab2dfc..4285c2bb97b 100644 --- a/CMakeModules/VersionUtils.cmake +++ b/CMakeModules/VersionUtils.cmake @@ -1,3 +1,4 @@ +cmake_minimum_required(VERSION 3.5) function(GENERATE_VERSION_METADATA) find_package(Git) if(EXISTS ${CMAKE_SOURCE_DIR}/.git AND GIT_FOUND) @@ -12,7 +13,7 @@ function(GENERATE_VERSION_METADATA) ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE ) string(REGEX MATCH "-dirty$" _VERSION_DIRTY_ ${_VERSION_DIRTY_}) - if(_VERSION_DIRTY_ STREQUAL "") + if("${_VERSION_DIRTY_}" STREQUAL "") set(_VERSION_DIRTY_ "false") else() set(_VERSION_DIRTY_ "true") From 146cb6abf4a92b43dd30cf8eaa91752a65300464 Mon Sep 17 00:00:00 2001 From: johndebord Date: Tue, 11 Jun 2019 11:52:55 -0400 Subject: [PATCH 13/28] Polish --- CMakeModules/VersionUtils.cmake | 4 +++- libraries/version/CMakeLists.txt | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeModules/VersionUtils.cmake b/CMakeModules/VersionUtils.cmake index 4285c2bb97b..87990ffd99a 100644 --- a/CMakeModules/VersionUtils.cmake +++ b/CMakeModules/VersionUtils.cmake @@ -1,4 +1,6 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required( + VERSION 3.5 ) + function(GENERATE_VERSION_METADATA) find_package(Git) if(EXISTS ${CMAKE_SOURCE_DIR}/.git AND GIT_FOUND) diff --git a/libraries/version/CMakeLists.txt b/libraries/version/CMakeLists.txt index 165a004833f..704bf402ea6 100644 --- a/libraries/version/CMakeLists.txt +++ b/libraries/version/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required( - VERSION 2.8.12 ) ### What should the version actually be? + VERSION 3.5 ) project( Version ) From fc19d3a5c5bdf691421c26a7e32569536768b993 Mon Sep 17 00:00:00 2001 From: johndebord Date: Tue, 11 Jun 2019 15:42:50 -0400 Subject: [PATCH 14/28] Polish --- CMakeModules/VersionUtils.cmake | 62 ++++++++++++++++---------------- libraries/version/CMakeLists.txt | 30 ++++++++-------- 2 files changed, 44 insertions(+), 48 deletions(-) diff --git a/CMakeModules/VersionUtils.cmake b/CMakeModules/VersionUtils.cmake index 87990ffd99a..b7bde067ad6 100644 --- a/CMakeModules/VersionUtils.cmake +++ b/CMakeModules/VersionUtils.cmake @@ -1,37 +1,35 @@ cmake_minimum_required( VERSION 3.5 ) -function(GENERATE_VERSION_METADATA) - find_package(Git) - if(EXISTS ${CMAKE_SOURCE_DIR}/.git AND GIT_FOUND) - execute_process( - COMMAND ${GIT_EXECUTABLE} rev-parse HEAD - OUTPUT_VARIABLE _VERSION_HASH_ - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE ) - execute_process( - COMMAND ${GIT_EXECUTABLE} describe --tags --dirty - OUTPUT_VARIABLE _VERSION_DIRTY_ - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE ) - string(REGEX MATCH "-dirty$" _VERSION_DIRTY_ ${_VERSION_DIRTY_}) - if("${_VERSION_DIRTY_}" STREQUAL "") - set(_VERSION_DIRTY_ "false") - else() - set(_VERSION_DIRTY_ "true") - endif() - set(_VERSION_MAJOR_ ${VERSION_MAJOR} PARENT_SCOPE) - set(_VERSION_MINOR_ ${VERSION_MINOR} PARENT_SCOPE) - set(_VERSION_PATCH_ ${VERSION_PATCH} PARENT_SCOPE) - set(_VERSION_SUFFIX_ ${VERSION_SUFFIX} PARENT_SCOPE) - set(_VERSION_HASH_ ${_VERSION_HASH_} PARENT_SCOPE) - set(_VERSION_DIRTY_ ${_VERSION_DIRTY_} PARENT_SCOPE) +find_package(Git) +if(EXISTS ${CMAKE_SOURCE_DIR}/.git AND GIT_FOUND) + execute_process( + COMMAND ${GIT_EXECUTABLE} rev-parse HEAD + OUTPUT_VARIABLE _VERSION_HASH_ + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE ) + execute_process( + COMMAND ${GIT_EXECUTABLE} describe --tags --dirty + OUTPUT_VARIABLE _VERSION_DIRTY_ + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE ) + string(REGEX MATCH "-dirty$" _VERSION_DIRTY_ ${_VERSION_DIRTY_}) + if("${_VERSION_DIRTY_}" STREQUAL "") + set(_VERSION_DIRTY_ "false") else() - set(_VERSION_MAJOR_ "unknown" PARENT_SCOPE) - set(_VERSION_MINOR_ "" PARENT_SCOPE) - set(_VERSION_PATCH_ "" PARENT_SCOPE) - set(_VERSION_SUFFIX_ "" PARENT_SCOPE) - set(_VERSION_HASH_ "" PARENT_SCOPE) - set(_VERSION_DIRTY_ "" PARENT_SCOPE) + set(_VERSION_DIRTY_ "true") endif() -endfunction() + set(_VERSION_MAJOR_ ${VERSION_MAJOR}) + set(_VERSION_MINOR_ ${VERSION_MINOR}) + set(_VERSION_PATCH_ ${VERSION_PATCH}) + set(_VERSION_SUFFIX_ ${VERSION_SUFFIX}) + set(_VERSION_HASH_ ${_VERSION_HASH_}) + set(_VERSION_DIRTY_ ${_VERSION_DIRTY_}) +else() + set(_VERSION_MAJOR_ "unknown") + set(_VERSION_MINOR_ "") + set(_VERSION_PATCH_ "") + set(_VERSION_SUFFIX_ "") + set(_VERSION_HASH_ "") + set(_VERSION_DIRTY_ "") +endif() diff --git a/libraries/version/CMakeLists.txt b/libraries/version/CMakeLists.txt index 704bf402ea6..5113b7b40cb 100644 --- a/libraries/version/CMakeLists.txt +++ b/libraries/version/CMakeLists.txt @@ -8,9 +8,6 @@ project( include( VersionUtils ) -# Generate the most up-to-date version metadata of the repository. -GENERATE_VERSION_METADATA() - # Construct the library. add_library( version @@ -20,27 +17,28 @@ add_library( # Make dependencies visible. target_include_directories( version - PUBLIC - "${CMAKE_CURRENT_SOURCE_DIR}/include/" - PRIVATE - "${CMAKE_CURRENT_SOURCE_DIR}/src/" ) + PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include/" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src/" ) # Install the library in the appropriate places. install( - TARGETS - version - RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR} ### Is this needed? It's just a library? - ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} ### Is this needed as both a static and dynamic lib? - LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} ) ### ... + TARGETS version + RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} ) # Install the header file in the appropriate place. install( - DIRECTORY - ${CMAKE_CURRENT_SOURCE_DIR}/include/eosio/version - DESTINATION - ${CMAKE_INSTALL_FULL_INCLUDEDIR}/eosio/ + DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/eosio/version + DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR}/eosio/ FILES_MATCHING PATTERN "*.hpp" ) +# Generate the most up-to-date version metadata of the repository. +add_custom_command( + TARGET version + PRE_BUILD + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/CMakeModules/VersionUtils.cmake) + # Modify and substitute the `.cpp.in` file for a `.cpp` in the build directory. configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/src/version_impl.cpp.in From d09c8a6580c3642b5540cfb71190d4f90f5fcc08 Mon Sep 17 00:00:00 2001 From: johndebord Date: Tue, 11 Jun 2019 16:05:37 -0400 Subject: [PATCH 15/28] Polish --- libraries/version/CMakeLists.txt | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/libraries/version/CMakeLists.txt b/libraries/version/CMakeLists.txt index 5113b7b40cb..6d999f34856 100644 --- a/libraries/version/CMakeLists.txt +++ b/libraries/version/CMakeLists.txt @@ -2,7 +2,10 @@ cmake_minimum_required( VERSION 3.5 ) project( - Version ) + Version + VERSION 0.0.0.1 + DESCRIPTION "This library determines the current version in which the target was built" + HOMEPAGE_URL "https://eos.io/" ) # Found in directory `eos/CMakeModules/`. include( @@ -17,7 +20,7 @@ add_library( # Make dependencies visible. target_include_directories( version - PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include/" + PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include/" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src/" ) # Install the library in the appropriate places. @@ -29,15 +32,19 @@ install( # Install the header file in the appropriate place. install( - DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/eosio/version + DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/eosio/version DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR}/eosio/ FILES_MATCHING PATTERN "*.hpp" ) -# Generate the most up-to-date version metadata of the repository. -add_custom_command( - TARGET version - PRE_BUILD - COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/CMakeModules/VersionUtils.cmake) +# Generate the most up-to-date version metadata of the repository on every build. +add_custom_target( + on_every_build + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/CMakeModules/VersionUtils.cmake ) + +# ... +add_dependencies( + version + on_every_build ) # Modify and substitute the `.cpp.in` file for a `.cpp` in the build directory. configure_file( From 8ed7ab38d8a76dcb94ca9c46888890c4de8faa42 Mon Sep 17 00:00:00 2001 From: johndebord Date: Tue, 11 Jun 2019 16:46:52 -0400 Subject: [PATCH 16/28] Polish --- libraries/version/CMakeLists.txt | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/libraries/version/CMakeLists.txt b/libraries/version/CMakeLists.txt index 6d999f34856..819f6526beb 100644 --- a/libraries/version/CMakeLists.txt +++ b/libraries/version/CMakeLists.txt @@ -23,6 +23,16 @@ target_include_directories( PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include/" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src/" ) +# Generate the most up-to-date version metadata of the repository on every build. +add_custom_target( + on_every_build + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/CMakeModules/VersionUtils.cmake ) + +# ... +add_dependencies( + version + on_every_build ) + # Install the library in the appropriate places. install( TARGETS version @@ -36,16 +46,6 @@ install( DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR}/eosio/ FILES_MATCHING PATTERN "*.hpp" ) -# Generate the most up-to-date version metadata of the repository on every build. -add_custom_target( - on_every_build - COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/CMakeModules/VersionUtils.cmake ) - -# ... -add_dependencies( - version - on_every_build ) - # Modify and substitute the `.cpp.in` file for a `.cpp` in the build directory. configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/src/version_impl.cpp.in From 384f2c1a97580e0847692c23ddcc2b220e2c3525 Mon Sep 17 00:00:00 2001 From: johndebord Date: Tue, 11 Jun 2019 17:03:27 -0400 Subject: [PATCH 17/28] Polish --- libraries/version/CMakeLists.txt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libraries/version/CMakeLists.txt b/libraries/version/CMakeLists.txt index 819f6526beb..0c60dcd6e02 100644 --- a/libraries/version/CMakeLists.txt +++ b/libraries/version/CMakeLists.txt @@ -2,10 +2,7 @@ cmake_minimum_required( VERSION 3.5 ) project( - Version - VERSION 0.0.0.1 - DESCRIPTION "This library determines the current version in which the target was built" - HOMEPAGE_URL "https://eos.io/" ) + Version ) # Found in directory `eos/CMakeModules/`. include( From 969699f58bcac54e0cedb3bbb1e26771b09d8ef7 Mon Sep 17 00:00:00 2001 From: johndebord Date: Tue, 11 Jun 2019 17:19:02 -0400 Subject: [PATCH 18/28] Polish --- libraries/version/CMakeLists.txt | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/libraries/version/CMakeLists.txt b/libraries/version/CMakeLists.txt index 0c60dcd6e02..01c52736ed3 100644 --- a/libraries/version/CMakeLists.txt +++ b/libraries/version/CMakeLists.txt @@ -20,15 +20,19 @@ target_include_directories( PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include/" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src/" ) -# Generate the most up-to-date version metadata of the repository on every build. -add_custom_target( - on_every_build - COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/CMakeModules/VersionUtils.cmake ) - -# ... -add_dependencies( - version - on_every_build ) +add_custom_target( on_every_build ALL + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/CMakeModules/VersionUtils.cmake + COMMENT "generating........................" VERBATIM) + +# # Generate the most up-to-date version metadata of the repository on every build. +# add_custom_target( +# on_every_build +# COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/CMakeModules/VersionUtils.cmake ) + +# # ... +# add_dependencies( +# version +# on_every_build ) # Install the library in the appropriate places. install( From bcaba024c6f06c5dd70649c6c8d74fe963974ada Mon Sep 17 00:00:00 2001 From: johndebord Date: Wed, 12 Jun 2019 16:49:16 -0400 Subject: [PATCH 19/28] Continuation; committing in case future reference needed --- CMakeModules/VersionUtils.cmake | 91 +++++++----- libraries/version/CMakeLists.txt | 167 +++++++++++++++++----- libraries/version/src/version_impl.cpp.in | 2 +- 3 files changed, 193 insertions(+), 67 deletions(-) diff --git a/CMakeModules/VersionUtils.cmake b/CMakeModules/VersionUtils.cmake index b7bde067ad6..51043f02259 100644 --- a/CMakeModules/VersionUtils.cmake +++ b/CMakeModules/VersionUtils.cmake @@ -1,35 +1,58 @@ -cmake_minimum_required( - VERSION 3.5 ) +# cmake_minimum_required( +# VERSION 3.5 ) -find_package(Git) -if(EXISTS ${CMAKE_SOURCE_DIR}/.git AND GIT_FOUND) - execute_process( - COMMAND ${GIT_EXECUTABLE} rev-parse HEAD - OUTPUT_VARIABLE _VERSION_HASH_ - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE ) - execute_process( - COMMAND ${GIT_EXECUTABLE} describe --tags --dirty - OUTPUT_VARIABLE _VERSION_DIRTY_ - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE ) - string(REGEX MATCH "-dirty$" _VERSION_DIRTY_ ${_VERSION_DIRTY_}) - if("${_VERSION_DIRTY_}" STREQUAL "") - set(_VERSION_DIRTY_ "false") - else() - set(_VERSION_DIRTY_ "true") - endif() - set(_VERSION_MAJOR_ ${VERSION_MAJOR}) - set(_VERSION_MINOR_ ${VERSION_MINOR}) - set(_VERSION_PATCH_ ${VERSION_PATCH}) - set(_VERSION_SUFFIX_ ${VERSION_SUFFIX}) - set(_VERSION_HASH_ ${_VERSION_HASH_}) - set(_VERSION_DIRTY_ ${_VERSION_DIRTY_}) -else() - set(_VERSION_MAJOR_ "unknown") - set(_VERSION_MINOR_ "") - set(_VERSION_PATCH_ "") - set(_VERSION_SUFFIX_ "") - set(_VERSION_HASH_ "") - set(_VERSION_DIRTY_ "") -endif() +# find_package(Git) +# function(GENERATE_VERSION_METADATA) + # message(STATUS "---------------------VersionUtils before if----------------------------------") + # find_package(Git) + # message(STATUS ${GIT_FOUND}) + # message(STATUS ${CMAKE_SOURCE_DIR}) + # if(EXISTS ${CMAKE_SOURCE_DIR}/.git AND GIT_FOUND) + message(STATUS ${_CMAKE_SOURCE_DIR_}) + message(STATUS ${_CMAKE_CURRENT_SOURCE_DIR_}) + message(STATUS "-----------------VersionUtils in if----------------------------------") + execute_process( + COMMAND ${_GIT_EXECUTABLE_} rev-parse HEAD + OUTPUT_VARIABLE _VERSION_HASH_ + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE ) + execute_process( + COMMAND ${_GIT_EXECUTABLE_} describe --tags --dirty + OUTPUT_VARIABLE _VERSION_DIRTY_ + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE ) + string(REGEX MATCH "-dirty$" _VERSION_DIRTY_ ${_VERSION_DIRTY_}) + + message(STATUS "--------------------") + message(STATUS ${_VERSION_MAJOR_}) + message(STATUS "--------------------") + message(STATUS ${_VERSION_MINOR_}) + message(STATUS "--------------------") + message(STATUS ${_VERSION_PATCH_}) + message(STATUS "--------------------") + message(STATUS ${_VERSION_SUFFIX_}) + message(STATUS "--------------------") + message(STATUS ${_VERSION_HASH_}) + message(STATUS "--------------------") + message(STATUS ${_VERSION_DIRTY_}) + if("${_VERSION_DIRTY_}" STREQUAL "") + set(_VERSION_TEMP_ "false" CACHE STRING "Current dirty state of repository" FORCE) + else() + set(_VERSION_TEMP_ "true" CACHE STRING "Current dirty state of repository" FORCE) + endif() + # set(_VERSION_MAJOR_ ${VERSION_MAJOR}) + # set(_VERSION_MINOR_ ${VERSION_MINOR}) + # set(_VERSION_PATCH_ ${VERSION_PATCH}) + # set(_VERSION_SUFFIX_ ${VERSION_SUFFIX}) + # set(_VERSION_HASH_ ${_VERSION_HASH_}) + # set(_VERSION_DIRTY_ ${_VERSION_DIRTY_}) + # else() + # set(_VERSION_MAJOR_ "unknown") + # set(_VERSION_MINOR_ "") + # set(_VERSION_PATCH_ "") + # set(_VERSION_SUFFIX_ "") + # set(_VERSION_HASH_ "") + # set(_VERSION_DIRTY_ "") + # endif() + message(STATUS "--------------VersionUtils after if----------------------------------") +# endfunction(GENERATE_VERSION_METADATA) diff --git a/libraries/version/CMakeLists.txt b/libraries/version/CMakeLists.txt index 01c52736ed3..b0646757174 100644 --- a/libraries/version/CMakeLists.txt +++ b/libraries/version/CMakeLists.txt @@ -1,54 +1,157 @@ -cmake_minimum_required( +cmake_minimum_required( VERSION 3.5 ) project( - Version ) + Version ) -# Found in directory `eos/CMakeModules/`. -include( - VersionUtils ) +# # The function which grabs the appropriate values for the repository version. +# function(GENERATE_VERSION_METADATA) +# if(EXISTS ${CMAKE_SOURCE_DIR}/.git AND GIT_FOUND) +# execute_process( +# COMMAND ${GIT_EXECUTABLE} rev-parse HEAD +# OUTPUT_VARIABLE _VERSION_HASH_ +# ERROR_QUIET +# OUTPUT_STRIP_TRAILING_WHITESPACE ) +# execute_process( +# COMMAND ${GIT_EXECUTABLE} describe --tags --dirty +# OUTPUT_VARIABLE _VERSION_DIRTY_ +# ERROR_QUIET +# OUTPUT_STRIP_TRAILING_WHITESPACE ) +# string(REGEX MATCH "-dirty$" _VERSION_DIRTY_ ${_VERSION_DIRTY_}) +# if("${_VERSION_DIRTY_}" STREQUAL "") +# set(_VERSION_DIRTY_ "false") +# else() +# set(_VERSION_DIRTY_ "true") +# endif() +# set(_VERSION_MAJOR_ ${VERSION_MAJOR}) +# set(_VERSION_MINOR_ ${VERSION_MINOR}) +# set(_VERSION_PATCH_ ${VERSION_PATCH}) +# set(_VERSION_SUFFIX_ ${VERSION_SUFFIX}) +# set(_VERSION_HASH_ ${_VERSION_HASH_}) +# set(_VERSION_DIRTY_ ${_VERSION_DIRTY_}) +# else() +# set(_VERSION_MAJOR_ "unknown") +# set(_VERSION_MINOR_ "") +# set(_VERSION_PATCH_ "") +# set(_VERSION_SUFFIX_ "") +# set(_VERSION_HASH_ "") +# set(_VERSION_DIRTY_ "") +# endif() +# endfunction(GENERATE_VERSION_METADATA) + +set(_VERSION_MAJOR_ "unknown" CACHE STRING "Current major version of repository") +set(_VERSION_MINOR_ "" CACHE STRING "Current minor version of repository") +set(_VERSION_PATCH_ "" CACHE STRING "Current patch version of repository") +set(_VERSION_SUFFIX_ "" CACHE STRING "Current suffiex of repository") +set(_VERSION_HASH_ "" CACHE STRING "Current hash of repository") +set(_VERSION_DIRTY_ "" CACHE STRING "Current dirty state of repository") # Construct the library. add_library( - version - "${CMAKE_CURRENT_SOURCE_DIR}/src/version.cpp" - "${CMAKE_CURRENT_BINARY_DIR}/src/version_impl.cpp" ) + version + "${CMAKE_CURRENT_SOURCE_DIR}/src/version.cpp" + "${CMAKE_CURRENT_BINARY_DIR}/src/version_impl.cpp" ) # Make dependencies visible. target_include_directories( - version - PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include/" - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src/" ) + version + PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include/" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src/" ) + +# This one runs everytime; save +# Create a custom target to be run upon every build. +message(STATUS ${CMAKE_SOURCE_DIR}) +message(STATUS ${CMAKE_CURRENT_SOURCE_DIR}) +find_package(Git) +if(EXISTS ${CMAKE_SOURCE_DIR}/.git AND ${GIT_FOUND}) + add_custom_target( + evaluate_every_build ALL + COMMAND ${CMAKE_COMMAND} -D_GIT_EXECUTABLE_=${GIT_EXECUTABLE} + -D_CMAKE_SOURCE_DIR_="VAR1" + -D_CMAKE_CURRENT_SOURCE_DIR_="VAR2" + -D_CMAKE_BINARY_DIR_=${CMAKE_BINARY_DIR} + -D_CMAKE_CURRENT_BINARY_DIR_=${CMAKE_CURRENT_BINARY_DIR} + -P ${CMAKE_SOURCE_DIR}/CMakeModules/VersionUtils.cmake + COMMENT "***********************Updating version metadata...**********************" VERBATIM ) + # string(REGEX MATCH "-dirty$" _VERSION_DIRTY_ ${_VERSION_DIRTY_}) + # if("${_VERSION_DIRTY_}" STREQUAL "") + # set(_VERSION_DIRTY_ "false") + # else() + # set(_VERSION_DIRTY_ "true") + # endif() + # set(_VERSION_MAJOR_ ${VERSION_MAJOR} CACHE STRING "Current major version of repository") + # set(_VERSION_MINOR_ ${VERSION_MINOR} CACHE STRING "Current minor version of repository") + # set(_VERSION_PATCH_ ${VERSION_PATCH} CACHE STRING "Current patch version of repository") + # set(_VERSION_SUFFIX_ ${VERSION_SUFFIX} CACHE STRING "Current suffiex of repository") + # set(_VERSION_HASH_ ${_VERSION_HASH_} CACHE STRING "Current hash of repository") + # set(_VERSION_DIRTY_ ${_VERSION_DIRTY_} CACHE STRING "Current dirty state of repository") + message(STATUS "--------------------") + message(STATUS ${_VERSION_MAJOR_}) + message(STATUS "--------------------") + message(STATUS ${_VERSION_MINOR_}) + message(STATUS "--------------------") + message(STATUS ${_VERSION_PATCH_}) + message(STATUS "--------------------") + message(STATUS ${_VERSION_SUFFIX_}) + message(STATUS "--------------------") + message(STATUS ${_VERSION_HASH_}) + message(STATUS "--------------------") + message(STATUS ${_VERSION_DIRTY_}) +endif() -add_custom_target( on_every_build ALL - COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/CMakeModules/VersionUtils.cmake - COMMENT "generating........................" VERBATIM) +# This one runs everytime; save +# Create a custom target to be run upon every build. +# find_package(Git) +# if(EXISTS ${CMAKE_SOURCE_DIR}/.git AND ${GIT_FOUND}) +# add_custom_target( evaluate_every_build ALL +# COMMAND ${CMAKE_COMMAND} -E ${GIT_EXECUTABLE} --version +# COMMENT "generating........................" VERBATIM ) +# string(REGEX MATCH "-dirty$" _VERSION_DIRTY_ ${_VERSION_DIRTY_}) +# if("${_VERSION_DIRTY_}" STREQUAL "") +# set(_VERSION_DIRTY_ "false") +# else() +# set(_VERSION_DIRTY_ "true") +# endif() +# set(_VERSION_MAJOR_ ${VERSION_MAJOR} CACHE STRING "Current major version of repository") +# set(_VERSION_MINOR_ ${VERSION_MINOR} CACHE STRING "Current minor version of repository") +# set(_VERSION_PATCH_ ${VERSION_PATCH} CACHE STRING "Current patch version of repository") +# set(_VERSION_SUFFIX_ ${VERSION_SUFFIX} CACHE STRING "Current suffiex of repository") +# set(_VERSION_HASH_ ${_VERSION_HASH_} CACHE STRING "Current hash of repository") +# set(_VERSION_DIRTY_ ${_VERSION_DIRTY_} CACHE STRING "Current dirty state of repository") +# endif() -# # Generate the most up-to-date version metadata of the repository on every build. -# add_custom_target( -# on_every_build -# COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/CMakeModules/VersionUtils.cmake ) +# # Create a custom target to be run upon every build. +# add_custom_target( evaluate_every_build ALL +# COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/CMakeModules/VersionUtils.cmake +# COMMENT "generating........................" VERBATIM) -# # ... -# add_dependencies( -# version -# on_every_build ) +# message(STATUS "BEFORE*******************") +# # Create a custom target to be run upon every build. +# find_package(Git) +# if(EXISTS ${CMAKE_SOURCE_DIR}/.git AND GIT_FOUND) +# message(STATUS "IN*******************") +# add_custom_target( evaluate_every_build ALL +# COMMAND +# COMMENT "generating........................" VERBATIM) +# message(STATUS "AFTER*******************") +# endif() +# message(STATUS "AFTER IF*******************") # Install the library in the appropriate places. install( - TARGETS version - RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} ) + TARGETS version + RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} ) # Install the header file in the appropriate place. install( - DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/eosio/version - DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR}/eosio/ - FILES_MATCHING PATTERN "*.hpp" ) + DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/eosio/version + DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR}/eosio/ + FILES_MATCHING PATTERN "*.hpp" ) # Modify and substitute the `.cpp.in` file for a `.cpp` in the build directory. configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/src/version_impl.cpp.in - ${CMAKE_CURRENT_BINARY_DIR}/src/version_impl.cpp - @ONLY ) + ${CMAKE_CURRENT_SOURCE_DIR}/src/version_impl.cpp.in + ${CMAKE_CURRENT_BINARY_DIR}/src/version_impl.cpp + @ONLY ) diff --git a/libraries/version/src/version_impl.cpp.in b/libraries/version/src/version_impl.cpp.in index 5d73457a7f4..6dba04e8b64 100644 --- a/libraries/version/src/version_impl.cpp.in +++ b/libraries/version/src/version_impl.cpp.in @@ -29,7 +29,7 @@ namespace eosio { namespace version { '.' + version_patch + '-' + version_suffix + '-' + version_hash + - '-' + ((version_dirty == true) ? ("true") : ("false"))}; + ((version_dirty == true) ? ("-dirty") : (""))}; return version; } From d9c24cdd2687933fae25382d5375df1a40cffde3 Mon Sep 17 00:00:00 2001 From: johndebord Date: Wed, 12 Jun 2019 17:47:16 -0400 Subject: [PATCH 20/28] Continuation; committing in case future reference needed --- CMakeModules/VersionUtils.cmake | 142 ++++++++++++++++++------------ libraries/version/CMakeLists.txt | 146 ++++++------------------------- 2 files changed, 110 insertions(+), 178 deletions(-) diff --git a/CMakeModules/VersionUtils.cmake b/CMakeModules/VersionUtils.cmake index 51043f02259..7c3845f4cbc 100644 --- a/CMakeModules/VersionUtils.cmake +++ b/CMakeModules/VersionUtils.cmake @@ -1,58 +1,86 @@ -# cmake_minimum_required( -# VERSION 3.5 ) +cmake_minimum_required( + VERSION 3.5 ) -# find_package(Git) -# function(GENERATE_VERSION_METADATA) - # message(STATUS "---------------------VersionUtils before if----------------------------------") - # find_package(Git) - # message(STATUS ${GIT_FOUND}) - # message(STATUS ${CMAKE_SOURCE_DIR}) - # if(EXISTS ${CMAKE_SOURCE_DIR}/.git AND GIT_FOUND) - message(STATUS ${_CMAKE_SOURCE_DIR_}) - message(STATUS ${_CMAKE_CURRENT_SOURCE_DIR_}) - message(STATUS "-----------------VersionUtils in if----------------------------------") - execute_process( - COMMAND ${_GIT_EXECUTABLE_} rev-parse HEAD - OUTPUT_VARIABLE _VERSION_HASH_ - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE ) - execute_process( - COMMAND ${_GIT_EXECUTABLE_} describe --tags --dirty - OUTPUT_VARIABLE _VERSION_DIRTY_ - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE ) - string(REGEX MATCH "-dirty$" _VERSION_DIRTY_ ${_VERSION_DIRTY_}) - - message(STATUS "--------------------") - message(STATUS ${_VERSION_MAJOR_}) - message(STATUS "--------------------") - message(STATUS ${_VERSION_MINOR_}) - message(STATUS "--------------------") - message(STATUS ${_VERSION_PATCH_}) - message(STATUS "--------------------") - message(STATUS ${_VERSION_SUFFIX_}) - message(STATUS "--------------------") - message(STATUS ${_VERSION_HASH_}) - message(STATUS "--------------------") - message(STATUS ${_VERSION_DIRTY_}) - if("${_VERSION_DIRTY_}" STREQUAL "") - set(_VERSION_TEMP_ "false" CACHE STRING "Current dirty state of repository" FORCE) - else() - set(_VERSION_TEMP_ "true" CACHE STRING "Current dirty state of repository" FORCE) - endif() - # set(_VERSION_MAJOR_ ${VERSION_MAJOR}) - # set(_VERSION_MINOR_ ${VERSION_MINOR}) - # set(_VERSION_PATCH_ ${VERSION_PATCH}) - # set(_VERSION_SUFFIX_ ${VERSION_SUFFIX}) - # set(_VERSION_HASH_ ${_VERSION_HASH_}) - # set(_VERSION_DIRTY_ ${_VERSION_DIRTY_}) - # else() - # set(_VERSION_MAJOR_ "unknown") - # set(_VERSION_MINOR_ "") - # set(_VERSION_PATCH_ "") - # set(_VERSION_SUFFIX_ "") - # set(_VERSION_HASH_ "") - # set(_VERSION_DIRTY_ "") - # endif() - message(STATUS "--------------VersionUtils after if----------------------------------") -# endfunction(GENERATE_VERSION_METADATA) +function(GENERATE_VERSION_METADATA) + # Execute `git` to grab the corresponding data. + message(STATUS "*********************************") + message(STATUS ${CMAKE_CURRENT_SOURCE_DIR}) + message(STATUS "*********************************") + message(STATUS ${ROOT_DIR}) + message(STATUS "*********************************") + message(STATUS ${GIT_EXEC}) + message(STATUS "*********************************") + message(STATUS ${LIB_BIN_DIR}) + message(STATUS "*********************************") + message(STATUS ${LIB_CUR_DIR}) + message(STATUS "*********************************") + message(STATUS ${V_MAJOR}) + message(STATUS "*********************************") + message(STATUS ${V_MINOR}) + message(STATUS "*********************************") + message(STATUS ${V_PATCH}) + message(STATUS "*********************************") + message(STATUS ${V_SUFFIX}) + message(STATUS "*********************************") + execute_process( + COMMAND ${GIT_EXEC} rev-parse HEAD + WORKING_DIRECTORY ${ROOT_DIR} + OUTPUT_VARIABLE _VERSION_HASH_ + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE ) + execute_process( + COMMAND ${GIT_EXEC} describe --tags --dirty + WORKING_DIRECTORY ${ROOT_DIR} + OUTPUT_VARIABLE _VERSION_DIRTY_ + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE ) + + message(STATUS "*********************************") + message(STATUS ${_VERSION_HASH_}) + message(STATUS "*********************************") + message(STATUS ${_VERSION_DIRTY_}) + message(STATUS "*********************************") + + string(REGEX MATCH "-dirty$" _VERSION_DIRTY_ ${_VERSION_DIRTY_}) + + if("${_VERSION_DIRTY_}" STREQUAL "") + set(_VERSION_DIRTY_ "false") + else() + set(_VERSION_DIRTY_ "true") + endif() + + # message(STATUS "*********************************") + # message(STATUS ${V_MAJOR}) + # message(STATUS "*********************************") + # message(STATUS ${V_MINOR}) + # message(STATUS "*********************************") + # message(STATUS ${V_PATCH}) + # message(STATUS "*********************************") + # message(STATUS ${V_SUFFIX}) + # message(STATUS "*********************************") + + set(_VERSION_MAJOR_ ${V_MAJOR}) + set(_VERSION_MINOR_ ${V_MINOR}) + set(_VERSION_PATCH_ ${V_PATCH}) + set(_VERSION_SUFFIX_ ${V_SUFFIX}) + set(_VERSION_HASH_ ${_VERSION_HASH_}) + set(_VERSION_DIRTY_ ${_VERSION_DIRTY_}) + + # message(STATUS "*********************************") + # message(STATUS ${_VERSION_MAJOR_}) + # message(STATUS "*********************************") + # message(STATUS ${_VERSION_MINOR_}) + # message(STATUS "*********************************") + # message(STATUS ${_VERSION_PATCH_}) + # message(STATUS "*********************************") + # message(STATUS ${_VERSION_SUFFIX_}) + # message(STATUS "*********************************") + + # Modify and substitute the `.cpp.in` file for a `.cpp` in the build directory. + configure_file( + ${LIB_CUR_DIR}/src/version_impl.cpp.in + ${LIB_BIN_DIR}/src/version_impl.cpp + @ONLY ) +endfunction(GENERATE_VERSION_METADATA) + +GENERATE_VERSION_METADATA() diff --git a/libraries/version/CMakeLists.txt b/libraries/version/CMakeLists.txt index b0646757174..7034e714067 100644 --- a/libraries/version/CMakeLists.txt +++ b/libraries/version/CMakeLists.txt @@ -4,47 +4,13 @@ cmake_minimum_required( project( Version ) -# # The function which grabs the appropriate values for the repository version. -# function(GENERATE_VERSION_METADATA) -# if(EXISTS ${CMAKE_SOURCE_DIR}/.git AND GIT_FOUND) -# execute_process( -# COMMAND ${GIT_EXECUTABLE} rev-parse HEAD -# OUTPUT_VARIABLE _VERSION_HASH_ -# ERROR_QUIET -# OUTPUT_STRIP_TRAILING_WHITESPACE ) -# execute_process( -# COMMAND ${GIT_EXECUTABLE} describe --tags --dirty -# OUTPUT_VARIABLE _VERSION_DIRTY_ -# ERROR_QUIET -# OUTPUT_STRIP_TRAILING_WHITESPACE ) -# string(REGEX MATCH "-dirty$" _VERSION_DIRTY_ ${_VERSION_DIRTY_}) -# if("${_VERSION_DIRTY_}" STREQUAL "") -# set(_VERSION_DIRTY_ "false") -# else() -# set(_VERSION_DIRTY_ "true") -# endif() -# set(_VERSION_MAJOR_ ${VERSION_MAJOR}) -# set(_VERSION_MINOR_ ${VERSION_MINOR}) -# set(_VERSION_PATCH_ ${VERSION_PATCH}) -# set(_VERSION_SUFFIX_ ${VERSION_SUFFIX}) -# set(_VERSION_HASH_ ${_VERSION_HASH_}) -# set(_VERSION_DIRTY_ ${_VERSION_DIRTY_}) -# else() -# set(_VERSION_MAJOR_ "unknown") -# set(_VERSION_MINOR_ "") -# set(_VERSION_PATCH_ "") -# set(_VERSION_SUFFIX_ "") -# set(_VERSION_HASH_ "") -# set(_VERSION_DIRTY_ "") -# endif() -# endfunction(GENERATE_VERSION_METADATA) - -set(_VERSION_MAJOR_ "unknown" CACHE STRING "Current major version of repository") -set(_VERSION_MINOR_ "" CACHE STRING "Current minor version of repository") -set(_VERSION_PATCH_ "" CACHE STRING "Current patch version of repository") -set(_VERSION_SUFFIX_ "" CACHE STRING "Current suffiex of repository") -set(_VERSION_HASH_ "" CACHE STRING "Current hash of repository") -set(_VERSION_DIRTY_ "" CACHE STRING "Current dirty state of repository") +# Define the default version metadata in case `git` cannot be found. +set(_VERSION_MAJOR_ "unknown") +set(_VERSION_MINOR_ "") +set(_VERSION_PATCH_ "") +set(_VERSION_SUFFIX_ "") +set(_VERSION_HASH_ "") +set(_VERSION_DIRTY_ "") # Construct the library. add_library( @@ -58,85 +24,29 @@ target_include_directories( PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include/" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src/" ) -# This one runs everytime; save # Create a custom target to be run upon every build. -message(STATUS ${CMAKE_SOURCE_DIR}) -message(STATUS ${CMAKE_CURRENT_SOURCE_DIR}) find_package(Git) if(EXISTS ${CMAKE_SOURCE_DIR}/.git AND ${GIT_FOUND}) - add_custom_target( - evaluate_every_build ALL - COMMAND ${CMAKE_COMMAND} -D_GIT_EXECUTABLE_=${GIT_EXECUTABLE} - -D_CMAKE_SOURCE_DIR_="VAR1" - -D_CMAKE_CURRENT_SOURCE_DIR_="VAR2" - -D_CMAKE_BINARY_DIR_=${CMAKE_BINARY_DIR} - -D_CMAKE_CURRENT_BINARY_DIR_=${CMAKE_CURRENT_BINARY_DIR} - -P ${CMAKE_SOURCE_DIR}/CMakeModules/VersionUtils.cmake - COMMENT "***********************Updating version metadata...**********************" VERBATIM ) - # string(REGEX MATCH "-dirty$" _VERSION_DIRTY_ ${_VERSION_DIRTY_}) - # if("${_VERSION_DIRTY_}" STREQUAL "") - # set(_VERSION_DIRTY_ "false") - # else() - # set(_VERSION_DIRTY_ "true") - # endif() - # set(_VERSION_MAJOR_ ${VERSION_MAJOR} CACHE STRING "Current major version of repository") - # set(_VERSION_MINOR_ ${VERSION_MINOR} CACHE STRING "Current minor version of repository") - # set(_VERSION_PATCH_ ${VERSION_PATCH} CACHE STRING "Current patch version of repository") - # set(_VERSION_SUFFIX_ ${VERSION_SUFFIX} CACHE STRING "Current suffiex of repository") - # set(_VERSION_HASH_ ${_VERSION_HASH_} CACHE STRING "Current hash of repository") - # set(_VERSION_DIRTY_ ${_VERSION_DIRTY_} CACHE STRING "Current dirty state of repository") - message(STATUS "--------------------") - message(STATUS ${_VERSION_MAJOR_}) - message(STATUS "--------------------") - message(STATUS ${_VERSION_MINOR_}) - message(STATUS "--------------------") - message(STATUS ${_VERSION_PATCH_}) - message(STATUS "--------------------") - message(STATUS ${_VERSION_SUFFIX_}) - message(STATUS "--------------------") - message(STATUS ${_VERSION_HASH_}) - message(STATUS "--------------------") - message(STATUS ${_VERSION_DIRTY_}) + add_custom_target( + evaluate_every_build ALL + COMMAND ${CMAKE_COMMAND} -DGIT_EXEC=${GIT_EXECUTABLE} + -DLIB_BIN_DIR=${CMAKE_CURRENT_BINARY_DIR} + -DLIB_CUR_DIR=${CMAKE_CURRENT_SOURCE_DIR} + -DROOT_DIR=${CMAKE_SOURCE_DIR} + -DV_MAJOR=${VERSION_MAJOR} + -DV_MINOR=${VERSION_MINOR} + -DV_PATCH=${VERSION_PATCH} + -DV_SUFFIX=${VERSION_SUFFIX} + -P ${CMAKE_SOURCE_DIR}/CMakeModules/VersionUtils.cmake + COMMENT "Updating version metadata.." VERBATIM ) +else() + # Modify and substitute the `.cpp.in` file for a `.cpp` in the build directory. + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/src/version_impl.cpp.in + ${CMAKE_CURRENT_BINARY_DIR}/src/version_impl.cpp + @ONLY ) endif() -# This one runs everytime; save -# Create a custom target to be run upon every build. -# find_package(Git) -# if(EXISTS ${CMAKE_SOURCE_DIR}/.git AND ${GIT_FOUND}) -# add_custom_target( evaluate_every_build ALL -# COMMAND ${CMAKE_COMMAND} -E ${GIT_EXECUTABLE} --version -# COMMENT "generating........................" VERBATIM ) -# string(REGEX MATCH "-dirty$" _VERSION_DIRTY_ ${_VERSION_DIRTY_}) -# if("${_VERSION_DIRTY_}" STREQUAL "") -# set(_VERSION_DIRTY_ "false") -# else() -# set(_VERSION_DIRTY_ "true") -# endif() -# set(_VERSION_MAJOR_ ${VERSION_MAJOR} CACHE STRING "Current major version of repository") -# set(_VERSION_MINOR_ ${VERSION_MINOR} CACHE STRING "Current minor version of repository") -# set(_VERSION_PATCH_ ${VERSION_PATCH} CACHE STRING "Current patch version of repository") -# set(_VERSION_SUFFIX_ ${VERSION_SUFFIX} CACHE STRING "Current suffiex of repository") -# set(_VERSION_HASH_ ${_VERSION_HASH_} CACHE STRING "Current hash of repository") -# set(_VERSION_DIRTY_ ${_VERSION_DIRTY_} CACHE STRING "Current dirty state of repository") -# endif() - -# # Create a custom target to be run upon every build. -# add_custom_target( evaluate_every_build ALL -# COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/CMakeModules/VersionUtils.cmake -# COMMENT "generating........................" VERBATIM) - -# message(STATUS "BEFORE*******************") -# # Create a custom target to be run upon every build. -# find_package(Git) -# if(EXISTS ${CMAKE_SOURCE_DIR}/.git AND GIT_FOUND) -# message(STATUS "IN*******************") -# add_custom_target( evaluate_every_build ALL -# COMMAND -# COMMENT "generating........................" VERBATIM) -# message(STATUS "AFTER*******************") -# endif() -# message(STATUS "AFTER IF*******************") - # Install the library in the appropriate places. install( TARGETS version @@ -149,9 +59,3 @@ install( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/eosio/version DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR}/eosio/ FILES_MATCHING PATTERN "*.hpp" ) - -# Modify and substitute the `.cpp.in` file for a `.cpp` in the build directory. -configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/src/version_impl.cpp.in - ${CMAKE_CURRENT_BINARY_DIR}/src/version_impl.cpp - @ONLY ) From 92d9c88e4d1cefc3394d2537a67751bb058bcb60 Mon Sep 17 00:00:00 2001 From: johndebord Date: Wed, 12 Jun 2019 19:06:46 -0400 Subject: [PATCH 21/28] Working on my machine when pre-built --- CMakeModules/VersionUtils.cmake | 48 +------------------------------- libraries/version/CMakeLists.txt | 7 ++--- 2 files changed, 3 insertions(+), 52 deletions(-) diff --git a/CMakeModules/VersionUtils.cmake b/CMakeModules/VersionUtils.cmake index 7c3845f4cbc..19d1f1dc5c9 100644 --- a/CMakeModules/VersionUtils.cmake +++ b/CMakeModules/VersionUtils.cmake @@ -1,27 +1,7 @@ -cmake_minimum_required( - VERSION 3.5 ) +cmake_minimum_required(VERSION 3.5) function(GENERATE_VERSION_METADATA) # Execute `git` to grab the corresponding data. - message(STATUS "*********************************") - message(STATUS ${CMAKE_CURRENT_SOURCE_DIR}) - message(STATUS "*********************************") - message(STATUS ${ROOT_DIR}) - message(STATUS "*********************************") - message(STATUS ${GIT_EXEC}) - message(STATUS "*********************************") - message(STATUS ${LIB_BIN_DIR}) - message(STATUS "*********************************") - message(STATUS ${LIB_CUR_DIR}) - message(STATUS "*********************************") - message(STATUS ${V_MAJOR}) - message(STATUS "*********************************") - message(STATUS ${V_MINOR}) - message(STATUS "*********************************") - message(STATUS ${V_PATCH}) - message(STATUS "*********************************") - message(STATUS ${V_SUFFIX}) - message(STATUS "*********************************") execute_process( COMMAND ${GIT_EXEC} rev-parse HEAD WORKING_DIRECTORY ${ROOT_DIR} @@ -34,12 +14,6 @@ function(GENERATE_VERSION_METADATA) OUTPUT_VARIABLE _VERSION_DIRTY_ ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE ) - - message(STATUS "*********************************") - message(STATUS ${_VERSION_HASH_}) - message(STATUS "*********************************") - message(STATUS ${_VERSION_DIRTY_}) - message(STATUS "*********************************") string(REGEX MATCH "-dirty$" _VERSION_DIRTY_ ${_VERSION_DIRTY_}) @@ -48,16 +22,6 @@ function(GENERATE_VERSION_METADATA) else() set(_VERSION_DIRTY_ "true") endif() - - # message(STATUS "*********************************") - # message(STATUS ${V_MAJOR}) - # message(STATUS "*********************************") - # message(STATUS ${V_MINOR}) - # message(STATUS "*********************************") - # message(STATUS ${V_PATCH}) - # message(STATUS "*********************************") - # message(STATUS ${V_SUFFIX}) - # message(STATUS "*********************************") set(_VERSION_MAJOR_ ${V_MAJOR}) set(_VERSION_MINOR_ ${V_MINOR}) @@ -65,16 +29,6 @@ function(GENERATE_VERSION_METADATA) set(_VERSION_SUFFIX_ ${V_SUFFIX}) set(_VERSION_HASH_ ${_VERSION_HASH_}) set(_VERSION_DIRTY_ ${_VERSION_DIRTY_}) - - # message(STATUS "*********************************") - # message(STATUS ${_VERSION_MAJOR_}) - # message(STATUS "*********************************") - # message(STATUS ${_VERSION_MINOR_}) - # message(STATUS "*********************************") - # message(STATUS ${_VERSION_PATCH_}) - # message(STATUS "*********************************") - # message(STATUS ${_VERSION_SUFFIX_}) - # message(STATUS "*********************************") # Modify and substitute the `.cpp.in` file for a `.cpp` in the build directory. configure_file( diff --git a/libraries/version/CMakeLists.txt b/libraries/version/CMakeLists.txt index 7034e714067..e14a42b18b2 100644 --- a/libraries/version/CMakeLists.txt +++ b/libraries/version/CMakeLists.txt @@ -1,8 +1,5 @@ -cmake_minimum_required( - VERSION 3.5 ) - -project( - Version ) +cmake_minimum_required(VERSION 3.5) +project(Version) # Define the default version metadata in case `git` cannot be found. set(_VERSION_MAJOR_ "unknown") From bc7379599dcde31c093608b5ada13128497199db Mon Sep 17 00:00:00 2001 From: johndebord Date: Thu, 13 Jun 2019 11:05:59 -0400 Subject: [PATCH 22/28] Fully functional --- CMakeModules/VersionUtils.cmake | 13 ++++++++----- libraries/version/CMakeLists.txt | 16 +++++++++++----- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/CMakeModules/VersionUtils.cmake b/CMakeModules/VersionUtils.cmake index 19d1f1dc5c9..de027cf28f5 100644 --- a/CMakeModules/VersionUtils.cmake +++ b/CMakeModules/VersionUtils.cmake @@ -14,27 +14,30 @@ function(GENERATE_VERSION_METADATA) OUTPUT_VARIABLE _VERSION_DIRTY_ ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE ) - + + # ... string(REGEX MATCH "-dirty$" _VERSION_DIRTY_ ${_VERSION_DIRTY_}) - + + # ... if("${_VERSION_DIRTY_}" STREQUAL "") set(_VERSION_DIRTY_ "false") else() set(_VERSION_DIRTY_ "true") endif() - + + # ... set(_VERSION_MAJOR_ ${V_MAJOR}) set(_VERSION_MINOR_ ${V_MINOR}) set(_VERSION_PATCH_ ${V_PATCH}) set(_VERSION_SUFFIX_ ${V_SUFFIX}) set(_VERSION_HASH_ ${_VERSION_HASH_}) set(_VERSION_DIRTY_ ${_VERSION_DIRTY_}) - + # Modify and substitute the `.cpp.in` file for a `.cpp` in the build directory. configure_file( ${LIB_CUR_DIR}/src/version_impl.cpp.in ${LIB_BIN_DIR}/src/version_impl.cpp @ONLY ) endfunction(GENERATE_VERSION_METADATA) - + GENERATE_VERSION_METADATA() diff --git a/libraries/version/CMakeLists.txt b/libraries/version/CMakeLists.txt index e14a42b18b2..00d1732585a 100644 --- a/libraries/version/CMakeLists.txt +++ b/libraries/version/CMakeLists.txt @@ -13,7 +13,7 @@ set(_VERSION_DIRTY_ "") add_library( version "${CMAKE_CURRENT_SOURCE_DIR}/src/version.cpp" - "${CMAKE_CURRENT_BINARY_DIR}/src/version_impl.cpp" ) + "${CMAKE_CURRENT_BINARY_DIR}/src/version_impl.cpp") # Make dependencies visible. target_include_directories( @@ -30,10 +30,10 @@ if(EXISTS ${CMAKE_SOURCE_DIR}/.git AND ${GIT_FOUND}) -DLIB_BIN_DIR=${CMAKE_CURRENT_BINARY_DIR} -DLIB_CUR_DIR=${CMAKE_CURRENT_SOURCE_DIR} -DROOT_DIR=${CMAKE_SOURCE_DIR} - -DV_MAJOR=${VERSION_MAJOR} - -DV_MINOR=${VERSION_MINOR} - -DV_PATCH=${VERSION_PATCH} - -DV_SUFFIX=${VERSION_SUFFIX} + -DV_MAJOR=${VERSION_MAJOR} + -DV_MINOR=${VERSION_MINOR} + -DV_PATCH=${VERSION_PATCH} + -DV_SUFFIX=${VERSION_SUFFIX} -P ${CMAKE_SOURCE_DIR}/CMakeModules/VersionUtils.cmake COMMENT "Updating version metadata.." VERBATIM ) else() @@ -44,6 +44,12 @@ else() @ONLY ) endif() +# ... +set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/src/version_impl.cpp PROPERTY GENERATED 1) + +# ... +add_dependencies(version evaluate_every_build) + # Install the library in the appropriate places. install( TARGETS version From cccfb5cd4a1d98b8b4392c2969713bd13b9eee8b Mon Sep 17 00:00:00 2001 From: johndebord Date: Thu, 13 Jun 2019 11:48:43 -0400 Subject: [PATCH 23/28] Polish --- CMakeModules/VersionUtils.cmake | 30 +++++++-------- libraries/version/CMakeLists.txt | 46 +++++++++++------------ libraries/version/src/version_impl.cpp.in | 37 +++++++++++------- libraries/version/src/version_impl.hpp | 4 +- 4 files changed, 63 insertions(+), 54 deletions(-) diff --git a/CMakeModules/VersionUtils.cmake b/CMakeModules/VersionUtils.cmake index de027cf28f5..7618f5710d3 100644 --- a/CMakeModules/VersionUtils.cmake +++ b/CMakeModules/VersionUtils.cmake @@ -4,39 +4,39 @@ function(GENERATE_VERSION_METADATA) # Execute `git` to grab the corresponding data. execute_process( COMMAND ${GIT_EXEC} rev-parse HEAD - WORKING_DIRECTORY ${ROOT_DIR} - OUTPUT_VARIABLE _VERSION_HASH_ + WORKING_DIRECTORY ${SRC_DIR} + OUTPUT_VARIABLE V_HASH ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE ) execute_process( COMMAND ${GIT_EXEC} describe --tags --dirty - WORKING_DIRECTORY ${ROOT_DIR} - OUTPUT_VARIABLE _VERSION_DIRTY_ + WORKING_DIRECTORY ${SRC_DIR} + OUTPUT_VARIABLE V_DIRTY ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE ) - # ... - string(REGEX MATCH "-dirty$" _VERSION_DIRTY_ ${_VERSION_DIRTY_}) + # Look for the substring "-dirty" in the variable `_VERSION_DIRTY_`. + string(REGEX MATCH "-dirty$" V_DIRTY ${V_DIRTY}) - # ... - if("${_VERSION_DIRTY_}" STREQUAL "") - set(_VERSION_DIRTY_ "false") + # If `_VERSION_DIRTY_` is empty, we know that the repository isn't dirty and vice versa. + if("${V_DIRTY}" STREQUAL "") + set(V_DIRTY "false") else() - set(_VERSION_DIRTY_ "true") + set(V_DIRTY "true") endif() - # ... + # Define the proper version metadata for the file `version_impl.cpp.in`. set(_VERSION_MAJOR_ ${V_MAJOR}) set(_VERSION_MINOR_ ${V_MINOR}) set(_VERSION_PATCH_ ${V_PATCH}) set(_VERSION_SUFFIX_ ${V_SUFFIX}) - set(_VERSION_HASH_ ${_VERSION_HASH_}) - set(_VERSION_DIRTY_ ${_VERSION_DIRTY_}) + set(_VERSION_HASH_ ${V_HASH}) + set(_VERSION_DIRTY_ ${V_DIRTY}) # Modify and substitute the `.cpp.in` file for a `.cpp` in the build directory. configure_file( - ${LIB_CUR_DIR}/src/version_impl.cpp.in - ${LIB_BIN_DIR}/src/version_impl.cpp + ${CUR_SRC_DIR}/src/version_impl.cpp.in + ${CUR_BIN_DIR}/src/version_impl.cpp @ONLY ) endfunction(GENERATE_VERSION_METADATA) diff --git a/libraries/version/CMakeLists.txt b/libraries/version/CMakeLists.txt index 00d1732585a..eddb0ce205b 100644 --- a/libraries/version/CMakeLists.txt +++ b/libraries/version/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.5) project(Version) -# Define the default version metadata in case `git` cannot be found. +# Define the version metadata by default, in case `git` cannot be found. set(_VERSION_MAJOR_ "unknown") set(_VERSION_MINOR_ "") set(_VERSION_PATCH_ "") @@ -9,33 +9,33 @@ set(_VERSION_SUFFIX_ "") set(_VERSION_HASH_ "") set(_VERSION_DIRTY_ "") -# Construct the library. +# Construct the library target. add_library( - version - "${CMAKE_CURRENT_SOURCE_DIR}/src/version.cpp" - "${CMAKE_CURRENT_BINARY_DIR}/src/version_impl.cpp") + version + "${CMAKE_CURRENT_SOURCE_DIR}/src/version.cpp" + "${CMAKE_CURRENT_BINARY_DIR}/src/version_impl.cpp") -# Make dependencies visible. +# Make dependencies visible to the given target library to be constructed. target_include_directories( - version - PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include/" - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src/" ) + version + PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include/" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src/" ) -# Create a custom target to be run upon every build. +# Create a custom target to update the version metadata upon every build. find_package(Git) if(EXISTS ${CMAKE_SOURCE_DIR}/.git AND ${GIT_FOUND}) add_custom_target( evaluate_every_build ALL COMMAND ${CMAKE_COMMAND} -DGIT_EXEC=${GIT_EXECUTABLE} - -DLIB_BIN_DIR=${CMAKE_CURRENT_BINARY_DIR} - -DLIB_CUR_DIR=${CMAKE_CURRENT_SOURCE_DIR} - -DROOT_DIR=${CMAKE_SOURCE_DIR} + -DCUR_BIN_DIR=${CMAKE_CURRENT_BINARY_DIR} + -DCUR_SRC_DIR=${CMAKE_CURRENT_SOURCE_DIR} + -DSRC_DIR=${CMAKE_SOURCE_DIR} -DV_MAJOR=${VERSION_MAJOR} -DV_MINOR=${VERSION_MINOR} -DV_PATCH=${VERSION_PATCH} -DV_SUFFIX=${VERSION_SUFFIX} -P ${CMAKE_SOURCE_DIR}/CMakeModules/VersionUtils.cmake - COMMENT "Updating version metadata.." VERBATIM ) + COMMENT "Updating version metadata..." VERBATIM ) else() # Modify and substitute the `.cpp.in` file for a `.cpp` in the build directory. configure_file( @@ -44,21 +44,21 @@ else() @ONLY ) endif() -# ... +# Wait for `version_impl.cpp` to get generated before building the target library. set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/src/version_impl.cpp PROPERTY GENERATED 1) -# ... +# Create a dependency for the given library target. add_dependencies(version evaluate_every_build) # Install the library in the appropriate places. install( - TARGETS version - RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} ) + TARGETS version + RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} ) # Install the header file in the appropriate place. install( - DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/eosio/version - DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR}/eosio/ - FILES_MATCHING PATTERN "*.hpp" ) + DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/eosio/version + DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR}/eosio/ + FILES_MATCHING PATTERN "*.hpp" ) diff --git a/libraries/version/src/version_impl.cpp.in b/libraries/version/src/version_impl.cpp.in index 6dba04e8b64..1e439a03881 100644 --- a/libraries/version/src/version_impl.cpp.in +++ b/libraries/version/src/version_impl.cpp.in @@ -15,22 +15,31 @@ namespace eosio { namespace version { const std::string version_hash {"@_VERSION_HASH_@" }; const bool version_dirty { @_VERSION_DIRTY_@ }; - const std::string& _version_client() { - static const std::string version{'v' + version_major + - '.' + version_minor + - '.' + version_patch + - '-' + version_suffix}; - return version; + std::string _version_client() { + if (version_major == "Unknown") { + std::string version{"Unknown"}; + return version; + } + else { + std::string version{'v' + version_major + '.' + version_minor + '.' + version_patch + '-' + version_suffix}; + return version; + } } - const std::string& _version_full() { - static const std::string version{'v' + version_major + - '.' + version_minor + - '.' + version_patch + - '-' + version_suffix + - '-' + version_hash + - ((version_dirty == true) ? ("-dirty") : (""))}; - return version; + std::string _version_full() { + if (version_major == "Unknown") { + std::string version{"Unknown"}; + return version; + } + else { + std::string version{'v' + version_major + '.' + version_minor + '.' + version_patch + '-' + version_suffix + '-' + version_hash}; + + if (version_dirty == true) { + version += "-dirty"; + } + + return version; + } } } } diff --git a/libraries/version/src/version_impl.hpp b/libraries/version/src/version_impl.hpp index 40997ce6d37..8266383a417 100644 --- a/libraries/version/src/version_impl.hpp +++ b/libraries/version/src/version_impl.hpp @@ -10,9 +10,9 @@ namespace eosio { namespace version { ///< Helper function for `version_client()` - const std::string& _version_client(); + std::string _version_client(); ///< Helper function for `version_full()` - const std::string& _version_full(); + std::string _version_full(); } } From 624115bf40e12d9b4d660495c0d982096726ca15 Mon Sep 17 00:00:00 2001 From: johndebord Date: Fri, 14 Jun 2019 15:38:21 -0400 Subject: [PATCH 24/28] Remove unnecessary installations --- libraries/version/CMakeLists.txt | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/libraries/version/CMakeLists.txt b/libraries/version/CMakeLists.txt index eddb0ce205b..1331942aefe 100644 --- a/libraries/version/CMakeLists.txt +++ b/libraries/version/CMakeLists.txt @@ -49,16 +49,3 @@ set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/src/version_impl.cpp PROPERTY GE # Create a dependency for the given library target. add_dependencies(version evaluate_every_build) - -# Install the library in the appropriate places. -install( - TARGETS version - RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} ) - -# Install the header file in the appropriate place. -install( - DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/eosio/version - DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR}/eosio/ - FILES_MATCHING PATTERN "*.hpp" ) From c3a4e7fef76833dfe08705b961c5a51a1f9aa5ee Mon Sep 17 00:00:00 2001 From: johndebord Date: Fri, 14 Jun 2019 17:03:26 -0400 Subject: [PATCH 25/28] Fix `Makefile` generation where `git` directory `.git/` are not found --- libraries/version/CMakeLists.txt | 6 +++--- libraries/version/src/version_impl.cpp.in | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libraries/version/CMakeLists.txt b/libraries/version/CMakeLists.txt index 1331942aefe..b6e56a0d27f 100644 --- a/libraries/version/CMakeLists.txt +++ b/libraries/version/CMakeLists.txt @@ -36,6 +36,9 @@ if(EXISTS ${CMAKE_SOURCE_DIR}/.git AND ${GIT_FOUND}) -DV_SUFFIX=${VERSION_SUFFIX} -P ${CMAKE_SOURCE_DIR}/CMakeModules/VersionUtils.cmake COMMENT "Updating version metadata..." VERBATIM ) + + # Create a dependency for the given library target. + add_dependencies(version evaluate_every_build) else() # Modify and substitute the `.cpp.in` file for a `.cpp` in the build directory. configure_file( @@ -46,6 +49,3 @@ endif() # Wait for `version_impl.cpp` to get generated before building the target library. set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/src/version_impl.cpp PROPERTY GENERATED 1) - -# Create a dependency for the given library target. -add_dependencies(version evaluate_every_build) diff --git a/libraries/version/src/version_impl.cpp.in b/libraries/version/src/version_impl.cpp.in index 1e439a03881..6a45c1dff1f 100644 --- a/libraries/version/src/version_impl.cpp.in +++ b/libraries/version/src/version_impl.cpp.in @@ -16,8 +16,8 @@ namespace eosio { namespace version { const bool version_dirty { @_VERSION_DIRTY_@ }; std::string _version_client() { - if (version_major == "Unknown") { - std::string version{"Unknown"}; + if (version_major == "unknown") { + std::string version{"unknown"}; return version; } else { @@ -27,8 +27,8 @@ namespace eosio { namespace version { } std::string _version_full() { - if (version_major == "Unknown") { - std::string version{"Unknown"}; + if (version_major == "unknown") { + std::string version{"unknown"}; return version; } else { From bc02b709dc6006f492b80b8f7da86e14ae8aea22 Mon Sep 17 00:00:00 2001 From: johndebord Date: Mon, 17 Jun 2019 11:34:30 -0400 Subject: [PATCH 26/28] Use `git diff --quiet` to get dirty info --- CMakeModules/VersionUtils.cmake | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/CMakeModules/VersionUtils.cmake b/CMakeModules/VersionUtils.cmake index 7618f5710d3..d4ef7b0d561 100644 --- a/CMakeModules/VersionUtils.cmake +++ b/CMakeModules/VersionUtils.cmake @@ -9,20 +9,17 @@ function(GENERATE_VERSION_METADATA) ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE ) execute_process( - COMMAND ${GIT_EXEC} describe --tags --dirty + COMMAND ${GIT_EXEC} diff --quiet WORKING_DIRECTORY ${SRC_DIR} - OUTPUT_VARIABLE V_DIRTY + RESULT_VARIABLE V_DIRTY ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE ) - # Look for the substring "-dirty" in the variable `_VERSION_DIRTY_`. - string(REGEX MATCH "-dirty$" V_DIRTY ${V_DIRTY}) - - # If `_VERSION_DIRTY_` is empty, we know that the repository isn't dirty and vice versa. - if("${V_DIRTY}" STREQUAL "") - set(V_DIRTY "false") - else() + # If `V_DIRTY` is equal to 1, we know that the repository is dirty and vice versa. + if(${V_DIRTY}) set(V_DIRTY "true") + else() + set(V_DIRTY "false") endif() # Define the proper version metadata for the file `version_impl.cpp.in`. From ef354e78eed42f7a1a675cbad46bd784993d10cb Mon Sep 17 00:00:00 2001 From: johndebord Date: Tue, 18 Jun 2019 18:26:56 -0400 Subject: [PATCH 27/28] Fix so `Ninja` doesn't start building before file is generated --- libraries/version/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/version/CMakeLists.txt b/libraries/version/CMakeLists.txt index b6e56a0d27f..b4324f3769a 100644 --- a/libraries/version/CMakeLists.txt +++ b/libraries/version/CMakeLists.txt @@ -35,6 +35,7 @@ if(EXISTS ${CMAKE_SOURCE_DIR}/.git AND ${GIT_FOUND}) -DV_PATCH=${VERSION_PATCH} -DV_SUFFIX=${VERSION_SUFFIX} -P ${CMAKE_SOURCE_DIR}/CMakeModules/VersionUtils.cmake + BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/src/version_impl.cpp COMMENT "Updating version metadata..." VERBATIM ) # Create a dependency for the given library target. From 38eca5840a7c6aa59d6cc7d495d55111eff90413 Mon Sep 17 00:00:00 2001 From: johndebord Date: Tue, 18 Jun 2019 18:36:36 -0400 Subject: [PATCH 28/28] Get rid of redundant `set_property` command --- libraries/version/CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/libraries/version/CMakeLists.txt b/libraries/version/CMakeLists.txt index b4324f3769a..239c479d92b 100644 --- a/libraries/version/CMakeLists.txt +++ b/libraries/version/CMakeLists.txt @@ -47,6 +47,3 @@ else() ${CMAKE_CURRENT_BINARY_DIR}/src/version_impl.cpp @ONLY ) endif() - -# Wait for `version_impl.cpp` to get generated before building the target library. -set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/src/version_impl.cpp PROPERTY GENERATED 1)