diff --git a/assets/meson.build b/assets/meson.build index 6659aa9a..90689915 100644 --- a/assets/meson.build +++ b/assets/meson.build @@ -25,3 +25,17 @@ foreach file : embedded_assets_f ) count += 1 endforeach + +if is_libretro + global_sources += custom_target( + 'GMGSx', + input: 'GMGSx.sf2', + output: 'GMGSx.sf2.cpp', + command: [ + embedtool, + '@INPUT@', + '@OUTPUT@', + 'mkxp_gmgsx_sf2', + ], + ) +endif diff --git a/binding-sandbox/meson.build b/binding-sandbox/meson.build new file mode 100644 index 00000000..c8774726 --- /dev/null +++ b/binding-sandbox/meson.build @@ -0,0 +1,8 @@ +global_sources += files([ + 'binding-base.cpp', + 'binding-util.cpp', + 'module_rpg.cpp', + 'sandbox.cpp', + 'wasi.cpp', + 'wasm-rt.cpp', +]) diff --git a/binding-sandbox/module_rpg.cpp b/binding-sandbox/module_rpg.cpp new file mode 100644 index 00000000..add68251 --- /dev/null +++ b/binding-sandbox/module_rpg.cpp @@ -0,0 +1,3 @@ +#include "../binding/module_rpg1.rb.xxd" +#include "../binding/module_rpg2.rb.xxd" +#include "../binding/module_rpg3.rb.xxd" diff --git a/meson.build b/meson.build index e66fd106..dfa9bfb7 100644 --- a/meson.build +++ b/meson.build @@ -4,21 +4,36 @@ host_system = host_machine.system() host_endian = host_machine.endian() host_cpu_family = host_machine.cpu_family() +compilers = {'c': meson.get_compiler('c'), 'cpp': meson.get_compiler('cpp')} + is_libretro = get_option('libretro') is_emscripten = host_system == 'emscripten' -core_is_static = is_emscripten or host_system == 'bare' or host_system == 'none' +core_is_static = is_libretro and (is_emscripten or host_system == 'bare' or host_system == 'none') +is_vita = core_is_static and host_cpu_family == 'arm' and compilers['c'].has_header_symbol('sys/config.h', '__vita__') +is_devkitarm = core_is_static and host_cpu_family == 'arm' and not is_vita +is_devkitppc = core_is_static and host_cpu_family == 'ppc' + +# Position-independent code is not supported on some platforms where we need to build a static library, e.g. https://github.com/vitasdk/vita-toolchain/issues/264 +use_pic = not core_is_static if not is_libretro and host_system == 'darwin' error('This Meson project no longer supports macOS. Please use the Xcode project instead.') endif -compilers = {'c': meson.get_compiler('c'), 'cpp': meson.get_compiler('cpp')} +if is_libretro and (host_cpu_family == 'ppc' or host_cpu_family == 'ppc64') and not get_option('b_lto') and not get_option('ruby_lto') + # We get a bunch of "relocation truncated to fit" when linking if LTO isn't enabled in libretro builds due to the sizes of the files generated by wasm2c. + error('LTO is required when building for PowerPC architectures. Please pass either `-Db_lto=true` or `-Druby_lto=true` to Meson.') +endif + +embedtool = executable('embedtool', sources: 'embedtool.cpp', native: true, override_options: ['buildtype=release', 'b_coverage=false', 'b_lto=false', 'b_ndebug=false', 'b_pgo=off', 'b_sanitize=none']) global_sources = [vcs_tag(command: ['git', 'rev-parse', '--short=7', 'HEAD'], fallback: 'unknown', input: 'src/git-hash.h.in', output: 'git-hash.h')] global_dependencies = [] global_include_dirs = [] global_args = [] +global_cpp_args = [] global_link_args = [] +libretro_ruby_args = [] sizeof = {'void*': compilers['cpp'].sizeof('void*'), 'long': compilers['cpp'].sizeof('long') @@ -28,638 +43,447 @@ win64 = (sizeof['void*'] != sizeof['long']) global_args += '-DMKXPZ_BUILD_MESON' global_args += '-DMKXPZ_VERSION="@0@"'.format(meson.project_version()) global_args += '-DHAVE_NANOSLEEP' -# ==================== -# Ext libs -# ==================== if is_libretro - is_vita = core_is_static and host_cpu_family == 'arm' and compilers['c'].has_header_symbol('sys/config.h', '__vita__') - is_devkitarm = core_is_static and host_cpu_family == 'arm' and not is_vita - is_devkitppc = core_is_static and host_cpu_family == 'ppc' + global_args += '-DMKXPZ_RETRO' + global_args += '-D_FILE_OFFSET_BITS=64' +endif - embedtool = executable('embedtool', sources: 'embedtool.cpp', native: true, override_options: ['buildtype=release', 'b_coverage=false', 'b_lto=false', 'b_ndebug=false', 'b_pgo=off', 'b_sanitize=none']) +if core_is_static and not is_emscripten and get_option('b_lto') + global_args += '-ffat-lto-objects' +endif - libretro_stage1_path = get_option('libretro_stage1_path') +if is_libretro and get_option('ruby_lto') and not get_option('b_lto') + libretro_ruby_args += '-flto' + libretro_ruby_args += '-ffat-lto-objects' +endif - libretro_link_args = [] - libretro_cflags = [] - libretro_cppflags = [] - libretro_ruby_cflags = [] +if is_vita + global_args += '-mword-relocations' +endif - if core_is_static and not is_emscripten and get_option('b_lto') - compilers['c'].has_argument('-ffat-lto-objects', required: true) - compilers['cpp'].has_argument('-ffat-lto-objects', required: true) - libretro_cflags += '-ffat-lto-objects' - libretro_cppflags += '-ffat-lto-objects' +if is_devkitarm + global_args += '-march=armv6k' + global_args += '-mtune=mpcore' +endif + +if core_is_static and host_cpu_family == 'arm' + global_args += '-mfloat-abi=hard' +endif + +if host_endian == 'big' + global_args += '-DMKXPZ_BIG_ENDIAN' +endif + +if is_emscripten or not compilers['cpp'].compiles('struct E {}; int main() { throw E(); }', name: 'C++ exceptions support check') + global_args += '-DMKXPZ_NO_EXCEPTIONS' + global_args += '-DBOOST_NO_EXCEPTIONS' +endif + +if not compilers['cpp'].has_header_symbol('stdio.h', 'sprintf') + global_args += '-DMKXPZ_NO_SPRINTF' +endif + +if not compilers['cpp'].has_header_symbol('stdio.h', 'snprintf') + global_args += '-DMKXPZ_NO_SNPRINTF' +endif + +if not compilers['cpp'].has_header_symbol('stdio.h', 'vsprintf') + global_args += '-DMKXPZ_NO_VSPRINTF' +endif + +if not compilers['cpp'].has_header_symbol('stdio.h', 'vsnprintf') + global_args += '-DMKXPZ_NO_VSNPRINTF' +endif + +if not compilers['cpp'].has_header_symbol('cstdio', 'std::sprintf') + global_args += '-DMKXPZ_NO_STD_SPRINTF' +endif + +if not compilers['cpp'].has_header_symbol('cstdio', 'std::snprintf') + global_args += '-DMKXPZ_NO_STD_SNPRINTF' +endif + +if not compilers['cpp'].has_header_symbol('cstdio', 'std::vsprintf') + global_args += '-DMKXPZ_NO_STD_VSPRINTF' +endif + +if not compilers['cpp'].has_header_symbol('cstdio', 'std::vsnprintf') + global_args += '-DMKXPZ_NO_STD_VSNPRINTF' +endif + +if not compilers['cpp'].has_header_symbol('cmath', 'std::round') + global_args += '-DMKXPZ_NO_STD_ROUND' +endif + +if not compilers['cpp'].has_header_symbol('cmath', 'std::lround') + global_args += '-DMKXPZ_NO_STD_LROUND' +endif + +if not compilers['cpp'].has_header_symbol('cmath', 'std::copysign') + global_args += '-DMKXPZ_NO_STD_COPYSIGN' +endif + +if not compilers['cpp'].has_header_symbol('cmath', 'std::cbrt') + global_args += '-DMKXPZ_NO_STD_CBRT' +endif + +if not compilers['cpp'].has_header_symbol('cmath', 'std::log2') + global_args += '-DMKXPZ_NO_STD_LOG2' +endif + +if not compilers['cpp'].has_header_symbol('string', 'std::to_string') + global_args += '-DMKXPZ_NO_STD_TO_STRING' +endif + +if not compilers['cpp'].has_header_symbol('string', 'std::stoi') + global_args += '-DMKXPZ_NO_STD_STOI' +endif + +if not compilers['cpp'].has_header_symbol('string', 'std::stol') + global_args += '-DMKXPZ_NO_STD_STOL' +endif + +if not compilers['cpp'].has_header_symbol('string', 'std::stoll') + global_args += '-DMKXPZ_NO_STD_STOLL' +endif + +if not compilers['cpp'].has_header_symbol('string', 'std::stoul') + global_args += '-DMKXPZ_NO_STD_STOUL' +endif + +if not compilers['cpp'].has_header_symbol('string', 'std::stoull') + global_args += '-DMKXPZ_NO_STD_STOULL' +endif + +if not compilers['cpp'].has_header_symbol('string', 'std::stof') + global_args += '-DMKXPZ_NO_STD_STOF' +endif + +if not compilers['cpp'].has_header_symbol('string', 'std::stod') + global_args += '-DMKXPZ_NO_STD_STOD' +endif + +if not compilers['cpp'].has_header_symbol('string', 'std::stold') + global_args += '-DMKXPZ_NO_STD_STOLD' +endif + +if not compilers['cpp'].has_header_symbol('mutex', 'std::mutex') + global_args += '-DMKXPZ_NO_STD_MUTEX' + + if not compilers['cpp'].has_header_symbol('condition_variable', 'std::condition_variable_any') + global_args += '-DMKXPZ_NO_STD_CONDITION_VARIABLE_ANY' endif +endif - if get_option('ruby_lto') and not get_option('b_lto') - compilers['c'].has_argument('-flto', required: true) - compilers['c'].has_argument('-ffat-lto-objects', required: true) - libretro_ruby_cflags += '-flto' - libretro_ruby_cflags += '-ffat-lto-objects' - endif +if not compilers['cpp'].has_header_symbol('mutex', 'std::recursive_mutex') + global_args += '-DMKXPZ_NO_STD_RECURSIVE_MUTEX' +endif - if (host_cpu_family == 'ppc' or host_cpu_family == 'ppc64') and not get_option('b_lto') and not get_option('ruby_lto') - # We get a bunch of "relocation truncated to fit" when linking if LTO isn't enabled. - error('LTO is required when building for PowerPC architectures. Please pass either `-Db_lto=true` or `-Druby_lto=true` to Meson.') - endif +if not compilers['cpp'].has_header_symbol('thread', 'std::this_thread::yield') + global_args += '-DMKXPZ_NO_STD_THIS_THREAD_YIELD' +endif - if is_vita - compilers['c'].has_argument('-mword-relocations', required: true) - compilers['cpp'].has_argument('-mword-relocations', required: true) - libretro_cflags += '-mword-relocations' - libretro_cppflags += '-mword-relocations' - endif +if not compilers['cpp'].has_header('pthread.h') or not compilers['cpp'].compiles(''' + #include + int main(void) { + pthread_mutex_t mutex; + pthread_cond_t cond; + pthread_mutex_init(&mutex, NULL); + pthread_cond_init(&cond, NULL); + pthread_cond_signal(&cond); + pthread_mutex_lock(&mutex); + pthread_cond_wait(&cond, &mutex); + int result = pthread_self() != pthread_self(); + pthread_mutex_unlock(&mutex); + pthread_cond_destroy(&cond); + pthread_mutex_destroy(&mutex); + return result; + } +''', name: 'pthread.h sanity check') + global_args += '-DMKXPZ_NO_PTHREAD_H' + global_args += '-DMKXPZ_NO_SEMAPHORE_H' +elif not compilers['cpp'].has_header('semaphore.h') or not compilers['cpp'].compiles(''' + #include + int main(void) { + sem_t sem; + sem_init(&sem, 0, 0); + sem_post(&sem); + sem_wait(&sem); + sem_destroy(&sem); + return 0; + } +''', name: 'semaphore.h sanity check') + global_args += '-DMKXPZ_NO_SEMAPHORE_H' +endif - if is_devkitarm - compilers['c'].has_argument('-march=armv6k', required: true) - compilers['cpp'].has_argument('-march=armv6k', required: true) - libretro_cflags += '-march=armv6k' - libretro_cppflags += '-march=armv6k' +if compilers['cpp'].has_header_symbol('stdlib.h', 'posix_memalign') and compilers['cpp'].links(''' + #include + int main(void) { + void *mem; + return posix_memalign(&mem, 16, 4); + } +''', name: 'posix_memalign sanity check') + global_args += '-DMKXPZ_HAVE_POSIX_MEMALIGN' +elif compilers['cpp'].has_header_symbol('malloc.h', '_aligned_malloc') and compilers['cpp'].links(''' + #include + int main(void) { + void *mem = _aligned_malloc(4, 16); + _aligned_free(mem); + return mem == NULL; + } +''', name: '_aligned_malloc sanity check') + global_args += '-DMKXPZ_HAVE_ALIGNED_MALLOC' +elif compilers['cpp'].has_header_symbol('stdlib.h', 'aligned_alloc') and compilers['cpp'].links(''' + #include + int main(void) { + return aligned_alloc(16, 4) == NULL; + } +''', name: 'aligned_alloc sanity check') + global_args += '-DMKXPZ_HAVE_ALIGNED_ALLOC' +endif - compilers['c'].has_argument('-mtune=mpcore', required: true) - compilers['cpp'].has_argument('-mtune=mpcore', required: true) - libretro_cflags += '-mtune=mpcore' - libretro_cppflags += '-mtune=mpcore' - endif +if compilers['cpp'].has_header('sys/stat.h') and (not compilers['cpp'].has_header_symbol('sys/stat.h', 'lstat') or not compilers['cpp'].links(''' + #include + int main(void) { + struct stat stat; + lstat("/", &stat); + return 0; + } +''', name: 'lstat sanity check')) + global_args += '-DMKXPZ_NO_LSTAT' +endif - if host_cpu_family == 'ppc64' - if compilers['c'].has_argument('-m64') - libretro_cflags += '-m64' - endif - if compilers['cpp'].has_argument('-m64') - libretro_cppflags += '-m64' - endif - endif +# Enable integer-only mode in FLAC when building with Vita SDK. Otherwise, we get an internal compiler error in FLAC__window_triangle: +# +# ../subprojects/flac/src/libFLAC/window.c: In function 'FLAC__window_triangle': +# ../subprojects/flac/src/libFLAC/window.c:197:1: error: unrecognizable insn: +# 197 | } +# | ^ +# (insn 191 190 192 21 (set (reg:V4SF 443) +# (mult:V4SF (reg:V4SF 443) +# (reg:V4SF 444))) "../subprojects/flac/src/libFLAC/window.c":189:43 -1 +# (nil)) +# during RTL pass: vregs +# ../subprojects/flac/src/libFLAC/window.c:197:1: internal compiler error: in extract_insn, at recog.c:2294 +# Please submit a full bug report, +# with preprocessed source if appropriate. +# See for instructions. +if is_vita + global_args += '-DFLAC__INTEGER_ONLY_LIBRARY' +endif - if core_is_static and host_cpu_family == 'arm' - libretro_cflags += '-mfloat-abi=hard' - libretro_cppflags += '-mfloat-abi=hard' - endif +if is_devkitarm + global_args += '-D__DEVKITPRO__' + global_args += '-D__DEVKITARM__' +endif +if is_devkitppc + global_args += '-D__DEVKITPRO__' + global_args += '-D__DEVKITPPC__' +endif + +if is_libretro # When targeting Emscripten, we need to build a relocatable object if is_emscripten compilers['cpp'].has_link_argument('-r', required: true) - libretro_link_args += '-r' + global_link_args += '-r' endif - # We need to statically link the C++ standard library (libstdc++/libc++), the compiler runtime library (libgcc/compiler-rt) and libpthread in MSYS2 builds for Windows because those are not part of the operating system - if (host_system == 'windows' or host_system == 'cygwin') and compilers['cpp'].has_link_argument('-static') - libretro_link_args += '-static' + # We need to statically link the C++ standard library (libstdc++/libc++), the compiler runtime library (libgcc/compiler-rt) and libpthread in MSYS2 libretro builds for Windows because those are not part of the operating system + if host_system == 'windows' + global_link_args += ['-static-libgcc', '-static-libstdc++', '-Wl,-Bstatic', '-lgcc', '-lstdc++', '-lpthread', '-Wl,-Bdynamic'] endif # Android doesn't have a built-in C++ standard library, so we need to statically link against the C++ standard library if host_system == 'android' compilers['cpp'].has_link_argument('-static-libstdc++', required: true) - libretro_link_args += '-static-libstdc++' + global_link_args += '-static-libstdc++' endif # If possible, put all functions and data objects in their own sections to allow the linker to remove dead code if compilers['c'].has_argument('-ffunction-sections') - libretro_cflags += '-ffunction-sections' - endif - if compilers['cpp'].has_argument('-ffunction-sections') - libretro_cppflags += '-ffunction-sections' + global_args += '-ffunction-sections' endif if compilers['c'].has_argument('-fdata-sections') - libretro_cflags += '-fdata-sections' + global_args += '-fdata-sections' endif - if compilers['cpp'].has_argument('-fdata-sections') - libretro_cppflags += '-fdata-sections' - endif - if compilers['cpp'].has_link_argument('-Wl,--gc-sections') - libretro_link_args += '-Wl,--gc-sections' + if not core_is_static and compilers['cpp'].has_link_argument('-Wl,--gc-sections') + global_link_args += '-Wl,--gc-sections' endif # If possible, stop the linker from reexporting the symbols from the static libraries we use (e.g. zlib) - if compilers['cpp'].has_link_argument('-Wl,--version-script,' + meson.current_source_dir() / 'libretro/link.T') # Only works with GNU linker and LLVM linker - libretro_link_args += '-Wl,--version-script,' + meson.current_source_dir() / 'libretro/link.T' + if not core_is_static and compilers['cpp'].has_link_argument('-Wl,--version-script,' + meson.current_source_dir() / 'libretro/link.T') # Only works with GNU linker and LLVM linker + global_link_args += '-Wl,--version-script,' + meson.current_source_dir() / 'libretro/link.T' endif - - libretro_defines = [ - '-DMKXPZ_VERSION="@0@"'.format(meson.project_version()), - '-DMKXPZ_RETRO', - '-D_FILE_OFFSET_BITS=64', - '-DMPG123_NO_LARGENAME', - '-DGL_GLES_PROTOTYPES=0', - ] - - if host_endian == 'big' - libretro_defines += '-DMKXPZ_BIG_ENDIAN' +elif get_option('static_executable') + if host_system == 'windows' + # '-static-libgcc', '-static-libstdc++' are here to avoid needing to ship a separate libgcc_s_seh-1.dll on Windows; it still works without those flags if you have the dll. + global_link_args += ['-static-libgcc', '-static-libstdc++', '-Wl,-Bstatic', '-lgcc', '-lstdc++', '-lpthread', '-Wl,-Bdynamic'] + else + global_link_args += ['-static-libgcc', '-static-libstdc++'] endif + global_args += '-DAL_LIBTYPE_STATIC' +endif - if is_emscripten or not compilers['cpp'].compiles('struct E {}; int main() { throw E(); }', name: 'C++ exceptions support check') - libretro_defines += '-DMKXPZ_NO_EXCEPTIONS' - libretro_defines += '-DBOOST_NO_EXCEPTIONS' - endif +# ==================== +# Ext libs +# ==================== - if not compilers['cpp'].has_header_symbol('stdio.h', 'sprintf') - libretro_defines += '-DMKXPZ_NO_SPRINTF' - endif +if not is_libretro + # STEAMWORKS + steamworks = false + steamworks_path = get_option('steamworks_path') + if steamworks_path != '' + libname = 'steam_api' + if host_system == 'linux' + if sizeof['void*'] == 4 + bindir = 'linux32' + else + bindir = 'linux64' + endif + else + if win64 == true + bindir = 'win64' + libname += '64' + else + bindir = '' + endif + endif - if not compilers['cpp'].has_header_symbol('stdio.h', 'snprintf') - libretro_defines += '-DMKXPZ_NO_SNPRINTF' - endif + steam_libpath = steamworks_path + '/redistributable_bin/' + bindir + steamlib = compilers['cpp'].find_library(libname, required: false, dirs: [steam_libpath]) - if not compilers['cpp'].has_header_symbol('stdio.h', 'vsprintf') - libretro_defines += '-DMKXPZ_NO_VSPRINTF' - endif - - if not compilers['cpp'].has_header_symbol('stdio.h', 'vsnprintf') - libretro_defines += '-DMKXPZ_NO_VSNPRINTF' - endif - - if not compilers['cpp'].has_header_symbol('cstdio', 'std::sprintf') - libretro_defines += '-DMKXPZ_NO_STD_SPRINTF' - endif - - if not compilers['cpp'].has_header_symbol('cstdio', 'std::snprintf') - libretro_defines += '-DMKXPZ_NO_STD_SNPRINTF' - endif - - if not compilers['cpp'].has_header_symbol('cstdio', 'std::vsprintf') - libretro_defines += '-DMKXPZ_NO_STD_VSPRINTF' - endif - - if not compilers['cpp'].has_header_symbol('cstdio', 'std::vsnprintf') - libretro_defines += '-DMKXPZ_NO_STD_VSNPRINTF' - endif - - if not compilers['cpp'].has_header_symbol('cmath', 'std::round') - libretro_defines += '-DMKXPZ_NO_STD_ROUND' - endif - - if not compilers['cpp'].has_header_symbol('cmath', 'std::lround') - libretro_defines += '-DMKXPZ_NO_STD_LROUND' - endif - - if not compilers['cpp'].has_header_symbol('cmath', 'std::copysign') - libretro_defines += '-DMKXPZ_NO_STD_COPYSIGN' - endif - - if not compilers['cpp'].has_header_symbol('cmath', 'std::cbrt') - libretro_defines += '-DMKXPZ_NO_STD_CBRT' - endif - - if not compilers['cpp'].has_header_symbol('cmath', 'std::log2') - libretro_defines += '-DMKXPZ_NO_STD_LOG2' - endif - - if not compilers['cpp'].has_header_symbol('string', 'std::to_string') - libretro_defines += '-DMKXPZ_NO_STD_TO_STRING' - endif - - if not compilers['cpp'].has_header_symbol('string', 'std::stoi') - libretro_defines += '-DMKXPZ_NO_STD_STOI' - endif - - if not compilers['cpp'].has_header_symbol('string', 'std::stol') - libretro_defines += '-DMKXPZ_NO_STD_STOL' - endif - - if not compilers['cpp'].has_header_symbol('string', 'std::stoll') - libretro_defines += '-DMKXPZ_NO_STD_STOLL' - endif - - if not compilers['cpp'].has_header_symbol('string', 'std::stoul') - libretro_defines += '-DMKXPZ_NO_STD_STOUL' - endif - - if not compilers['cpp'].has_header_symbol('string', 'std::stoull') - libretro_defines += '-DMKXPZ_NO_STD_STOULL' - endif - - if not compilers['cpp'].has_header_symbol('string', 'std::stof') - libretro_defines += '-DMKXPZ_NO_STD_STOF' - endif - - if not compilers['cpp'].has_header_symbol('string', 'std::stod') - libretro_defines += '-DMKXPZ_NO_STD_STOD' - endif - - if not compilers['cpp'].has_header_symbol('string', 'std::stold') - libretro_defines += '-DMKXPZ_NO_STD_STOLD' - endif - - if not compilers['cpp'].has_header_symbol('mutex', 'std::mutex') - libretro_defines += '-DMKXPZ_NO_STD_MUTEX' - - if not compilers['cpp'].has_header_symbol('condition_variable', 'std::condition_variable_any') - libretro_defines += '-DMKXPZ_NO_STD_CONDITION_VARIABLE_ANY' + if steamlib.found() == true + global_include_dirs += include_directories('steamshim') + global_args += '-DMKXPZ_STEAM' + global_sources += 'steamshim/steamshim_child.c' + steamworks = true endif endif - if not compilers['cpp'].has_header_symbol('mutex', 'std::recursive_mutex') - libretro_defines += '-DMKXPZ_NO_STD_RECURSIVE_MUTEX' + # GLES + gfx_backend = get_option('gfx_backend') + if gfx_backend == 'gles' + # Needs to be manually set up for now + global_args += '-DGLES2_HEADER' + elif gfx_backend == 'gl' + global_dependencies += dependency('gl') + # boop + endif +endif + +# ==================== +# Main source +# ==================== + +# Suppress warnings +global_cpp_args += ['-Wno-non-virtual-dtor', '-Wno-reorder'] +global_args += ['-Wno-uninitialized', '-Wno-unknown-pragmas', '-Wno-stringop-truncation'] +if compilers['cpp'].get_id() == 'clang' + global_args += ['-Wno-undefined-var-template', '-Wno-delete-non-abstract-non-virtual-dtor'] +endif +if host_system == 'windows' + if compilers['cpp'].get_id() != 'clang' + global_args += '-masm=intel' + endif +endif + +if not is_libretro + # Decide whether or not to use MiniFFI + miniffi = get_option('use_miniffi') + if miniffi == true + miniffi = true + global_args += '-DMKXPZ_MINIFFI' endif - if not compilers['cpp'].has_header_symbol('thread', 'std::this_thread::yield') - libretro_defines += '-DMKXPZ_NO_STD_THIS_THREAD_YIELD' + # Defines + if get_option('workdir_current') + global_args += '-DWORKDIR_CURRENT' endif - if not compilers['cpp'].has_header('pthread.h') or not compilers['cpp'].compiles(''' - #include - int main() { - pthread_mutex_t mutex; - pthread_cond_t cond; - pthread_mutex_init(&mutex, NULL); - pthread_cond_init(&cond, NULL); - pthread_cond_signal(&cond); - pthread_mutex_lock(&mutex); - pthread_cond_wait(&cond, &mutex); - int result = pthread_self() != pthread_self(); - pthread_mutex_unlock(&mutex); - pthread_cond_destroy(&cond); - pthread_mutex_destroy(&mutex); - return result; - } - ''', name: 'pthread.h sanity check') - libretro_defines += '-DMKXPZ_NO_PTHREAD_H' - libretro_defines += '-DMKXPZ_NO_SEMAPHORE_H' - elif not compilers['cpp'].has_header('semaphore.h') or not compilers['cpp'].compiles(''' - #include - int main() { - sem_t sem; - sem_init(&sem, 0, 0); - sem_post(&sem); - sem_wait(&sem); - sem_destroy(&sem); - return 0; - } - ''', name: 'semaphore.h sanity check') - libretro_defines += '-DMKXPZ_NO_SEMAPHORE_H' + if get_option('cxx11_experimental') == true + global_args += '-DMKXPZ_EXP_FS' endif - if compilers['cpp'].has_header_symbol('stdlib.h', 'posix_memalign') and compilers['cpp'].links(''' - #include - int main() { - void *mem; - return posix_memalign(&mem, 16, 4); - } - ''', name: 'posix_memalign sanity check') - libretro_defines += '-DMKXPZ_HAVE_POSIX_MEMALIGN' - elif compilers['cpp'].has_header_symbol('malloc.h', '_aligned_malloc') and compilers['cpp'].links(''' - #include - int main() { - void *mem = _aligned_malloc(4, 16); - _aligned_free(mem); - return mem == NULL; - } - ''', name: '_aligned_malloc sanity check') - libretro_defines += '-DMKXPZ_HAVE_ALIGNED_MALLOC' - elif compilers['cpp'].has_header_symbol('stdlib.h', 'aligned_alloc') and compilers['cpp'].links(''' - #include - int main() { - return aligned_alloc(16, 4) == NULL; - } - ''', name: 'aligned_alloc sanity check') - libretro_defines += '-DMKXPZ_HAVE_ALIGNED_ALLOC' + if get_option('force32') == true + global_args += '-m32' endif - if compilers['cpp'].has_header('sys/stat.h') and (not compilers['cpp'].has_header_symbol('sys/stat.h', 'lstat') or not compilers['cpp'].links(''' - #include - int main() { - struct stat stat; - lstat("/", &stat); - return 0; - } - ''', name: 'lstat sanity check')) - libretro_defines += '-DMKXPZ_NO_LSTAT' + build_static = false + if get_option('static_executable') == true + build_static = true endif - # Enable integer-only mode in FLAC when building with Vita SDK. Otherwise, we get an internal compiler error in FLAC__window_triangle: - # - # ../subprojects/flac/src/libFLAC/window.c: In function 'FLAC__window_triangle': - # ../subprojects/flac/src/libFLAC/window.c:197:1: error: unrecognizable insn: - # 197 | } - # | ^ - # (insn 191 190 192 21 (set (reg:V4SF 443) - # (mult:V4SF (reg:V4SF 443) - # (reg:V4SF 444))) "../subprojects/flac/src/libFLAC/window.c":189:43 -1 - # (nil)) - # during RTL pass: vregs - # ../subprojects/flac/src/libFLAC/window.c:197:1: internal compiler error: in extract_insn, at recog.c:2294 - # Please submit a full bug report, - # with preprocessed source if appropriate. - # See for instructions. - if is_vita - libretro_defines += '-DFLAC__INTEGER_ONLY_LIBRARY' - endif + global_args += '-DMKXPZ_INIT_GL_LATER' +endif - if is_devkitarm - libretro_defines += '-D__DEVKITPRO__' - libretro_defines += '-D__DEVKITARM__' - endif +subdir('src') +subdir(is_libretro ? 'binding-sandbox' : 'binding') +subdir('shader') +subdir('assets') - if is_devkitppc - libretro_defines += '-D__DEVKITPRO__' - libretro_defines += '-D__DEVKITPPC__' - endif +global_include_dirs += include_directories('src', 'binding') +if is_libretro + global_include_dirs += include_directories('binding-sandbox') +endif - # Position-independent code is not supported on some platforms where we need to build a static library, e.g. https://github.com/vitasdk/vita-toolchain/issues/264 - use_pic = not core_is_static +if is_libretro + libretro_stage1_path = get_option('libretro_stage1_path') - subdir('shader') - subdir('assets') + libretro_ruby_sources = [] + foreach i : range(8) + libretro_ruby_sources += libretro_stage1_path / 'mkxp-retro-ruby/mkxp-retro-ruby_@0@.c'.format(i) + endforeach - cmake = import('cmake') - - boost_options = cmake.subproject_options() - boost_options.add_cmake_defines({ - 'CMAKE_POLICY_VERSION_MINIMUM': '3.10', - 'CMAKE_C_FLAGS': ' '.join(libretro_defines + libretro_cflags), - 'CMAKE_CXX_FLAGS': ' '.join(libretro_defines + libretro_cppflags), - 'CMAKE_POSITION_INDEPENDENT_CODE': use_pic, - 'BUILD_TESTING': false, - }) - - zlib_options = cmake.subproject_options() - zlib_options.add_cmake_defines({ - 'CMAKE_POLICY_VERSION_MINIMUM': '3.10', - 'CMAKE_C_FLAGS': ' '.join(libretro_defines + libretro_cflags), - 'CMAKE_CXX_FLAGS': ' '.join(libretro_defines + libretro_cppflags), - 'CMAKE_POSITION_INDEPENDENT_CODE': use_pic, - 'BUILD_SHARED_LIBS': false, - 'ZLIB_BUILD_EXAMPLES': false, - }) - - physfs_options = cmake.subproject_options() - physfs_options.add_cmake_defines({ - 'CMAKE_POLICY_VERSION_MINIMUM': '3.10', - 'CMAKE_C_FLAGS': ' '.join(libretro_defines + libretro_cflags), - 'CMAKE_CXX_FLAGS': ' '.join(libretro_defines + libretro_cppflags), - 'CMAKE_POSITION_INDEPENDENT_CODE': use_pic, - 'PHYSFS_BUILD_STATIC': true, - 'PHYSFS_BUILD_SHARED': false, - 'PHYSFS_BUILD_TEST': false, - 'PHYSFS_BUILD_DOCS': false, - }) - - openal_options = cmake.subproject_options() - openal_options.add_cmake_defines({ - 'CMAKE_POLICY_VERSION_MINIMUM': '3.10', - 'CMAKE_C_FLAGS': ' '.join(libretro_defines + libretro_cflags), - 'CMAKE_CXX_FLAGS': ' '.join(libretro_defines + libretro_cppflags), - 'CMAKE_POSITION_INDEPENDENT_CODE': use_pic, - 'LIBTYPE': 'STATIC', - 'ALSOFT_DLOPEN': false, - 'ALSOFT_UTILS': false, - 'ALSOFT_NO_CONFIG_UTIL': true, - 'ALSOFT_EXAMPLES': false, - 'ALSOFT_UPDATE_BUILD_VERSION': false, - 'ALSOFT_EMBED_HRTF_DATA': false, - 'ALSOFT_RTKIT': false, - 'ALSOFT_BACKEND_PIPEWIRE': false, - 'ALSOFT_BACKEND_PULSEAUDIO': false, - 'ALSOFT_BACKEND_ALSA': false, - 'ALSOFT_BACKEND_OSS': false, - 'ALSOFT_BACKEND_SOLARIS': false, - 'ALSOFT_BACKEND_SNDIO': false, - 'ALSOFT_BACKEND_WINMM': false, - 'ALSOFT_BACKEND_DSOUND': false, - 'ALSOFT_BACKEND_WASAPI': false, - 'ALSOFT_BACKEND_OTHERIO': false, - 'ALSOFT_BACKEND_JACK': false, - 'ALSOFT_BACKEND_COREAUDIO': false, - 'ALSOFT_BACKEND_OBOE': false, - 'ALSOFT_BACKEND_OPENSL': false, - 'ALSOFT_BACKEND_PORTAUDIO': false, - 'ALSOFT_BACKEND_SDL3': false, - 'ALSOFT_BACKEND_SDL2': false, - 'ALSOFT_BACKEND_WAVE': false, - }) - - fluidsynth_options = cmake.subproject_options() - fluidsynth_options.add_cmake_defines({ - 'CMAKE_POLICY_VERSION_MINIMUM': '3.10', - 'CMAKE_C_FLAGS': ' '.join(libretro_defines + libretro_cflags), - 'CMAKE_CXX_FLAGS': ' '.join(libretro_defines + libretro_cppflags), - 'CMAKE_POSITION_INDEPENDENT_CODE': use_pic, - 'BUILD_SHARED_LIBS': false, - 'enable-aufile': false, - 'enable-dbus': false, - 'enable-ipv6 ': false, - 'enable-jack': false, - 'enable-ladspa': false, - 'enable-libinstpatch': false, - 'enable-libsndfile': false, - 'enable-midishare': false, - 'enable-opensles': false, - 'enable-oboe': false, - 'enable-network': false, - 'enable-oss': false, - 'enable-dsound': false, - 'enable-waveout': false, - 'enable-winmidi': false, - 'enable-sdl2': false, - 'enable-pkgconfig': false, - 'enable-pulseaudio': false, - 'enable-readline': false, - 'enable-threads': false, - 'enable-lash': false, - 'enable-alsa': false, - 'enable-systemd': false, - 'enable-coreaudio': false, - 'enable-coremidi': false, - 'enable-framework': false, - 'enable-dart': false, - }) - - ogg_options = cmake.subproject_options() - ogg_options.add_cmake_defines({ - 'CMAKE_POLICY_VERSION_MINIMUM': '3.10', - 'CMAKE_C_FLAGS': ' '.join(libretro_defines + libretro_cflags), - 'CMAKE_CXX_FLAGS': ' '.join(libretro_defines + libretro_cppflags), - 'CMAKE_POSITION_INDEPENDENT_CODE': use_pic, - 'BUILD_SHARED_LIBS': false, - 'BUILD_TESTING': false, - 'BUILD_FRAMEWORK': false, - }) - - vorbis_options = cmake.subproject_options() - vorbis_options.add_cmake_defines({ - 'CMAKE_POLICY_VERSION_MINIMUM': '3.10', - 'CMAKE_C_FLAGS': ' '.join(libretro_defines + libretro_cflags), - 'CMAKE_CXX_FLAGS': ' '.join(libretro_defines + libretro_cppflags), - 'CMAKE_POSITION_INDEPENDENT_CODE': use_pic, - 'BUILD_SHARED_LIBS': false, - 'BUILD_TESTING': false, - 'BUILD_FRAMEWORK': false, - }) - - flac_options = cmake.subproject_options() - flac_options.add_cmake_defines({ - 'CMAKE_POLICY_VERSION_MINIMUM': '3.10', - 'CMAKE_C_FLAGS': ' '.join(libretro_defines + libretro_cflags), - 'CMAKE_CXX_FLAGS': ' '.join(libretro_defines + libretro_cppflags), - 'CMAKE_POSITION_INDEPENDENT_CODE': use_pic, - 'BUILD_SHARED_LIBS': false, - 'BUILD_CXXLIBS': false, - 'BUILD_PROGRAMS': false, - 'BUILD_EXAMPLES': false, - 'BUILD_TESTING': false, - 'BUILD_DOCS': false, - 'BUILD_UTILS': false, - 'ENABLE_MULTITHREADING': false, - 'INSTALL_MANPAGES': false, - 'WITH_OGG': false, - 'WITH_FORTIFY_SOURCE': false, - 'WITH_STACK_PROTECTOR': false, - }) - - opus_options = cmake.subproject_options() - opus_options.add_cmake_defines({ - 'CMAKE_POLICY_VERSION_MINIMUM': '3.10', - 'CMAKE_C_FLAGS': ' '.join(libretro_defines + libretro_cflags), - 'CMAKE_CXX_FLAGS': ' '.join(libretro_defines + libretro_cppflags), - 'CMAKE_POSITION_INDEPENDENT_CODE': use_pic, - 'BUILD_SHARED_LIBS': false, - 'OPUS_BUILD_SHARED_LIBRARY': false, - 'OPUS_BUILD_TESTING': false, - 'OPUS_CUSTOM_MODES': false, - 'OPUS_BUILD_PROGRAMS': false, - 'OPUS_DISABLE_INTRINSICS': true, - 'OPUS_FLOAT_APPROX': false, - 'OPUS_BUILD_FRAMEWORK': false, - 'OPUS_STATIC_RUNTIME': false, - 'OPUS_FORTIFY_SOURCE': false, - 'OPUS_STACK_PROTECTOR': false, - }) - - mpg123_options = cmake.subproject_options() - mpg123_options.add_cmake_defines({ - 'CMAKE_POLICY_VERSION_MINIMUM': '3.10', - 'CMAKE_C_FLAGS': ' '.join(libretro_defines + libretro_cflags), - 'CMAKE_CXX_FLAGS': ' '.join(libretro_defines + libretro_cppflags), - 'CMAKE_POSITION_INDEPENDENT_CODE': use_pic, - 'BUILD_SHARED_LIBS': false, - 'BUILD_PROGRAMS': false, - 'BUILD_LIBOUT123': false, - 'CHECK_MODULES': false, - 'FIFO': false, - }) - - libsndfile_options = cmake.subproject_options() - libsndfile_options.add_cmake_defines({ - 'CMAKE_POLICY_VERSION_MINIMUM': '3.10', - 'CMAKE_C_FLAGS': ' '.join(libretro_defines + libretro_cflags), - 'CMAKE_CXX_FLAGS': ' '.join(libretro_defines + libretro_cppflags), - 'CMAKE_POSITION_INDEPENDENT_CODE': use_pic, - 'BUILD_SHARED_LIBS': false, - 'BUILD_PROGRAMS': false, - 'BUILD_EXAMPLES': false, - 'BUILD_REGTEST': false, - 'BUILD_TESTING': false, - 'ENABLE_CPACK': false, - 'ENABLE_PACKAGE_CONFIG': false, - 'INSTALL_PKGCONFIG_MODULE': false, - 'ENABLE_EXTERNAL_LIBS': true, - 'ENABLE_MPEG': true, - 'ENABLE_EXPERIMENTAL': false, - }) - - pixman_region_options = cmake.subproject_options() - pixman_region_options.add_cmake_defines({ - 'CMAKE_POLICY_VERSION_MINIMUM': '3.10', - 'CMAKE_C_FLAGS': ' '.join(libretro_defines + libretro_cflags), - 'CMAKE_CXX_FLAGS': ' '.join(libretro_defines + libretro_cppflags), - 'CMAKE_POSITION_INDEPENDENT_CODE': use_pic, - 'CMAKE_BUILD_TYPE': 'None', - }) - - freetype_options = [ - 'cflags=@0@'.format(','.join(libretro_defines + libretro_cflags)), - 'cppflags=@0@'.format(','.join(libretro_defines + libretro_cppflags)), - 'default_library=static', - 'b_staticpic=@0@'.format(use_pic), - 'brotli=disabled', - 'bzip2=disabled', - 'harfbuzz=disabled', - 'mmap=disabled', - 'png=disabled', - 'tests=disabled', - 'zlib=disabled', - ] - - libretro_deps = [ - subproject('libretro-common').get_variable('libretro_common'), - cmake.subproject('boost_asio', options: boost_options).dependency('boost_asio'), - cmake.subproject('boost_mp11', options: boost_options).dependency('boost_mp11'), - cmake.subproject('boost_describe', options: boost_options).dependency('boost_describe'), - cmake.subproject('boost_config', options: boost_options).dependency('boost_config'), - cmake.subproject('boost_assert', options: boost_options).dependency('boost_assert'), - cmake.subproject('boost_static_assert', options: boost_options).dependency('boost_static_assert'), - cmake.subproject('boost_throw_exception', options: boost_options).dependency('boost_throw_exception'), - cmake.subproject('boost_core', options: boost_options).dependency('boost_core'), - cmake.subproject('boost_container_hash', options: boost_options).dependency('boost_container_hash'), - cmake.subproject('boost_type_index', options: boost_options).dependency('boost_type_index'), - cmake.subproject('boost_type_traits', options: boost_options).dependency('boost_type_traits'), - cmake.subproject('boost_optional', options: boost_options).dependency('boost_optional'), - cmake.subproject(host_system == 'darwin' ? 'zlib-darwin' : 'zlib', options: zlib_options).dependency('zlibstatic'), - cmake.subproject('physfs', options: physfs_options).dependency('physfs-static'), - cmake.subproject('openal-soft', options: openal_options).dependency('OpenAL'), - cmake.subproject('openal-soft', options: openal_options).dependency('alsoft.fmt'), - cmake.subproject('fluidsynth', options: fluidsynth_options).dependency('libfluidsynth'), - cmake.subproject('ogg', options: ogg_options).dependency('ogg'), - cmake.subproject('vorbis', options: vorbis_options).dependency('vorbis'), - cmake.subproject('vorbis', options: vorbis_options).dependency('vorbisfile'), - cmake.subproject('flac', options: flac_options).dependency('FLAC'), - cmake.subproject('opus', options: opus_options).dependency('opus'), - cmake.subproject('mpg123', options: mpg123_options).dependency('libmpg123'), - cmake.subproject('mpg123', options: mpg123_options).dependency('compat'), - cmake.subproject('libsndfile', options: libsndfile_options).dependency('sndfile'), - cmake.subproject('pixman-region', options: pixman_region_options).dependency('pixman-region'), - subproject('stb').get_variable('stb'), - subproject('opengl-registry').get_variable('opengl_registry'), - subproject('freetype', default_options: freetype_options).get_variable('freetype_dep'), - declare_dependency( - link_with: static_library( - 'ruby', - c_args: libretro_cflags + libretro_ruby_cflags + libretro_defines + [ - '-frounding-math', - '-fsignaling-nans', - '-Wno-unused-function', - '-Wno-unused-value', - '-Wno-unused-variable', - '-Wno-unused-but-set-variable', - ], - include_directories: [ - include_directories('binding-sandbox'), - include_directories(libretro_stage1_path), - include_directories(libretro_stage1_path / 'mkxp-retro-ruby'), - ], - sources: [ - libretro_stage1_path / 'mkxp-retro-ruby/mkxp-retro-ruby_0.c', - libretro_stage1_path / 'mkxp-retro-ruby/mkxp-retro-ruby_1.c', - libretro_stage1_path / 'mkxp-retro-ruby/mkxp-retro-ruby_2.c', - libretro_stage1_path / 'mkxp-retro-ruby/mkxp-retro-ruby_3.c', - libretro_stage1_path / 'mkxp-retro-ruby/mkxp-retro-ruby_4.c', - libretro_stage1_path / 'mkxp-retro-ruby/mkxp-retro-ruby_5.c', - libretro_stage1_path / 'mkxp-retro-ruby/mkxp-retro-ruby_6.c', - libretro_stage1_path / 'mkxp-retro-ruby/mkxp-retro-ruby_7.c', - ], - gnu_symbol_visibility: 'hidden', - install: false, - pic: use_pic, - ), + global_dependencies += declare_dependency( + link_with: static_library( + 'ruby', + c_args: global_args + libretro_ruby_args + [ + '-frounding-math', + '-fsignaling-nans', + '-Wno-unused-function', + '-Wno-unused-value', + '-Wno-unused-variable', + '-Wno-unused-but-set-variable', + ], include_directories: [ + include_directories('binding-sandbox'), include_directories(libretro_stage1_path), include_directories(libretro_stage1_path / 'mkxp-retro-ruby'), ], + sources: libretro_ruby_sources, + gnu_symbol_visibility: 'hidden', + install: false, + pic: use_pic, ), - ] - if host_system == 'darwin' - libretro_deps += compilers['cpp'].find_library('iconv') - endif + include_directories: [ + include_directories(libretro_stage1_path), + include_directories(libretro_stage1_path / 'mkxp-retro-ruby'), + ], + ) + + global_sources += libretro_stage1_path / 'mkxp-sandbox-bindgen.cpp' + + global_sources += custom_target( + 'mkxp-retro-dist', + input: libretro_stage1_path / 'mkxp-retro-dist.zip', + output: 'mkxp-retro-dist.zip.cpp', + command: [ + embedtool, + '@INPUT@', + '@OUTPUT@', + 'mkxp_retro_dist_zip', + ], + ) if core_is_static - libretro_deps_processed = [] - foreach dep : libretro_deps - libretro_deps_processed += dep.as_link_whole() + global_dependencies_processed = [] + foreach dep : global_dependencies + global_dependencies_processed += dep.as_link_whole() endforeach else - libretro_deps_processed = libretro_deps + global_dependencies_processed = global_dependencies endif if is_emscripten @@ -675,278 +499,88 @@ if is_libretro name_prefix: '', name_suffix: is_emscripten ? 'bc' : [], target_type: libretro_target_type, - dependencies: libretro_deps_processed, - c_args: libretro_cflags + libretro_defines, - cpp_args: libretro_cppflags + libretro_defines, - link_args: libretro_link_args, + dependencies: global_dependencies_processed, + c_args: global_args, + cpp_args: global_args + global_cpp_args, + link_args: global_link_args, pic: use_pic, gnu_symbol_visibility: 'hidden', install: true, # Prevents Meson from creating thin archives; see https://github.com/mesonbuild/meson/issues/9479 - include_directories: [ - include_directories('.'), - include_directories('binding-sandbox'), - include_directories('src'), - include_directories('src/audio'), - include_directories('src/crypto'), - include_directories('src/display'), - include_directories('src/display/gl'), - include_directories('src/display/libnsgif'), - include_directories('src/display/libnsgif/utils'), - include_directories('src/etc'), - include_directories('src/filesystem'), - include_directories('src/filesystem/ghc'), - include_directories('src/input'), - include_directories('src/net'), - include_directories('src/system'), - include_directories('src/util'), - include_directories('src/util/sigslot'), - include_directories('src/util/sigslot/adapter'), - ], - sources: global_sources + [ - 'src/core.cpp', - 'src/mkxp-polyfill.cpp', - 'src/sharedstate.cpp', - 'src/stb_image.cpp', - 'src/stb_snprintf.cpp', - 'src/audio/alstream.cpp', - 'src/audio/audio.cpp', - 'src/audio/audiostream.cpp', - 'src/audio/fluid-fun.cpp', - 'src/audio/midisource.cpp', - 'src/audio/sndfilesource.cpp', - 'src/audio/soundemitter.cpp', - 'src/audio/vorbissource.cpp', - 'src/crypto/rgssad.cpp', - 'src/display/autotiles.cpp', - 'src/display/bitmap.cpp', - 'src/display/font.cpp', - 'src/display/plane.cpp', - 'src/display/sprite.cpp', - 'src/display/tilemap.cpp', - 'src/display/viewport.cpp', - 'src/display/window.cpp', - 'src/display/gl/gl-debug.cpp', - 'src/display/gl/gl-fun.cpp', - 'src/display/gl/gl-meta.cpp', - 'src/display/gl/glstate.cpp', - 'src/display/gl/scene.cpp', - 'src/display/gl/shader.cpp', - 'src/display/gl/texpool.cpp', - 'src/display/gl/tileatlas.cpp', - 'src/display/gl/tilequad.cpp', - 'src/display/gl/vertex.cpp', - 'src/display/graphics.cpp', - 'src/etc/etc.cpp', - 'src/etc/table.cpp', - 'src/filesystem/filesystem.cpp', - 'src/input/input-retro.cpp', - 'binding-sandbox/binding-base.cpp', - 'binding-sandbox/binding-util.cpp', - 'binding-sandbox/sandbox.cpp', - 'binding-sandbox/wasi.cpp', - 'binding-sandbox/wasm-rt.cpp', - 'binding/module_rpg.cpp', - libretro_stage1_path / 'mkxp-sandbox-bindgen.cpp', - custom_target( - 'GMGSx', - input: 'assets/GMGSx.sf2', - output: 'GMGSx.sf2.cpp', - command: [ - embedtool, - '@INPUT@', - '@OUTPUT@', - 'mkxp_gmgsx_sf2', - ], - ), - custom_target( - 'mkxp-retro-dist', - input: libretro_stage1_path / 'mkxp-retro-dist.zip', - output: 'mkxp-retro-dist.zip.cpp', - command: [ - embedtool, - '@INPUT@', - '@OUTPUT@', - 'mkxp_retro_dist_zip', - ], - ), - ], + include_directories: global_include_dirs, + sources: global_sources, ) else + rpath = '' -if host_endian == 'big' - global_args += '-DMKXPZ_BIG_ENDIAN' -endif -if is_emscripten or not compilers['cpp'].compiles('struct E {}; int main() { throw E(); }', name: 'check if C++ exceptions are enabled') - libretro_defines += '-DMKXPZ_NO_EXCEPTIONS' - libretro_defines += '-DBOOST_NO_EXCEPTIONS' -endif - -# STEAMWORKS - -steamworks = false -steamworks_path = get_option('steamworks_path') -if steamworks_path != '' - libname = 'steam_api' - if host_system == 'linux' - if sizeof['void*'] == 4 - bindir = 'linux32' - else - bindir = 'linux64' - endif + if host_system == 'windows' + windows_resource_directory = '../' + get_option('windows_resource_directory') + subdir('windows') + global_sources += windows_resources + global_include_dirs += include_directories('windows') else - if win64 == true - bindir = 'win64' - libname += '64' - else - bindir = '' + subdir('linux') + rpath = '$ORIGIN/lib' + if get_option('appimage') != true + if sizeof['long'] == 8 and get_option('force32') != true + rpath += '64' + else + rpath += '32' + endif endif endif - steam_libpath = steamworks_path + '/redistributable_bin/' + bindir - steamlib = compilers['cpp'].find_library(libname, required: false, dirs: [steam_libpath]) + exe_name = meson.project_name() - if steamlib.found() == true - global_include_dirs += include_directories('steamshim') - global_args += '-DMKXPZ_STEAM' - global_sources += 'steamshim/steamshim_child.c' - steamworks = true + if host_system == 'linux' and get_option('appimage') == false + exe_name += '.' + host_machine.cpu() endif -endif -# GLES -gfx_backend = get_option('gfx_backend') -if gfx_backend == 'gles' - # Needs to be manually set up for now - global_args += '-DGLES2_HEADER' -elif gfx_backend == 'gl' - global_dependencies += dependency('gl') - # boop -endif - -# ==================== -# Main source -# ==================== - -# Suppress warnings -global_args += ['-Wno-non-virtual-dtor', '-Wno-reorder', '-Wno-uninitialized', '-Wno-unknown-pragmas', '-Wno-stringop-truncation'] -if compilers['cpp'].get_id() == 'clang' - global_args += ['-Wno-undefined-var-template', '-Wno-delete-non-abstract-non-virtual-dtor'] -endif -if host_system == 'windows' - if compilers['cpp'].get_id() != 'clang' - global_args += '-masm=intel' - endif -endif - -# Decide whether or not to use MiniFFI -miniffi = get_option('use_miniffi') -if miniffi == true - miniffi = true - global_args += '-DMKXPZ_MINIFFI' -endif - -# Defines -if get_option('workdir_current') - global_args += '-DWORKDIR_CURRENT' -endif - -if get_option('cxx11_experimental') == true - global_args += '-DMKXPZ_EXP_FS' -endif - -if get_option('force32') == true - global_args += '-m32' -endif - -build_static = false -if get_option('static_executable') == true - build_static = true -endif - -global_args += '-DMKXPZ_INIT_GL_LATER' - -subdir('src') - -embedtool = executable('embedtool', sources: 'embedtool.cpp', native: true, override_options: ['buildtype=release', 'b_coverage=false', 'b_lto=false', 'b_ndebug=false', 'b_pgo=off', 'b_sanitize=none']) - -subdir('binding') -subdir('shader') -subdir('assets') - -global_include_dirs += include_directories('src', 'binding') - -rpath = '' - -if host_system == 'windows' - windows_resource_directory = '../' + get_option('windows_resource_directory') - subdir('windows') - global_sources += windows_resources - global_include_dirs += include_directories('windows') -else - subdir('linux') - rpath = '$ORIGIN/lib' - if get_option('appimage') != true - if sizeof['long'] == 8 and get_option('force32') != true - rpath += '64' - else - rpath += '32' + if steamworks == true + exe_name = 'steam_' + exe_name + la = '' + if build_static == true + if host_system == 'windows' + la = '-static' + else + la = '-static-libgcc -static-libstdc++' + endif endif - endif -endif -exe_name = meson.project_name() + shim_args = [ + '-DGAME_LAUNCH_NAME="' + exe_name + '"', + '-I' + steamworks_path + '/public' + ] -if host_system == 'linux' and get_option('appimage') == false - exe_name += '.' + host_machine.cpu() -endif - -if steamworks == true - exe_name = 'steam_' + exe_name - la = '' - if build_static == true - if host_system == 'windows' - la = '-static' - else - la = '-static-libgcc -static-libstdc++' + if get_option('steam_appid') != '' + shim_args += '-DSTEAM_APPID=' + get_option('steam_appid') endif + + if get_option('steamshim_debug') == true + shim_args += '-DSTEAMSHIM_DEBUG' + shim_ws = 'console' + else + shim_ws = 'windows' + endif + + executable(meson.project_name(), + sources: files('steamshim/steamshim_parent.cpp'), + dependencies: steamlib, + cpp_args: shim_args, + link_args: la.split(), + win_subsystem: shim_ws, + install: (host_system != 'windows')) endif - shim_args = [ - '-DGAME_LAUNCH_NAME="' + exe_name + '"', - '-I' + steamworks_path + '/public' - ] - - if get_option('steam_appid') != '' - shim_args += '-DSTEAM_APPID=' + get_option('steam_appid') - endif - - if get_option('steamshim_debug') == true - shim_args += '-DSTEAMSHIM_DEBUG' - shim_ws = 'console' - else - shim_ws = 'windows' - endif - - executable(meson.project_name(), - sources: files('steamshim/steamshim_parent.cpp'), - dependencies: steamlib, - cpp_args: shim_args, - link_args: la.split(), - win_subsystem: shim_ws, - install: (host_system != 'windows')) -endif - -executable(exe_name, - sources: global_sources, - dependencies: global_dependencies, - include_directories: global_include_dirs, - install_rpath: rpath, - link_args: global_link_args, - cpp_args: global_args, - objc_args: global_args, - objcpp_args: global_args, - win_subsystem: 'windows', - install: (host_system != 'windows') -) - + executable(exe_name, + sources: global_sources, + dependencies: global_dependencies, + include_directories: global_include_dirs, + install_rpath: rpath, + link_args: global_link_args, + cpp_args: global_args + global_cpp_args, + objc_args: global_args, + objcpp_args: global_args + global_cpp_args, + win_subsystem: 'windows', + install: (host_system != 'windows') + ) endif diff --git a/src/meson.build b/src/meson.build index 4ce97aec..83f5af24 100755 --- a/src/meson.build +++ b/src/meson.build @@ -1,182 +1,443 @@ -physfs = dependency('physfs', version: '>=2.1', static: build_static) -openal = dependency('openal', static: build_static, method: 'pkg-config') -theora = dependency('theora', static: build_static) -vorbisfile = dependency('vorbisfile', static: build_static) -vorbis = dependency('vorbis', static: build_static) -ogg = dependency('ogg', static: build_static) -sdl2 = dependency('SDL2', static: build_static) -sdl_sound = compilers['cpp'].find_library('SDL2_sound') -sdl2_ttf = dependency('SDL2_ttf', static: build_static) -freetype = dependency('freetype2', static: build_static) -pixman = dependency('pixman-1', static: build_static) -png = dependency('libpng', static: build_static) -zlib = dependency('zlib', static: build_static) -uchardet = dependency('uchardet', static: build_static) - -# As no pkg-config file is generated for static sdl2_image, and pkg-config is -# the default option for meson detecting dependencies, pkg-config will fail to -# find sdl2_image.pc in the build's lib/pkgconfig folder and instead pull it -# from the locally installed packages if it exists. -# To work around this, we first check to see if cmake can find our sdl2_image -# sub project and use that, then check using pkg-config as normal if we are not -# building the sub project. -# It looks like upstream SDL_image fixed this for SDL3, so we can hopefully -# remove this workaround after eventually upgrading to SDL3. -sdl2_image = dependency('SDL2_image', modules: ['SDL2_image::SDL2_image-static', 'SDL2_image::brotlidec-static', 'SDL2_image::brotlicommon-static', 'SDL2_image::hwy', 'SDL2_image::jxl_dec-static'], static: build_static, method: 'cmake', required: false) -if sdl2_image.found() == false - sdl2_image = dependency('SDL2_image', modules: ['SDL2_image::SDL2_image-static', 'SDL2_image::brotlidec-static', 'SDL2_image::brotlicommon-static', 'SDL2_image::hwy', 'SDL2_image::jxl_dec-static'], static: build_static) -endif - -if host_system == 'windows' - bz2 = dependency('bzip2', static: build_static) - iconv = compilers['cpp'].find_library('iconv', static: build_static) -else - bz2 = compilers['cpp'].find_library('bz2') - # FIXME: Specifically asking for static doesn't work if iconv isn't - # installed in the system prefix somewhere - iconv = compilers['cpp'].find_library('iconv') - global_dependencies += compilers['cpp'].find_library('charset') -endif - -# If OpenSSL is present, you get HTTPS support -if get_option('enable-https') == true - openssl = dependency('openssl', required: false, static: build_static) - if openssl.found() == true - global_dependencies += openssl - global_args += '-DMKXPZ_SSL' - if host_system == 'windows' - global_link_args += '-lcrypt32' - endif - else - warning('Could not locate OpenSSL. HTTPS will be disabled.') - endif -endif - -# Windows needs to be treated like a special needs child here -explicit_libs = '' -if host_system == 'windows' - # Newer versions of Ruby will refuse to link without these - explicit_libs += 'libmsvcrt;libgcc;libmingwex;libgmp;' -endif -if build_static == true - if host_system == 'windows' - # '-static-libgcc', '-static-libstdc++' are here to avoid needing to ship a separate libgcc_s_seh-1.dll on Windows; it still works without those flags if you have the dll. - global_link_args += ['-static-libgcc', '-static-libstdc++', '-Wl,-Bstatic', '-lgcc', '-lstdc++', '-lpthread', '-Wl,-Bdynamic'] - else - global_link_args += ['-static-libgcc', '-static-libstdc++'] - endif - global_args += '-DAL_LIBTYPE_STATIC' -endif - -foreach l : explicit_libs.split(';') - if l != '' - global_link_args += '-l:' + l + '.a' - endif -endforeach - -alcdev_struct = 'ALCdevice_struct' -if openal.type_name() == 'pkgconfig' - if openal.version().version_compare('>=1.20.1') - alcdev_struct = 'ALCdevice' - endif -endif - -global_args += '-DMKXPZ_ALCDEVICE=' + alcdev_struct - - -global_include_dirs += include_directories('.', - 'audio', - 'crypto', - 'display', 'display/gl', 'display/libnsgif', 'display/libnsgif/utils', - 'etc', - 'filesystem', 'filesystem/ghc', - 'input', - 'net', - 'system', - 'util', 'util/sigslot', 'util/sigslot/adapter' -) - -global_dependencies += [openal, zlib, bz2, sdl2, sdl_sound, pixman, physfs, theora, vorbisfile, vorbis, ogg, sdl2_ttf, freetype, sdl2_image, png, iconv, uchardet] -if host_system == 'windows' - global_dependencies += compilers['cpp'].find_library('wsock32') -endif - -if get_option('shared_fluid') == true - fluidsynth = dependency('fluidsynth', static: build_static) - add_project_arguments('-DSHARED_FLUID', language: 'cpp') - global_dependencies += fluidsynth - if host_system == 'windows' - global_dependencies += compilers['cpp'].find_library('dsound') - endif -endif - -if get_option('cjk_fallback_font') == true - add_project_arguments('-DMKXPZ_CJK_FONT', language: 'cpp') -endif - -main_source = files( - 'main.cpp', - 'config.cpp', - 'eventthread.cpp', - 'settingsmenu.cpp', - 'sharedstate.cpp', - - 'audio/alstream.cpp', - 'audio/audio.cpp', - 'audio/audiostream.cpp', - 'audio/fluid-fun.cpp', - 'audio/midisource.cpp', - 'audio/sdlsoundsource.cpp', - 'audio/soundemitter.cpp', - 'audio/vorbissource.cpp', - 'theoraplay/theoraplay.c', - - 'crypto/rgssad.cpp', - - 'display/autotiles.cpp', - 'display/autotilesvx.cpp', - 'display/bitmap.cpp', - 'display/font.cpp', - 'display/graphics.cpp', - 'display/plane.cpp', - 'display/sprite.cpp', - 'display/tilemap.cpp', - 'display/tilemapvx.cpp', - 'display/viewport.cpp', - 'display/window.cpp', - 'display/windowvx.cpp', - - 'display/libnsgif/libnsgif.c', - 'display/libnsgif/lzw.c', - - 'display/gl/gl-debug.cpp', - 'display/gl/gl-fun.cpp', - 'display/gl/gl-meta.cpp', - 'display/gl/glstate.cpp', - 'display/gl/scene.cpp', - 'display/gl/shader.cpp', - 'display/gl/texpool.cpp', - 'display/gl/tileatlas.cpp', - 'display/gl/tileatlasvx.cpp', - 'display/gl/tilequad.cpp', - 'display/gl/vertex.cpp', - - 'util/iniconfig.cpp', - 'util/win-consoleutils.cpp', - - 'etc/etc.cpp', - 'etc/table.cpp', - - 'filesystem/filesystem.cpp', - 'filesystem/filesystemImpl.cpp', - - 'input/input.cpp', - 'input/keybindings.cpp', - - 'net/LUrlParser.cpp', - 'net/net.cpp', - - 'system/systemImpl.cpp' -) - -global_sources += main_source +if is_libretro + cmake = import('cmake') + + global_args += '-DMPG123_NO_LARGENAME' + global_args += '-DGL_GLES_PROTOTYPES=0' + + if host_system == 'darwin' + global_dependencies += compilers['cpp'].find_library('iconv') + endif + + global_dependencies += subproject('libretro-common').get_variable('libretro_common') + + boost_options = cmake.subproject_options() + boost_options.add_cmake_defines({ + 'CMAKE_POLICY_VERSION_MINIMUM': '3.10', + 'CMAKE_C_FLAGS': ' '.join(global_args), + 'CMAKE_CXX_FLAGS': ' '.join(global_args), + 'CMAKE_POSITION_INDEPENDENT_CODE': use_pic, + 'BUILD_TESTING': false, + }) + global_dependencies += [ + cmake.subproject('boost_asio', options: boost_options).dependency('boost_asio'), + cmake.subproject('boost_mp11', options: boost_options).dependency('boost_mp11'), + cmake.subproject('boost_describe', options: boost_options).dependency('boost_describe'), + cmake.subproject('boost_config', options: boost_options).dependency('boost_config'), + cmake.subproject('boost_assert', options: boost_options).dependency('boost_assert'), + cmake.subproject('boost_static_assert', options: boost_options).dependency('boost_static_assert'), + cmake.subproject('boost_throw_exception', options: boost_options).dependency('boost_throw_exception'), + cmake.subproject('boost_core', options: boost_options).dependency('boost_core'), + cmake.subproject('boost_container_hash', options: boost_options).dependency('boost_container_hash'), + cmake.subproject('boost_type_index', options: boost_options).dependency('boost_type_index'), + cmake.subproject('boost_type_traits', options: boost_options).dependency('boost_type_traits'), + cmake.subproject('boost_optional', options: boost_options).dependency('boost_optional'), + ] + + zlib_options = cmake.subproject_options() + zlib_options.add_cmake_defines({ + 'CMAKE_POLICY_VERSION_MINIMUM': '3.10', + 'CMAKE_C_FLAGS': ' '.join(global_args), + 'CMAKE_CXX_FLAGS': ' '.join(global_args), + 'CMAKE_POSITION_INDEPENDENT_CODE': use_pic, + 'BUILD_SHARED_LIBS': false, + 'ZLIB_BUILD_EXAMPLES': false, + }) + global_dependencies += cmake.subproject(host_system == 'darwin' ? 'zlib-darwin' : 'zlib', options: zlib_options).dependency('zlibstatic') + + physfs_options = cmake.subproject_options() + physfs_options.add_cmake_defines({ + 'CMAKE_POLICY_VERSION_MINIMUM': '3.10', + 'CMAKE_C_FLAGS': ' '.join(global_args), + 'CMAKE_CXX_FLAGS': ' '.join(global_args), + 'CMAKE_POSITION_INDEPENDENT_CODE': use_pic, + 'PHYSFS_BUILD_STATIC': true, + 'PHYSFS_BUILD_SHARED': false, + 'PHYSFS_BUILD_TEST': false, + 'PHYSFS_BUILD_DOCS': false, + }) + global_dependencies += cmake.subproject('physfs', options: physfs_options).dependency('physfs-static') + + openal_options = cmake.subproject_options() + openal_options.add_cmake_defines({ + 'CMAKE_POLICY_VERSION_MINIMUM': '3.10', + 'CMAKE_C_FLAGS': ' '.join(global_args), + 'CMAKE_CXX_FLAGS': ' '.join(global_args), + 'CMAKE_POSITION_INDEPENDENT_CODE': use_pic, + 'LIBTYPE': 'STATIC', + 'ALSOFT_DLOPEN': false, + 'ALSOFT_UTILS': false, + 'ALSOFT_NO_CONFIG_UTIL': true, + 'ALSOFT_EXAMPLES': false, + 'ALSOFT_UPDATE_BUILD_VERSION': false, + 'ALSOFT_EMBED_HRTF_DATA': false, + 'ALSOFT_RTKIT': false, + 'ALSOFT_BACKEND_PIPEWIRE': false, + 'ALSOFT_BACKEND_PULSEAUDIO': false, + 'ALSOFT_BACKEND_ALSA': false, + 'ALSOFT_BACKEND_OSS': false, + 'ALSOFT_BACKEND_SOLARIS': false, + 'ALSOFT_BACKEND_SNDIO': false, + 'ALSOFT_BACKEND_WINMM': false, + 'ALSOFT_BACKEND_DSOUND': false, + 'ALSOFT_BACKEND_WASAPI': false, + 'ALSOFT_BACKEND_OTHERIO': false, + 'ALSOFT_BACKEND_JACK': false, + 'ALSOFT_BACKEND_COREAUDIO': false, + 'ALSOFT_BACKEND_OBOE': false, + 'ALSOFT_BACKEND_OPENSL': false, + 'ALSOFT_BACKEND_PORTAUDIO': false, + 'ALSOFT_BACKEND_SDL3': false, + 'ALSOFT_BACKEND_SDL2': false, + 'ALSOFT_BACKEND_WAVE': false, + }) + global_dependencies += cmake.subproject('openal-soft', options: openal_options).dependency('OpenAL') + global_dependencies += cmake.subproject('openal-soft', options: openal_options).dependency('alsoft.fmt') + + fluidsynth_options = cmake.subproject_options() + fluidsynth_options.add_cmake_defines({ + 'CMAKE_POLICY_VERSION_MINIMUM': '3.10', + 'CMAKE_C_FLAGS': ' '.join(global_args), + 'CMAKE_CXX_FLAGS': ' '.join(global_args), + 'CMAKE_POSITION_INDEPENDENT_CODE': use_pic, + 'BUILD_SHARED_LIBS': false, + 'enable-aufile': false, + 'enable-dbus': false, + 'enable-ipv6 ': false, + 'enable-jack': false, + 'enable-ladspa': false, + 'enable-libinstpatch': false, + 'enable-libsndfile': false, + 'enable-midishare': false, + 'enable-opensles': false, + 'enable-oboe': false, + 'enable-network': false, + 'enable-oss': false, + 'enable-dsound': false, + 'enable-waveout': false, + 'enable-winmidi': false, + 'enable-sdl2': false, + 'enable-pkgconfig': false, + 'enable-pulseaudio': false, + 'enable-readline': false, + 'enable-threads': false, + 'enable-lash': false, + 'enable-alsa': false, + 'enable-systemd': false, + 'enable-coreaudio': false, + 'enable-coremidi': false, + 'enable-framework': false, + 'enable-dart': false, + }) + global_dependencies += cmake.subproject('fluidsynth', options: fluidsynth_options).dependency('libfluidsynth') + + ogg_options = cmake.subproject_options() + ogg_options.add_cmake_defines({ + 'CMAKE_POLICY_VERSION_MINIMUM': '3.10', + 'CMAKE_C_FLAGS': ' '.join(global_args), + 'CMAKE_CXX_FLAGS': ' '.join(global_args), + 'CMAKE_POSITION_INDEPENDENT_CODE': use_pic, + 'BUILD_SHARED_LIBS': false, + 'BUILD_TESTING': false, + 'BUILD_FRAMEWORK': false, + }) + global_dependencies += cmake.subproject('ogg', options: ogg_options).dependency('ogg') + + vorbis_options = cmake.subproject_options() + vorbis_options.add_cmake_defines({ + 'CMAKE_POLICY_VERSION_MINIMUM': '3.10', + 'CMAKE_C_FLAGS': ' '.join(global_args), + 'CMAKE_CXX_FLAGS': ' '.join(global_args), + 'CMAKE_POSITION_INDEPENDENT_CODE': use_pic, + 'BUILD_SHARED_LIBS': false, + 'BUILD_TESTING': false, + 'BUILD_FRAMEWORK': false, + }) + global_dependencies += cmake.subproject('vorbis', options: vorbis_options).dependency('vorbis') + global_dependencies += cmake.subproject('vorbis', options: vorbis_options).dependency('vorbisfile') + + flac_options = cmake.subproject_options() + flac_options.add_cmake_defines({ + 'CMAKE_POLICY_VERSION_MINIMUM': '3.10', + 'CMAKE_C_FLAGS': ' '.join(global_args), + 'CMAKE_CXX_FLAGS': ' '.join(global_args), + 'CMAKE_POSITION_INDEPENDENT_CODE': use_pic, + 'BUILD_SHARED_LIBS': false, + 'BUILD_CXXLIBS': false, + 'BUILD_PROGRAMS': false, + 'BUILD_EXAMPLES': false, + 'BUILD_TESTING': false, + 'BUILD_DOCS': false, + 'BUILD_UTILS': false, + 'ENABLE_MULTITHREADING': false, + 'INSTALL_MANPAGES': false, + 'WITH_OGG': false, + 'WITH_FORTIFY_SOURCE': false, + 'WITH_STACK_PROTECTOR': false, + }) + global_dependencies += cmake.subproject('flac', options: flac_options).dependency('FLAC') + + opus_options = cmake.subproject_options() + opus_options.add_cmake_defines({ + 'CMAKE_POLICY_VERSION_MINIMUM': '3.10', + 'CMAKE_C_FLAGS': ' '.join(global_args), + 'CMAKE_CXX_FLAGS': ' '.join(global_args), + 'CMAKE_POSITION_INDEPENDENT_CODE': use_pic, + 'BUILD_SHARED_LIBS': false, + 'OPUS_BUILD_SHARED_LIBRARY': false, + 'OPUS_BUILD_TESTING': false, + 'OPUS_CUSTOM_MODES': false, + 'OPUS_BUILD_PROGRAMS': false, + 'OPUS_DISABLE_INTRINSICS': true, + 'OPUS_FLOAT_APPROX': false, + 'OPUS_BUILD_FRAMEWORK': false, + 'OPUS_STATIC_RUNTIME': false, + 'OPUS_FORTIFY_SOURCE': false, + 'OPUS_STACK_PROTECTOR': false, + }) + global_dependencies += cmake.subproject('opus', options: opus_options).dependency('opus') + + mpg123_options = cmake.subproject_options() + mpg123_options.add_cmake_defines({ + 'CMAKE_POLICY_VERSION_MINIMUM': '3.10', + 'CMAKE_C_FLAGS': ' '.join(global_args), + 'CMAKE_CXX_FLAGS': ' '.join(global_args), + 'CMAKE_POSITION_INDEPENDENT_CODE': use_pic, + 'BUILD_SHARED_LIBS': false, + 'BUILD_PROGRAMS': false, + 'BUILD_LIBOUT123': false, + 'CHECK_MODULES': false, + 'FIFO': false, + }) + global_dependencies += cmake.subproject('mpg123', options: mpg123_options).dependency('libmpg123') + global_dependencies += cmake.subproject('mpg123', options: mpg123_options).dependency('compat') + + libsndfile_options = cmake.subproject_options() + libsndfile_options.add_cmake_defines({ + 'CMAKE_POLICY_VERSION_MINIMUM': '3.10', + 'CMAKE_C_FLAGS': ' '.join(global_args), + 'CMAKE_CXX_FLAGS': ' '.join(global_args), + 'CMAKE_POSITION_INDEPENDENT_CODE': use_pic, + 'BUILD_SHARED_LIBS': false, + 'BUILD_PROGRAMS': false, + 'BUILD_EXAMPLES': false, + 'BUILD_REGTEST': false, + 'BUILD_TESTING': false, + 'ENABLE_CPACK': false, + 'ENABLE_PACKAGE_CONFIG': false, + 'INSTALL_PKGCONFIG_MODULE': false, + 'ENABLE_EXTERNAL_LIBS': true, + 'ENABLE_MPEG': true, + 'ENABLE_EXPERIMENTAL': false, + }) + global_dependencies += cmake.subproject('libsndfile', options: libsndfile_options).dependency('sndfile') + + pixman_region_options = cmake.subproject_options() + pixman_region_options.add_cmake_defines({ + 'CMAKE_POLICY_VERSION_MINIMUM': '3.10', + 'CMAKE_C_FLAGS': ' '.join(global_args), + 'CMAKE_CXX_FLAGS': ' '.join(global_args), + 'CMAKE_POSITION_INDEPENDENT_CODE': use_pic, + 'CMAKE_BUILD_TYPE': 'None', + }) + global_dependencies += cmake.subproject('pixman-region', options: pixman_region_options).dependency('pixman-region') + + global_dependencies += subproject('stb').get_variable('stb') + global_sources += files('stb_image.c', 'stb_sprintf.c') + + global_dependencies += subproject('opengl-registry').get_variable('opengl_registry') + + freetype_options = [ + 'cflags=@0@'.format(','.join(global_args)), + 'cppflags=@0@'.format(','.join(global_args)), + 'default_library=static', + 'b_staticpic=@0@'.format(use_pic), + 'brotli=disabled', + 'bzip2=disabled', + 'harfbuzz=disabled', + 'mmap=disabled', + 'png=disabled', + 'tests=disabled', + 'zlib=disabled', + ] + global_dependencies += subproject('freetype', default_options: freetype_options).get_variable('freetype_dep') +else + physfs = dependency('physfs', version: '>=2.1', static: build_static) + openal = dependency('openal', static: build_static, method: 'pkg-config') + theora = dependency('theora', static: build_static) + vorbisfile = dependency('vorbisfile', static: build_static) + vorbis = dependency('vorbis', static: build_static) + ogg = dependency('ogg', static: build_static) + sdl2 = dependency('SDL2', static: build_static) + sdl_sound = compilers['cpp'].find_library('SDL2_sound') + sdl2_ttf = dependency('SDL2_ttf', static: build_static) + freetype = dependency('freetype2', static: build_static) + pixman = dependency('pixman-1', static: build_static) + png = dependency('libpng', static: build_static) + zlib = dependency('zlib', static: build_static) + uchardet = dependency('uchardet', static: build_static) + + # As no pkg-config file is generated for static sdl2_image, and pkg-config is + # the default option for meson detecting dependencies, pkg-config will fail to + # find sdl2_image.pc in the build's lib/pkgconfig folder and instead pull it + # from the locally installed packages if it exists. + # To work around this, we first check to see if cmake can find our sdl2_image + # sub project and use that, then check using pkg-config as normal if we are not + # building the sub project. + # It looks like upstream SDL_image fixed this for SDL3, so we can hopefully + # remove this workaround after eventually upgrading to SDL3. + sdl2_image = dependency('SDL2_image', modules: ['SDL2_image::SDL2_image-static', 'SDL2_image::brotlidec-static', 'SDL2_image::brotlicommon-static', 'SDL2_image::hwy', 'SDL2_image::jxl_dec-static'], static: build_static, method: 'cmake', required: false) + if sdl2_image.found() == false + sdl2_image = dependency('SDL2_image', modules: ['SDL2_image::SDL2_image-static', 'SDL2_image::brotlidec-static', 'SDL2_image::brotlicommon-static', 'SDL2_image::hwy', 'SDL2_image::jxl_dec-static'], static: build_static) + endif + + if host_system == 'windows' + bz2 = dependency('bzip2', static: build_static) + iconv = compilers['cpp'].find_library('iconv', static: build_static) + else + bz2 = compilers['cpp'].find_library('bz2') + # FIXME: Specifically asking for static doesn't work if iconv isn't + # installed in the system prefix somewhere + iconv = compilers['cpp'].find_library('iconv') + global_dependencies += compilers['cpp'].find_library('charset') + endif + + # If OpenSSL is present, you get HTTPS support + if get_option('enable-https') == true + openssl = dependency('openssl', required: false, static: build_static) + if openssl.found() == true + global_dependencies += openssl + global_args += '-DMKXPZ_SSL' + if host_system == 'windows' + global_link_args += '-lcrypt32' + endif + else + warning('Could not locate OpenSSL. HTTPS will be disabled.') + endif + endif + + # Windows needs to be treated like a special needs child here + explicit_libs = '' + if host_system == 'windows' + # Newer versions of Ruby will refuse to link without these + explicit_libs += 'libmsvcrt;libgcc;libmingwex;libgmp;' + endif + + foreach l : explicit_libs.split(';') + if l != '' + global_link_args += '-l:' + l + '.a' + endif + endforeach + + alcdev_struct = 'ALCdevice_struct' + if openal.type_name() == 'pkgconfig' + if openal.version().version_compare('>=1.20.1') + alcdev_struct = 'ALCdevice' + endif + endif + + global_args += '-DMKXPZ_ALCDEVICE=' + alcdev_struct + + global_dependencies += [openal, zlib, bz2, sdl2, sdl_sound, pixman, physfs, theora, vorbisfile, vorbis, ogg, sdl2_ttf, freetype, sdl2_image, png, iconv, uchardet] + if host_system == 'windows' + global_dependencies += compilers['cpp'].find_library('wsock32') + endif + + if get_option('shared_fluid') == true + fluidsynth = dependency('fluidsynth', static: build_static) + global_args += '-DSHARED_FLUID' + global_dependencies += fluidsynth + if host_system == 'windows' + global_dependencies += compilers['cpp'].find_library('dsound') + endif + endif +endif + +if get_option('cjk_fallback_font') == true + global_args += '-DMKXPZ_CJK_FONT' +endif + +global_include_dirs += include_directories('.', + 'audio', + 'crypto', + 'display', 'display/gl', 'display/libnsgif', 'display/libnsgif/utils', + 'etc', + 'filesystem', 'filesystem/ghc', + 'input', + 'net', + 'system', + 'util', 'util/sigslot', 'util/sigslot/adapter' +) + +main_source = files( + is_libretro ? 'core.cpp' : 'main.cpp', + is_libretro ? [] : 'config.cpp', + is_libretro ? [] : 'eventthread.cpp', + is_libretro ? [] : 'settingsmenu.cpp', + 'sharedstate.cpp', + is_libretro ? 'mkxp-polyfill.cpp' : [], + + 'audio/alstream.cpp', + 'audio/audio.cpp', + 'audio/audiostream.cpp', + 'audio/fluid-fun.cpp', + 'audio/midisource.cpp', + is_libretro ? 'audio/sndfilesource.cpp' : 'audio/sdlsoundsource.cpp', + 'audio/soundemitter.cpp', + 'audio/vorbissource.cpp', + is_libretro ? [] : 'theoraplay/theoraplay.c', + + 'crypto/rgssad.cpp', + + 'display/autotiles.cpp', + is_libretro ? [] : 'display/autotilesvx.cpp', + 'display/bitmap.cpp', + 'display/font.cpp', + 'display/graphics.cpp', + 'display/plane.cpp', + 'display/sprite.cpp', + 'display/tilemap.cpp', + is_libretro ? [] : 'display/tilemapvx.cpp', + 'display/viewport.cpp', + 'display/window.cpp', + is_libretro ? [] : 'display/windowvx.cpp', + + is_libretro ? [] : 'display/libnsgif/libnsgif.c', + is_libretro ? [] : 'display/libnsgif/lzw.c', + + 'display/gl/gl-debug.cpp', + 'display/gl/gl-fun.cpp', + 'display/gl/gl-meta.cpp', + 'display/gl/glstate.cpp', + 'display/gl/scene.cpp', + 'display/gl/shader.cpp', + 'display/gl/texpool.cpp', + 'display/gl/tileatlas.cpp', + is_libretro ? [] : 'display/gl/tileatlasvx.cpp', + 'display/gl/tilequad.cpp', + 'display/gl/vertex.cpp', + + is_libretro ? [] : 'util/iniconfig.cpp', + is_libretro ? [] : 'util/win-consoleutils.cpp', + + 'etc/etc.cpp', + 'etc/table.cpp', + + 'filesystem/filesystem.cpp', + is_libretro ? [] : 'filesystem/filesystemImpl.cpp', + + is_libretro ? [ + 'input/input-retro.cpp', + ] : [ + 'input/input.cpp', + 'input/keybindings.cpp', + ], + + is_libretro ? [] : [ + 'net/LUrlParser.cpp', + 'net/net.cpp', + ], + + is_libretro ? [] : 'system/systemImpl.cpp', +) + +global_sources += main_source diff --git a/src/stb_image.cpp b/src/stb_image.c similarity index 100% rename from src/stb_image.cpp rename to src/stb_image.c diff --git a/src/stb_image_malloc.h b/src/stb_image_malloc.h index 02d0eebb..84505649 100644 --- a/src/stb_image_malloc.h +++ b/src/stb_image_malloc.h @@ -1,10 +1,10 @@ #ifndef MKXPZ_STB_IMAGE_MALLOC_H #define MKXPZ_STB_IMAGE_MALLOC_H -#include +#include -#define STBI_MALLOC std::malloc -#define STBI_REALLOC std::realloc -#define STBI_FREE std::free +#define STBI_MALLOC malloc +#define STBI_REALLOC realloc +#define STBI_FREE free #endif // MKXPZ_STB_IMAGE_MALLOC_H diff --git a/src/stb_snprintf.cpp b/src/stb_sprintf.c similarity index 100% rename from src/stb_snprintf.cpp rename to src/stb_sprintf.c