Browse Source

Updated libopenmpt to version 0.3.6.

master
Christopher Snowhill 2 years ago
parent
commit
6cd51431bd
100 changed files with 52312 additions and 4 deletions
  1. +0
    -3
      .gitmodules
  2. +0
    -1
      Frameworks/OpenMPT/OpenMPT
  3. +27
    -0
      Frameworks/OpenMPT/OpenMPT/LICENSE
  4. +1375
    -0
      Frameworks/OpenMPT/OpenMPT/Makefile
  5. +370
    -0
      Frameworks/OpenMPT/OpenMPT/README.md
  6. +736
    -0
      Frameworks/OpenMPT/OpenMPT/common/BuildSettings.h
  7. +367
    -0
      Frameworks/OpenMPT/OpenMPT/common/CompilerDetect.h
  8. +465
    -0
      Frameworks/OpenMPT/OpenMPT/common/ComponentManager.cpp
  9. +507
    -0
      Frameworks/OpenMPT/OpenMPT/common/ComponentManager.h
  10. +1061
    -0
      Frameworks/OpenMPT/OpenMPT/common/Endianness.h
  11. +154
    -0
      Frameworks/OpenMPT/OpenMPT/common/FileReader.cpp
  12. +1167
    -0
      Frameworks/OpenMPT/OpenMPT/common/FileReader.h
  13. +42
    -0
      Frameworks/OpenMPT/OpenMPT/common/FileReaderFwd.h
  14. +412
    -0
      Frameworks/OpenMPT/OpenMPT/common/FlagSet.h
  15. +423
    -0
      Frameworks/OpenMPT/OpenMPT/common/Logging.cpp
  16. +264
    -0
      Frameworks/OpenMPT/OpenMPT/common/Logging.h
  17. +221
    -0
      Frameworks/OpenMPT/OpenMPT/common/Profiler.cpp
  18. +125
    -0
      Frameworks/OpenMPT/OpenMPT/common/Profiler.h
  19. +410
    -0
      Frameworks/OpenMPT/OpenMPT/common/StringFixer.h
  20. +71
    -0
      Frameworks/OpenMPT/OpenMPT/common/WriteMemoryDump.h
  21. +135
    -0
      Frameworks/OpenMPT/OpenMPT/common/misc_util.cpp
  22. +1134
    -0
      Frameworks/OpenMPT/OpenMPT/common/misc_util.h
  23. +175
    -0
      Frameworks/OpenMPT/OpenMPT/common/mptBufferIO.h
  24. +376
    -0
      Frameworks/OpenMPT/OpenMPT/common/mptCPU.cpp
  25. +72
    -0
      Frameworks/OpenMPT/OpenMPT/common/mptCPU.h
  26. +245
    -0
      Frameworks/OpenMPT/OpenMPT/common/mptCRC.h
  27. +383
    -0
      Frameworks/OpenMPT/OpenMPT/common/mptFileIO.cpp
  28. +589
    -0
      Frameworks/OpenMPT/OpenMPT/common/mptFileIO.h
  29. +827
    -0
      Frameworks/OpenMPT/OpenMPT/common/mptIO.cpp
  30. +926
    -0
      Frameworks/OpenMPT/OpenMPT/common/mptIO.h
  31. +550
    -0
      Frameworks/OpenMPT/OpenMPT/common/mptLibrary.cpp
  32. +118
    -0
      Frameworks/OpenMPT/OpenMPT/common/mptLibrary.h
  33. +233
    -0
      Frameworks/OpenMPT/OpenMPT/common/mptMutex.h
  34. +564
    -0
      Frameworks/OpenMPT/OpenMPT/common/mptOS.cpp
  35. +163
    -0
      Frameworks/OpenMPT/OpenMPT/common/mptOS.h
  36. +889
    -0
      Frameworks/OpenMPT/OpenMPT/common/mptPathString.cpp
  37. +503
    -0
      Frameworks/OpenMPT/OpenMPT/common/mptPathString.h
  38. +318
    -0
      Frameworks/OpenMPT/OpenMPT/common/mptRandom.cpp
  39. +643
    -0
      Frameworks/OpenMPT/OpenMPT/common/mptRandom.h
  40. +1691
    -0
      Frameworks/OpenMPT/OpenMPT/common/mptString.cpp
  41. +668
    -0
      Frameworks/OpenMPT/OpenMPT/common/mptString.h
  42. +498
    -0
      Frameworks/OpenMPT/OpenMPT/common/mptStringFormat.cpp
  43. +782
    -0
      Frameworks/OpenMPT/OpenMPT/common/mptStringFormat.h
  44. +120
    -0
      Frameworks/OpenMPT/OpenMPT/common/mptStringParse.cpp
  45. +196
    -0
      Frameworks/OpenMPT/OpenMPT/common/mptStringParse.h
  46. +460
    -0
      Frameworks/OpenMPT/OpenMPT/common/mptThread.h
  47. +307
    -0
      Frameworks/OpenMPT/OpenMPT/common/mptTime.cpp
  48. +114
    -0
      Frameworks/OpenMPT/OpenMPT/common/mptTime.h
  49. +142
    -0
      Frameworks/OpenMPT/OpenMPT/common/mptTypeTraits.h
  50. +756
    -0
      Frameworks/OpenMPT/OpenMPT/common/mptUUID.cpp
  51. +146
    -0
      Frameworks/OpenMPT/OpenMPT/common/mptUUID.h
  52. +766
    -0
      Frameworks/OpenMPT/OpenMPT/common/mptWine.cpp
  53. +127
    -0
      Frameworks/OpenMPT/OpenMPT/common/mptWine.h
  54. +735
    -0
      Frameworks/OpenMPT/OpenMPT/common/serialization_utils.cpp
  55. +552
    -0
      Frameworks/OpenMPT/OpenMPT/common/serialization_utils.h
  56. +20
    -0
      Frameworks/OpenMPT/OpenMPT/common/stdafx.cpp
  57. +124
    -0
      Frameworks/OpenMPT/OpenMPT/common/stdafx.h
  58. +49
    -0
      Frameworks/OpenMPT/OpenMPT/common/typedefs.cpp
  59. +544
    -0
      Frameworks/OpenMPT/OpenMPT/common/typedefs.h
  60. +794
    -0
      Frameworks/OpenMPT/OpenMPT/common/version.cpp
  61. +120
    -0
      Frameworks/OpenMPT/OpenMPT/common/version.h
  62. +30
    -0
      Frameworks/OpenMPT/OpenMPT/common/versionNumber.h
  63. +304
    -0
      Frameworks/OpenMPT/OpenMPT/contrib/fuzzing/all_formats.dict
  64. +4
    -0
      Frameworks/OpenMPT/OpenMPT/contrib/fuzzing/build.sh
  65. +15
    -0
      Frameworks/OpenMPT/OpenMPT/contrib/fuzzing/fuzz-master.sh
  66. +18
    -0
      Frameworks/OpenMPT/OpenMPT/contrib/fuzzing/fuzz-settings.sh
  67. +5
    -0
      Frameworks/OpenMPT/OpenMPT/contrib/fuzzing/fuzz-slave.sh
  68. +54
    -0
      Frameworks/OpenMPT/OpenMPT/contrib/fuzzing/fuzz.c
  69. +16
    -0
      Frameworks/OpenMPT/OpenMPT/contrib/fuzzing/get-afl.sh
  70. +46
    -0
      Frameworks/OpenMPT/OpenMPT/contrib/fuzzing/readme.md
  71. +109
    -0
      Frameworks/OpenMPT/OpenMPT/contrib/libopenmpt/libopenmpt_bass.c
  72. +63
    -0
      Frameworks/OpenMPT/OpenMPT/examples/.clang-format
  73. +203
    -0
      Frameworks/OpenMPT/OpenMPT/examples/libopenmpt_example_c.c
  74. +292
    -0
      Frameworks/OpenMPT/OpenMPT/examples/libopenmpt_example_c_mem.c
  75. +152
    -0
      Frameworks/OpenMPT/OpenMPT/examples/libopenmpt_example_c_pipe.c
  76. +181
    -0
      Frameworks/OpenMPT/OpenMPT/examples/libopenmpt_example_c_probe.c
  77. +176
    -0
      Frameworks/OpenMPT/OpenMPT/examples/libopenmpt_example_c_stdout.c
  78. +65
    -0
      Frameworks/OpenMPT/OpenMPT/examples/libopenmpt_example_c_unsafe.c
  79. +78
    -0
      Frameworks/OpenMPT/OpenMPT/examples/libopenmpt_example_cxx.cpp
  80. +504
    -0
      Frameworks/OpenMPT/OpenMPT/include/minimp3/LGPL.txt
  81. +10
    -0
      Frameworks/OpenMPT/OpenMPT/include/minimp3/OpenMPT.txt
  82. +184
    -0
      Frameworks/OpenMPT/OpenMPT/include/minimp3/libc.h
  83. +2692
    -0
      Frameworks/OpenMPT/OpenMPT/include/minimp3/minimp3.c
  84. +23
    -0
      Frameworks/OpenMPT/OpenMPT/include/minimp3/minimp3.h
  85. +17
    -0
      Frameworks/OpenMPT/OpenMPT/include/miniz/OpenMPT.txt
  86. +7579
    -0
      Frameworks/OpenMPT/OpenMPT/include/miniz/miniz.c
  87. +1349
    -0
      Frameworks/OpenMPT/OpenMPT/include/miniz/miniz.h
  88. +13
    -0
      Frameworks/OpenMPT/OpenMPT/include/modplug/include/libmodplug/libmodplug.pc.in
  89. +171
    -0
      Frameworks/OpenMPT/OpenMPT/include/modplug/include/libmodplug/modplug.h
  90. +168
    -0
      Frameworks/OpenMPT/OpenMPT/include/modplug/include/libmodplug/modplug_0.8.7.h
  91. +1017
    -0
      Frameworks/OpenMPT/OpenMPT/include/modplug/include/libmodplug/sndfile.h
  92. +127
    -0
      Frameworks/OpenMPT/OpenMPT/include/modplug/include/libmodplug/stdafx.h
  93. +17
    -0
      Frameworks/OpenMPT/OpenMPT/include/stb_vorbis/OpenMPT.txt
  94. +5463
    -0
      Frameworks/OpenMPT/OpenMPT/include/stb_vorbis/stb_vorbis.c
  95. +2466
    -0
      Frameworks/OpenMPT/OpenMPT/libopenmpt/Doxyfile
  96. +1615
    -0
      Frameworks/OpenMPT/OpenMPT/libopenmpt/bindings/freebasic/libopenmpt.bi
  97. +332
    -0
      Frameworks/OpenMPT/OpenMPT/libopenmpt/bindings/freebasic/libopenmpt_ext.bi
  98. +1
    -0
      Frameworks/OpenMPT/OpenMPT/libopenmpt/doc/foo_openmpt.txt
  99. +1
    -0
      Frameworks/OpenMPT/OpenMPT/libopenmpt/doc/in_openmpt.txt
  100. +1
    -0
      Frameworks/OpenMPT/OpenMPT/libopenmpt/doc/xmp-openmpt.txt

