GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/utils/dumplibs.cpp Lines: 0 47 0.0 %
Date: 2018-07-14 Branches: 0 10 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/xmlversion.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", LIBXML_DOTTED_VERSION);
121
#endif  // ENABLE_LIBXML
122
123
    logger->log(" libcurl: %s", LIBCURL_VERSION);
124
    logger->log(" libpng: %s", PNG_LIBPNG_VER_STRING);
125
126
    dumpCompiledSdlVersion("SDL", SDL);
127
    dumpCompiledSdlVersion("SDL_net", SDL_NET);
128
    dumpCompiledSdlVersion("SDL_image", SDL_IMAGE);
129
    dumpCompiledSdlVersion("SDL_mixer", SDL_MIXER);
130
    dumpCompiledSdlVersion("SDL_ttf", SDL_TTF);
131
132
    logger->log("Linked with:");
133
#if ZLIB_VERNUM >= 0x1020
134
    logger->log(" zLib: %s", zlibVersion());
135
#endif  // ZLIB_VERNUM >= 0x1020
136
#ifdef LIBXML_TEST_VERSION
137
    LIBXML_TEST_VERSION
138
#endif  // LIBXML_TEST_VERSION
139
#ifdef USE_SDL2
140
    SDL_version sdlVersion;
141
    sdlVersion.major = 0;
142
    sdlVersion.minor = 0;
143
    sdlVersion.patch = 0;
144
    SDL_GetVersion(&sdlVersion);
145
    dumpLinkedSdlVersion("SDL", &sdlVersion);
146
#else  // USE_SDL2
147
    dumpLinkedSdlVersion("SDL", SDL_Linked_Version());
148
#endif  // USE_SDL2
149
    dumpLinkedSdlVersion("SDL_net", SDLNet_Linked_Version());
150
    dumpLinkedSdlVersion("SDL_image", IMG_Linked_Version());
151
    dumpLinkedSdlVersion("SDL_mixer", Mix_Linked_Version());
152
    dumpLinkedSdlVersion("SDL_ttf", TTF_Linked_Version());
153
154
    compareVersions("zLib", ZLIB_VERSION, zlibVersion());
155
#ifdef USE_SDL2
156
    compareSDLVersions("SDL", sdlVersionJoin(SDL), &sdlVersion);
157
#else  // USE_SDL2
158
    compareSDLVersions("SDL", sdlVersionJoin(SDL), SDL_Linked_Version());
159
#endif  // USE_SDL2
160
161
    compareSDLVersions("SDL_net",
162
        sdlVersionJoin(SDL_NET),
163
        SDLNet_Linked_Version());
164
    compareSDLVersions("SDL_image",
165
        sdlVersionJoin(SDL_IMAGE),
166
        IMG_Linked_Version());
167
    compareSDLVersions("SDL_mixer",
168
        sdlVersionJoin(SDL_MIXER),
169
        Mix_Linked_Version());
170
    compareSDLVersions("SDL_ttf",
171
        sdlVersionJoin(SDL_TTF),
172
        TTF_Linked_Version());
173
}