Skip to content

Commit

Permalink
Add meson build system support
Browse files Browse the repository at this point in the history
  • Loading branch information
mochaaP committed Sep 14, 2024
1 parent 419cde9 commit c1545cd
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 0 deletions.
148 changes: 148 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
project(
'Zycore',
'c',
version: '1.5.0',
license: 'MIT',
license_files: 'LICENSE',
meson_version: '>=1.3',
default_options: [
'c_std=c11',
'cpp_std=c++17',
'warning_level=3',
],
)

inc = include_directories('include')

dep = []

hdrs_api = files(
# API
'include/Zycore/API/Memory.h',
'include/Zycore/API/Process.h',
'include/Zycore/API/Synchronization.h',
'include/Zycore/API/Terminal.h',
'include/Zycore/API/Thread.h',
)

hdrs_common = files(
# Common
'include/Zycore/Allocator.h',
'include/Zycore/ArgParse.h',
'include/Zycore/Atomic.h',
'include/Zycore/Bitset.h',
'include/Zycore/Comparison.h',
'include/Zycore/Defines.h',
'include/Zycore/Format.h',
'include/Zycore/LibC.h',
'include/Zycore/List.h',
'include/Zycore/Object.h',
'include/Zycore/Status.h',
'include/Zycore/String.h',
'include/Zycore/Types.h',
'include/Zycore/Vector.h',
'include/Zycore/Zycore.h',
)

hdrs_internal = files(
'include/Zycore/Internal/AtomicGNU.h',
'include/Zycore/Internal/AtomicMSVC.h',
)

hdrs = hdrs_api + hdrs_common + hdrs_internal

src = files(
# API
'src/API/Memory.c',
'src/API/Process.c',
'src/API/Synchronization.c',
'src/API/Terminal.c',
'src/API/Thread.c',
# Common
'src/Allocator.c',
'src/ArgParse.c',
'src/Bitset.c',
'src/Format.c',
'src/List.c',
'src/String.c',
'src/Vector.c',
'src/Zycore.c',
)

if host_machine.system() == 'windows'
src += files('resources/VersionInfo.rc')
endif

if get_option('nolibc')
add_project_arguments(
'-DZYAN_NO_LIBC',
language: 'c',
)
dep += declare_dependency(link_args: ['-nostdlib', '-nodefaultlibs'])
elif host_machine.system() == 'linux'
add_project_arguments(
'-D_GNU_SOURCE',
language: 'c',
)
dep += dependency('threads')
endif

zycore_lib = library(
'Zycore',
src + hdrs,
c_static_args: ['-DZYCORE_STATIC_BUILD'],
include_directories: inc,
implicit_include_directories: false,
dependencies: dep,
version: meson.project_version(),
install: true,
)

install_headers(hdrs_common, subdir: 'Zycore')
install_headers(hdrs_api, subdir: 'Zycore/API')
install_headers(hdrs_internal, subdir: 'Zycore/Internal')

zycore_dep = declare_dependency(
include_directories: inc,
link_with: zycore_lib,
)

if not get_option('nolibc')
gtest_dep = dependency('gtest', required: false)
if gtest_dep.found() and add_languages('cpp', native: false)
test(
'string',
executable(
'test_string',
'tests/String.cpp',
dependencies: [gtest_dep, zycore_dep],
),
)
test(
'vector',
executable(
'test_vector',
'tests/Vector.cpp',
dependencies: [gtest_dep, zycore_dep],
),
)
test(
'argparse',
executable(
'test_argparse',
'tests/ArgParse.cpp',
dependencies: [gtest_dep, zycore_dep],
),
)
endif
endif

pkg = import('pkgconfig')
pkg.generate(
zycore_lib,
name: 'zycore',
description: 'Internal library providing platform independent types, macros and a fallback for environments without LibC.',
url: 'https://github.com/zyantific/zycore-c',
)

meson.override_dependency('zycore', zycore_dep)
6 changes: 6 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
option(
'nolibc',
type: 'boolean',
value: false,
description: 'Do not use any C standard library functions (for exotic build-envs like kernel drivers)',
)
16 changes: 16 additions & 0 deletions subprojects/gtest.wrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[wrap-file]
directory = googletest-1.15.0
source_url = https://github.com/google/googletest/archive/refs/tags/v1.15.0.tar.gz
source_filename = gtest-1.15.0.tar.gz
source_hash = 7315acb6bf10e99f332c8a43f00d5fbb1ee6ca48c52f6b936991b216c586aaad
patch_filename = gtest_1.15.0-1_patch.zip
patch_url = https://wrapdb.mesonbuild.com/v2/gtest_1.15.0-1/get_patch
patch_hash = 5f8e484c48fdc1029c7fd08807bd2615f8c9d16f90df6d81984f4f292752c925
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/gtest_1.15.0-1/gtest-1.15.0.tar.gz
wrapdb_version = 1.15.0-1

[provide]
gtest = gtest_dep
gtest_main = gtest_main_dep
gmock = gmock_dep
gmock_main = gmock_main_dep

0 comments on commit c1545cd

Please sign in to comment.