+ 0
- 3
.gitmodules View File

@@ -4,9 +4,6 @@
[submodule "Frameworks/mGBA/mGBA/mgba"]
path = Frameworks/mGBA/mGBA/mgba
url = https://github.com/kode54/mgba.git
[submodule "Frameworks/OpenMPT/OpenMPT"]
path = Frameworks/OpenMPT/OpenMPT
url = https://gitlab.kode54.net/kode54/OpenMPT.git
[submodule "Frameworks/AdPlug/AdPlug/adplug"]
path = Frameworks/AdPlug/AdPlug/adplug
url = https://github.com/adplug/adplug.git


+ 0
- 1
Frameworks/OpenMPT/OpenMPT

@@ -1 +0,0 @@
Subproject commit bf3d5ea380157da7aa0b7bc58c3d889ac7e31b37

+ 27
- 0
Frameworks/OpenMPT/OpenMPT/LICENSE View File

@@ -0,0 +1,27 @@
The OpenMPT code is licensed under the BSD license.
Copyright (c) 2004-2018, OpenMPT contributors
Copyright (c) 1997-2003, Olivier Lapicque
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the OpenMPT project nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+ 1375
- 0
Frameworks/OpenMPT/OpenMPT/Makefile
File diff suppressed because it is too large
View File


+ 370
- 0
Frameworks/OpenMPT/OpenMPT/README.md View File

@@ -0,0 +1,370 @@

README
======

OpenMPT and libopenmpt
======================


How to compile
--------------


### OpenMPT

- Supported Visual Studio versions:

- Visual Studio 2015 Update 3 Community/Professional/Enterprise

To compile the project, open `build/vs2015/OpenMPT.sln` and hit the
compile button.

- Visual Studio 2017 Community/Professional/Enterprise

To compile the project, open `build/vs2017/OpenMPT.sln` and hit the
compile button.

- The Windows 8.1 SDK and Microsoft Foundation Classes (MFC) are required to
build OpenMPT (both are included with Visual Studio, however may need to be
selected explicitly during setup). In order to build OpenMPT for Windows XP,
the XP targetting toolset also needs to be installed.

- The VST and ASIO SDKs are needed for compiling with VST and ASIO support.

If you don't want this, uncomment `#define NO_VST` and comment out
`#define MPT_WITH_ASIO` in the file `common/BuildSettings.h`.

The ASIO and VST SDKs can be downloaded automatically on Windows 7 or later
with 7-Zip installed by just running the `build/download_externals.cmd`
script.

If you do not want to or cannot use this script, you may follow these manual
steps instead:

- ASIO:

If you use `#define MPT_WITH_ASIO`, you will need to put the ASIO SDK in
the `include/ASIOSDK2` folder. The top level directory of the SDK is
already named `ASIOSDK2`, so simply move that directory in the include
folder.

