Skip to content

Commit

Permalink
3rdparty: use meson subprojects instead
Browse files Browse the repository at this point in the history
Major refactor of the source code structure. Now uses meson subprojects
for "third party" dependencies (including bstr and talloc), and moves a
lot of the meson boilerplate from src/meson.build to the top-level
meson.build.

We choose the name 'xtalloc' to make sure we don't collide with samba
libtalloc, and to reflect the fact that our wrappers abort on OOM.
  • Loading branch information
haasn committed Dec 4, 2018
1 parent 5c88b30 commit 195f28e
Show file tree
Hide file tree
Showing 24 changed files with 168 additions and 119 deletions.
64 changes: 64 additions & 0 deletions meson.build
Expand Up @@ -2,6 +2,70 @@ project('libplacebo', ['c', 'cpp'],
license: 'LGPL2.1+',
default_options: ['c_std=c99'],
meson_version: '>=0.47',
version: '1.7.0',
)

# Version number
version = meson.project_version()
version_pretty = 'v' + version
version_split = version.split('.')

majorver = version_split[0]
apiver = version_split[1]
fixver = version_split[2]

# update `version_pretty` with `git describe` information if available
git = find_program('git', required: false)
if git.found()
gitdesc = run_command(git, 'describe')
if gitdesc.returncode() == 0
version_pretty = gitdesc.stdout().strip()
endif
endif


# Global build options
build_opts = [
# Warnings
'-Wall', '-Wundef', '-Wshadow', '-Wparentheses', '-Wpointer-arith',

# Warnings to treat as errors
'-Werror=implicit-function-declaration',
]

link_args = []

cc = meson.get_compiler('c')
cxx = meson.get_compiler('cpp')

c_opts = [
'-D_ISOC99_SOURCE', '-D_GNU_SOURCE', '-D_XOPEN_SOURCE=700',
'-U__STRICT_ANSI__', '-fvisibility=hidden',
'-Wmissing-prototypes', '-Wno-pointer-sign'
]

# glslang needs c++11
cpp_opts = [
'-std=c++11', '-fvisibility=hidden',
]

if cc.has_argument('-Wincompatible-pointer-types')
build_opts += ['-Werror=incompatible-pointer-types']
endif

# clang's version of -Wmissing-braces rejects the common {0} initializers
if cc.get_id() == 'clang'
build_opts += ['-Wno-missing-braces']
endif

# don't leak library symbols if possible
vflag = '-Wl,--exclude-libs=ALL'
if cc.has_link_argument(vflag)
link_args += [vflag]
endif

add_global_arguments(build_opts + c_opts, language: 'c')
add_global_arguments(build_opts + cpp_opts, language: 'cpp')
add_global_link_arguments(link_args, language: 'c')

subdir('src')
4 changes: 3 additions & 1 deletion src/common.h
Expand Up @@ -24,11 +24,13 @@
#include <stdint.h>
#include <inttypes.h>

#include "ta/talloc.h"
#include "config.h"
#include "config_internal.h"
#include "pl_assert.h"

#include <xtalloc.h>
#include <bstr.h>

// Include all of the symbols that should be public in a way that marks them
// as being externally visible. (Otherwise, all symbols are hidden by default)
#pragma GCC visibility push(default)
Expand Down
2 changes: 0 additions & 2 deletions src/context.h
Expand Up @@ -18,8 +18,6 @@
#pragma once

#include <stdarg.h>
#include "bstr/bstr.h"

#include "common.h"

