GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/utils/dumplibs.cpp Lines: 0 54 0.0 %
Date: 2021-03-17 Branches: 0 14 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2017-2019  The ManaPlus Developers
4
 *  Copyright (C) 2019-2021  Andrei Karas
5
 *
6
 *  This file is part of The ManaPlus Client.
7
 *
8
 *  This program is free software; you can redistribute it and/or modify
9
 *  it under the terms of the GNU General Public License as published by
10
 *  the Free Software Foundation; either version 2 of the License, or
11
 *  any later version.
12
 *
13
 *  This program is distributed in the hope that it will be useful,
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 *  GNU General Public License for more details.
17
 *
18
 *  You should have received a copy of the GNU General Public License
19
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 */
21
22
#include "utils/dumplibs.h"
23
24
#include "logger.h"
25
26
#include "utils/stringutils.h"
27
28
#include <png.h>
29
PRAGMA48(GCC diagnostic push)
30
PRAGMA48(GCC diagnostic ignored "-Wshadow")
31
#include <SDL_image.h>
32
#include <SDL_mixer.h>
33
34
PRAGMACLANG5(GCC diagnostic push)
35
PRAGMACLANG5(GCC diagnostic ignored "-Wzero-as-null-pointer-constant")
36
PRAGMACLANG6GCC(GCC diagnostic push)
37
PRAGMACLANG6GCC(GCC diagnostic ignored "-Wold-style-cast")
38
#include <SDL_net.h>
39
PRAGMACLANG6GCC(GCC diagnostic pop)
40
PRAGMACLANG5(GCC diagnostic pop)
41
#include <SDL_ttf.h>
42
PRAGMA48(GCC diagnostic pop)
43
44
#include <zlib.h>
45
46
#include <curl/curl.h>
47
48
#ifdef ENABLE_LIBXML
49
#include <libxml/globals.h>
50
#endif  // ENABLE_LIBXML
51
52
#include "debug.h"
53
54
#define dumpCompiledSdlVersion(text, prefix) \
55
    logger->log(" " text ": %d.%d.%d", \
56
        prefix##_MAJOR_VERSION, \
57
        prefix##_MINOR_VERSION, \
58
        prefix##_PATCHLEVEL)
59
60
#define sdlVersionJoin(prefix) \
61
    prefix##_MAJOR_VERSION, \
62
    prefix##_MINOR_VERSION, \
63
    prefix##_PATCHLEVEL
64
65
static void dumpLinkedSdlVersion(const char *const text,
66
                                 const SDL_version *const version)
67
{
68
    if (version != nullptr)
69
    {
70
        logger->log(" %s: %d.%d.%d",
71
            text,
72
            version->major,
73
            version->minor,
74
            version->patch);
75
    }
76
}
77
78
static void compareVersions(const char *const libName,
79
                            const char *const buildVersion,
80
                            const char *const linkedVersion)
81
{
82
    if (strcmp(buildVersion, linkedVersion) != 0)
83
    {
84
        logger->assertLog(
85
            "%s: compiled and linked versions not same: %s vs %s",
86
            libName,
87
            buildVersion,
88
            linkedVersion);
89
    }
90
}
91
92
static void compareSDLVersions(const char *const libName,
93
                               const int major,
94
                               const int minor,
95
                               const int patch,
96
                               const SDL_version *const linkedVersion)
97
{
98
    const std::string buildVersionStr = strprintf("%d.%d.%d",
99
        major,
100
        minor,
101
        patch);
102
    const std::string linkedVersionStr = strprintf("%d.%d.%d",
103
        linkedVersion->major,
104
        linkedVersion->minor,
105
        linkedVersion->patch);
106
    if (buildVersionStr != linkedVersionStr)
107
    {
108
        logger->assertLog(
109
            "%s: compiled and linked versions not same: %s vs %s",
110
            libName,
111
            buildVersionStr.c_str(),
112
            linkedVersionStr.c_str());
113
    }
114
}
115
116
void dumpLibs()
117
{
118
    logger->log("Compiled with:");
119
    logger->log(" zLib: %s", ZLIB_VERSION);
120
#ifdef ENABLE_LIBXML
121
    logger->log(" libxml2: %s, %s",
122
        LIBXML_DOTTED_VERSION,
123
        LIBXML_VERSION_STRING LIBXML_VERSION_EXTRA);
124
#endif  // ENABLE_LIBXML
125
126
    logger->log(" libcurl: %s", LIBCURL_VERSION);
127
    logger->log(" libpng: %s", PNG_LIBPNG_VER_STRING);
128
129
    dumpCompiledSdlVersion("SDL", SDL);
130
    dumpCompiledSdlVersion("SDL_net", SDL_NET);
131
    dumpCompiledSdlVersion("SDL_image", SDL_IMAGE);
132
    dumpCompiledSdlVersion("SDL_mixer", SDL_MIXER);
133
    dumpCompiledSdlVersion("SDL_ttf", SDL_TTF);
134
135
    logger->log("Linked with:");
136
#if ZLIB_VERNUM >= 0x1020
137
    logger->log(" zLib: %s", zlibVersion());
138
#endif  // ZLIB_VERNUM >= 0x1020
139
#ifdef LIBXML_TEST_VERSION
140
    LIBXML_TEST_VERSION
141
#endif  // LIBXML_TEST_VERSION
142
#ifdef ENABLE_LIBXML
143
    const char **xmlVersion = __xmlParserVersion();
144
    if (xmlVersion != nullptr)
145
        logger->log(" libxml2: %s", *xmlVersion);
146
#endif  // ENABLE_LIBXML
147
#ifdef USE_SDL2
148
    SDL_version sdlVersion;
149
    sdlVersion.major = 0;
150
    sdlVersion.minor = 0;
151
    sdlVersion.patch = 0;
152
    SDL_GetVersion(&sdlVersion);
153
    dumpLinkedSdlVersion("SDL", &sdlVersion);
154
#else  // USE_SDL2
155
    dumpLinkedSdlVersion("SDL", SDL_Linked_Version());
156
#endif  // USE_SDL2
157
    dumpLinkedSdlVersion("SDL_net", SDLNet_Linked_Version());
158
    dumpLinkedSdlVersion("SDL_image", IMG_Linked_Version());
159
    dumpLinkedSdlVersion("SDL_mixer", Mix_Linked_Version());
160
    dumpLinkedSdlVersion("SDL_ttf", TTF_Linked_Version());
161
162
    compareVersions("zLib", ZLIB_VERSION, zlibVersion());
163
#ifdef ENABLE_LIBXML
164
    if (xmlVersion != nullptr)
165
    {
166
        compareVersions("libxml2",
167
            LIBXML_VERSION_STRING LIBXML_VERSION_EXTRA,
168
            *xmlVersion);
169
    }
170
#endif  // ENABLE_LIBXML
171
#ifdef USE_SDL2
172
    compareSDLVersions("SDL", sdlVersionJoin(SDL), &sdlVersion);
173
#else  // USE_SDL2
174
    compareSDLVersions("SDL", sdlVersionJoin(SDL), SDL_Linked_Version());
175
#endif  // USE_SDL2
176
177
    compareSDLVersions("SDL_net",
178
        sdlVersionJoin(SDL_NET),
179
        SDLNet_Linked_Version());
180
    compareSDLVersions("SDL_image",
181
        sdlVersionJoin(SDL_IMAGE),
182
        IMG_Linked_Version());
183
    compareSDLVersions("SDL_mixer",
184
        sdlVersionJoin(SDL_MIXER),
185
        Mix_Linked_Version());
186
    compareSDLVersions("SDL_ttf",
187
        sdlVersionJoin(SDL_TTF),
188
        TTF_Linked_Version());
189
}