~rycwo/forge

forge/meson.build -rw-r--r-- 4.2 KiB
d7ee94d6Ryan Chan Fix missing cd in .build.yml 11 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
project(
    'forge',
    'c',
    version : '0.1.0',
    license : 'GPL-3.0-only',
    meson_version: '>=0.54.0',
    default_options : [
        'warning_level=3',  # Enables -Wall, -Wextra, etc.
        'c_std=c11',
    ])

deps = [
    dependency('GL'),
    dependency('glew', version : '>=2.1.0'),
]

# https://mesonbuild.com/howtox.html#add-math-library-lm-portably
cc = meson.get_compiler('c')
deps += cc.find_library('m', required : false)

# Pre-compile GL 4.6 shaders to SPIR-V IR to be included directly in the binary.
glsl_validator = find_program('glslangValidator')
glsl_validator_args = ['-G', '-x']

optimization = get_option('optimization')

if get_option('debug') or optimization == 'g'
    glsl_validator_args += ['-g']
endif

if optimization != 'g'
    if optimization == 's'
        glsl_validator_args += ['-Os']
    elif optimization.to_int() == 0
        glsl_validator_args += ['-Od']
    endif
endif

spirv_gen = generator(
    glsl_validator,
    output : '@PLAINNAME@.spv',
    arguments : glsl_validator_args + ['-o', '@OUTPUT@', '@INPUT@'])

spirv_binary = spirv_gen.process(
    files([
        'shader/gui_rect.vert.glsl',
        'shader/gui_rect.frag.glsl'
    ]))

# Headers must be generated from inside include/forge for two reasons relating
# to custom_target behavior:
#
# 1. It is an error for output file names to have a path in its name.
# 2. Output files are placed in a directory layout in the private build tree
#    mirroring the source layout.
#
# We can then use include_directories as intended as it includes relative
# paths to both the source root *and* the private build root.
#
# Some helpful links:
#
# - https://github.com/mesonbuild/meson/issues/2320#issuecomment-774569905
# - https://mesonbuild.com/Reference-manual.html#include_directories
#
# Generated headers can thus be found in build/include/forge (assuming 'build'
# is your build directory).

# Declares:
# gen_headers:       list[custom_tgt]
subdir('include/forge')

includes = include_directories('include')

lib = library(
    meson.project_name(),
    files([
        'src/compare_float.c',
        'src/gui_basic.c',
        'src/gui_context.c',
        'src/gui_draw.c',
        'src/gui_graph.c',
        'src/gui_input.c',
        'src/gui_layout.c',
        'src/gui_opengl_46.c',
        'src/gui_util.c',
        'src/gui_window.c',
        'src/hash_table.c',
        'src/memory_pool.c',
        'src/murmur_hash.c',
        'src/pack_float.c',
        'src/pcg_basic.c',
        'src/random_double.c',
        'src/stb_sprintf.c',
    ]),
    gen_headers,
    spirv_binary,
    version : meson.project_version(),
    dependencies : deps,
    include_directories : includes,
    implicit_include_directories : false,
    install : true)

forge_dep = declare_dependency(
    sources : gen_headers,
    link_with : lib,
    version : meson.project_version(),
    dependencies : deps,
    include_directories : includes)

install_headers(
    files([
        'include/forge/allocator.h',
        'include/forge/collection.h',
        'include/forge/compare_float.h',
        'include/forge/compiler_attribute.h',
        'include/forge/expect.h',
        'include/forge/gui.h',
        'include/forge/gui_basic.h',
        'include/forge/gui_context.h',
        'include/forge/gui_draw.h',
        'include/forge/gui_graph.h',
        'include/forge/gui_input.h',
        'include/forge/gui_layout.h',
        'include/forge/gui_opengl_46.h',
        'include/forge/gui_type.h',
        'include/forge/gui_util.h',
        'include/forge/gui_window.h',
        'include/forge/hash_table.h',
        'include/forge/input.h',
        'include/forge/memory_pool.h',
        'include/forge/murmur_hash.h',
        'include/forge/pack_float.h',
        'include/forge/pcg_basic.h',
        'include/forge/random_double.h',
        'include/forge/stb_sprintf.h',
        'include/forge/stretchy_buffer.h',
    ]),
    subdir : meson.project_name())

pkgconfig = import('pkgconfig')
pkgconfig.generate(
    libraries : lib,
    name : lib.name(),
    version : meson.project_version(),
    filebase : meson.project_name(),
    description : 'Foundation library for Forge tools.',
    url : 'https://git.sr.ht/~rycwo/forge/')

subdir('test')