Skip to content

Commit f918930

Browse files
authored
Switched language standard to C++20, bumped compiler requirement to GCC 11. (mamedev#15182)
* Hackery to allow UTF-8 strings as well as plain strings: - emu/ioport.h: Allow char8_t for names in field configuration helper. - emu/device.h, emu/gamedrv.h: Allow char8_t for descriptions and manufacturers. - util/language.h: Allow char8_t message input. * util/strformat.h: Allow char8_t format and string arguments with char output. * ui/videoopt.cpp: Deal with UTF-8 strings as a distinct type. * osd/windows: Assume Windows 8 or later.
1 parent 56d8cb9 commit f918930

12 files changed

Lines changed: 144 additions & 121 deletions

File tree

docs/source/commandline/commandline-all.rst

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3022,7 +3022,7 @@ Core Sound Options
30223022
* - ``wasapi``
30233023
- Windows
30243024
- Yes
3025-
- Yes [#SoundWASAPIMonitoring]_
3025+
- Yes
30263026
- Yes
30273027
- Yes
30283028
* - ``xaudio2``
@@ -3065,9 +3065,6 @@ Core Sound Options
30653065
30663066
.. rubric:: Footnotes
30673067
3068-
.. [#SoundWASAPIMonitoring] MAME requires Windows 10 1703 or later to use
3069-
output monitoring with WASAPI.
3070-
30713068
.. [#SoundXAudio2OS] MAME requires Windows 8 or later to use XAudio2.
30723069
30733070
.. [#SoundWinSDL] While SDL is not a supported option on official MAME builds

docs/source/initialsetup/compilingmame.rst

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ Compiling MAME
88
All Platforms
99
-------------
1010

11-
* To compile MAME, you need a C++17 compiler and runtime library. We
12-
support building with GCC version 10.3 or later and clang version 11
13-
or later. MAME should run with GNU libstdc++ version 10.3 or later or
11+
* To compile MAME, you need a C++20 compiler and runtime library. We
12+
support building with GCC version 11 or later and clang version 11 or
13+
later. MAME should run with GNU libstdc++ version 11 or later or
1414
libc++ version 11 or later. The initial release of any major version
1515
of GCC should be avoided. For example, if you want to compile MAME
1616
with GCC 12, you should use version 12.1 or later.
@@ -795,23 +795,6 @@ omitted).
795795
Issues affecting Microsoft Visual Studio
796796
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
797797

798-
Microsoft introduced a new version of XAudio2 with Windows 8 that’s incompatible
799-
with the version included with DirectX for prior Windows versions at the API
800-
level. Newer versions of the Microsoft Windows SDK include headers and libraries
801-
for the new version of XAudio2. By default, the target Windows version is set to
802-
Windows Vista (6.0) when compiling MAME, which prevents the use of this version
803-
of the XAudio2 headers and libraries. To build MAME with XAudio2 support using
804-
the Microsoft Windows SDK, you must do one of the following:
805-
806-
* Add ``MODERN_WIN_API=1`` to the options passed to make when generating the
807-
Visual Studio project files. This will set the target Windows version to
808-
Windows 8 (6.2). The resulting binaries may not run on earlier versions of
809-
Windows.
810-
* Install the `DirectX SDK <https://www.microsoft.com/en-US/download/details.aspx?id=6812>`_ (already included since Windows 8.0 SDK and
811-
automatically installed with Visual Studio 2013 and later). Configure the
812-
**osd_windows** project to search the DirectX header/library paths before
813-
searching the Microsoft Windows SDK paths.
814-
815798
The MSVC compiler produces spurious warnings about potentially uninitialised
816799
local variables. You currently need to add ``NOWERROR=1`` to the options passed
817800
to make when generating the Visual Studio project files. This stops warnings
@@ -873,7 +856,7 @@ Using a GCC/GNU libstdc++ installation in a non-standard location on Linux
873856
GCC may be built and installed to a custom location, typically by supplying the
874857
**--prefix=** option to the **configure** command. This may be useful if you
875858
want to build MAME on a Linux distribution that still uses a version of GNU
876-
libstdC++ that predates C++17 support. To use an alternate GCC installation to,
859+
libstdc++ that predates C++20 support. To use an alternate GCC installation to
877860
build MAME, set the C and C++ compilers to the full paths to the **gcc** and
878861
**g++** commands, and add the library path to the run-time search path. If you
879862
installed GCC in /opt/local/gcc72, you might use a command like this::

scripts/genie.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,6 @@ language "C++"
489489

490490
flags {
491491
"StaticRuntime",
492-
"Cpp17",
493492
}
494493

495494
if not _OPTIONS["NOWERROR"] then
@@ -727,11 +726,11 @@ end
727726

728727
local version = str_to_version(_OPTIONS["gcc_version"])
729728
buildoptions_cpp {
730-
"-std=c++17",
729+
"-std=c++20",
731730
}
732731

733732
buildoptions_objcpp {
734-
"-std=c++17",
733+
"-std=c++20",
735734
}
736735
-- this speeds it up a bit by piping between the preprocessor/compiler/assembler
737736
buildoptions {
@@ -1054,8 +1053,8 @@ end
10541053
}
10551054
end
10561055
else
1057-
if version < 100300 then
1058-
print("GCC version 10.3 or later needed")
1056+
if version < 110000 then
1057+
print("GCC version 11 or later needed")
10591058
os.exit(-1)
10601059
end
10611060
buildoptions_cpp {
@@ -1122,7 +1121,7 @@ configuration { "asmjs" }
11221121
"-s USE_SDL_TTF=2",
11231122
}
11241123
buildoptions_cpp {
1125-
"-std=c++17",
1124+
"-std=c++20",
11261125
"-s EXCEPTION_CATCHING_ALLOWED=\"['_ZN15running_machine17start_all_devicesEv','_ZN12cli_frontend7executeEiPPc','_ZN8chd_file11open_commonEb','_ZN8chd_file13read_metadataEjjRNSt3__212basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE','_ZN8chd_file13read_metadataEjjRNSt3__26vectorIhNS0_9allocatorIhEEEE','_ZNK19netlist_mame_device19base_validity_checkER16validity_checker']\"",
11271126
}
11281127
defines {
@@ -1308,6 +1307,7 @@ if _OPTIONS["vs"]==nil then
13081307

13091308
buildoptions_cpp {
13101309
"/Zc:__cplusplus",
1310+
"/std:c++20",
13111311
}
13121312

13131313
flags {

src/emu/device.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ class device_type_impl_base
243243
: m_creator(&create_device<DeviceClass>)
244244
, m_type(typeid(DeviceClass))
245245
, m_shortname(Traits::shortname)
246-
, m_fullname(Traits::fullname)
246+
, m_fullname((char const *)Traits::fullname)
247247
, m_source(Traits::source)
248248
, m_emulation_flags(DeviceClass::emulation_flags())
249249
, m_unemulated_features(DeviceClass::unemulated_features())
@@ -258,7 +258,7 @@ class device_type_impl_base
258258
: m_creator(&create_driver<DriverClass>)
259259
, m_type(typeid(DriverClass))
260260
, m_shortname(Traits::shortname)
261-
, m_fullname(Traits::fullname)
261+
, m_fullname((char const *)Traits::fullname)
262262
, m_source(Traits::source)
263263
, m_emulation_flags(DriverClass::emulation_flags() | Flags)
264264
, m_unemulated_features(DriverClass::unemulated_features() | Unemulated)
@@ -404,7 +404,7 @@ extern emu::detail::device_registrar const registered_device_types;
404404
{ \
405405
static inline constexpr char const *const shortname = (ShortName); \
406406
static inline constexpr char const *const source = __FILE__; \
407-
static constexpr char const fullname[] = (FullName); \
407+
static constexpr std::remove_reference_t<decltype((FullName)[0])> const fullname[] = (FullName); \
408408
}; \
409409
constexpr decltype(Type##_device_traits::fullname) Type##_device_traits::fullname; \
410410
} \
@@ -446,7 +446,7 @@ extern emu::detail::device_registrar const registered_device_types;
446446
{ \
447447
static inline constexpr char const *const shortname = (ShortName); \
448448
static inline constexpr char const *const source = __FILE__; \
449-
static constexpr char const fullname[] = (FullName); \
449+
static constexpr std::remove_reference_t<decltype((FullName)[0])> const fullname[] = (FullName); \
450450
}; \
451451
constexpr decltype(Type##_device_traits::fullname) Type##_device_traits::fullname; \
452452
} \

src/emu/gamedrv.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ class game_driver
203203
{ \
204204
static inline constexpr char const *const shortname = #NAME; \
205205
static inline constexpr char const *const source = __FILE__; \
206-
static inline constexpr char const *manufacturer = (COMPANY); \
207-
static constexpr char const fullname[] = (FULLNAME); \
206+
static inline constexpr auto const *const manufacturer = (COMPANY); \
207+
static constexpr std::remove_reference_t<decltype((FULLNAME)[0])> const fullname[] = (FULLNAME); \
208208
}; \
209209
constexpr decltype(GAME_TRAITS_NAME(NAME)::fullname) GAME_TRAITS_NAME(NAME)::fullname; \
210210
}
@@ -610,7 +610,7 @@ extern game_driver const GAME_NAME(NAME) \
610610
GAME_DRIVER_TYPE(NAME, CLASS, FLAGS), \
611611
#PARENT, \
612612
#YEAR, \
613-
GAME_TRAITS_NAME(NAME)::manufacturer, \
613+
(const char *)GAME_TRAITS_NAME(NAME)::manufacturer, \
614614
[] (machine_config &config, device_t &owner) { downcast<CLASS &>(owner).MACHINE(config); }, \
615615
INPUT_PORTS_NAME(INPUT), \
616616
[] (device_t &owner) { downcast<CLASS &>(owner).INIT(); }, \
@@ -682,7 +682,7 @@ extern game_driver const GAME_NAME(NAME) \
682682
GAME_DRIVER_TYPE(NAME, CLASS, FLAGS), \
683683
#PARENT, \
684684
#YEAR, \
685-
GAME_TRAITS_NAME(NAME)::manufacturer, \
685+
(const char *)GAME_TRAITS_NAME(NAME)::manufacturer, \
686686
[] (machine_config &config, device_t &owner) { downcast<CLASS &>(owner).MACHINE(config); }, \
687687
INPUT_PORTS_NAME(INPUT), \
688688
[] (device_t &owner) { downcast<CLASS &>(owner).INIT(); }, \
@@ -748,7 +748,7 @@ extern game_driver const GAME_NAME(NAME) \
748748
GAME_DRIVER_TYPE(NAME, CLASS, FLAGS), \
749749
#PARENT, \
750750
#YEAR, \
751-
GAME_TRAITS_NAME(NAME)::manufacturer, \
751+
(const char *)GAME_TRAITS_NAME(NAME)::manufacturer, \
752752
[] (machine_config &config, device_t &owner) { downcast<CLASS &>(owner).MACHINE(config); }, \
753753
INPUT_PORTS_NAME(INPUT), \
754754
[] (device_t &owner) { downcast<CLASS &>(owner).INIT(); }, \

src/emu/ioport.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,12 @@ class ioport_configurer
11741174
ioport_configurer& set_condition(ioport_condition::condition_t condition, const char *tag, ioport_value mask, ioport_value value);
11751175
ioport_configurer& onoff_alloc(const char *name, ioport_value defval, ioport_value mask, const char *diplocation);
11761176

1177+
// allow UTF-8 strings to be used for names transparently
1178+
ioport_configurer& field_alloc(ioport_type type, ioport_value defval, ioport_value mask, const char8_t *name) { return field_alloc(type, defval, mask, reinterpret_cast<const char *>(name)); }
1179+
ioport_configurer& field_set_name(const char8_t *name) { return field_set_name(reinterpret_cast<const char *>(name)); }
1180+
ioport_configurer& setting_alloc(ioport_value value, const char8_t *name) { return setting_alloc(value, reinterpret_cast<const char *>(name)); }
1181+
ioport_configurer& onoff_alloc(const char8_t *name, ioport_value defval, ioport_value mask, const char *diplocation) { return onoff_alloc(reinterpret_cast<const char *>(name), defval, mask, diplocation); }
1182+
11771183
private:
11781184
// internal state
11791185
device_t & m_owner;

src/frontend/mame/ui/videoopt.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,18 @@ void menu_video_options::populate()
148148
item_append(menu_item_type::SEPARATOR);
149149
}
150150

151-
const char *subtext = "";
152-
153-
// add a rotate item
154-
switch (m_target.orientation())
155151
{
156-
case ROT0: subtext = "None"; break;
157-
case ROT90: subtext = u8"CW 90°"; break;
158-
case ROT180: subtext = u8"180°"; break;
159-
case ROT270: subtext = u8"CCW 90°"; break;
152+
// add a rotate item
153+
const auto *subtext = u8"";
154+
switch (m_target.orientation())
155+
{
156+
case ROT0: subtext = u8"None"; break;
157+
case ROT90: subtext = u8"CW 90°"; break;
158+
case ROT180: subtext = u8"180°"; break;
159+
case ROT270: subtext = u8"CCW 90°"; break;
160+
}
161+
item_append(_("Rotate"), (char const *)subtext, FLAG_LEFT_ARROW | FLAG_RIGHT_ARROW, reinterpret_cast<void *>(ITEM_ROTATE));
160162
}
161-
item_append(_("Rotate"), subtext, FLAG_LEFT_ARROW | FLAG_RIGHT_ARROW, reinterpret_cast<void *>(ITEM_ROTATE));
162163

163164
// cropping
164165
bool const canzoom(curview.has_art() && !curview.visible_screens().empty());
@@ -167,6 +168,7 @@ void menu_video_options::populate()
167168
if (!m_snapshot)
168169
{
169170
// uneven stretch
171+
const auto *subtext = "";
170172
switch (m_target.scale_mode())
171173
{
172174
case SCALE_FRACTIONAL:

src/lib/util/language.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ char const *lang_translate(char const *context, char const *message);
3838
std::string_view lang_translate(char const *context, std::string_view message);
3939
std::string_view lang_translate(std::string_view context, std::string_view message);
4040

41+
// allow UTF-8 messages to be used as keys transparently
42+
inline char const *lang_translate(char8_t const *message)
43+
{ return lang_translate(reinterpret_cast<char const *>(message)); }
44+
inline std::string_view lang_translate(std::u8string_view message)
45+
{ return lang_translate(std::string_view(reinterpret_cast<char const *>(message.data()), message.size())); }
46+
47+
// allow UTF-8 messages to be used as keys transparently (with context)
48+
inline char const *lang_translate(char const *context, char8_t const *message)
49+
{ return lang_translate(context, reinterpret_cast<char const *>(message)); }
50+
inline std::string_view lang_translate(char const *context, std::u8string_view message)
51+
{ return lang_translate(context, std::string_view(reinterpret_cast<char const *>(message.data()), message.size())); }
52+
inline std::string_view lang_translate(std::string_view context, std::u8string_view message)
53+
{ return lang_translate(context, std::string_view(reinterpret_cast<char const *>(message.data()), message.size())); }
54+
4155
} // namespace util
4256

4357
#endif // MAME_LIB_UTIL_LANGUAGE_H

0 commit comments

Comments
 (0)