bi: Keep track of optional build features and add a report function
Also added this information to --version's output.
This commit is contained in:
parent
3a4c11a2e7
commit
10baf45766
3 changed files with 117 additions and 1 deletions
|
@ -12,9 +12,12 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#define GETTEXT_DOMAIN "wesnoth-lib"
|
||||
|
||||
#include "build_info.hpp"
|
||||
|
||||
#include "formatter.hpp"
|
||||
#include "gettext.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
|
@ -40,6 +43,7 @@ namespace {
|
|||
struct version_table_manager
|
||||
{
|
||||
std::vector<std::string> compiled, linked, names;
|
||||
std::vector<optional_feature> features;
|
||||
|
||||
version_table_manager();
|
||||
};
|
||||
|
@ -64,6 +68,7 @@ version_table_manager::version_table_manager()
|
|||
: compiled(LIB_COUNT, "")
|
||||
, linked(LIB_COUNT, "")
|
||||
, names(LIB_COUNT, "")
|
||||
, features()
|
||||
{
|
||||
SDL_version sdl_version;
|
||||
const SDL_version* sdl_rt_version = NULL;
|
||||
|
@ -171,12 +176,71 @@ version_table_manager::version_table_manager()
|
|||
linked[LIB_PNG] = png_get_libpng_ver(NULL);
|
||||
names[LIB_PNG] = "libpng";
|
||||
#endif
|
||||
|
||||
//
|
||||
// Features table.
|
||||
//
|
||||
|
||||
features.push_back(N_("feature^Experimental OpenMP support"));
|
||||
#ifdef _OPENMP
|
||||
features.back().enabled = true;
|
||||
#endif
|
||||
|
||||
features.push_back(N_("feature^PNG screenshots"));
|
||||
#ifdef HAVE_LIBPNG
|
||||
features.back().enabled = true;
|
||||
#endif
|
||||
|
||||
features.push_back(N_("feature^Lua console completion"));
|
||||
#ifdef HAVE_HISTORY
|
||||
features.back().enabled = true;
|
||||
#endif
|
||||
|
||||
features.push_back(N_("feature^Legacy bidirectional rendering"));
|
||||
#ifdef HAVE_FRIBIDI
|
||||
features.back().enabled = true;
|
||||
#endif
|
||||
|
||||
features.push_back(N_("feature^D-Bus notifications back end"));
|
||||
#ifdef HAVE_LIBDBUS
|
||||
features.back().enabled = true;
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
// Always compiled in.
|
||||
features.push_back(N_("feature^Win32 notifications back-end"));
|
||||
features.back().enabled = true;
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
||||
features.push_back(N_("feature^Cocoa notifications back-end"));
|
||||
#ifdef HAVE_NS_USER_NOTIFICATION
|
||||
features.back().enabled = true;
|
||||
#endif
|
||||
|
||||
features.push_back(N_("feature^Growl notifications back-end"));
|
||||
#ifdef HAVE_GROWL
|
||||
features.back().enabled = true;
|
||||
#endif
|
||||
|
||||
#endif /* __APPLE__ */
|
||||
}
|
||||
|
||||
const std::string empty_version = "";
|
||||
|
||||
} // end anonymous namespace 1
|
||||
|
||||
std::vector<optional_feature> optional_features_table()
|
||||
{
|
||||
std::vector<optional_feature> res = versions.features;
|
||||
|
||||
for(size_t k = 0; k < res.size(); ++k) {
|
||||
res[k].name = _(res[k].name.c_str());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
const std::string& library_build_version(LIBRARY_ID lib)
|
||||
{
|
||||
if(lib >= LIB_COUNT) {
|
||||
|
@ -261,4 +325,36 @@ std::string library_versions_report()
|
|||
return o.str();
|
||||
}
|
||||
|
||||
std::string optional_features_report()
|
||||
{
|
||||
// Yes, it's for stdout/stderr but we still want the localized version so
|
||||
// that the context prefixes are stripped.
|
||||
const std::vector<optional_feature>& features = optional_features_table();
|
||||
|
||||
size_t col2_start = 0;
|
||||
|
||||
for(size_t k = 0; k < features.size(); ++k)
|
||||
{
|
||||
col2_start = std::max(col2_start, features[k].name.length() + 2);
|
||||
}
|
||||
|
||||
std::ostringstream o;
|
||||
|
||||
for(size_t k = 0; k < features.size(); ++k)
|
||||
{
|
||||
const optional_feature& f = features[k];
|
||||
|
||||
o << f.name << ": ";
|
||||
|
||||
const size_t pos2 = f.name.length() + 2;
|
||||
if(pos2 < col2_start) {
|
||||
o << std::string(col2_start - pos2, ' ');
|
||||
}
|
||||
|
||||
o << (f.enabled ? "yes" : "no") << '\n';
|
||||
}
|
||||
|
||||
return o.str();
|
||||
}
|
||||
|
||||
} // end namespace game_config
|
||||
|
|
|
@ -38,6 +38,24 @@ enum LIBRARY_ID
|
|||
LIB_COUNT
|
||||
};
|
||||
|
||||
struct optional_feature
|
||||
{
|
||||
std::string name;
|
||||
bool enabled;
|
||||
|
||||
optional_feature(const char* n) : name(n), enabled(false) {}
|
||||
};
|
||||
|
||||
/**
|
||||
* Return a localized features table.
|
||||
*/
|
||||
std::vector<optional_feature> optional_features_table();
|
||||
|
||||
/**
|
||||
* Produce a plain-text report of features suitable for stdout/stderr.
|
||||
*/
|
||||
std::string optional_features_report();
|
||||
|
||||
/**
|
||||
* Retrieve the build-time version number of the given library.
|
||||
*/
|
||||
|
|
|
@ -451,7 +451,9 @@ static int process_command_args(const commandline_options& cmdline_opts) {
|
|||
}
|
||||
if(cmdline_opts.version) {
|
||||
std::cout << "Battle for Wesnoth" << " " << game_config::version << "\n\n";
|
||||
std::cout << "Library versions:\n" << game_config::library_versions_report();
|
||||
std::cout << "Library versions:\n" << game_config::library_versions_report() << '\n';
|
||||
std::cout << "Optional features:\n" << game_config::optional_features_report();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue