Skip to content

Commit

Permalink
Provide Meson alternative to CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Lyons committed Apr 27, 2022
1 parent 303f257 commit f04d583
Show file tree
Hide file tree
Showing 12 changed files with 330 additions and 186 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions assets/meson.build
Original file line number Diff line number Diff line change
@@ -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: '@[email protected]'.format(embedded_assets[count]),
command: [
xxd, '-i', '@INPUT@'
],
capture: true,
depend_files: embedded_assets_f[count]
)
count += 1
endforeach
42 changes: 42 additions & 0 deletions binding-mri/meson.build
Original file line number Diff line number Diff line change
@@ -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
76 changes: 76 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -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')
)
10 changes: 10 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -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.')
10 changes: 5 additions & 5 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
51 changes: 51 additions & 0 deletions shader/meson.build
Original file line number Diff line number Diff line change
@@ -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: '@[email protected]'.format(embedded_shaders[count]),
command: [
xxd, '-i', '@INPUT@'
],
capture: true,
depend_files: embedded_shaders_f[count]
)
count += 1
endforeach
6 changes: 3 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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

Expand Down
118 changes: 118 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit f04d583

Please sign in to comment.