Please visit
[steinberg.net](http://www.steinberg.net/en/company/developers.html) to
download the SDK.

- VST:

If you don't use `#define NO_VST`, you will need to put the VST SDK in
the `include/vstsdk2.4` folder.
Simply copy all files from the `VST3 SDK` folder in the SDK .zip file to
`include/vstsdk2.4/`.

Note: OpenMPT makes use of the VST 2.4 specification only. The VST3 SDK
still contains all necessary files in the right locations. If you still
have the old VST 2.4 SDK laying around, this should also work fine.

Please visit
[steinberg.net](http://www.steinberg.net/en/company/developers.html) to
download the SDK.

If you need further help with the VST and ASIO SDKs, get in touch with the
main OpenMPT developers.

- 7-Zip is required to be installed in the default path in order to build the
required files for OpenMPT Wine integration.

Please visit [7-zip.org](http://www.7-zip.org/) to download 7-Zip.


### libopenmpt and openmpt123

For detailed requirements, see `libopenmpt/dox/quickstart.md`.

- Autotools

Grab a `libopenmpt-VERSION-autotools.tar.gz` tarball.

./configure
make
make check
sudo make install

- Visual Studio:

- You will find solutions for Visual Studio 2015 to 2017 in the
corresponding `build/vsVERSION/` folder.
Projects that target Windows versions before Windows 7 are available in
`build/vsVERSIONxp/`
Most projects are supported with any of the mentioned Visual Studio
verions, with the following exceptions:

- in_openmpt: Requires Visual Studio with MFC.

- xmp-openmpt: Requires Visual Studio with MFC.

- You will need the Winamp 5 SDK and the XMPlay SDK if you want to
compile the plugins for these 2 players. They can be downloaded
automatically on Windows 7 or later with 7-Zip installed by just running
the `build/download_externals.cmd` script.

If you do not want to or cannot use this script, you may follow these
manual steps instead:

- Winamp 5 SDK:

To build libopenmpt as a winamp input plugin, copy the contents of
`WA5.55_SDK.exe` to include/winamp/.

Please visit
[winamp.com](http://wiki.winamp.com/wiki/Plug-in_Developer) to
download the SDK.
You can disable in_openmpt in the solution configuration.

- XMPlay SDK:

To build libopenmpt with XMPlay input plugin support, copy the
contents of xmp-sdk.zip into include/xmplay/.

Please visit [un4seen.com](http://www.un4seen.com/xmplay.html) to
download the SDK.
You can disable xmp-openmpt in the solution configuration.

- Makefile

The makefile supports different build environments and targets via the
`CONFIG=` parameter directly to the make invocation.
Use `make CONFIG=$newconfig clean` when switching between different configs
because the makefile cleans only intermediates and target that are active
for the current config and no configuration state is kept around across
invocations.

- mingw-w64:

The required version is at least 4.8.

make CONFIG=mingw64-win32 # for win32

make CONFIG=mingw64-win64 # for win64

- gcc or clang (on Unix-like systems, including Mac OS X with MacPorts):

The minimum required compiler versions are:

- gcc 4.8

- clang 3.4

The Makefile requires pkg-config for native builds.
For sound output in openmpt123, PortAudio or SDL is required.
openmpt123 can optionally use libflac and libsndfile to render PCM
files to disk.

When using gcc, run:

make CONFIG=gcc

When using clang, it is recommended to do:

make CONFIG=clang

Otherwise, simply run

make

which will try to guess the compiler based on your operating system.

- emscripten (on Unix-like systems):

libopenmpt has been tested and verified to work with emscripten 1.31 or
later (earlier versions might or might not work).

Run:

make CONFIG=emscripten

Running the test suite on the command line is also supported by using
node.js. Version 0.10.25 or greater has been tested. Earlier versions
might or might not work. Depending on how your distribution calls the
`node.js` binary, you might have to edit
`build/make/config-emscripten.mk`.

- Haiku:

To compile libopenmpt on Haiku (using the 32-bit gcc2h), run:

make CONFIG=haiku

- American Fuzzy Lop:

To compile libopenmpt with fuzzing instrumentation for afl-fuzz, run:
make CONFIG=afl
For more detailed instructions, read contrib/fuzzing/readme.md

- other compilers:

To compiler libopenmpt with other C++11 compliant compilers, run:
make CONFIG=generic
The `Makefile` supports some customizations. You might want to read the top
which should get you some possible make settings, like e.g.
`make DYNLINK=0` or similar. Cross compiling or different compiler would
best be implemented via new `config-*.mk` files.

The `Makefile` also supports building doxygen documentation by using

make doc

Binaries and documentation can be installed systen-wide with

make PREFIX=/yourprefix install
make PREFIX=/yourprefix install-doc

Some systems (i.e. Linux) require running

sudo ldconfig

in order for the system linker to be able to pick up newly installed
libraries.

`PREFIX` defaults to `/usr/local`. A `DESTDIR=` parameter is also
supported.

- Android NDK

See `build/android_ndk/README.AndroidNDK.txt`.



Coding conventions
------------------


### OpenMPT

(see below for an example)

- Place curly braces at the beginning of the line, not at the end
- Generally make use of the custom index types like `SAMPLEINDEX` or
`ORDERINDEX` when referring to samples, orders, etc.
- When changing playback behaviour, make sure that you use the function
`CSoundFile::IsCompatibleMode()` so that modules made with previous versions
of MPT still sound correct (if the change is extremely small, this might be
unnecessary)
- `CamelCase` function and variable names are preferred.

#### OpenMPT code example

~~~~{.cpp}
void Foo::Bar(int foobar)
{
while(true)
{
// some code
}
}
~~~~


### libopenmpt

**Note:**
**This applies to `libopenmpt/` and `openmpt123/` directories only.**
**Use OpenMPT style (see above) otherwise.**

The code generally tries to follow these conventions, but they are not
strictly enforced and there are valid reasons to diverge from these
conventions. Using common sense is recommended.

- In general, the most important thing is to keep style consistent with
directly surrounding code.
- Use C++ std types when possible, prefer `std::size_t` and `std::int32_t`
over `long` or `int`. Do not use C99 std types (e.g. no pure `int32_t`)
- Qualify namespaces explicitly, do not use `using`.
Members of `namespace openmpt` can be named without full namespace
qualification.
- Prefer the C++ version in `namespace std` if the same functionality is
provided by the C standard library as well. Also, include the C++
version of C standard library headers (e.g. use `<cstdio>` instead of
`<stdio.h>`.
- Do not use ANY locale-dependant C functions. For locale-dependant C++
functionaly (especially iostream), always imbue the
`std::locale::classic()` locale.
- Prefer kernel_style_names over CamelCaseNames.
- If a folder (or one of its parent folders) contains .clang-format,
use clang-format v3.5 for indenting C++ and C files, otherwise:
- `{` are placed at the end of the opening line.
- Enclose even single statements in curly braces.
- Avoid placing single statements on the same line as the `if`.
- Opening parentheses are separated from keywords with a space.
- Opening parentheses are not separated from function names.
- Place spaces around operators and inside parentheses.
- Align `:` and `,` when inheriting or initializing members in a
constructor.
- The pointer `*` is separated from both the type and the variable name.
- Use tabs for identation, spaces for formatting.
Tabs should only appear at the very beginning of a line.
Do not assume any particular width of the TAB character. If width is
important for formatting reasons, use spaces.
- Use empty lines at will.
- API documentation is done with doxygen.
Use general C doxygen for the C API.
Use QT-style doxygen for the C++ API.

#### libopenmpt indentation example

~~~~{.cpp}
namespace openmpt {

// This is totally meaningless code and just illustrates indentation.

class foo
: public base
, public otherbase
{

private:

std::int32_t x;
std::int16_t y;

public:

foo()
: x(0)
, y(-1)
{
return;
}

int bar() const;

}; // class foo

int foo::bar() const {

for ( int i = 0; i < 23; ++i ) {
switch ( x ) {
case 2:
something( y );
break;
default:
something( ( y - 1 ) * 2 );
break;
}
}
if ( x == 12 ) {
return -1;
} else if ( x == 42 ) {
return 1;
}
return 42;

}

} // namespace openmpt
~~~~

+ 736
- 0
Frameworks/OpenMPT/OpenMPT/common/BuildSettings.h View File

@@ -0,0 +1,736 @@
/*
* BuildSettings.h
* ---------------
* Purpose: Global, user settable compile time flags (and some global system header configuration)
* Notes : (currently none)
* Authors: OpenMPT Devs
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
*/


#pragma once



#include "CompilerDetect.h"



// set windows version early so that we can deduce dependencies from SDK version

#if MPT_OS_WINDOWS

#if defined(MPT_BUILD_MSVC)

#if defined(MPT_BUILD_TARGET_XP)

#if defined(_M_X64)
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0502 // _WIN32_WINNT_WS03
#endif
#else // !_M_X64
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0501 // _WIN32_WINNT_WINXP
#endif
#endif // _M_X64

#else // MPT_BUILD_TARGET

#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0601 // _WIN32_WINNT_WIN7
#endif

#endif // MPT_BUILD_TARGET

#else // !MPT_BUILD_MSVC

#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0501 // _WIN32_WINNT_WINXP
#endif

#endif // MPT_BUILD_MSVC

#ifndef WINVER
#define WINVER _WIN32_WINNT
#endif

#endif // MPT_OS_WINDOWS



#if defined(MODPLUG_TRACKER) && defined(LIBOPENMPT_BUILD)
#error "either MODPLUG_TRACKER or LIBOPENMPT_BUILD has to be defined"
#elif defined(MODPLUG_TRACKER)
// nothing
#elif defined(LIBOPENMPT_BUILD)
// nothing
#else
#error "either MODPLUG_TRACKER or LIBOPENMPT_BUILD has to be defined"
#endif // MODPLUG_TRACKER || LIBOPENMPT_BUILD



// wrapper for autoconf macros

#if defined(HAVE_CONFIG_H)

#include "config.h"

// Fixup dependencies which are currently not used in libopenmpt itself
#ifdef MPT_WITH_FLAC
#undef MPT_WITH_FLAC
#endif

#endif // HAVE_CONFIG_H



// Dependencies from the MSVC build system
#if defined(MPT_BUILD_MSVC)

// This section defines which dependencies are available when building with
// MSVC. Other build systems provide MPT_WITH_* macros via command-line or other
// means.
// OpenMPT and libopenmpt should compile and run successfully (albeit with
// reduced functionality) with any or all dependencies missing/disabled.
// The defaults match the bundled third-party libraries with the addition of
// ASIO and VST SDKs.

#if defined(MODPLUG_TRACKER)

// OpenMPT-only dependencies
#define MPT_WITH_ASIO
#define MPT_WITH_DSOUND
#define MPT_WITH_LHASA
#define MPT_WITH_MINIZIP
#define MPT_WITH_OPUS
#define MPT_WITH_OPUSENC
#define MPT_WITH_OPUSFILE
#define MPT_WITH_PICOJSON
#define MPT_WITH_PORTAUDIO
//#define MPT_WITH_PULSEAUDIO
//#define MPT_WITH_PULSEAUDIOSIMPLE
#define MPT_WITH_SMBPITCHSHIFT
#define MPT_WITH_UNRAR
#define MPT_WITH_VORBISENC

// OpenMPT and libopenmpt dependencies (not for openmp123, player plugins or examples)
//#define MPT_WITH_DL
#define MPT_WITH_FLAC
//#define MPT_WITH_ICONV
//#define MPT_WITH_LTDL
#if MPT_OS_WINDOWS
#if (_WIN32_WINNT >= 0x0601)
#define MPT_WITH_MEDIAFOUNDATION
#endif
#endif
//#define MPT_WITH_MINIMP3
//#define MPT_WITH_MINIZ
#define MPT_WITH_MPG123
#define MPT_WITH_OGG
//#define MPT_WITH_STBVORBIS
#define MPT_WITH_VORBIS
#define MPT_WITH_VORBISFILE
#define MPT_WITH_ZLIB

#endif // MODPLUG_TRACKER

#if defined(LIBOPENMPT_BUILD)

// OpenMPT and libopenmpt dependencies (not for openmp123, player plugins or examples)
#if defined(LIBOPENMPT_BUILD_FULL) && defined(LIBOPENMPT_BUILD_SMALL)
#error "only one of LIBOPENMPT_BUILD_FULL or LIBOPENMPT_BUILD_SMALL can be defined"
#endif // LIBOPENMPT_BUILD_FULL && LIBOPENMPT_BUILD_SMALL

#if defined(LIBOPENMPT_BUILD_FULL)

//#define MPT_WITH_DL
//#define MPT_WITH_FLAC
//#define MPT_WITH_ICONV
//#define MPT_WITH_LTDL
#if MPT_OS_WINDOWS && !MPT_OS_WINDOWS_WINRT
#if (_WIN32_WINNT >= 0x0601)
#define MPT_WITH_MEDIAFOUNDATION
#endif
#endif
//#define MPT_WITH_MINIMP3
//#define MPT_WITH_MINIZ
#define MPT_WITH_MPG123
#define MPT_WITH_OGG
//#define MPT_WITH_STBVORBIS
#define MPT_WITH_VORBIS
#define MPT_WITH_VORBISFILE
#define MPT_WITH_ZLIB

#elif defined(LIBOPENMPT_BUILD_SMALL)

//#define MPT_WITH_DL
//#define MPT_WITH_FLAC
//#define MPT_WITH_ICONV
//#define MPT_WITH_LTDL
//#define MPT_WITH_MEDIAFOUNDATION
#define MPT_WITH_MINIMP3
#define MPT_WITH_MINIZ
//#define MPT_WITH_MPG123
//#define MPT_WITH_OGG
#define MPT_WITH_STBVORBIS
//#define MPT_WITH_VORBIS
//#define MPT_WITH_VORBISFILE
//#define MPT_WITH_ZLIB

#else // !LIBOPENMPT_BUILD_SMALL

//#define MPT_WITH_DL
//#define MPT_WITH_FLAC
//#define MPT_WITH_ICONV
//#define MPT_WITH_LTDL
//#define MPT_WITH_MEDIAFOUNDATION
//#define MPT_WITH_MINIMP3
//#define MPT_WITH_MINIZ
#define MPT_WITH_MPG123
#define MPT_WITH_OGG
//#define MPT_WITH_STBVORBIS
#define MPT_WITH_VORBIS
#define MPT_WITH_VORBISFILE
#define MPT_WITH_ZLIB

#endif // LIBOPENMPT_BUILD_SMALL

#endif // LIBOPENMPT_BUILD

#endif // MPT_BUILD_MSVC



#if defined(MODPLUG_TRACKER)

// Enable built-in test suite.
#ifdef _DEBUG
#define ENABLE_TESTS
#endif

// Disable any file saving functionality (not really useful except for the player library)
//#define MODPLUG_NO_FILESAVE

// Disable any debug logging
//#define NO_LOGGING
#if !defined(_DEBUG) && !defined(MPT_BUILD_WINESUPPORT)
#define MPT_LOG_GLOBAL_LEVEL_STATIC
#define MPT_LOG_GLOBAL_LEVEL 0
#endif

// Disable all runtime asserts
#if !defined(_DEBUG) && !defined(MPT_BUILD_WINESUPPORT)
#define NO_ASSERTS
#endif

// Enable std::istream support in class FileReader (this is generally not needed for the tracker, local files can easily be mmapped as they have been before introducing std::istream support)
//#define MPT_FILEREADER_STD_ISTREAM

// Enable callback stream wrapper for FileReader (required by libopenmpt C API).
//#define MPT_FILEREADER_CALLBACK_STREAM

// Support for externally linked samples e.g. in MPTM files
#define MPT_EXTERNAL_SAMPLES

// Support mpt::ChartsetLocale
#define MPT_ENABLE_CHARSET_LOCALE

// Use inline assembly
#define ENABLE_ASM

// Disable unarchiving support
//#define NO_ARCHIVE_SUPPORT

// Disable the built-in reverb effect
//#define NO_REVERB

// Disable built-in miscellaneous DSP effects (surround, mega bass, noise reduction)
//#define NO_DSP

// Disable the built-in equalizer.
//#define NO_EQ

// Disable the built-in automatic gain control
//#define NO_AGC

// Define to build without VST plugin support; makes build possible without VST SDK.
//#define NO_VST

// Define to build without DMO plugin support
//#define NO_DMO

// (HACK) Define to build without any plugin support
//#define NO_PLUGINS

// Do not build libopenmpt C api
#define NO_LIBOPENMPT_C

// Do not build libopenmpt C++ api
#define NO_LIBOPENMPT_CXX

#endif // MODPLUG_TRACKER



#if defined(LIBOPENMPT_BUILD)

#if (defined(_DEBUG) || defined(DEBUG)) && !defined(MPT_BUILD_DEBUG)
#define MPT_BUILD_DEBUG
#endif

#if defined(LIBOPENMPT_BUILD_TEST)
#define ENABLE_TESTS
#else
#define MODPLUG_NO_FILESAVE
#endif
#if defined(MPT_BUILD_ANALZYED) || defined(MPT_BUILD_CHECKED) || defined(ENABLE_TESTS)
// enable asserts
#else
#define NO_ASSERTS
#endif
//#define NO_LOGGING
#define MPT_FILEREADER_STD_ISTREAM
#define MPT_FILEREADER_CALLBACK_STREAM
//#define MPT_EXTERNAL_SAMPLES
#if defined(ENABLE_TESTS) || defined(MPT_BUILD_HACK_ARCHIVE_SUPPORT)
#define MPT_ENABLE_CHARSET_LOCALE
#else
//#define MPT_ENABLE_CHARSET_LOCALE
#endif
// Do not use inline asm in library builds. There is just about no codepath which would use it anyway.
//#define ENABLE_ASM
#if defined(MPT_BUILD_HACK_ARCHIVE_SUPPORT)
//#define NO_ARCHIVE_SUPPORT
#else
#define NO_ARCHIVE_SUPPORT
#endif
//#define NO_REVERB
#define NO_DSP
#define NO_EQ
#define NO_AGC
#define NO_VST
//#if !MPT_OS_WINDOWS || MPT_OS_WINDOWS_WINRT || !MPT_COMPILER_MSVC || !defined(LIBOPENMPT_BUILD_FULL)
#define NO_DMO
//#endif
//#define NO_PLUGINS
//#define NO_LIBOPENMPT_C
//#define NO_LIBOPENMPT_CXX

#endif // LIBOPENMPT_BUILD



#if MPT_OS_WINDOWS

#define MPT_CHARSET_WIN32

#elif MPT_OS_LINUX

#define MPT_CHARSET_ICONV

#elif MPT_OS_ANDROID

#define MPT_CHARSET_INTERNAL

#elif MPT_OS_EMSCRIPTEN

#define MPT_CHARSET_INTERNAL
#ifndef MPT_LOCALE_ASSUME_CHARSET
#define MPT_LOCALE_ASSUME_CHARSET CharsetUTF8
#endif

#elif MPT_OS_MACOSX_OR_IOS

#if defined(MPT_WITH_ICONV)
#define MPT_CHARSET_ICONV
#ifndef MPT_ICONV_NO_WCHAR
#define MPT_ICONV_NO_WCHAR
#endif
#else
#define MPT_CHARSET_INTERNAL
#endif
//#ifndef MPT_LOCALE_ASSUME_CHARSET
//#define MPT_LOCALE_ASSUME_CHARSET CharsetUTF8
//#endif

#elif defined(MPT_WITH_ICONV)

#define MPT_CHARSET_ICONV

#endif



#if MPT_COMPILER_MSVC

// Use wide strings for MSVC because this is the native encoding on
// microsoft platforms.
#define MPT_USTRING_MODE_WIDE 1
#define MPT_USTRING_MODE_UTF8 0

#else // !MPT_COMPILER_MSVC

#define MPT_USTRING_MODE_WIDE 0
#define MPT_USTRING_MODE_UTF8 1

#endif // MPT_COMPILER_MSVC

#if MPT_USTRING_MODE_UTF8

// MPT_USTRING_MODE_UTF8 mpt::ustring is implemented via mpt::u8string
#define MPT_ENABLE_U8STRING 1

#else

#define MPT_ENABLE_U8STRING 0

#endif

#if defined(MODPLUG_TRACKER) || MPT_USTRING_MODE_WIDE

// mpt::ToWString, mpt::wfmt, ConvertStrTo<std::wstring>
// Required by the tracker to ease interfacing with WinAPI.
// Required by MPT_USTRING_MODE_WIDE to ease type tunneling in mpt::format.
#define MPT_WSTRING_FORMAT 1

#else

#define MPT_WSTRING_FORMAT 0

#endif

#if MPT_OS_WINDOWS || MPT_USTRING_MODE_WIDE || MPT_WSTRING_FORMAT

// mpt::ToWide
// Required on Windows by mpt::PathString.
// Required by MPT_USTRING_MODE_WIDE as they share the conversion functions.
// Required by MPT_WSTRING_FORMAT because of std::string<->std::wstring conversion in mpt::ToString and mpt::ToWString.
#define MPT_WSTRING_CONVERT 1

#else

#define MPT_WSTRING_CONVERT 0

#endif



// fixing stuff up

#if defined(MPT_BUILD_TARGET_XP)
// Also support Wine 1.6 in addition to Windows XP
#ifndef MPT_QUIRK_NO_CPP_THREAD
#define MPT_QUIRK_NO_CPP_THREAD
#endif
#endif

#if defined(MPT_BUILD_ANALYZED) || defined(MPT_BUILD_CHECKED)
#ifdef NO_ASSERTS
#undef NO_ASSERTS // static or dynamic analyzers want assertions on
#endif
#endif

#if defined(MPT_BUILD_FUZZER)
#ifndef MPT_FUZZ_TRACKER
#define MPT_FUZZ_TRACKER
#endif
#endif

#if !MPT_COMPILER_MSVC && defined(ENABLE_ASM)
#undef ENABLE_ASM // inline assembly requires MSVC compiler
#endif

#if defined(ENABLE_ASM)
#if MPT_COMPILER_MSVC && defined(_M_IX86)

// Generate general x86 inline assembly / intrinsics.
#define ENABLE_X86
// Generate inline assembly using MMX instructions (only used when the CPU supports it).
#define ENABLE_MMX
// Generate inline assembly using SSE instructions (only used when the CPU supports it).
#define ENABLE_SSE
// Generate inline assembly using SSE2 instructions (only used when the CPU supports it).
#define ENABLE_SSE2
// Generate inline assembly using SSE3 instructions (only used when the CPU supports it).
#define ENABLE_SSE3
// Generate inline assembly using SSE4 instructions (only used when the CPU supports it).
#define ENABLE_SSE4
// Generate inline assembly using AMD specific instruction set extensions (only used when the CPU supports it).
#define ENABLE_X86_AMD

#elif MPT_COMPILER_MSVC && defined(_M_X64)

// Generate general x64 inline assembly / intrinsics.
#define ENABLE_X64
// Generate inline assembly using SSE2 instructions (only used when the CPU supports it).
#define ENABLE_SSE2
// Generate inline assembly using SSE3 instructions (only used when the CPU supports it).
#define ENABLE_SSE3
// Generate inline assembly using SSE4 instructions (only used when the CPU supports it).
#define ENABLE_SSE4

#endif // arch
#endif // ENABLE_ASM

#if defined(MPT_WITH_MPG123) && defined(MPT_BUILD_MSVC) && defined(MPT_BUILD_MSVC_STATIC) && !MPT_OS_WINDOWS_WINRT
#define MPT_ENABLE_MPG123_DELAYLOAD
#endif

#if defined(ENABLE_TESTS) && defined(MODPLUG_NO_FILESAVE)
#undef MODPLUG_NO_FILESAVE // tests recommend file saving
#endif

#if defined(MPT_WITH_ZLIB) && defined(MPT_WITH_MINIZ)
// Only one deflate implementation should be used. Prefer zlib.
#undef MPT_WITH_MINIZ
#endif

#if !MPT_OS_WINDOWS && defined(MPT_WITH_MEDIAFOUNDATION)
#undef MPT_WITH_MEDIAFOUNDATION // MediaFoundation requires Windows
#endif

#if defined(MPT_WITH_MEDIAFOUNDATION) && !defined(MPT_ENABLE_TEMPFILE)
#define MPT_ENABLE_TEMPFILE
#endif

#if defined(MODPLUG_TRACKER) && !defined(MPT_ENABLE_TEMPFILE)
#define MPT_ENABLE_TEMPFILE
#endif

#if !defined(MPT_CHARSET_WIN32) && !defined(MPT_CHARSET_ICONV) && !defined(MPT_CHARSET_CODECVTUTF8) && !defined(MPT_CHARSET_INTERNAL)
#define MPT_CHARSET_INTERNAL
#endif

#if defined(MODPLUG_TRACKER) && !defined(MPT_ENABLE_DYNBIND)
#define MPT_ENABLE_DYNBIND // Tracker requires dynamic library loading for export codecs
#endif

#if defined(MPT_ENABLE_MPG123_DELAYLOAD) && !defined(MPT_ENABLE_DYNBIND)
#define MPT_ENABLE_DYNBIND // static MSVC builds require dynbind to load delay-loaded DLLs
#endif

#if defined(MPT_WITH_MEDIAFOUNDATION) && !defined(MPT_ENABLE_DYNBIND)
#define MPT_ENABLE_DYNBIND // MediaFoundation needs dynamic loading in order to test availability of delay loaded libs
#endif

#if (defined(MPT_WITH_MPG123) || defined(MPT_WITH_MINIMP3)) && !defined(MPT_ENABLE_MP3_SAMPLES)
#define MPT_ENABLE_MP3_SAMPLES
#endif

#if defined(ENABLE_TESTS)
#define MPT_ENABLE_FILEIO // Test suite requires PathString for file loading.
#endif

#if !MPT_OS_WINDOWS && !defined(MPT_FILEREADER_STD_ISTREAM)
#define MPT_FILEREADER_STD_ISTREAM // MMAP is only supported on Windows
#endif

#if defined(MODPLUG_TRACKER) && !defined(MPT_ENABLE_FILEIO)
#define MPT_ENABLE_FILEIO // Tracker requires disk file io
#endif

#if defined(MODPLUG_TRACKER) && !defined(MPT_ENABLE_THREAD)
#define MPT_ENABLE_THREAD // Tracker requires threads
#endif

#if defined(MPT_EXTERNAL_SAMPLES) && !defined(MPT_ENABLE_FILEIO)
#define MPT_ENABLE_FILEIO // External samples require disk file io
#endif

#if !defined(MODPLUG_NO_FILESAVE) && !defined(MPT_ENABLE_FILEIO_STDIO)
#define MPT_ENABLE_FILEIO_STDIO // file saving requires FILE*
#endif

#if defined(NO_PLUGINS)
// Any plugin type requires NO_PLUGINS to not be defined.
#define NO_VST
#define NO_DMO
#endif



#if defined(MODPLUG_TRACKER) && !defined(MPT_BUILD_WINESUPPORT) && !defined(MPT_BUILD_WINESUPPORT_WRAPPER)
#ifndef MPT_NO_NAMESPACE
#define MPT_NO_NAMESPACE
#endif
#endif

#if defined(MPT_NO_NAMESPACE)

#ifdef OPENMPT_NAMESPACE
#undef OPENMPT_NAMESPACE
#endif
#define OPENMPT_NAMESPACE

#ifdef OPENMPT_NAMESPACE_BEGIN
#undef OPENMPT_NAMESPACE_BEGIN
#endif
#define OPENMPT_NAMESPACE_BEGIN

#ifdef OPENMPT_NAMESPACE_END
#undef OPENMPT_NAMESPACE_END
#endif
#define OPENMPT_NAMESPACE_END

#else

#ifndef OPENMPT_NAMESPACE
#define OPENMPT_NAMESPACE OpenMPT
#endif

#ifndef OPENMPT_NAMESPACE_BEGIN
#define OPENMPT_NAMESPACE_BEGIN namespace OPENMPT_NAMESPACE {
#endif
#ifndef OPENMPT_NAMESPACE_END
#define OPENMPT_NAMESPACE_END }
#endif

#endif



// platform configuration

#if MPT_OS_WINDOWS

#define WIN32_LEAN_AND_MEAN

// windows.h excludes
#define NOMEMMGR // GMEM_*, LMEM_*, GHND, LHND, associated routines
#define NOMINMAX // Macros min(a,b) and max(a,b)
#define NOSERVICE // All Service Controller routines, SERVICE_ equates, etc.
#define NOCOMM // COMM driver routines
#define NOKANJI // Kanji support stuff.
#define NOPROFILER // Profiler interface.
#define NOMCX // Modem Configuration Extensions

// mmsystem.h excludes
#define MMNODRV
//#define MMNOSOUND
//#define MMNOWAVE
//#define MMNOMIDI
#define MMNOAUX
#define MMNOMIXER
//#define MMNOTIMER
#define MMNOJOY
#define MMNOMCI
//#define MMNOMMIO
//#define MMNOMMSYSTEM

// mmreg.h excludes
#define NOMMIDS
//#define NONEWWAVE
#define NONEWRIFF
#define NOJPEGDIB
#define NONEWIC
#define NOBITMAP

#endif // MPT_OS_WINDOWS



// stdlib configuration

#define __STDC_CONSTANT_MACROS
#define __STDC_LIMIT_MACROS

#define _USE_MATH_DEFINES

#if !MPT_OS_ANDROID
#ifndef _FILE_OFFSET_BITS
#define _FILE_OFFSET_BITS 64
#endif
#endif // !MPT_OS_ANDROID



// compiler configuration

#if MPT_COMPILER_MSVC

#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers

#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS // Define to disable the "This function or variable may be unsafe" warnings.
#endif
#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1
#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT 1
#ifndef _SCL_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
#endif

#ifndef NO_WARN_MBCS_MFC_DEPRECATION
#define NO_WARN_MBCS_MFC_DEPRECATION
#endif

#pragma warning(disable:4355) // 'this' : used in base member initializer list

// happens for immutable classes (i.e. classes containing const members)
#pragma warning(disable:4512) // assignment operator could not be generated

#pragma warning(error:4309) // Treat "truncation of constant value"-warning as error.

#ifdef MPT_BUILD_ANALYZED
// Disable Visual Studio static analyzer warnings that generate too many false positives in VS2010.
//#pragma warning(disable:6246)
//#pragma warning(disable:6262)
#pragma warning(disable:6326) // Potential comparison of a constant with another constant
//#pragma warning(disable:6385)
//#pragma warning(disable:6386)
#endif // MPT_BUILD_ANALYZED

#endif // MPT_COMPILER_MSVC

#if MPT_COMPILER_MSVCCLANGC2

#if MPT_OS_WINDOWS
// As Clang defines __STDC__ 1, Windows headers will use named union fields. The MediaFoundation headers do not support this, though.
// Clang supports nameless union fields just fine, and luckily there is a way to override the Windows headers behaviour.
#define _FORCENAMELESSUNION
#endif // MPT_OS_WINDOWS

#endif // MPT_COMPILER_MSVCCLANGC2



// third-party library configuration

#ifdef MPT_WITH_FLAC
#ifdef MPT_BUILD_MSVC_STATIC
#define FLAC__NO_DLL
#endif
#endif

#ifdef MPT_WITH_PICOJSON
#define PICOJSON_USE_INT64
#endif

#ifdef MPT_WITH_SMBPITCHSHIFT
#ifdef MPT_BUILD_MSVC_SHARED
#define SMBPITCHSHIFT_USE_DLL
#endif
#endif

#ifdef MPT_WITH_STBVORBIS
#define STB_VORBIS_HEADER_ONLY
#ifndef STB_VORBIS_NO_PULLDATA_API
#define STB_VORBIS_NO_PULLDATA_API
#endif
#ifndef STB_VORBIS_NO_STDIO
#define STB_VORBIS_NO_STDIO
#endif
#endif

#ifdef MPT_WITH_VORBISFILE
#ifndef OV_EXCLUDE_STATIC_CALLBACKS
#define OV_EXCLUDE_STATIC_CALLBACKS
#endif
#endif

#ifdef MPT_WITH_ZLIB
#ifdef MPT_BUILD_MSVC_SHARED
#define ZLIB_DLL
#endif
#endif


+ 367
- 0
Frameworks/OpenMPT/OpenMPT/common/CompilerDetect.h View File

@@ -0,0 +1,367 @@
/*
* CompilerDetect.h
* ----------------
* Purpose: Detect current compiler and provide readable version test macros.
* Notes : (currently none)
* Authors: OpenMPT Devs
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
*/


#pragma once



#define MPT_COMPILER_MAKE_VERSION2(version,sp) ((version) * 100 + (sp))
#define MPT_COMPILER_MAKE_VERSION3(major,minor,patch) ((major) * 10000 + (minor) * 100 + (patch))
#define MPT_COMPILER_MAKE_VERSION3_BUILD(major,minor,build) ((major) * 10000000 + (minor) * 100000 + (patch))



#if defined(MPT_COMPILER_GENERIC)

#undef MPT_COMPILER_GENERIC
#define MPT_COMPILER_GENERIC 1

#elif defined(__clang__) && defined(_MSC_VER) && defined(__c2__)

#define MPT_COMPILER_MSVCCLANGC2 1
#define MPT_COMPILER_MSVCCLANGC2_VERSION (__c2_version__)
#define MPT_MSVCCLANGC2_AT_LEAST(major,minor,build) (MPT_COMPILER_MSVCCLANGC2_VERSION >= MPT_COMPILER_MAKE_VERSION3_BUILD((major),(minor),(build)))
#define MPT_MSVCCLANGC2_BEFORE(major,minor,build) (MPT_COMPILER_MSVCCLANGC2_VERSION < MPT_COMPILER_MAKE_VERSION3_BUILD((major),(minor),(build)))

#elif defined(__clang__)

#define MPT_COMPILER_CLANG 1
#define MPT_COMPILER_CLANG_VERSION MPT_COMPILER_MAKE_VERSION3(__clang_major__,__clang_minor__,__clang_patchlevel__)
#define MPT_CLANG_AT_LEAST(major,minor,patch) (MPT_COMPILER_CLANG_VERSION >= MPT_COMPILER_MAKE_VERSION3((major),(minor),(patch)))
#define MPT_CLANG_BEFORE(major,minor,patch) (MPT_COMPILER_CLANG_VERSION < MPT_COMPILER_MAKE_VERSION3((major),(minor),(patch)))

#if MPT_CLANG_BEFORE(3,4,0)
#error "clang version 3.4 required"
#endif

#if defined(__clang_analyzer__)
#ifndef MPT_BUILD_ANALYZED
#define MPT_BUILD_ANALYZED
#endif
#endif

#elif defined(__GNUC__)

#define MPT_COMPILER_GCC 1
#define MPT_COMPILER_GCC_VERSION MPT_COMPILER_MAKE_VERSION3(__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__)
#define MPT_GCC_AT_LEAST(major,minor,patch) (MPT_COMPILER_GCC_VERSION >= MPT_COMPILER_MAKE_VERSION3((major),(minor),(patch)))
#define MPT_GCC_BEFORE(major,minor,patch) (MPT_COMPILER_GCC_VERSION < MPT_COMPILER_MAKE_VERSION3((major),(minor),(patch)))

#if MPT_GCC_BEFORE(4,8,0)
#error "GCC version 4.8 required"
#endif

#elif defined(_MSC_VER)

#define MPT_COMPILER_MSVC 1
#if (_MSC_VER >= 1912)
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2017,5)
#elif (_MSC_VER >= 1911)
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2017,3)
#elif (_MSC_VER >= 1910)
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2017,0)
#elif (_MSC_VER >= 1900)
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2015,0)
#elif (_MSC_VER >= 1800)
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2013,0)
#elif (_MSC_VER >= 1700)
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2012,0)
#elif (_MSC_VER >= 1600)
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2010,0)
#elif (_MSC_VER >= 1500)
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2008,0)
#else
#define MPT_COMPILER_MSVC_VERSION MPT_COMPILER_MAKE_VERSION2(2005,0)
#endif
#define MPT_MSVC_AT_LEAST(version,sp) (MPT_COMPILER_MSVC_VERSION >= MPT_COMPILER_MAKE_VERSION2((version),(sp)))
#define MPT_MSVC_BEFORE(version,sp) (MPT_COMPILER_MSVC_VERSION < MPT_COMPILER_MAKE_VERSION2((version),(sp)))

