1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-02-02 11:45:13 +01:00
Files
OpenRCT2/src/openrct2/Version.cpp
Jan Strauss fdc4d4d892 Set -Wmissing-prototypes for clang builds (#24757)
* Set -Wmissing-prototypes for clang builds.

GCC defines -Wmissing-declarations as specialization of -Wmissing-prototypes for C++ (See https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wmissing-declarations and https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wmissing-prototypes) while Clang uses -Wmissing-prototypes for both languages and -Wmissing-declarations is a different diagnostic (See https://clang.llvm.org/docs/DiagnosticsReference.html#wmissing-prototypes and
https://clang.llvm.org/docs/DiagnosticsReference.html#wmissing-declarations).
Use MATCHES against CMAKE_CXX_COMPILER_ID (See https://stackoverflow.com/a/10055571, https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html) as conditional to handle both AppleClang and Clang.
Clang enables -Wmissing-declarations by default so no point in setting it only if !Clang.

See also:
https://github.com/llvm/llvm-project/issues/16660
https://reviews.llvm.org/D119361

* Make HasMatchingLanguage in Platform.macOS.mm static.

Uncovered by setting -Wmissing-prototypes flag for Clang builds in 306c277c.

* Ignore -Wmissing-prototypes for extern GetVersion.

Result of setting -Wmissing-prototypes flag for Clang builds in 306c277c.

See also: https://github.com/llvm/llvm-project/issues/94138
2025-07-11 14:06:41 -03:00

116 lines
3.5 KiB
C++

/*****************************************************************************
* Copyright (c) 2014-2025 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include "Version.h"
#include "config/Config.h"
#include "core/Console.hpp"
#include "core/Http.h"
#include "core/Json.hpp"
#include <chrono>
using namespace OpenRCT2;
#ifdef OPENRCT2_BUILD_INFO_HEADER
#include OPENRCT2_BUILD_INFO_HEADER
#endif
const char gVersionInfoTag[] =
#ifdef OPENRCT2_VERSION_TAG
OPENRCT2_VERSION_TAG
#else
"v" kOpenRCT2Version
#endif
;
const char gVersionInfoFull[] = OPENRCT2_NAME ", "
#ifdef OPENRCT2_VERSION_TAG
OPENRCT2_VERSION_TAG
#else
"v" kOpenRCT2Version
#endif
#if defined(OPENRCT2_BRANCH) || defined(OPENRCT2_COMMIT_SHA1_SHORT) || !defined(NDEBUG)
" ("
#if defined(OPENRCT2_BRANCH) && defined(OPENRCT2_COMMIT_SHA1_SHORT)
OPENRCT2_COMMIT_SHA1_SHORT " on " OPENRCT2_BRANCH
#elif defined(OPENRCT2_COMMIT_SHA1_SHORT)
OPENRCT2_COMMIT_SHA1_SHORT
#elif defined(OPENRCT2_BRANCH)
OPENRCT2_BRANCH
#endif
#ifndef NDEBUG
", DEBUG"
#endif
")"
#endif
#ifdef OPENRCT2_BUILD_SERVER
" provided by " OPENRCT2_BUILD_SERVER
#endif
;
#ifdef __EMSCRIPTEN__
// This must be wrapped in extern "C", according to the emscripten docs, "to prevent C++ name mangling"
// Ignore -Wmissing-prototypes here, see https://github.com/llvm/llvm-project/issues/94138
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-prototypes"
extern "C" {
const char* GetVersion()
{
return gVersionInfoFull;
}
}
#pragma clang diagnostic pop
#endif
NewVersionInfo GetLatestVersion()
{
// If the check doesn't succeed, provide current version so we don't bother user
// with invalid data.
std::string tag = gVersionInfoTag;
NewVersionInfo verinfo{ tag, "", "" };
#if !defined(DISABLE_HTTP) && !defined(DISABLE_VERSION_CHECKER)
auto now = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
auto then = Config::Get().general.LastVersionCheckTime;
using namespace std::chrono_literals;
if (then < now - std::chrono::seconds(24h).count())
{
Http::Request request;
request.url = "https://api.github.com/repos/OpenRCT2/OpenRCT2/releases/latest";
request.method = Http::Method::GET;
Http::Response res;
try
{
res = Do(request);
if (res.status != Http::Status::Ok)
throw std::runtime_error("bad http status");
}
catch (std::exception& e)
{
Console::Error::WriteLine("Failed to download '%s', cause %s", request.url.c_str(), e.what());
return {};
}
json_t root = Json::FromString(res.body);
verinfo.tag = Json::GetString(root["tag_name"]);
verinfo.name = Json::GetString(root["name"]);
verinfo.changelog = Json::GetString(root["body"]);
Config::Get().general.LastVersionCheckTime = now;
Config::Save();
}
#endif
return verinfo;
}