Skip to content

Commit

Permalink
Add a version.h header with full Git version information.
Browse files Browse the repository at this point in the history
  • Loading branch information
mosra committed Jun 1, 2020
1 parent 19e0e96 commit 293f092
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 4 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions doc/changelog.dox
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions doc/developers.dox
Original file line number Diff line number Diff line change
Expand Up @@ -905,8 +905,9 @@ inverse.
properly
8. Convert all occurences of <tt>\@m_since_latest</tt> to
<tt>\@m_since{20XY,ab}</tt>
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
Expand Down
29 changes: 28 additions & 1 deletion src/Magnum/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/Magnum/Test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
66 changes: 66 additions & 0 deletions src/Magnum/Test/VersionTest.cpp
Original file line number Diff line number Diff line change
@@ -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š <mosra@centrum.cz>
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 <Corrade/TestSuite/Tester.h>
#include <Corrade/TestSuite/Compare/Numeric.h>

#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<void*>(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)
38 changes: 38 additions & 0 deletions src/Magnum/version.h.cmake
Original file line number Diff line number Diff line change
@@ -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š <mosra@centrum.cz>

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

0 comments on commit 293f092

Please sign in to comment.