#if MPT_MSVC_BEFORE(2015,0)
#error "MSVC version 2015 required"
#endif

#if defined(_PREFAST_)
#ifndef MPT_BUILD_ANALYZED
#define MPT_BUILD_ANALYZED
#endif
#endif

#else

#define MPT_COMPILER_GENERIC 1

#endif



#ifndef MPT_COMPILER_GENERIC
#define MPT_COMPILER_GENERIC 0
#endif
#ifndef MPT_COMPILER_MSVCCLANGC2
#define MPT_COMPILER_MSVCCLANGC2 0
#define MPT_MSVCCLANGC2_AT_LEAST(major,minor,build) 0
#define MPT_MSVCCLANGC2_BEFORE(major,minor,build) 0
#endif
#ifndef MPT_COMPILER_CLANG
#define MPT_COMPILER_CLANG 0
#define MPT_CLANG_AT_LEAST(major,minor,patch) 0
#define MPT_CLANG_BEFORE(major,minor,patch) 0
#endif
#ifndef MPT_COMPILER_GCC
#define MPT_COMPILER_GCC 0
#define MPT_GCC_AT_LEAST(major,minor,patch) 0
#define MPT_GCC_BEFORE(major,minor,patch) 0
#endif
#ifndef MPT_COMPILER_MSVC
#define MPT_COMPILER_MSVC 0
#define MPT_MSVC_AT_LEAST(version,sp) 0
#define MPT_MSVC_BEFORE(version,sp) 0
#endif



