diff --git a/CMakeLists.txt b/CMakeLists.txt index 3363a60fc9..6be9322e05 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -420,9 +420,12 @@ if(MAGNUM_PLUGINS_RELEASE_DIR) set(MAGNUM_PLUGINS_AUDIOIMPORTER_RELEASE_DIR ${MAGNUM_PLUGINS_RELEASE_DIR}/audioimporters) endif() -# Library version +# Library version. MAGNUM_VERSION_YEAR/MONTH is used in +# src/Magnum/CMakeLists.txt to generate the version.h header. set(MAGNUM_LIBRARY_VERSION 2.3) set(MAGNUM_LIBRARY_SOVERSION 2) +set(MAGNUM_VERSION_YEAR 2019) +set(MAGNUM_VERSION_MONTH 10) # A single output location. After a decade of saying NO THIS IS A NON-SOLUTION # TO A NON-PROBLEM I reconsidered my views and enabled this, because: diff --git a/doc/changelog.dox b/doc/changelog.dox index c54907f64a..200262dd72 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -330,6 +330,12 @@ See also: for more information. - Added an ability to disable unique globals across shared libraries using @ref MAGNUM_BUILD_STATIC_UNIQUE_GLOBALS on static builds that don't need it +- Library version is now exposed through `MAGNUM_VERSION_YEAR`, + `MAGNUM_VERSION_MONTH`, `MAGNUM_VERSION_COMMIT`, `MAGNUM_VERSION_HASH` + and `MAGNUM_VERSION_STRING` preprocessor defines in a new + `Magnum/version.h` header. This header is not included by any other header + to avoid trigerring a full rebuild when Git commit changes. If Git is not + found, only the first two defines are present. @subsubsection changelog-latest-changes-audio Audio library diff --git a/doc/developers.dox b/doc/developers.dox index 9e82fea84e..4fe2114668 100644 --- a/doc/developers.dox +++ b/doc/developers.dox @@ -905,8 +905,9 @@ inverse. properly 8. Convert all occurences of \@m_since_latest to \@m_since{20XY,ab} -9. Bump `MAGNUM_LIBRARY_VERSION` and `MAGNUM_LIBRARY_SOVERSION` in all - projects, if needed --- ensure all projects have the exact same version +9. Bump `MAGNUM*_LIBRARY_VERSION`, `MAGNUM*_LIBRARY_SOVERSION` + `MAGNUM*_VERSION_YEAR` and `MAGNUM*_VERSION_MONTH` in all projects. Ensure + all projects have the exact same version. 10. Rebuild all projects with the new shared library version numbers, verify all tools and examples still behave properly 11. Build and upload public docs (see @ref developers-documentation), verify diff --git a/src/Magnum/CMakeLists.txt b/src/Magnum/CMakeLists.txt index 8a705d463d..788e9296bf 100644 --- a/src/Magnum/CMakeLists.txt +++ b/src/Magnum/CMakeLists.txt @@ -23,9 +23,33 @@ # DEALINGS IN THE SOFTWARE. # +# Generate configure header configure_file(${CMAKE_CURRENT_SOURCE_DIR}/configure.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/configure.h) +# Generate version header. If Git is found and this is a Git working copy, +# extract values from there, otherwise use just MAGNUM_VERSION_YEAR/MONTH that +# are set in project root CMakeLists. +find_package(Git) +if(Git_FOUND) + # Match only tags starting with `v`, always use the long format so we have + # a commit hash also on a tagged version + execute_process(COMMAND ${GIT_EXECUTABLE} describe --match "v*" --long + OUTPUT_VARIABLE MAGNUM_VERSION_STRING + RESULT_VARIABLE _MAGNUM_VERSION_RESULT + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) + if(MAGNUM_VERSION_STRING MATCHES "^v([0-9][0-9][0-9][0-9])\\.0?([0-9][0-9])-([0-9]+)-g([a-f0-9]+)$") + set(MAGNUM_VERSION_YEAR ${CMAKE_MATCH_1}) + set(MAGNUM_VERSION_MONTH ${CMAKE_MATCH_2}) + set(MAGNUM_VERSION_COMMIT ${CMAKE_MATCH_3}) + set(MAGNUM_VERSION_HASH ${CMAKE_MATCH_4}) + elseif(_MAGNUM_VERSION_RESULT EQUAL 0) + message(WARNING "Can't match Git version from ${MAGNUM_VERSION_STRING}") + endif() +endif() +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/version.h.cmake + ${CMAKE_CURRENT_BINARY_DIR}/version.h) + # Files shared between main library and unit test library set(Magnum_SRCS FileCallback.cpp @@ -148,7 +172,10 @@ install(TARGETS Magnum LIBRARY DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR} ARCHIVE DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) install(FILES ${Magnum_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/configure.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}) +install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/configure.h + ${CMAKE_CURRENT_BINARY_DIR}/version.h + DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}) add_subdirectory(Animation) add_subdirectory(Math) diff --git a/src/Magnum/Test/CMakeLists.txt b/src/Magnum/Test/CMakeLists.txt index 861fe37a25..c618c8c84c 100644 --- a/src/Magnum/Test/CMakeLists.txt +++ b/src/Magnum/Test/CMakeLists.txt @@ -33,6 +33,7 @@ corrade_add_test(PixelStorageTest PixelStorageTest.cpp LIBRARIES Magnum) corrade_add_test(ResourceManagerTest ResourceManagerTest.cpp LIBRARIES Magnum) corrade_add_test(SamplerTest SamplerTest.cpp LIBRARIES MagnumTestLib) corrade_add_test(TagsTest TagsTest.cpp LIBRARIES Magnum) +corrade_add_test(VersionTest VersionTest.cpp LIBRARIES Magnum) corrade_add_test(VertexFormatTest VertexFormatTest.cpp LIBRARIES MagnumTestLib) set_target_properties( diff --git a/src/Magnum/Test/VersionTest.cpp b/src/Magnum/Test/VersionTest.cpp new file mode 100644 index 0000000000..5d96b4ff4a --- /dev/null +++ b/src/Magnum/Test/VersionTest.cpp @@ -0,0 +1,66 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, + 2020 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include +#include + +#include "Magnum/Magnum.h" +#include "Magnum/version.h" + +namespace Magnum { namespace Test { namespace { + +struct VersionTest: TestSuite::Tester { + explicit VersionTest(); + + void test(); +}; + +VersionTest::VersionTest() { + addTests({&VersionTest::test}); +} + +void VersionTest::test() { + Debug{} << "MAGNUM_VERSION_YEAR:" << MAGNUM_VERSION_YEAR; + Debug{} << "MAGNUM_VERSION_MONTH:" << MAGNUM_VERSION_MONTH; + #ifdef MAGNUM_VERSION_COMMIT + Debug{} << "MAGNUM_VERSION_COMMIT:" << MAGNUM_VERSION_COMMIT; + Debug{} << "MAGNUM_VERSION_HASH:" << reinterpret_cast(MAGNUM_VERSION_HASH); + Debug{} << "MAGNUM_VERSION_STRING:" << MAGNUM_VERSION_STRING; + #else + Debug{} << "No Git version information available."; + #endif + + CORRADE_COMPARE_AS(MAGNUM_VERSION_YEAR, 2019, TestSuite::Compare::GreaterOrEqual); + CORRADE_COMPARE_AS(MAGNUM_VERSION_YEAR, 2100, TestSuite::Compare::LessOrEqual); + CORRADE_COMPARE_AS(MAGNUM_VERSION_MONTH, 0, TestSuite::Compare::Greater); + CORRADE_COMPARE_AS(MAGNUM_VERSION_MONTH, 12, TestSuite::Compare::LessOrEqual); + #ifdef MAGNUM_VERSION_COMMIT + CORRADE_COMPARE_AS(MAGNUM_VERSION_COMMIT, 0, TestSuite::Compare::GreaterOrEqual); + #endif +} + +}}} + +CORRADE_TEST_MAIN(Magnum::Test::VersionTest) diff --git a/src/Magnum/version.h.cmake b/src/Magnum/version.h.cmake new file mode 100644 index 0000000000..3fa199ebad --- /dev/null +++ b/src/Magnum/version.h.cmake @@ -0,0 +1,38 @@ +#ifndef Magnum_version_h +#define Magnum_version_h +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, + 2020 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +/* Note: this header is deliberately not included from anywhere except + VersionTest to avoid triggering a full rebuild every time the Git commit + hash changes. */ + +#define MAGNUM_VERSION_YEAR ${MAGNUM_VERSION_YEAR} +#define MAGNUM_VERSION_MONTH ${MAGNUM_VERSION_MONTH} +#cmakedefine MAGNUM_VERSION_COMMIT ${MAGNUM_VERSION_COMMIT} +#cmakedefine MAGNUM_VERSION_HASH 0x${MAGNUM_VERSION_HASH} +#cmakedefine MAGNUM_VERSION_STRING "${MAGNUM_VERSION_STRING}" + +#endif