From 66b5807368e6cd6f9dfa6eb9f88b59e820fc07ff Mon Sep 17 00:00:00 2001 From: mmcomando Date: Sun, 21 Feb 2021 20:44:58 +0100 Subject: [PATCH 1/2] Improve meson build. -Add all required packages as wrap dependencies -Move source lsitnings to separate files -Proper dependencies declarations -Set global D compiler arguments -Add few asserts -Add test exe -Other small improvements Tested with dmd with betterC, demos executable has to be run from 'demos' directory to properly load assets. --- .gitignore | 1 + demos/external/meson.build | 12 ++++ demos/meson.build | 72 ++++++++----------- demos/source/meson.build | 20 ++++++ demos/utils/meson.build | 44 +++++------- demos/utils/source/ecs_utils/meson.build | 18 +++++ meson.build | 70 +++++++++--------- meson_options.txt | 4 +- source/meson.build | 17 +++++ subprojects/bindbc-loader.wrap | 7 ++ subprojects/bindbc-sdl.wrap | 7 ++ subprojects/cimgui.wrap | 8 +++ .../packagefiles/bindbc-loader/meson.build | 24 +++++++ .../packagefiles/bindbc-sdl/meson.build | 72 +++++++++++++++++++ subprojects/packagefiles/cimgui/meson.build | 29 ++++++++ tests/meson.build | 13 ++++ 16 files changed, 314 insertions(+), 104 deletions(-) create mode 100644 demos/external/meson.build create mode 100644 demos/source/meson.build create mode 100644 demos/utils/source/ecs_utils/meson.build create mode 100644 source/meson.build create mode 100644 subprojects/bindbc-loader.wrap create mode 100644 subprojects/bindbc-sdl.wrap create mode 100644 subprojects/cimgui.wrap create mode 100644 subprojects/packagefiles/bindbc-loader/meson.build create mode 100644 subprojects/packagefiles/bindbc-sdl/meson.build create mode 100644 subprojects/packagefiles/cimgui/meson.build create mode 100644 tests/meson.build diff --git a/.gitignore b/.gitignore index 01f3210..f2e30a3 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ !codecov.yml !skeleton.html !**/meson.build +!**/*.wrap !meson_options.txt !compile_wasm.py !compile_android.py \ No newline at end of file diff --git a/demos/external/meson.build b/demos/external/meson.build new file mode 100644 index 0000000..0bfd84c --- /dev/null +++ b/demos/external/meson.build @@ -0,0 +1,12 @@ +demos_src += files( + 'sources/cimgui/cimgui.d', + 'sources/glad/gl/all.d', + 'sources/glad/gl/enums.d', + 'sources/glad/gl/ext.d', + 'sources/glad/gl/funcs.d', + 'sources/glad/gl/gl.d', + 'sources/glad/gl/gles2.d', + 'sources/glad/gl/loader.d', + 'sources/glad/gl/types.d', + 'sources/mmutils/thread_pool.d', +) \ No newline at end of file diff --git a/demos/meson.build b/demos/meson.build index 031928f..20df64c 100644 --- a/demos/meson.build +++ b/demos/meson.build @@ -1,45 +1,35 @@ -demos_src = [ - 'source/app.d', - 'source/demos/brick_breaker.d', - 'source/demos/snake.d', - 'source/demos/simple.d', - 'source/demos/sandbox.d', - 'source/demos/bullet_madnes.d', - 'source/demos/particles.d', - 'source/demos/physics.d', - 'source/demos/space_invaders.d', - 'source/game_core/basic.d', - 'source/game_core/job_updater.d', - 'source/game_core/rendering.d', - 'source/game_core/collision.d', - 'source/gui/component.d', - 'source/gui/manager.d', - 'source/gui/template_.d', - 'source/gui/tool_circle.d', - 'source/gui/system.d' -] +# Files +demos_src = files() +external_src = files() +subdir('source') +subdir('external') -external_src = [ - 'external/sources/mmutils/thread_pool.d', - 'external/sources/glad/gl/gl.d', - 'external/sources/glad/gl/loader.d', - 'external/sources/glad/gl/ext.d', - 'external/sources/glad/gl/all.d', - 'external/sources/glad/gl/funcs.d', - 'external/sources/glad/gl/gles2.d', - 'external/sources/glad/gl/enums.d', - 'external/sources/glad/gl/types.d', - 'external/sources/cimgui/cimgui.d' -] +demos_inc = include_directories('source/') +external_inc = include_directories('external/sources/') -demos_inc = include_directories(['source/']) +# Argumesnts +versions = ['BindSDL_Image','SDL_208', 'BindBC_Static', 'BindSDL_Static'] -#link_args += '-rpath=libs/linux/x64/' -link_args += '-L=' + meson.current_source_dir() + '/libs/linux/x64/libcimgui.so' -link_args += '-L' + meson.current_source_dir() + '/libs/linux/x64' -link_args += '-lcimgui' -#,"SDL2_image +# Dependencies +bindbc_loader_dep = dependency('bindbc-loader') +bindbc_sdl_dep = dependency('bindbc-sdl') +cimgui_dep = dependency('cimgui') +sdl2_dep = dependency('SDL2') +sdl2_image_dep = dependency('SDL2_image') -executable('demos', [demos_src, external_src], include_directories : [demos_inc, utils_inc, inc], d_args: args, link_args: link_args, - d_module_versions: ['BindSDL_Image','SDL_2010'], link_with: [ecs_lib, ecs_utils_lib], dependencies: [bc_loader_dep,sdl_dep], - build_rpath: '-L' + meson.current_source_dir() + '/libs/linux/x64/', install_rpath: 'libs/linux/x64/') \ No newline at end of file +subdir('utils') # Utils library + +executable('decs-demos', [demos_src, external_src], + include_directories : [demos_inc, external_inc], + d_module_versions : versions, + link_with : [ecs_lib, ecs_utils_lib], + dependencies : [ + bindbc_loader_dep, + bindbc_sdl_dep, + cimgui_dep, + decs_dep, + ecs_utils_dep, + sdl2_dep, + sdl2_image_dep, + ], +) \ No newline at end of file diff --git a/demos/source/meson.build b/demos/source/meson.build new file mode 100644 index 0000000..e578ca0 --- /dev/null +++ b/demos/source/meson.build @@ -0,0 +1,20 @@ +demos_src += files( + 'app.d', + 'demos/brick_breaker.d', + 'demos/bullet_madnes.d', + 'demos/particles.d', + 'demos/physics.d', + 'demos/sandbox.d', + 'demos/simple.d', + 'demos/snake.d', + 'demos/space_invaders.d', + 'game_core/basic.d', + 'game_core/collision.d', + 'game_core/job_updater.d', + 'game_core/rendering.d', + 'gui/component.d', + 'gui/manager.d', + 'gui/system.d', + 'gui/template_.d', + 'gui/tool_circle.d', +) \ No newline at end of file diff --git a/demos/utils/meson.build b/demos/utils/meson.build index f184e16..de9e958 100644 --- a/demos/utils/meson.build +++ b/demos/utils/meson.build @@ -1,31 +1,25 @@ -#project('ECSUtils', 'd') +# Files +utils_src = files() +subdir('source/ecs_utils') -utils_src = [ - 'source/ecs_utils/gfx/mesh.d', - 'source/ecs_utils/gfx/sprite.d', - 'source/ecs_utils/gfx/mesh_module.d', - 'source/ecs_utils/gfx/material.d', - 'source/ecs_utils/gfx/shader.d', - 'source/ecs_utils/gfx/vertex.d', - 'source/ecs_utils/gfx/config.d', - 'source/ecs_utils/gfx/buffer.d', - 'source/ecs_utils/gfx/render_list.d', - 'source/ecs_utils/gfx/renderer.d', - 'source/ecs_utils/gfx/texture.d', - 'source/ecs_utils/utils.d', - 'source/ecs_utils/math/matrix.d', - 'source/ecs_utils/math/vector.d', - 'source/ecs_utils/imgui_styles.d', - 'source/ecs_utils/imgui_bind.d' -] +utils_inc = include_directories('source/') -bc_loader_dep = dependency('bindbc-loader', method: 'dub') -sdl_dep = dependency('bindbc-sdl', method: 'dub') +# Dependencies +ecs_utils_lib = library('ecs_utils', utils_src, + include_directories : [demos_inc, external_inc, utils_inc], + link_args : link_args, + d_module_versions : versions, + dependencies : [ + decs_dep, + bindbc_loader_dep, + bindbc_sdl_dep, + ] +) -utils_inc = include_directories(['source/','../external/sources/']) - -ecs_utils_lib = library('ecs_utils', utils_src, include_directories : [utils_inc, inc], d_args: args, link_args: link_args, - d_module_versions: ['BindSDL_Image','SDL_2010'], link_with: ecs_lib, dependencies: [bc_loader_dep,sdl_dep]) +ecs_utils_dep = declare_dependency( + include_directories : utils_inc, + link_with : ecs_utils_lib, +) #shared_library('ecs_utils', utils_src, include_directories : [utils_inc], d_args: args, link_args: link_args, link_with: ecs_lib) diff --git a/demos/utils/source/ecs_utils/meson.build b/demos/utils/source/ecs_utils/meson.build new file mode 100644 index 0000000..14d443d --- /dev/null +++ b/demos/utils/source/ecs_utils/meson.build @@ -0,0 +1,18 @@ +utils_src += files( + 'gfx/mesh.d', + 'gfx/sprite.d', + 'gfx/mesh_module.d', + 'gfx/material.d', + 'gfx/shader.d', + 'gfx/vertex.d', + 'gfx/config.d', + 'gfx/buffer.d', + 'gfx/render_list.d', + 'gfx/renderer.d', + 'gfx/texture.d', + 'utils.d', + 'math/matrix.d', + 'math/vector.d', + 'imgui_styles.d', + 'imgui_bind.d', +) \ No newline at end of file diff --git a/meson.build b/meson.build index 4951584..d5cb683 100644 --- a/meson.build +++ b/meson.build @@ -1,42 +1,29 @@ -project('DECS', 'd') - -src = [ - 'source/bubel/ecs/atomic.d', - 'source/bubel/ecs/attributes.d', - 'source/bubel/ecs/block_allocator.d', - 'source/bubel/ecs/core.d', - 'source/bubel/ecs/entity.d', - 'source/bubel/ecs/events.d', - 'source/bubel/ecs/hash_map.d', - 'source/bubel/ecs/id_manager.d', - 'source/bubel/ecs/manager.d', - 'source/bubel/ecs/package.d', - 'source/bubel/ecs/simple_vector.d', - 'source/bubel/ecs/std.d', - 'source/bubel/ecs/system.d', - 'source/bubel/ecs/traits.d', - 'source/bubel/ecs/vector.d' -] - -tests_src = [ - 'tests/tests.d' -] +project('decs', 'd', version : '0.5.0') +# Options betterC_opt = get_option('betterC') BuildDemos_opt = get_option('BuildDemos') LTO_otp = get_option('LTO') -comp = meson.get_compiler('d') +summary('betterC enabled', betterC_opt) +summary('build demos', BuildDemos_opt) +summary('LTO enabled', LTO_otp) -comp_id = comp.get_id() +meson_minimum_version = '>=0.57.1' +assert(meson.version().version_compare(meson_minimum_version), 'Newer verson of meson required, current version: @0@, required: @1@'.format(meson.version(), meson_minimum_version)) +# Files +src = files() +subdir('source') + +inc = include_directories('source/') + +# Arguments args = [] link_args = [] -if comp_id == 'gcc' - args += '-pthread' - link_args += '-pthread' -endif +comp = meson.get_compiler('d') +comp_id = comp.get_id() if LTO_otp if comp_id == 'gcc' @@ -46,7 +33,7 @@ if LTO_otp args += '-flto=thin' link_args += '-flto=thin' else - message('LTO don\'t work with DMD') + assert(false, 'Compiler "@0@" doesn\'t support LTO'.format(comp_id)) endif endif @@ -60,16 +47,27 @@ if betterC_opt endif endif -inc = include_directories('source/') -tests_inc = include_directories('source/') +add_global_arguments(args, language : 'd') +add_global_link_arguments(link_args, language : 'd') -ecs_lib = library('ecs', src, include_directories : [tests_inc, inc], d_args: args, link_args: link_args) +# Dependencies +threads_dep = dependency('threads') -executable('tests', tests_src, include_directories : [tests_inc, inc], d_args: args, link_args: link_args, link_with: ecs_lib) +ecs_lib = library('decs', + src, + include_directories : [inc], +) -bubel_ecs_dep = declare_dependency(include_directories : [inc], link_with : ecs_lib) +decs_dep = declare_dependency( + include_directories : [inc], + link_with : ecs_lib, + dependencies : threads_dep, +) +# Tests +subdir('tests') + +# Demos if BuildDemos_opt - subdir('demos/utils') subdir('demos') endif diff --git a/meson_options.txt b/meson_options.txt index 0ea2df9..ba79c90 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,3 +1,3 @@ -option('betterC', type: 'boolean', value: false) -option('BuildDemos', type: 'boolean', value: false) +option('betterC', type: 'boolean', value: true) +option('BuildDemos', type: 'boolean', value: true) option('LTO', type: 'boolean', value: false) \ No newline at end of file diff --git a/source/meson.build b/source/meson.build new file mode 100644 index 0000000..de5da33 --- /dev/null +++ b/source/meson.build @@ -0,0 +1,17 @@ +src += files( + 'bubel/ecs/atomic.d', + 'bubel/ecs/attributes.d', + 'bubel/ecs/block_allocator.d', + 'bubel/ecs/core.d', + 'bubel/ecs/entity.d', + 'bubel/ecs/events.d', + 'bubel/ecs/hash_map.d', + 'bubel/ecs/id_manager.d', + 'bubel/ecs/manager.d', + 'bubel/ecs/package.d', + 'bubel/ecs/simple_vector.d', + 'bubel/ecs/std.d', + 'bubel/ecs/system.d', + 'bubel/ecs/traits.d', + 'bubel/ecs/vector.d', +) \ No newline at end of file diff --git a/subprojects/bindbc-loader.wrap b/subprojects/bindbc-loader.wrap new file mode 100644 index 0000000..b99f744 --- /dev/null +++ b/subprojects/bindbc-loader.wrap @@ -0,0 +1,7 @@ +[wrap-git] +url = https://github.com/BindBC/bindbc-loader.git +revision = 9a51af991acce3c67e51695c07bf3fa6419ef938 +patch_directory = bindbc-loader + +[provide] +dependency_names = bindbc-loader diff --git a/subprojects/bindbc-sdl.wrap b/subprojects/bindbc-sdl.wrap new file mode 100644 index 0000000..3b159a0 --- /dev/null +++ b/subprojects/bindbc-sdl.wrap @@ -0,0 +1,7 @@ +[wrap-git] +url = https://github.com/BindBC/bindbc-sdl.git +revision = 5c936064b7226630f5080f4b12b77ee39c8ac64b +patch_directory = bindbc-sdl + +[provide] +dependency_names = bindbc-sdl diff --git a/subprojects/cimgui.wrap b/subprojects/cimgui.wrap new file mode 100644 index 0000000..67d2107 --- /dev/null +++ b/subprojects/cimgui.wrap @@ -0,0 +1,8 @@ +[wrap-git] +url = https://github.com/cimgui/cimgui.git +revision = 1c65ee2bdc719fb3ef62b4615d66fe8effa21148 +clone-recursive = true +patch_directory = cimgui + +[provide] +dependency_names = cimgui diff --git a/subprojects/packagefiles/bindbc-loader/meson.build b/subprojects/packagefiles/bindbc-loader/meson.build new file mode 100644 index 0000000..ce3bdf0 --- /dev/null +++ b/subprojects/packagefiles/bindbc-loader/meson.build @@ -0,0 +1,24 @@ +project('bindbc-loader', 'd', version : '0.3.2', default_options: ['default_library=static']) + +# Files +src = files( + 'source/bindbc/loader/package.d', + 'source/bindbc/loader/sharedlib.d', + 'source/bindbc/loader/system.d', +) + +inc = include_directories('source') + +# Dependencies +lib = library('bindbc-loader', src, + include_directories : [inc], + pic : true, + d_module_versions: ['BindBC_Static'], +) + +bindbc_loader_dep = declare_dependency( + include_directories : [inc], + link_with : lib, +) + +meson.override_dependency('bindbc-loader', bindbc_loader_dep) \ No newline at end of file diff --git a/subprojects/packagefiles/bindbc-sdl/meson.build b/subprojects/packagefiles/bindbc-sdl/meson.build new file mode 100644 index 0000000..0c95cc5 --- /dev/null +++ b/subprojects/packagefiles/bindbc-sdl/meson.build @@ -0,0 +1,72 @@ +project('bindbc-sdl', 'd', version : '0.19.2', default_options: ['default_library=static']) + +# Files +src = files( + 'source/bindbc/sdl/bind/package.d', + 'source/bindbc/sdl/bind/sdl.d', + 'source/bindbc/sdl/bind/sdlassert.d', + 'source/bindbc/sdl/bind/sdlatomic.d', + 'source/bindbc/sdl/bind/sdlaudio.d', + 'source/bindbc/sdl/bind/sdlblendmode.d', + 'source/bindbc/sdl/bind/sdlclipboard.d', + 'source/bindbc/sdl/bind/sdlcpuinfo.d', + 'source/bindbc/sdl/bind/sdlerror.d', + 'source/bindbc/sdl/bind/sdlevents.d', + 'source/bindbc/sdl/bind/sdlfilesystem.d', + 'source/bindbc/sdl/bind/sdlgamecontroller.d', + 'source/bindbc/sdl/bind/sdlgesture.d', + 'source/bindbc/sdl/bind/sdlhaptic.d', + 'source/bindbc/sdl/bind/sdlhints.d', + 'source/bindbc/sdl/bind/sdljoystick.d', + 'source/bindbc/sdl/bind/sdlkeyboard.d', + 'source/bindbc/sdl/bind/sdlkeycode.d', + 'source/bindbc/sdl/bind/sdlloadso.d', + 'source/bindbc/sdl/bind/sdllog.d', + 'source/bindbc/sdl/bind/sdlmessagebox.d', + 'source/bindbc/sdl/bind/sdlmouse.d', + 'source/bindbc/sdl/bind/sdlmutex.d', + 'source/bindbc/sdl/bind/sdlpixels.d', + 'source/bindbc/sdl/bind/sdlplatform.d', + 'source/bindbc/sdl/bind/sdlpower.d', + 'source/bindbc/sdl/bind/sdlrect.d', + 'source/bindbc/sdl/bind/sdlrender.d', + 'source/bindbc/sdl/bind/sdlrwops.d', + 'source/bindbc/sdl/bind/sdlscancode.d', + 'source/bindbc/sdl/bind/sdlshape.d', + 'source/bindbc/sdl/bind/sdlstdinc.d', + 'source/bindbc/sdl/bind/sdlsurface.d', + 'source/bindbc/sdl/bind/sdlsystem.d', + 'source/bindbc/sdl/bind/sdlsyswm.d', + 'source/bindbc/sdl/bind/sdlthread.d', + 'source/bindbc/sdl/bind/sdltimer.d', + 'source/bindbc/sdl/bind/sdltouch.d', + 'source/bindbc/sdl/bind/sdlversion.d', + 'source/bindbc/sdl/bind/sdlvideo.d', + 'source/bindbc/sdl/bind/sdlvulkan.d', + 'source/bindbc/sdl/config.d', + 'source/bindbc/sdl/dynload.d', + 'source/bindbc/sdl/image.d', + 'source/bindbc/sdl/mixer.d', + 'source/bindbc/sdl/net.d', + 'source/bindbc/sdl/package.d', + 'source/bindbc/sdl/ttf.d', +) + +inc = include_directories('source') + +# Dependencies +bindbc_loader_dep = dependency('bindbc-loader') + +lib = library('bindbc-sdl', src, + dependencies : bindbc_loader_dep, + include_directories : [inc], + d_module_versions: ['BindBC_Static'], + pic : true, +) + +bindbc_sdl_dep = declare_dependency( + include_directories : [inc], + link_with : lib, +) + +meson.override_dependency('bindbc-sdl', bindbc_sdl_dep) \ No newline at end of file diff --git a/subprojects/packagefiles/cimgui/meson.build b/subprojects/packagefiles/cimgui/meson.build new file mode 100644 index 0000000..e4c1a41 --- /dev/null +++ b/subprojects/packagefiles/cimgui/meson.build @@ -0,0 +1,29 @@ +project('cimgui', 'cpp', version : '1.73.0', default_options: ['default_library=shared', 'warning_level=1']) + +# Files +src = [ + 'cimgui.cpp', + 'imgui/imgui.cpp', + 'imgui/imgui_draw.cpp', + 'imgui/imgui_demo.cpp', + 'imgui/imgui_widgets.cpp', +] + +inc = [ '.' ] +pub_inc = [ 'imgui' ] + +# Dependencies +# bindbc_loader_dep = dependency('bindbc-loader') + +lib = shared_library('cimgui', src, + # dependencies : bindbc_loader_dep, + include_directories : [inc, pub_inc], + # pic : true, +) + +cimgui_dep = declare_dependency( + include_directories : [pub_inc], + link_with : lib, +) + +meson.override_dependency('cimgui', cimgui_dep) \ No newline at end of file diff --git a/tests/meson.build b/tests/meson.build new file mode 100644 index 0000000..dae8536 --- /dev/null +++ b/tests/meson.build @@ -0,0 +1,13 @@ +tests_src = files( + 'tests.d', +) + +exe = executable('decs-tests', + tests_src, + include_directories : [inc], + d_args : args, + link_args : link_args, + dependencies : decs_dep, +) + +test('basic-tests', exe) From 073f91fc4a0a0d213e5d89c22872e263000889bf Mon Sep 17 00:00:00 2001 From: Dawid Masiukiewicz Date: Thu, 25 Feb 2021 18:49:39 +0000 Subject: [PATCH 2/2] Update meson_options.txt --- meson_options.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/meson_options.txt b/meson_options.txt index ba79c90..1ab62f0 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,3 +1,3 @@ -option('betterC', type: 'boolean', value: true) -option('BuildDemos', type: 'boolean', value: true) -option('LTO', type: 'boolean', value: false) \ No newline at end of file +option('betterC', type: 'boolean', value: false) +option('BuildDemos', type: 'boolean', value: false) +option('LTO', type: 'boolean', value: false)