#if MPT_COMPILER_GENERIC || MPT_COMPILER_GCC || MPT_COMPILER_CLANG

#if (__cplusplus >= 201703)
#define MPT_CXX 17
#elif (__cplusplus >= 201402)
#define MPT_CXX 14
#else
#define MPT_CXX 11
#endif

#elif MPT_COMPILER_MSVC

#if MPT_MSVC_AT_LEAST(2017,0)
#if (_MSVC_LANG >= 201402)
#define MPT_CXX 14
#else
#define MPT_CXX 11
#endif
#else
#define MPT_CXX 11
#endif

#else

#define MPT_CXX 11

#endif

// MPT_CXX is stricter than just using __cplusplus directly.
// We will only claim a language version as supported IFF all core language and
// library fatures that we need are actually supported AND working correctly
// (to our needs).

#define MPT_CXX_AT_LEAST(version) (MPT_CXX >= (version))
#define MPT_CXX_BEFORE(version) (MPT_CXX < (version))



#if MPT_COMPILER_MSVC
#define MPT_PLATFORM_LITTLE_ENDIAN
#elif MPT_COMPILER_GCC
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
#define MPT_PLATFORM_BIG_ENDIAN
#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define MPT_PLATFORM_LITTLE_ENDIAN
#endif
#elif MPT_COMPILER_CLANG || MPT_COMPILER_MSVCCLANGC2
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
#define MPT_PLATFORM_BIG_ENDIAN
#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define MPT_PLATFORM_LITTLE_ENDIAN
#endif
#endif

