GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/utils/dumplibs.cpp Lines: 0 41 0.0 %
Date: 2017-11-29 Branches: 0 10 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2017  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
PRAGMACLANG6GCC(GCC diagnostic push)
33
PRAGMACLANG6GCC(GCC diagnostic ignored "-Wold-style-cast")
34
#include <SDL_net.h>
35
PRAGMACLANG6GCC(GCC diagnostic pop)
36
#include <SDL_ttf.h>
37
PRAGMA48(GCC diagnostic pop)
38
39
#include <zlib.h>
40
41
#include <curl/curl.h>
42
43
#ifdef ENABLE_LIBXML
44
#include <libxml/xmlversion.h>
45
#endif  // ENABLE_LIBXML
46
47
#include "debug.h"
48
49
#define dumpCompiledSdlVersion(text, prefix) \
50
    logger->log(" " text ": %d.%d.%d", \
51
        prefix##_MAJOR_VERSION, \
52
        prefix##_MINOR_VERSION, \
53
        prefix##_PATCHLEVEL)
54
55
#define sdlVersionJoin(prefix) \
56
    prefix##_MAJOR_VERSION, \
57
    prefix##_MINOR_VERSION, \
58
    prefix##_PATCHLEVEL
59
60
static void dumpLinkedSdlVersion(const char *const text,
61
                                 const SDL_version *const version)
62
{
63
    if (version != nullptr)
64
    {
65
        logger->log(" %s: %d.%d.%d",
66
            text,
67
            version->major,
68
            version->minor,
69
            version->patch);
70
    }
71
}
72
73
static void compareVersions(const char *const libName,
74
                            const char *const buildVersion,
75
                            const char *const linkedVersion)
76
{
77
    if (strcmp(buildVersion, linkedVersion) != 0)
78
    {
79
        logger->assertLog(
80
            "%s: compiled and linked versions not same: %s vs %s",
81
            libName,
82
            buildVersion,
83
            linkedVersion);
84
    }
85
}
86
87
static void compareSDLVersions(const char *const libName,
88
                               const int major,
89
                               const int minor,
90
                               const int patch,
91
                               const SDL_version *const linkedVersion)
92
{
93
    const std::string buildVersionStr = strprintf("%d.%d.%d",
94
        major,
95
        minor,
96
        patch);
97
    const std::string linkedVersionStr = strprintf("%d.%d.%d",
98
        linkedVersion->major,
99
        linkedVersion->minor,
100
        linkedVersion->patch);
101
    if (buildVersionStr != linkedVersionStr)
102
    {
103
        logger->assertLog(
104
            "%s: compiled and linked versions not same: %s vs %s",
105
            libName,
106
            buildVersionStr.c_str(),
107
            linkedVersionStr.c_str());
108
    }
109
}
110
111
void dumpLibs()
112
{
113
    logger->log("Compiled with:");
114
    logger->log(" zLib: %s", ZLIB_VERSION);
115
#ifdef ENABLE_LIBXML
116
    logger->log(" libxml2: %s", LIBXML_DOTTED_VERSION);
117
#endif  // ENABLE_LIBXML
118
119
    logger->log(" libcurl: %s", LIBCURL_VERSION);
120
    logger->log(" libpng: %s", PNG_LIBPNG_VER_STRING);
121
122
    dumpCompiledSdlVersion("SDL", SDL);
123
    dumpCompiledSdlVersion("SDL_net", SDL_NET);
124
    dumpCompiledSdlVersion("SDL_image", SDL_IMAGE);
125
    dumpCompiledSdlVersion("SDL_mixer", SDL_MIXER);
126
    dumpCompiledSdlVersion("SDL_ttf", SDL_TTF);
127
128
    logger->log("Linked with:");
129
#if ZLIB_VERNUM >= 0x1020
130
    logger->log(" zLib: %s", zlibVersion());
131
#endif  // ZLIB_VERNUM >= 0x1020
132
#ifdef LIBXML_TEST_VERSION
133
    LIBXML_TEST_VERSION
134
#endif  // LIBXML_TEST_VERSION
135
#ifdef USE_SDL2
136
    SDL_version sdlVersion;
137
    sdlVersion.major = 0;
138
    sdlVersion.minor = 0;
139
    sdlVersion.patch = 0;
140
    SDL_GetVersion(&sdlVersion);
141
    dumpLinkedSdlVersion("SDL", &sdlVersion);
142
#else  // USE_SDL2
143
    dumpLinkedSdlVersion("SDL", SDL_Linked_Version());
144
#endif  // USE_SDL2
145
    dumpLinkedSdlVersion("SDL_net", SDLNet_Linked_Version());
146
    dumpLinkedSdlVersion("SDL_image", IMG_Linked_Version());
147
    dumpLinkedSdlVersion("SDL_mixer", Mix_Linked_Version());
148
    dumpLinkedSdlVersion("SDL_ttf", TTF_Linked_Version());
149
150
    compareVersions("zLib", ZLIB_VERSION, zlibVersion());
151
#ifdef USE_SDL2
152
    compareSDLVersions("SDL", sdlVersionJoin(SDL), &sdlVersion);
153
#else  // USE_SDL2
154
    compareSDLVersions("SDL", sdlVersionJoin(SDL), SDL_Linked_Version());
155
#endif  // USE_SDL2
156
157
    compareSDLVersions("SDL_net",
158
        sdlVersionJoin(SDL_NET),
159
        SDLNet_Linked_Version());
160
    compareSDLVersions("SDL_image",
161
        sdlVersionJoin(SDL_IMAGE),
162
        IMG_Linked_Version());
163
    compareSDLVersions("SDL_mixer",
164
        sdlVersionJoin(SDL_MIXER),
165
        Mix_Linked_Version());
166
    compareSDLVersions("SDL_ttf",
167
        sdlVersionJoin(SDL_TTF),
168
        TTF_Linked_Version());
169
}