struct pl_context {
Expand Down
2 changes: 1 addition & 1 deletion src/glsl/glslang.cc
Expand Up @@ -19,7 +19,7 @@
#include <pthread.h>

extern "C" {
#include "ta/talloc.h"
#include <xtalloc.h>
}

#include <glslang/Include/ResourceLimits.h>
Expand Down
1 change: 0 additions & 1 deletion src/lcms.h
Expand Up @@ -18,7 +18,6 @@
#pragma once

#include "common.h"
#include "bstr/bstr.h"

// Compute a transformation from one color profile to another, and fill the
// provided array by the resulting 3DLUT. The array must have room for four
Expand Down
148 changes: 46 additions & 102 deletions src/meson.build
@@ -1,109 +1,25 @@
majorver = '1'
apiver = '7'
fixver = '0'

version = majorver + '.' + apiver + '.' + fixver

# Configuration
conf_public = configuration_data()
conf_internal = configuration_data()
conf_public.set('majorver', majorver)
conf_public.set('apiver', apiver)
conf_public.set('fixver', fixver)
conf_public.set_quoted('version', 'v' + version)

## Update PL_VERSION with `git describe` information if available
git = find_program('git', required: false)
if git.found()
gitdesc = run_command(git, 'describe')
if gitdesc.returncode() == 0
conf_public.set_quoted('version', gitdesc.stdout().strip())
endif
endif

c_opts = [
'-D_ISOC99_SOURCE', '-D_GNU_SOURCE', '-D_XOPEN_SOURCE=700',
'-U__STRICT_ANSI__', '-fvisibility=hidden',
'-Wmissing-prototypes', '-Wno-pointer-sign'
]

# glslang needs c++11
cpp_opts = [
'-std=c++11', '-fvisibility=hidden',
]

# Build options mostly taken from mpv
build_opts = [
# Warnings
'-Wall', '-Wundef', '-Wshadow', '-Wparentheses', '-Wpointer-arith',

# Warnings to treat as errors
'-Werror=implicit-function-declaration',
]

link_args = []

# Depedencies
cc = meson.get_compiler('c')
cxx = meson.get_compiler('cpp')

if cc.has_argument('-Wincompatible-pointer-types')
build_opts += ['-Werror=incompatible-pointer-types']
endif

# clang's version of -Wmissing-braces rejects the common {0} initializers
if cc.get_id() == 'clang'
build_opts += ['-Wno-missing-braces']
endif

vflag = '-Wl,--exclude-libs=ALL'
if cc.has_link_argument(vflag)
link_args += [vflag]
endif

# Global dependencies
build_deps = [
dependency('threads'),
cc.find_library('m', required: false),
subproject('xtalloc').get_variable('dep'),
subproject('bstr').get_variable('dep'),
]

vulkan = dependency('vulkan', version: '>=1.0.42', required: get_option('vulkan'))

# Source files
sources = [
'colorspace.c',
'common.c',
'context.c',
'dither.c',
'dispatch.c',
'filters.c',
'gpu.c',
'renderer.c',
'shaders.c',
'shaders/av1.c',
'shaders/colorspace.c',
'shaders/sampling.c',
'spirv.c',
'swapchain.c',
'utils/upload.c',

# Helpers ported from mpv or other projects
'bstr/bstr.c',
'bstr/format.c',
'3rdparty/siphash.c',
'ta/ta.c',
'ta/ta_utils.c',
'ta/talloc.c',
]
# configuration data
conf_public = configuration_data()
conf_internal = configuration_data()
conf_public.set('majorver', majorver)
conf_public.set('apiver', apiver)
conf_public.set('fixver', fixver)
conf_public.set_quoted('version', version_pretty)

tests = [
'context.c',
'colorspace.c',
'dither.c',
'filters.c',
'utils.c',
]

# Work-arounds for shaderc braindeath
# work-arounds for shaderc braindeath
shaderc_names = [
'shaderc_shared',
'shaderc_combined',
Expand All @@ -124,7 +40,7 @@ if shaderc.found()
))
endif

# Work-arounds for glslang braindeath
# work-arounds for glslang braindeath
glslang_combined = disabler()
glslang_min_ver = 2763
glslang_req = get_option('glslang')
Expand Down Expand Up @@ -173,6 +89,35 @@ if glslang_found
endif
endif