// fallback:
#if !defined(MPT_PLATFORM_BIG_ENDIAN) && !defined(MPT_PLATFORM_LITTLE_ENDIAN)
// taken from boost/detail/endian.hpp
#if (defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)) \
|| (defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__)) \
|| (defined(_STLP_BIG_ENDIAN) && !defined(_STLP_LITTLE_ENDIAN))
#define MPT_PLATFORM_BIG_ENDIAN
#elif (defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)) \
|| (defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)) \
|| (defined(_STLP_LITTLE_ENDIAN) && !defined(_STLP_BIG_ENDIAN))
#define MPT_PLATFORM_LITTLE_ENDIAN
#elif defined(__sparc) || defined(__sparc__) \
|| defined(_POWER) || defined(__powerpc__) \
|| defined(__ppc__) || defined(__hpux) || defined(__hppa) \
|| defined(_MIPSEB) || defined(_POWER) \
|| defined(__s390__)
#define MPT_PLATFORM_BIG_ENDIAN
#elif defined(__i386__) || defined(__alpha__) \
|| defined(__ia64) || defined(__ia64__) \
|| defined(_M_IX86) || defined(_M_IA64) \
|| defined(_M_ALPHA) || defined(__amd64) \
|| defined(__amd64__) || defined(_M_AMD64) \
|| defined(__x86_64) || defined(__x86_64__) \
|| defined(_M_X64) || defined(__bfin__)
#define MPT_PLATFORM_LITTLE_ENDIAN
#endif
#endif

#if defined(MPT_PLATFORM_BIG_ENDIAN) || defined(MPT_PLATFORM_LITTLE_ENDIAN)
#define MPT_PLATFORM_ENDIAN_KNOWN 1
#else
#define MPT_PLATFORM_ENDIAN_KNOWN 0
#endif



// This should really be based on __STDCPP_THREADS__, but that is not defined by
// GCC or clang. Stupid.
// Just assume multithreaded and disable for platforms we know are
// singlethreaded later on.
#define MPT_PLATFORM_MULTITHREADED 1



// specific C++ features



// C++11 constexpr

#if MPT_COMPILER_MSVC
#define MPT_COMPILER_QUIRK_CONSTEXPR_NO_STRING_LITERALS
#endif



#if MPT_COMPILER_MSVC
// Compiler has multiplication/division semantics when shifting signed integers.
#define MPT_COMPILER_SHIFT_SIGNED 1
#endif

#ifndef MPT_COMPILER_SHIFT_SIGNED
#define MPT_COMPILER_SHIFT_SIGNED 0
#endif



#if MPT_COMPILER_GCC || MPT_COMPILER_MSVC
// Compiler supports type-punning through unions. This is not stricly standard-conforming.
// For GCC, this is documented, for MSVC this is apparently not documented, but we assume it.
#define MPT_COMPILER_UNION_TYPE_ALIASES 1
#endif

#ifndef MPT_COMPILER_UNION_TYPE_ALIASES
// Compiler does not support type-punning through unions. std::memcpy is used instead.
// This is the safe fallback and strictly standard-conforming.
// Another standard-compliant alternative would be casting pointers to a character type pointer.
// This results in rather unreadable code and,
// in most cases, compilers generate better code by just inlining the memcpy anyway.
// (see <http://blog.regehr.org/archives/959>).
#define MPT_COMPILER_UNION_TYPE_ALIASES 0
#endif



