ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
VersionTagging.h
1 /* Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009 Dean Beeler, Jerome Fisher
2  * Copyright (C) 2011-2022 Dean Beeler, Jerome Fisher, Sergey V. Mikayev
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 2.1 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef MT32EMU_VERSION_TAG_H
19 #define MT32EMU_VERSION_TAG_H
20 
21 #include "globals.h"
22 
23 /* This is intended to implement a simple check of a shared library version in runtime. Sadly, per-symbol versioning
24  * is unavailable on many platforms, and even where it is, it's still not too easy to maintain for a C++ library.
25  * Therefore, the goal here is just to ensure that the client application quickly bails out when attempted to run
26  * with an older version of shared library, as well as to produce a more readable error message indicating a version mismatch
27  * rather than a report about some missing symbols with unreadable mangled names.
28  * This is an optional feature, since it adds some minor burden to both the library and client applications code,
29  * albeit it is ought to work on platforms that do not implement symbol versioning.
30  */
31 
32 #define MT32EMU_REALLY_BUILD_VERSION_TAG(major, minor) mt32emu_ ## major ## _ ## minor
33 /* This macro expansion step permits resolution the actual version numbers. */
34 #define MT32EMU_BUILD_VERSION_TAG(major, minor) MT32EMU_REALLY_BUILD_VERSION_TAG(major, minor)
35 #define MT32EMU_VERSION_TAG MT32EMU_BUILD_VERSION_TAG(MT32EMU_VERSION_MAJOR, MT32EMU_VERSION_MINOR)
36 
37 #if defined(__cplusplus)
38 
39 extern "C" {
40 MT32EMU_EXPORT extern const volatile char MT32EMU_VERSION_TAG;
41 }
42 // This pulls the external reference in yet prevents it from being optimised out.
43 static const volatile char mt32emu_version_tag = MT32EMU_VERSION_TAG;
44 
45 #else
46 
47 static void mt32emu_refer_version_tag(void) {
48  MT32EMU_EXPORT extern const volatile char MT32EMU_VERSION_TAG;
49  (void)MT32EMU_VERSION_TAG;
50 }
51 
52 static void (*const volatile mt32emu_refer_version_tag_ref)(void) = mt32emu_refer_version_tag;
53 
54 #endif
55 
56 #undef MT32EMU_REALLY_BUILD_VERSION_TAG
57 #undef MT32EMU_BUILD_VERSION_TAG
58 #undef MT32EMU_VERSION_TAG
59 
60 #endif