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

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