// The order of the checks matters!
#if defined(__EMSCRIPTEN__)
#define MPT_OS_EMSCRIPTEN 1
#if defined(__EMSCRIPTEN_major__) && defined(__EMSCRIPTEN_minor__)
#if (__EMSCRIPTEN_major__ > 1)
#define MPT_OS_EMSCRIPTEN_ANCIENT 0
#elif (__EMSCRIPTEN_major__ == 1) && (__EMSCRIPTEN_minor__ >= 36)
#define MPT_OS_EMSCRIPTEN_ANCIENT 0
#else
#define MPT_OS_EMSCRIPTEN_ANCIENT 1
#endif
#else
#define MPT_OS_EMSCRIPTEN_ANCIENT 1
#endif
#elif defined(_WIN32)
#define MPT_OS_WINDOWS 1
#if defined(WINAPI_FAMILY)
#include <winapifamily.h>
#if (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)
#define MPT_OS_WINDOWS_WINRT 0
#else
#define MPT_OS_WINDOWS_WINRT 1
#endif
#else // !WINAPI_FAMILY
#define MPT_OS_WINDOWS_WINRT 0
#endif // WINAPI_FAMILY
#elif defined(__APPLE__)
#define MPT_OS_MACOSX_OR_IOS 1
//#include "TargetConditionals.h"
//#if TARGET_IPHONE_SIMULATOR
//#elif TARGET_OS_IPHONE
//#elif TARGET_OS_MAC
//#else
//#endif
#elif defined(__ANDROID__) || defined(ANDROID)
#define MPT_OS_ANDROID 1
#elif defined(__linux__)
#define MPT_OS_LINUX 1
#elif defined(__DragonFly__)
#define MPT_OS_DRAGONFLYBSD 1
#elif defined(__FreeBSD__)
#define MPT_OS_FREEBSD 1
#elif defined(__OpenBSD__)
#define MPT_OS_OPENBSD 1
#elif defined(__NetBSD__)
#define MPT_OS_NETBSD 1
#elif defined(__unix__)
#define MPT_OS_GENERIC_UNIX 1
#else
#define MPT_OS_UNKNOWN 1
#endif

#ifndef MPT_OS_EMSCRIPTEN
#define MPT_OS_EMSCRIPTEN 0
#endif
#ifndef MPT_OS_WINDOWS
#define MPT_OS_WINDOWS 0
#endif
#ifndef MPT_OS_WINDOWS_WINRT
#define MPT_OS_WINDOWS_WINRT 0
#endif
#ifndef MPT_OS_MACOSX_OR_IOS
#define MPT_OS_MACOSX_OR_IOS 0
#endif
#ifndef MPT_OS_ANDROID
#define MPT_OS_ANDROID 0
#endif
#ifndef MPT_OS_LINUX
#define MPT_OS_LINUX 0
#endif
#ifndef MPT_OS_DRAGONFLYBSD
#define MPT_OS_DRAGONFLYBSD 0
#endif
#ifndef MPT_OS_FREEBSD
#define MPT_OS_FREEBSD 0
#endif
#ifndef MPT_OS_OPENBSD
#define MPT_OS_OPENBSD 0
#endif
#ifndef MPT_OS_NETBSD
#define MPT_OS_NETBSD 0
#endif
#ifndef MPT_OS_GENERIC_UNIX
#define MPT_OS_GENERIC_UNIX 0
#endif
#ifndef MPT_OS_UNKNOWN
#define MPT_OS_UNKNOWN 0
#endif

#ifndef MPT_OS_EMSCRIPTEN_ANCIENT
#define MPT_OS_EMSCRIPTEN_ANCIENT 0
#endif



#if MPT_OS_EMSCRIPTEN
#undef MPT_PLATFORM_MULTITHREADED
#define MPT_PLATFORM_MULTITHREADED 0
#endif

+ 465
- 0
Frameworks/OpenMPT/OpenMPT/common/ComponentManager.cpp View File

@@ -0,0 +1,465 @@
/*
* ComponentManager.cpp
* --------------------
* Purpose: Manages loading of optional components.
* Notes : (currently none)
* Authors: Joern Heusipp
* OpenMPT Devs
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
*/

#include "stdafx.h"
#include "ComponentManager.h"

#include "Logging.h"

#include "mptMutex.h"

OPENMPT_NAMESPACE_BEGIN


#if defined(MPT_ENABLE_COMPONENTS)


ComponentBase::ComponentBase(ComponentType type)
: m_Type(type)
, m_Initialized(false)
, m_Available(false)
{
return;
}


ComponentBase::~ComponentBase()
{
return;
}


void ComponentBase::SetInitialized()
{
m_Initialized = true;
}


void ComponentBase::SetAvailable()
{
m_Available = true;
}


ComponentType ComponentBase::GetType() const
{
return m_Type;
}


bool ComponentBase::IsInitialized() const
{
return m_Initialized;
}


bool ComponentBase::IsAvailable() const
{
return m_Initialized && m_Available;
}


mpt::ustring ComponentBase::GetVersion() const
{
return mpt::ustring();
}


void ComponentBase::Initialize()
{
if(IsInitialized())
{
return;
}
if(DoInitialize())
{
SetAvailable();
}
SetInitialized();
}


#if defined(MPT_ENABLE_DYNBIND)


ComponentLibrary::ComponentLibrary(ComponentType type)
: ComponentBase(type)
, m_BindFailed(false)
{
return;
}


ComponentLibrary::~ComponentLibrary()
{
return;
}


bool ComponentLibrary::AddLibrary(const std::string &libName, const mpt::LibraryPath &libPath)
{
if(m_Libraries[libName].IsValid())
{
// prefer previous
return true;
}
mpt::Library lib(libPath);
if(!lib.IsValid())
{
return false;
}
m_Libraries[libName] = lib;
return true;
}


void ComponentLibrary::ClearLibraries()
{
m_Libraries.clear();
}


void ComponentLibrary::SetBindFailed()
{
m_BindFailed = true;
}


void ComponentLibrary::ClearBindFailed()
{
m_BindFailed = false;
}


bool ComponentLibrary::HasBindFailed() const
{
return m_BindFailed;
}


mpt::Library ComponentLibrary::GetLibrary(const std::string &libName) const
{
const auto it = m_Libraries.find(libName);
if(it == m_Libraries.end())
{
return mpt::Library();
}
return it->second;
}


#endif // MPT_ENABLE_DYNBIND


#if MPT_COMPONENT_MANAGER


ComponentFactoryBase::ComponentFactoryBase(const std::string &id, const std::string &settingsKey)
: m_ID(id)
, m_SettingsKey(settingsKey)
{
return;
}


ComponentFactoryBase::~ComponentFactoryBase()
{
return;
}


std::string ComponentFactoryBase::GetID() const
{
return m_ID;
}


std::string ComponentFactoryBase::GetSettingsKey() const
{
return m_SettingsKey;
}


void ComponentFactoryBase::PreConstruct() const
{
MPT_LOG(LogInformation, "Components",
mpt::format(MPT_USTRING("Constructing Component %1"))
( mpt::ToUnicode(mpt::CharsetASCII, m_ID)
)
);
}


void ComponentFactoryBase::Initialize(ComponentManager &componentManager, std::shared_ptr<IComponent> component) const
{
if(componentManager.IsComponentBlocked(GetSettingsKey()))
{
return;
}
componentManager.InitializeComponent(component);
}


// Global list of component register functions.
// We do not use a global scope static list head because the corresponding
// mutex would be no POD type and would thus not be safe to be usable in
// zero-initialized state.
// Function scope static initialization is guaranteed to be thread safe
// in C++11.
// We use this implementation to be future-proof.
// MSVC currently does not exploit the possibility of using multiple threads
// for global lifetime object's initialization.
// An implementation with a simple global list head and no mutex at all would
// thus work fine for MSVC (currently).

static mpt::mutex & ComponentListMutex()
{
static mpt::mutex g_ComponentListMutex;
return g_ComponentListMutex;
}

static ComponentListEntry * & ComponentListHead()
{
static ComponentListEntry *g_ComponentListHead = nullptr;
return g_ComponentListHead;
}

bool ComponentListPush(ComponentListEntry *entry)
{
MPT_LOCK_GUARD<mpt::mutex> guard(ComponentListMutex());
entry->next = ComponentListHead();
ComponentListHead() = entry;
return true;
}


static std::shared_ptr<ComponentManager> g_ComponentManager;


void ComponentManager::Init(const IComponentManagerSettings &settings)
{
MPT_LOG(LogInformation, "Components", MPT_USTRING("Init"));
// cannot use make_shared because the constructor is private
g_ComponentManager = std::shared_ptr<ComponentManager>(new ComponentManager(settings));
}


void ComponentManager::Release()
{
MPT_LOG(LogInformation, "Components", MPT_USTRING("Release"));
g_ComponentManager = nullptr;
}


std::shared_ptr<ComponentManager> ComponentManager::Instance()
{
return g_ComponentManager;
}


ComponentManager::ComponentManager(const IComponentManagerSettings &settings)
: m_Settings(settings)
{
MPT_LOCK_GUARD<mpt::mutex> guard(ComponentListMutex());
for(ComponentListEntry *entry = ComponentListHead(); entry; entry = entry->next)
{
entry->reg(*this);
}
}


void ComponentManager::Register(const IComponentFactory &componentFactory)
{
if(m_Components.find(componentFactory.GetID()) != m_Components.end())
{
return;
}
RegisteredComponent registeredComponent;
registeredComponent.settingsKey = componentFactory.GetSettingsKey();
registeredComponent.factoryMethod = componentFactory.GetStaticConstructor();
registeredComponent.instance = nullptr;
registeredComponent.weakInstance = std::weak_ptr<IComponent>();
m_Components.insert(std::make_pair(componentFactory.GetID(), registeredComponent));
}


void ComponentManager::Startup()
{
MPT_LOG(LogDebug, "Components", MPT_USTRING("Startup"));
if(m_Settings.LoadOnStartup())
{
for(auto &it : m_Components)
{
it.second.instance = it.second.factoryMethod(*this);
it.second.weakInstance = it.second.instance;
}
}
if(!m_Settings.KeepLoaded())
{
for(auto &it : m_Components)
{
it.second.instance = nullptr;
}
}
}