# Source files
sources = [
'colorspace.c',
'common.c',
'context.c',
'dither.c',
'dispatch.c',
'filters.c',
'gpu.c',
'renderer.c',
'shaders.c',
'shaders/av1.c',
'shaders/colorspace.c',
'shaders/sampling.c',
'spirv.c',
'swapchain.c',
'utils/upload.c',
]

tests = [
'context.c',
'colorspace.c',
'dither.c',
'filters.c',
'utils.c',
]


# Optional dependencies / components
components = [
{
Expand Down Expand Up @@ -204,7 +149,6 @@ components = [
}
]

# Build process
defs = ''
comps = configuration_data()

Expand All @@ -223,7 +167,7 @@ foreach c : components
endif
endforeach

# Check to see if libplacebo built this way is sane
# check to see if libplacebo built this way is sane
if not comps.has('vulkan')
warning('Building without support for Vulkan. Currently, libplacebo only ' +
'supports the Vulkan graphics API. libplacebo built this way still ' +
Expand All @@ -237,7 +181,8 @@ if comps.has('vulkan') and not (comps.has('shaderc') or comps.has('glslang'))
'compile GLSL to SPIR-V (needed by the Vulkan API)!')
endif

# Generate the config headers

# Build process
conf_public.set('extra_defs', defs)

configure_file(
Expand All @@ -252,9 +197,6 @@ configure_file(
configuration: conf_internal
)

# Build process
add_project_arguments(build_opts + c_opts, language: 'c')
add_project_arguments(build_opts + cpp_opts, language: 'cpp')
inc = include_directories('./include')
lib = library('placebo', sources,
install: true,
Expand All @@ -264,6 +206,7 @@ lib = library('placebo', sources,
link_args: link_args,
)


# Install process
install_subdir('include/libplacebo', install_dir: get_option('includedir'))

Expand All @@ -275,6 +218,7 @@ pkg.generate(
version: version,
)


# Tests
tdeps = [ declare_dependency(link_with: lib) ]

Expand Down
1 change: 0 additions & 1 deletion src/shaders.c
Expand Up @@ -18,7 +18,6 @@
#include <stdio.h>
#include <math.h>

#include "bstr/bstr.h"
#include "common.h"
#include "context.h"
#include "shaders.h"
Expand Down
1 change: 0 additions & 1 deletion src/shaders.h
Expand Up @@ -18,7 +18,6 @@
#pragma once

#include <stdio.h>
#include "bstr/bstr.h"

#include "common.h"
#include "context.h"
Expand Down
File renamed without changes.
3 changes: 1 addition & 2 deletions src/bstr/bstr.c → subprojects/bstr/bstr.c
Expand Up @@ -24,8 +24,7 @@
#include <stdio.h>
#include <limits.h>

#include "ta/talloc.h"
#include "bstr.h"
#include "include/bstr.h"
#include "ctype.h"

#define MIN(a, b) ((a) > (b) ? (b) : (a))
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/bstr/format.c → subprojects/bstr/format.c
Expand Up @@ -20,7 +20,7 @@
#include <stdio.h>
#include <stdarg.h>

#include "bstr.h"
#include "include/bstr.h"

int ccStrPrintInt32( char *str, int32_t n );
int ccStrPrintUint32( char *str, uint32_t n );
Expand Down
7 changes: 4 additions & 3 deletions src/bstr/bstr.h → subprojects/bstr/include/bstr.h
Expand Up @@ -23,9 +23,10 @@
#include <stdbool.h>
#include <stdarg.h>

#include "osdep/compiler.h"
#include "ta/talloc.h"
#include "3rdparty/siphash.h"
#include "../osdep.h"
#include "../siphash.h"

#include <xtalloc.h>

/* NOTE: 'len' is size_t, but most string-handling functions below assume
* that input size has been sanity checked and len fits in an int.
Expand Down

0 comments on commit 195f28e

Please sign in to comment.