From f04d583cfb365dd7b6ebdc44dcc5ea100da1734f Mon Sep 17 00:00:00 2001 From: Matthew Lyons Date: Wed, 27 Apr 2022 10:54:36 -0700 Subject: [PATCH] Provide Meson alternative to CMake --- CMakeLists.txt | 4 +- assets/meson.build | 20 +++++ binding-mri/meson.build | 42 ++++++++++ meson.build | 76 +++++++++++++++++ meson_options.txt | 10 +++ setup.sh | 10 +-- shader/meson.build | 51 ++++++++++++ src/main.cpp | 6 +- src/meson.build | 118 ++++++++++++++++++++++++++ src/opengl/source/shader.cpp | 6 +- src/otherview-message.cpp.old | 153 ---------------------------------- src/otherview-message.h.old | 20 ----- 12 files changed, 330 insertions(+), 186 deletions(-) create mode 100644 assets/meson.build create mode 100644 binding-mri/meson.build create mode 100644 meson.build create mode 100644 meson_options.txt create mode 100644 shader/meson.build create mode 100644 src/meson.build delete mode 100644 src/otherview-message.cpp.old delete mode 100644 src/otherview-message.h.old diff --git a/CMakeLists.txt b/CMakeLists.txt index 002f246d..f5909a27 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,7 @@ set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) set(CMAKE_INSTALL_RPATH ${BIN_RPATH}) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE) -set(MRI_VERSION "3.0" CACHE STRING "Version of MRI to link with") +set(MRI_VERSION "3.1" CACHE STRING "Version of MRI to link with") find_package(PkgConfig REQUIRED) @@ -33,7 +33,7 @@ pkg_check_modules(SDL2 REQUIRED sdl2) pkg_check_modules(SDL2_TTF REQUIRED SDL2_ttf) pkg_check_modules(SDL2_IMAGE REQUIRED SDL2_image) pkg_check_modules(SDL_SOUND REQUIRED SDL_sound) -pkg_check_modules(MRI REQUIRED ruby-3.0) +pkg_check_modules(MRI REQUIRED ruby-3.1) pkg_check_modules(ZMQPP REQUIRED libzmqpp) pkg_check_modules(OGG REQUIRED ogg) pkg_check_modules(SPEEX REQUIRED speex) diff --git a/assets/meson.build b/assets/meson.build new file mode 100644 index 00000000..ba490ebd --- /dev/null +++ b/assets/meson.build @@ -0,0 +1,20 @@ +embedded_assets = [ + 'icon.png', + 'gamecontrollerdb.txt' +] + +embedded_assets_f = files(embedded_assets) + +count = 0 +foreach file : embedded_assets_f + global_sources += custom_target(embedded_assets[count], + input: file, + output: '@0@.xxd'.format(embedded_assets[count]), + command: [ + xxd, '-i', '@INPUT@' + ], + capture: true, + depend_files: embedded_assets_f[count] + ) + count += 1 +endforeach diff --git a/binding-mri/meson.build b/binding-mri/meson.build new file mode 100644 index 00000000..cd4aa5e7 --- /dev/null +++ b/binding-mri/meson.build @@ -0,0 +1,42 @@ +if get_option('mri_includes') == '' + ver = get_option('mri_version') + if ver.version_compare('>=3.0') and compilers['cpp'].get_id() == 'clang' + global_args += '-fdeclspec' + endif + global_dependencies += dependency('ruby-' + ver) +else + global_args += ('-I' + get_option('mri_includes')) + global_dependencies += compilers['cpp'].find_library(get_option('mri_library'), dirs: get_option('mri_libpath')) +endif + +global_include_dirs += include_directories('.') + +binding_source = [files( + 'aleffect-binding.cpp', + 'audio-binding.cpp', + 'binding-mri.cpp', + 'binding-util.cpp', + 'bitmap-binding.cpp', + 'etc-binding.cpp', + 'filesystem-binding.cpp', + 'font-binding.cpp', + 'graphics-binding.cpp', + 'input-binding.cpp', + 'journal-binding.cpp', + 'modshot-window-binding.cpp', + 'module_rpg.cpp', + 'niko-binding.cpp', + 'oneshot-binding.cpp', + 'plane-binding.cpp', + 'screen-binding.cpp', + 'sprite-binding.cpp', + 'steam-binding.cpp', + 'table-binding.cpp', + 'tilemap-binding.cpp', + 'viewport-binding.cpp', + 'wallpaper-binding.cpp', + 'window-binding.cpp', + 'otherview-binding.cpp', +)] + +global_sources += binding_source diff --git a/meson.build b/meson.build new file mode 100644 index 00000000..df6a540f --- /dev/null +++ b/meson.build @@ -0,0 +1,76 @@ +project('modshot', 'c', 'cpp', version: '1.0.0', meson_version: '>=0.56.0', default_options: ['cpp_std=c++14', 'buildtype=release']) + +host_system = host_machine.system() + +xxd = find_program('xxd', native: true) + +compilers = {'cpp': meson.get_compiler('cpp')} + +global_sources = [] +global_dependencies = [] +global_include_dirs = [] +global_args = [] +global_link_args = [] + +sizeof = {'void*': compilers['cpp'].sizeof('void*'), + 'long': compilers['cpp'].sizeof('long') + } +win64 = (sizeof['void*'] != sizeof['long']) + +global_args += '-DHAVE_NANOSLEEP' + +gfx_backend = get_option('gfx_backend') +if gfx_backend == 'gles' + global_args += '-DGLES2_HEADER' +elif gfx_backend == 'gl' + global_dependencies += dependency('gl') +endif + +# ==================== +# Main source +# ==================== + +# Suppress warnings +global_args += ['-Wno-non-virtual-dtor', '-Wno-reorder', '-Wno-uninitialized', '-Wno-unknown-pragmas', '-Wno-stringop-truncation', '-Wno-parentheses', '-Wno-sign-compare', '-Wno-misleading-indentation'] +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 + +# Defines +if get_option('workdir_current') + global_args += '-DWORKDIR_CURRENT' +endif + +steam = false +if get_option('steam') == true + steam = true +endif + +subdir('src') +subdir('binding-mri') +subdir('shader') +subdir('assets') + +global_include_dirs += include_directories('src', 'binding-mri') + +rpath = '$ORIGIN/lib' + +exe_name = meson.project_name() + +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') +) diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 00000000..ec321ab3 --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,10 @@ +option('mri_version', type: 'string', value: '3.0', description: 'Version of MRI to link with') +option('mri_includes', type: 'string', value: '', description: 'Ruby manual include path') +option('mri_libpath', type: 'string', value: '', description: 'Ruby manual lib path') +option('mri_library', type: 'string', value: '', description: 'Ruby manual link name') + +option('workdir_current', type: 'boolean', value: false, description: 'Keep current directory on startup') + +option('steam', type: 'boolean', value: false, description: 'Add steamworks support') + +option('gfx_backend', type: 'combo', value: 'gl', choices: ['gl', 'gles'], description: 'Graphics rendering API to use.') diff --git a/setup.sh b/setup.sh index bfbd7d7a..79ee0858 100755 --- a/setup.sh +++ b/setup.sh @@ -15,8 +15,8 @@ if [[ $OSTYPE == msys ]]; then pacman -S pactoys --noconfirm pacboy -S git: gcc:p make:p cmake:p bison: doxygen:p ruby:p \ SDL2:p SDL2_image:p SDL2_ttf:p openal:p \ - physfs:p pixman:p libwebp:p zlib:p zeromq:p \ - bzip2:p libvorbis:p libogg:p zeromq:p \ + physfs:p pixman:p libwebp:p zlib:p meson:p\ + bzip2:p libvorbis:p libogg:p zeromq:p \ boost:p libpng:p libjpeg-turbo:p libtiff:p --noconfirm else @@ -27,7 +27,7 @@ else libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev libopenal-dev \ libphysfs-dev libpixman-1-dev libwebp-dev libbz2-dev \ libvorbis-dev libogg-dev libsodium-dev libboost-dev libpng-dev \ - libjpeg-dev libtiff-dev + libjpeg-dev libtiff-dev meson echo "* ZeroMQ not found in Debian's repositories. Building from source..." git clone https://github.com/zeromq/libzmq.git $libpath/zmq @@ -48,7 +48,7 @@ else libpng libjpeg libtiff zeromq mm-common base-devel vim gtk2 echo "* Installing dependencies with pamac..." sudo pamac install sdl2_image sdl2_ttf physfs boost boost-libs \ - libsigc++ sdl_sound m4 --no-confirm + libsigc++ sdl_sound m4 meson --no-confirm fi if cat /etc/redhat-release; then @@ -62,7 +62,7 @@ else zeromq zeromq-devel physfs physfs-devel pixman pixman-devel \ bzip2 openal-soft speex speex-devel libmodplug libmodplug-devel \ boost boost-devel openal-soft-devel xfconf xfconf-devel gtk2 gtk2-devel \ - vim + vim meson echo "* Building SDL2_ttf." git clone https://github.com/libsdl-org/SDL_ttf $libpath/SDL_ttf diff --git a/shader/meson.build b/shader/meson.build new file mode 100644 index 00000000..644ea09b --- /dev/null +++ b/shader/meson.build @@ -0,0 +1,51 @@ +embedded_shaders = [ + 'binary_glitch.frag', + 'bitmapBlit.frag', + 'blur.frag', + 'blurH.vert', + 'blurV.vert', + 'chronos.frag', + 'common.h', + 'crt_sprite.frag', + 'crt.frag', + 'cubic_lens.frag', + 'flashMap.frag', + 'flatColor.frag', + 'gray.frag', + 'hue.frag', + 'mask.frag', + 'mask.vert', + 'minimal.vert', + 'obscured.frag', + 'plane.frag', + 'simple.frag', + 'simple.vert', + 'simpleAlpha.frag', + 'simpleAlphaUni.frag', + 'simpleColor.frag', + 'simpleColor.vert', + 'simpleMatrix.vert', + 'sprite.frag', + 'sprite.vert', + 'tilemap.vert', + 'trans.frag', + 'transSimple.frag', + 'water.frag', + 'zoom.vert' +] + +embedded_shaders_f = files(embedded_shaders) + +count = 0 +foreach file : embedded_shaders_f + global_sources += custom_target(embedded_shaders[count], + input: file, + output: '@0@.xxd'.format(embedded_shaders[count]), + command: [ + xxd, '-i', '@INPUT@' + ], + capture: true, + depend_files: embedded_shaders_f[count] + ) + count += 1 +endforeach diff --git a/src/main.cpp b/src/main.cpp index e2ff5f19..a9bce68a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -180,7 +180,7 @@ static void setupWindowIcon(const Config &conf, SDL_Window *win) SDL_RWops *iconSrc; if (conf.iconPath.empty()) - iconSrc = SDL_RWFromConstMem(assets_icon_png, assets_icon_png_len); + iconSrc = SDL_RWFromConstMem(___assets_icon_png, ___assets_icon_png_len); else iconSrc = SDL_RWFromFile(conf.iconPath.c_str(), "rb"); @@ -391,8 +391,8 @@ int main(int argc, char *argv[]) { #ifndef STEAM /* Add controller bindings from embedded controller DB */ - SDL_RWops *controllerDB = SDL_RWFromConstMem(assets_gamecontrollerdb_txt, - assets_gamecontrollerdb_txt_len); + SDL_RWops *controllerDB = SDL_RWFromConstMem(___assets_gamecontrollerdb_txt, + ___assets_gamecontrollerdb_txt_len); SDL_GameControllerAddMappingsFromRW(controllerDB, 1); #endif diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 00000000..95b2c38e --- /dev/null +++ b/src/meson.build @@ -0,0 +1,118 @@ +boost = dependency('boost', version: '>=1.49', modules: ['program_options']) +physfs = dependency('physfs', version: '>=2.1') +openal = dependency('openal') +vorbisfile = dependency('vorbisfile') +vorbis = dependency('vorbis') +ogg = dependency('ogg') +sdl2 = dependency('SDL2') +sdl_sound = compilers['cpp'].find_library('SDL2_sound') +sdl2_ttf = dependency('SDL2_ttf') +sdl2_image = dependency('SDL2_image') +sigcxx = dependency('sigc++-2.0') +pixman = dependency('pixman-1') +png = dependency('libpng') +jpeg = dependency('libjpeg') +zlib = dependency('zlib') +zmqpp = dependency('libzmqpp') + +if host_system == 'windows' + bz2 = dependency('bzip2') +else + bz2 = compilers['cpp'].find_library('bz2') + gtk = dependency('gtk+-2.0') + xfconf = dependency('libxfconf-0') +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 + +global_include_dirs += include_directories('.', + 'audio/headers', + 'filesystem/headers', + 'graphics/headers', + 'input/headers', + 'opengl/headers' +) + +global_dependencies += [boost, bz2, openal, zlib, sdl2, sdl_sound, pixman, physfs, vorbisfile, vorbis, ogg, sdl2_ttf, sigcxx, sdl2_image, png, jpeg, zmqpp, gtk, xfconf] +if host_system == 'windows' + global_dependencies += compilers['cpp'].find_library('wsock32') + global_dependencies += compilers['cpp'].find_library('winmm.lib') + global_dependencies += compilers['cpp'].find_library('Secur32') + global_dependencies += compilers['cpp'].find_library('Shlwapi') +endif + +main_source = files( + 'audio/source/alstream.cpp', + 'audio/source/audiostream.cpp', + 'audio/source/audiochannels.cpp', + 'audio/source/audio.cpp', + 'audio/source/soundemitter.cpp', + 'audio/source/sdlsoundsource.cpp', + 'audio/source/vorbissource.cpp', + 'graphics/source/autotiles.cpp', + 'graphics/source/bitmap.cpp', + 'graphics/source/graphics.cpp', + 'graphics/source/font.cpp', + 'graphics/source/sprite.cpp', + 'graphics/source/scene.cpp', + 'graphics/source/tilemap.cpp', + 'graphics/source/tileatlas.cpp', + 'opengl/source/glstate.cpp', + 'opengl/source/gl-debug.cpp', + 'opengl/source/gl-fun.cpp', + 'opengl/source/gl-meta.cpp', + 'opengl/source/plane.cpp', + 'opengl/source/shader.cpp', + 'opengl/source/texpool.cpp', + 'opengl/source/vertex.cpp', + 'opengl/source/tilequad.cpp', + 'opengl/source/window.cpp', + 'opengl/source/screen.cpp', + 'opengl/source/viewport.cpp', + 'opengl/source/table.cpp', + 'input/source/input.cpp', + 'input/source/keybindings.cpp', + 'filesystem/source/filesystem.cpp', + 'filesystem/source/rgssad.cpp', + 'main.cpp', + 'eventthread.cpp', + 'etc.cpp', + 'config.cpp', + 'settingsmenu.cpp', + 'sharedstate.cpp', + 'oneshot.cpp', + 'i18n.cpp', + 'otherview-message.cpp', + 'crash-handler.cpp' +) + +global_sources += main_source + +if steam == true + global_sources += files( + 'steam/steam.cpp', + '../steamshim/steamshim_child.c' + ) + global_include_dirs += include_directories( + 'steam', + '../steamshim' + ) + + global_args += '-DSTEAM' +endif + +if host_system == 'windows' +else + global_sources += files('xdg-user-dir-lookup.c') +endif diff --git a/src/opengl/source/shader.cpp b/src/opengl/source/shader.cpp index 6ac765f6..25199014 100644 --- a/src/opengl/source/shader.cpp +++ b/src/opengl/source/shader.cpp @@ -65,7 +65,7 @@ #define INIT_SHADER(vert, frag, name) \ { \ - Shader::init(shader_##vert##_vert, shader_##vert##_vert_len, shader_##frag##_frag, shader_##frag##_frag_len, \ + Shader::init(___shader_##vert##_vert, ___shader_##vert##_vert_len, ___shader_##frag##_frag, ___shader_##frag##_frag_len, \ #vert, #frag, #name); \ } @@ -144,8 +144,8 @@ static void setupShaderSource(GLuint shader, GLenum type, ++i; } - shaderSrc[i] = (const GLchar*) shader_common_h; - shaderSrcSize[i] = shader_common_h_len; + shaderSrc[i] = (const GLchar*) ___shader_common_h; + shaderSrcSize[i] = ___shader_common_h_len; ++i; shaderSrc[i] = (const GLchar*) body; diff --git a/src/otherview-message.cpp.old b/src/otherview-message.cpp.old deleted file mode 100644 index ab61f1b0..00000000 --- a/src/otherview-message.cpp.old +++ /dev/null @@ -1,153 +0,0 @@ -// Standard libraries. -#include -#include -#include -#include -#include -#include -#include - -// ModShot libraries. -#include "otherview-message.h" -#include "config.h" -#include "debugwriter.h" -#include "sharedstate.h" - -// Boost Interprocess. -#include -#include -#include - -#ifdef __linux -#include -#include -#endif - -#include - - -using namespace boost::process; -using namespace std; - -#define OSFM_NAMEDPIPE_NAME "OSFMOtherViewPipe_DontTouch" - -/*io_service ioService; - -void ovm_server_thread() { - tcp::acceptor acceptor(ioService, tcp::endpoint(tcp::v4(), OSFM_OTHERVIEW_PORT)); - - while(true) { - tcp::socket socket(ioService); - acceptor.accept(socket); - - boost::asio::streambuf buf; - boost::system::error_code errorcode; - while(read(socket, buf, errorcode)) { - cout << &buf << endl; - if(errorcode) { - cout << "Error: " << errorcode << endl; - break; - } - } - } -} - -void ovm_client_thread() { - tcp::socket socket(ioService); - tcp::endpoint endpoint(ip::address::from_string("127.0.0.1"), OSFM_OTHERVIEW_PORT); - socket.connect(endpoint); - - boost::system::error_code errorcode; - boost::asio::streambuf buf; - socket.send("Echo!"); - while(read(socket, buf, errorcode)) { - cout << &buf << endl; - if(errorcode) { - cout << "Error: " << errorcode << endl; - } - } -}*/ - -void ovh_write_named_pipe(string message) { - ofstream fifo(OSFM_NAMEDPIPE_NAME); - - fifo << message << endl; - fifo.close(); -} - -void clearPipe() { - ofstream fifo(OSFM_NAMEDPIPE_NAME); - fifo.clear(); - fifo.close(); -} - -string ovh_read_named_pipe() { - ifstream fifo(OSFM_NAMEDPIPE_NAME); - - string str; - while(fifo >> str) { - str += str; - } - fifo.close(); - clearPipe(); - - return str; -} - -OtherViewMessager::OtherViewMessager(const Config &c): - conf(c) -{ - Debug() << "Interprocessing start."; - try { - if (conf.isOtherView) { // Server-mode - ovh_write_named_pipe("Boo!"); - Debug() << ovh_read_named_pipe(); - - //OtherViewMessager::OpenOneShot(); - } else { - //ovh_read_shared_memory(); - //boost::thread c(ovm_client_thread); - } - } catch(exception& e) { - std::cerr << "[EXCEPTION] " << e.what() << endl; - } - Debug() << "If you see this, interprocessing has succeeded."; - // LowLevelCrashHandler::upload("If you see this, this is not a crash, it's just a test.\n -s"); -} - -void openoneshot_thread() { - ipstream pipeStream; - const std::string &path = shState->config().customDataPath; - const std::string &s = path.empty() ? "." : path; - #ifdef STEAM - #ifdef _WIN32 - child c(s + "/steamshim.exe --isOtherView=true", std_out > pipeStream); - #else - child c(s + "/steamshim --isOtherView=true", std_out > pipeStream); - #endif - #else - #ifdef _WIN32 - child c(s + "oneshot.exe --isOtherView=true", std_out > pipeStream); - #else - child c(s + "/lib/oneshot --isOtherView=true", std_out > pipeStream); - #endif - #endif - - string line; - while(pipeStream && getline(pipeStream, line) && !line.empty()) - cerr << "[Child ModShot] " << line << endl; -} - -void OtherViewMessager::OpenOneShot() { - boost::thread childModShot(openoneshot_thread); -} - -void OtherViewMessager::sendMsg(string str) { - ovh_write_named_pipe(str); -} - -string OtherViewMessager::getMsg() { - if(ovh_read_named_pipe() != "") - return ovh_read_named_pipe(); - else return ""; -} diff --git a/src/otherview-message.h.old b/src/otherview-message.h.old deleted file mode 100644 index 64004786..00000000 --- a/src/otherview-message.h.old +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include "etc.h" -#include - -struct Config; - -class OtherViewMessager { - const Config &conf; - -public: - OtherViewMessager(const Config &c); - void update(); - void sendMsg(std::string str); - std::string getMsg(); - int unreadMsgs(); - void closeSockets(); - - void OpenOneShot(); -}; \ No newline at end of file