bool ComponentManager::IsComponentBlocked(const std::string &settingsKey) const
{
return m_Settings.IsBlocked(settingsKey);
}


void ComponentManager::InitializeComponent(std::shared_ptr<IComponent> component) const
{
if(!component)
{
return;
}
if(component->IsInitialized())
{
return;
}
component->Initialize();
}


std::shared_ptr<const IComponent> ComponentManager::GetComponent(const IComponentFactory &componentFactory)
{
std::shared_ptr<IComponent> component = nullptr;
auto it = m_Components.find(componentFactory.GetID());
if(it != m_Components.end())
{ // registered component
if((*it).second.instance)
{ // loaded
component = (*it).second.instance;
} else
{ // not loaded
component = (*it).second.weakInstance.lock();
if(!component)
{
component = (*it).second.factoryMethod(*this);
}
if(m_Settings.KeepLoaded())
{ // keep the component loaded
(*it).second.instance = component;
}
(*it).second.weakInstance = component;
}
} else
{ // unregistered component
component = componentFactory.Construct(*this);
}
MPT_ASSERT(component);
return component;
}


std::shared_ptr<const IComponent> ComponentManager::ReloadComponent(const IComponentFactory &componentFactory)
{
std::shared_ptr<IComponent> component = nullptr;
auto it = m_Components.find(componentFactory.GetID());
if(it != m_Components.end())
{ // registered component
if((*it).second.instance)
{ // loaded
(*it).second.instance = nullptr;
if(!(*it).second.weakInstance.expired())
{
throw std::runtime_error("Component not completely unloaded. Cannot reload.");
}
(*it).second.weakInstance = std::weak_ptr<IComponent>();
}
// not loaded
component = (*it).second.factoryMethod(*this);
if(m_Settings.KeepLoaded())
{ // keep the component loaded
(*it).second.instance = component;
}
(*it).second.weakInstance = component;
} else
{ // unregistered component
component = componentFactory.Construct(*this);
}
MPT_ASSERT(component);
return component;
}


std::vector<std::string> ComponentManager::GetRegisteredComponents() const
{
std::vector<std::string> result;
result.reserve(m_Components.size());
for(const auto &it : m_Components)
{
result.push_back(it.first);
}
return result;
}


ComponentInfo ComponentManager::GetComponentInfo(std::string name) const
{
ComponentInfo result;
result.name = name;
result.state = ComponentStateUnregistered;
result.settingsKey = "";
result.type = ComponentTypeUnknown;
const auto it = m_Components.find(name);
if(it == m_Components.end())
{
result.state = ComponentStateUnregistered;
return result;
}
result.settingsKey = it->second.settingsKey;
if(IsComponentBlocked(it->second.settingsKey))
{
result.state = ComponentStateBlocked;
return result;
}
std::shared_ptr<IComponent> component = it->second.instance;
if(!component)
{
component = it->second.weakInstance.lock();
}
if(!component)
{
result.state = ComponentStateUnintialized;
return result;
}
result.type = component->GetType();
if(!component->IsInitialized())
{
result.state = ComponentStateUnintialized;
return result;
}
if(!component->IsAvailable())
{
result.state = ComponentStateUnavailable;
return result;
}
result.state = ComponentStateAvailable;
return result;
}


mpt::PathString ComponentManager::GetComponentPath() const
{
return m_Settings.Path();
}


#endif // MPT_COMPONENT_MANAGER


#endif // MPT_ENABLE_COMPONENTS


OPENMPT_NAMESPACE_END

+ 507
- 0
Frameworks/OpenMPT/OpenMPT/common/ComponentManager.h View File

@@ -0,0 +1,507 @@
/*
* ComponentManager.h
* ------------------
* Purpose: Manages loading of optional components.
* Notes : (currently none)
* Authors: Joern Heusipp
* OpenMPT Devs
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
*/

#pragma once

#include <map>
#include <vector>
#include "../common/misc_util.h"
#include "../common/mptMutex.h"


OPENMPT_NAMESPACE_BEGIN


#define MPT_ENABLE_COMPONENTS


#if defined(MPT_ENABLE_COMPONENTS)


#if defined(MODPLUG_TRACKER)
#define MPT_COMPONENT_MANAGER 1
#else
#define MPT_COMPONENT_MANAGER 0
#endif


enum ComponentType
{
ComponentTypeUnknown = 0,
ComponentTypeBuiltin, // PortAudio
ComponentTypeSystem, // mf.dll
ComponentTypeSystemInstallable, // acm mp3 codec
ComponentTypeBundled, // libsoundtouch
ComponentTypeForeign, // libmp3lame
};


class ComponentFactoryBase;


class IComponent
{

friend class ComponentFactoryBase;

protected:

IComponent() { }

public:

virtual ~IComponent() { }

public:

virtual ComponentType GetType() const = 0;
virtual bool IsInitialized() const = 0; // Initialize() has been called
virtual bool IsAvailable() const = 0; // Initialize() has been successfull
virtual mpt::ustring GetVersion() const = 0;

virtual void Initialize() = 0; // try to load the component

};


class ComponentBase
: public IComponent
{

private:

ComponentType m_Type;

bool m_Initialized;
bool m_Available;

protected:

ComponentBase(ComponentType type);

public:

virtual ~ComponentBase();

protected:

void SetInitialized();
void SetAvailable();

public:

virtual ComponentType GetType() const;
virtual bool IsInitialized() const;
virtual bool IsAvailable() const;

virtual mpt::ustring GetVersion() const;

public:

virtual void Initialize();

protected:

virtual bool DoInitialize() = 0;

};


class ComponentBuiltin : public ComponentBase
{
public:
ComponentBuiltin()
: ComponentBase(ComponentTypeBuiltin)
{
return;
}
virtual bool DoInitialize()
{
return true;
}
};


#define MPT_GLOBAL_BIND(lib, name) name = &::name;


#if defined(MPT_ENABLE_DYNBIND)


class ComponentLibrary
: public ComponentBase
{

private:
typedef std::map<std::string, mpt::Library> TLibraryMap;
TLibraryMap m_Libraries;
bool m_BindFailed;

protected:

ComponentLibrary(ComponentType type);

public:

virtual ~ComponentLibrary();

protected:

bool AddLibrary(const std::string &libName, const mpt::LibraryPath &libPath);
void ClearLibraries();
void SetBindFailed();
void ClearBindFailed();
bool HasBindFailed() const;

public:
virtual mpt::Library GetLibrary(const std::string &libName) const;
template <typename Tfunc>
bool Bind(Tfunc * & f, const std::string &libName, const std::string &symbol) const
{
return GetLibrary(libName).Bind(f, symbol);
}

protected:

virtual bool DoInitialize() = 0;

};


#define MPT_COMPONENT_BIND(libName, func) MPT_DO { if(!Bind( func , libName , #func )) { SetBindFailed(); } } MPT_WHILE_0
#define MPT_COMPONENT_BIND_OPTIONAL(libName, func) Bind( func , libName , #func )
#define MPT_COMPONENT_BIND_SYMBOL(libName, symbol, func) MPT_DO { if(!Bind( func , libName , symbol )) { SetBindFailed(); } } MPT_WHILE_0
#define MPT_COMPONENT_BIND_SYMBOL_OPTIONAL(libName, symbol, func) Bind( func , libName , symbol )


class ComponentSystemDLL : public ComponentLibrary
{
private:
mpt::PathString m_BaseName;
public:
ComponentSystemDLL(const mpt::PathString &baseName)
: ComponentLibrary(ComponentTypeSystem)
, m_BaseName(baseName)
{
return;
}
virtual bool DoInitialize()
{
AddLibrary(m_BaseName.ToUTF8(), mpt::LibraryPath::System(m_BaseName));
return GetLibrary(m_BaseName.ToUTF8()).IsValid();
}
};


class ComponentBundledDLL : public ComponentLibrary
{
private:
mpt::PathString m_FullName;
public:
ComponentBundledDLL(const mpt::PathString &fullName)
: ComponentLibrary(ComponentTypeBundled)
, m_FullName(fullName)
{
return;
}
virtual bool DoInitialize()
{
AddLibrary(m_FullName.ToUTF8(), mpt::LibraryPath::AppFullName(m_FullName));
return GetLibrary(m_FullName.ToUTF8()).IsValid();
}
};


#endif // MPT_ENABLE_DYNBIND


#if MPT_COMPONENT_MANAGER


class ComponentManager;

typedef std::shared_ptr<IComponent> (*ComponentFactoryMethod)(ComponentManager &componentManager);


class IComponentFactory
{
protected:
IComponentFactory() { }
public:
virtual ~IComponentFactory() { }
public:
virtual std::string GetID() const = 0;
virtual std::string GetSettingsKey() const = 0;
virtual std::shared_ptr<IComponent> Construct(ComponentManager &componentManager) const = 0;
virtual ComponentFactoryMethod GetStaticConstructor() const = 0;
};


class ComponentFactoryBase
: public IComponentFactory
{
private:
std::string m_ID;
std::string m_SettingsKey;
protected:
ComponentFactoryBase(const std::string &id, const std::string &settingsKey);
void PreConstruct() const;
void Initialize(ComponentManager &componentManager, std::shared_ptr<IComponent> component) const;
public:
virtual ~ComponentFactoryBase();
virtual std::string GetID() const;
virtual std::string GetSettingsKey() const;
virtual std::shared_ptr<IComponent> Construct(ComponentManager &componentManager) const = 0;
virtual ComponentFactoryMethod GetStaticConstructor() const = 0;
};


template <typename T>
class ComponentFactory
: public ComponentFactoryBase
{
public:
ComponentFactory()
: ComponentFactoryBase(T::g_ID, T::g_SettingsKey)
{