From 877d17236578a83822710fe241f3b4bdc8796862 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Thu, 4 Dec 2025 12:04:25 -0500 Subject: [PATCH 1/3] meson: Add top level meson.build --- .github/workflows/ffmpeg.yml | 4 ++-- .github/workflows/libvmaf.yml | 6 +++--- .github/workflows/windows.yml | 6 +++--- Makefile | 11 +++++------ libvmaf/meson.build | 10 ---------- meson.build | 11 +++++++++++ libvmaf/meson_options.txt => meson_options.txt | 0 resource/doc/windows.md | 4 ++-- 8 files changed, 26 insertions(+), 26 deletions(-) create mode 100644 meson.build rename libvmaf/meson_options.txt => meson_options.txt (100%) diff --git a/.github/workflows/ffmpeg.yml b/.github/workflows/ffmpeg.yml index 5d04cb354..086f371e0 100644 --- a/.github/workflows/ffmpeg.yml +++ b/.github/workflows/ffmpeg.yml @@ -44,8 +44,8 @@ jobs: - uses: actions/checkout@v6 - name: Build vmaf run: | - meson setup libvmaf libvmaf/build --buildtype release - sudo ninja -vC libvmaf/build install + meson setup builddir --buildtype release + sudo ninja -vC builddir install - name: Prepare FFmpeg run: | git clone -q --branch master --depth=1 "https://github.com/FFmpeg/FFmpeg" ffmpeg diff --git a/.github/workflows/libvmaf.yml b/.github/workflows/libvmaf.yml index cb044043a..2d24bde01 100644 --- a/.github/workflows/libvmaf.yml +++ b/.github/workflows/libvmaf.yml @@ -71,13 +71,13 @@ jobs: - uses: actions/checkout@v6 - name: Run meson run: | - meson setup libvmaf libvmaf/build --buildtype release --prefix $PWD/install -Denable_float=true + meson setup builddir --buildtype release --prefix $PWD/install -Denable_float=true - name: Run ninja run: | - sudo ninja -vC libvmaf/build install + sudo ninja -vC builddir install - name: Run tests run: | - sudo ninja -vC libvmaf/build test + sudo ninja -vC builddir test - name: Set up tox run: | mkdir -p ~/.ccache && sudo chown -R $(whoami) ~/.ccache diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index d8763d6bb..a4b365e6e 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -50,12 +50,12 @@ jobs: run: echo "name=CCACHE_DIR::$PWD/.ccache" >> $GITHUB_ENV - name: Configure vmaf - run: meson setup libvmaf libvmaf/build --buildtype release --default-library static --prefix "$MINGW_PREFIX" + run: meson setup builddir --buildtype release --default-library static --prefix "$MINGW_PREFIX" - name: Build vmaf - run: meson install -C libvmaf/build + run: meson install -C builddir - name: Test vmaf - run: meson test -C libvmaf/build --num-processes $(nproc) + run: meson test -C builddir --num-processes $(nproc) - name: Get binary path & Current Release id: get_info diff --git a/Makefile b/Makefile index a83910b51..10dd92242 100644 --- a/Makefile +++ b/Makefile @@ -21,9 +21,8 @@ ENABLE_NVCC := true ENABLE_CUDA := -Denable_cuda=true -Denable_nvcc=$(ENABLE_NVCC) # Directories -LIBVMAF_DIR := libvmaf -BUILD_DIR := $(LIBVMAF_DIR)/build -DEBUG_DIR := $(LIBVMAF_DIR)/debug +BUILD_DIR := builddir +DEBUG_DIR := builddir-debug .PHONY: default all debug build install cythonize clean distclean cythonize-deps @@ -32,10 +31,10 @@ default: build all: build debug install test cythonize $(BUILD_DIR): $(MESON) $(NINJA) - PATH="$(VENV)/bin:$$PATH" $(MESON_SETUP) $(BUILD_DIR) $(LIBVMAF_DIR) $(BUILDTYPE_RELEASE) $(ENABLE_FLOAT) $(ENABLE_CUDA) + PATH="$(VENV)/bin:$$PATH" $(MESON_SETUP) $(BUILD_DIR) $(BUILDTYPE_RELEASE) $(ENABLE_FLOAT) $(ENABLE_CUDA) $(DEBUG_DIR): $(MESON) $(NINJA) - PATH="$(VENV)/bin:$$PATH" $(MESON_SETUP) $(DEBUG_DIR) $(LIBVMAF_DIR) $(BUILDTYPE_DEBUG) $(ENABLE_FLOAT) $(ENABLE_CUDA) + PATH="$(VENV)/bin:$$PATH" $(MESON_SETUP) $(DEBUG_DIR) $(BUILDTYPE_DEBUG) $(ENABLE_FLOAT) $(ENABLE_CUDA) cythonize: cythonize-deps pushd python && ../$(VENV_PYTHON) setup.py build_ext --build-lib . && popd || exit 1 @@ -73,4 +72,4 @@ $(NINJA): $(VENV_PIP) $(VENV_PIP) install ninja || { echo "Failed to install ninja"; exit 1; } cythonize-deps: $(VENV_PIP) - $(VENV_PIP) install setuptools cython numpy || { echo "Failed to install dependencies"; exit 1; } \ No newline at end of file + $(VENV_PIP) install setuptools cython numpy || { echo "Failed to install dependencies"; exit 1; } diff --git a/libvmaf/meson.build b/libvmaf/meson.build index cf20cecbd..f09d69a14 100644 --- a/libvmaf/meson.build +++ b/libvmaf/meson.build @@ -1,13 +1,3 @@ -project('libvmaf', ['c', 'cpp'], - version : '3.0.0', - default_options : ['c_std=c11', - 'cpp_std=c++11', - 'warning_level=2', - 'buildtype=release', - 'default_library=both', - ], - meson_version: '>= 0.56.1') - vmaf_soname_version = '3.0.0' vmaf_api_version_array = vmaf_soname_version.split('.') vmaf_api_version_major = vmaf_api_version_array[0] diff --git a/meson.build b/meson.build new file mode 100644 index 000000000..219c8dc28 --- /dev/null +++ b/meson.build @@ -0,0 +1,11 @@ +project('libvmaf', ['c', 'cpp'], + version : '3.0.0', + default_options : ['c_std=c11', + 'cpp_std=c++11', + 'warning_level=2', + 'buildtype=release', + 'default_library=both', + ], + meson_version: '>= 0.56.1') + +subdir('libvmaf') diff --git a/libvmaf/meson_options.txt b/meson_options.txt similarity index 100% rename from libvmaf/meson_options.txt rename to meson_options.txt diff --git a/resource/doc/windows.md b/resource/doc/windows.md index 8c3d9bace..806ffb5fb 100644 --- a/resource/doc/windows.md +++ b/resource/doc/windows.md @@ -16,5 +16,5 @@ We are going to build vmaf in Windows. These steps are in accordance with the co cd mkdir C:/vmaf-install - meson setup libvmaf libvmaf/build --buildtype release --default-library static --prefix C:/vmaf-install - meson install -C libvmaf/build + meson setup builddir --buildtype release --default-library static --prefix C:/vmaf-install + meson install -C builddir From 699a18332453f328b3b599530390410da14a0243 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Thu, 4 Dec 2025 12:19:06 -0500 Subject: [PATCH 2/3] Fix public header includes Applications, and thus our public headers, should be included as `#include `. Adding `include/libvmaf` into include directories means applications could do e.g. `#include ` which is ambiguous. --- libvmaf/include/libvmaf/libvmaf.h | 6 +++--- libvmaf/include/libvmaf/libvmaf_cuda.h | 2 +- libvmaf/include/libvmaf/model.h | 2 +- libvmaf/src/meson.build | 1 + 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/libvmaf/include/libvmaf/libvmaf.h b/libvmaf/include/libvmaf/libvmaf.h index 11d0d1190..a15131e5d 100644 --- a/libvmaf/include/libvmaf/libvmaf.h +++ b/libvmaf/include/libvmaf/libvmaf.h @@ -22,9 +22,9 @@ #include #include -#include "libvmaf/model.h" -#include "libvmaf/picture.h" -#include "libvmaf/feature.h" +#include +#include +#include #ifdef __cplusplus extern "C" { diff --git a/libvmaf/include/libvmaf/libvmaf_cuda.h b/libvmaf/include/libvmaf/libvmaf_cuda.h index ac34c24a3..ea3a1723a 100644 --- a/libvmaf/include/libvmaf/libvmaf_cuda.h +++ b/libvmaf/include/libvmaf/libvmaf_cuda.h @@ -19,7 +19,7 @@ #ifndef __VMAF_CUDA_H__ #define __VMAF_CUDA_H__ -#include "libvmaf/libvmaf.h" +#include #ifdef __cplusplus extern "C" { diff --git a/libvmaf/include/libvmaf/model.h b/libvmaf/include/libvmaf/model.h index 98211466f..eff25f122 100644 --- a/libvmaf/include/libvmaf/model.h +++ b/libvmaf/include/libvmaf/model.h @@ -21,7 +21,7 @@ #include -#include "feature.h" +#include #ifdef __cplusplus extern "C" { diff --git a/libvmaf/src/meson.build b/libvmaf/src/meson.build index 80a34bc4f..1095c0355 100644 --- a/libvmaf/src/meson.build +++ b/libvmaf/src/meson.build @@ -572,5 +572,6 @@ pkg_mod.generate(libraries: libvmaf, name: 'libvmaf', filebase: 'libvmaf', description: 'VMAF, Video Multimethod Assessment Fusion', + # FIXME: We should remove libvmaf, but FFmpeg relies on it for now. subdirs: [ '.', 'libvmaf'] ) From 4af6b47c2d2746f6eab00dbb6742faa573b381c2 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Thu, 4 Dec 2025 14:36:57 -0500 Subject: [PATCH 3/3] meson: Support building in both top level and libvmaf/ --- libvmaf/include/libvmaf/meson.build | 5 ++++ libvmaf/include/meson.build | 4 ++- libvmaf/meson.build | 46 +++++++---------------------- libvmaf/meson_options.txt | 44 +++++++++++++++++++++++++++ libvmaf/src/meson.build | 35 ++++++++++++++++++++-- meson.build | 6 +++- 6 files changed, 100 insertions(+), 40 deletions(-) create mode 100644 libvmaf/meson_options.txt diff --git a/libvmaf/include/libvmaf/meson.build b/libvmaf/include/libvmaf/meson.build index c8927a70b..0a97a5539 100644 --- a/libvmaf/include/libvmaf/meson.build +++ b/libvmaf/include/libvmaf/meson.build @@ -1,3 +1,8 @@ +vmaf_api_version_array = meson.project_version().split('.') +vmaf_api_version_major = vmaf_api_version_array[0] +vmaf_api_version_minor = vmaf_api_version_array[1] +vmaf_api_version_revision = vmaf_api_version_array[2] + # installed version.h header generation version_h_data = configuration_data() version_h_data.set('VMAF_API_VERSION_MAJOR', vmaf_api_version_major) diff --git a/libvmaf/include/meson.build b/libvmaf/include/meson.build index 492558c4c..4fc2c6928 100644 --- a/libvmaf/include/meson.build +++ b/libvmaf/include/meson.build @@ -1,5 +1,5 @@ # Revision file (vcs_version.h) generation -vmaf_git_dir = join_paths(libvmaf_src_root + '/../', '.git') +vmaf_git_dir = meson.project_source_root() / '.git' rev_target = vcs_tag(command: [ 'git', '--git-dir', vmaf_git_dir, 'describe', '--tags', '--long', @@ -9,4 +9,6 @@ rev_target = vcs_tag(command: [ output: 'vcs_version.h' ) +libvmaf_inc = include_directories('.') + subdir('libvmaf') diff --git a/libvmaf/meson.build b/libvmaf/meson.build index f09d69a14..eef4c9e47 100644 --- a/libvmaf/meson.build +++ b/libvmaf/meson.build @@ -1,40 +1,14 @@ -vmaf_soname_version = '3.0.0' -vmaf_api_version_array = vmaf_soname_version.split('.') -vmaf_api_version_major = vmaf_api_version_array[0] -vmaf_api_version_minor = vmaf_api_version_array[1] -vmaf_api_version_revision = vmaf_api_version_array[2] +project('libvmaf', ['c', 'cpp'], + version : '3.0.0', + default_options : ['c_std=c11', + 'cpp_std=c++11', + 'warning_level=2', + 'buildtype=release', + 'default_library=both', + ], + meson_version: '>= 0.56.1') -libvmaf_src_root = meson.current_source_dir() -cc = meson.get_compiler('c') -libvmaf_inc = include_directories(['include']) - -# Arguments in test_args will be used even on feature tests -test_args = [] -if host_machine.system() == 'linux' or host_machine.system() == 'windows' or host_machine.system() == 'cygwin' - test_args += '-D_GNU_SOURCE' - add_project_arguments('-D_GNU_SOURCE', language: ['c', 'cpp']) -elif host_machine.system() == 'darwin' - test_args += '-D_DARWIN_C_SOURCE' - add_project_arguments('-D_DARWIN_C_SOURCE', language: ['c', 'cpp']) -endif - -# Header checks -stdatomic_dependency = [] -if not cc.check_header('stdatomic.h') - if cc.get_id() == 'msvc' - # we have a custom replacement for MSVC - stdatomic_dependency = declare_dependency( - include_directories : include_directories('src/compat/msvc'), - ) - elif cc.compiles('''int main() { int v = 0; return __atomic_fetch_add(&v, 1, __ATOMIC_SEQ_CST); }''', - name : 'GCC-style atomics', args : test_args) - stdatomic_dependency = declare_dependency( - include_directories : include_directories('src/compat/gcc'), - ) - else - error('Atomics not supported') - endif -endif +warning('Please run meson in top source directory instead of libvmaf/ subdir.') subdir('include') subdir('src') diff --git a/libvmaf/meson_options.txt b/libvmaf/meson_options.txt new file mode 100644 index 000000000..b5011831d --- /dev/null +++ b/libvmaf/meson_options.txt @@ -0,0 +1,44 @@ +option('enable_tests', + type: 'boolean', + value: true, + description: 'Build libvmaf tests') + +option('enable_docs', + type: 'boolean', + value: true, + description: 'Build libvmaf documentation') + +option('enable_asm', + type: 'boolean', + value: true, + description: 'Build asm files, if available') + +option('enable_avx512', + type: 'boolean', + value: true, + description: 'Build AVX-512 asm files, requires nasm 2.14') + +option('built_in_models', + type: 'boolean', + value: true, + description: 'Compile default vmaf models into the library') + +option('enable_float', + type: 'boolean', + value: false, + description: 'Compile floating-point feature extractors into the library') + +option('enable_cuda', + type: 'boolean', + value: false, + description: 'Enable CUDA support') + +option('enable_nvtx', + type: 'boolean', + value: false, + description: 'Enable NVTX range support') + +option('enable_nvcc', + type: 'boolean', + value: true, + description: 'Use clang to compile CUDA code.') diff --git a/libvmaf/src/meson.build b/libvmaf/src/meson.build index 1095c0355..470916d1c 100644 --- a/libvmaf/src/meson.build +++ b/libvmaf/src/meson.build @@ -1,3 +1,4 @@ +vmaf_soname_version = vmaf_api_version_major + '.0.0' vmaf_soversion = vmaf_api_version_major # Build libvmaf @@ -8,6 +9,36 @@ cuda_dir = './cuda/' vmaf_base_include = include_directories('./', './feature/common') +cc = meson.get_compiler('c') + +# Arguments in test_args will be used even on feature tests +test_args = [] +if host_machine.system() == 'linux' or host_machine.system() == 'windows' or host_machine.system() == 'cygwin' + test_args += '-D_GNU_SOURCE' + add_project_arguments('-D_GNU_SOURCE', language: ['c', 'cpp']) +elif host_machine.system() == 'darwin' + test_args += '-D_DARWIN_C_SOURCE' + add_project_arguments('-D_DARWIN_C_SOURCE', language: ['c', 'cpp']) +endif + +# Header checks +stdatomic_dependency = [] +if not cc.check_header('stdatomic.h') + if cc.get_id() == 'msvc' + # we have a custom replacement for MSVC + stdatomic_dependency = declare_dependency( + include_directories : include_directories('src/compat/msvc'), + ) + elif cc.compiles('''int main() { int v = 0; return __atomic_fetch_add(&v, 1, __ATOMIC_SEQ_CST); }''', + name : 'GCC-style atomics', args : test_args) + stdatomic_dependency = declare_dependency( + include_directories : include_directories('src/compat/gcc'), + ) + else + error('Atomics not supported') + endif +endif + if cc.get_id() != 'msvc' vmaf_cflags_common = [ '-pedantic', @@ -111,7 +142,7 @@ if is_asm_enabled depfile: '@BASENAME@.obj.ndep', arguments: [ '-f', nasm_format, - '-I', '@0@/src/'.format(libvmaf_src_root), + '-I', '@0@/'.format(meson.current_source_dir()), '-I', '@0@/'.format(meson.current_build_dir()), '-MQ', '@OUTPUT@', '-MF', '@DEPFILE@', '@EXTRA_ARGS@', @@ -561,7 +592,7 @@ libvmaf = library( libvmaf_cpu_static_lib.extract_all_objects(recursive: true), libsvm_static_lib.extract_all_objects(recursive: true), ], - version : vmaf_soname_version, + version: vmaf_soname_version, soversion : vmaf_soversion, install: true, ) diff --git a/meson.build b/meson.build index 219c8dc28..bf3b9a75c 100644 --- a/meson.build +++ b/meson.build @@ -8,4 +8,8 @@ project('libvmaf', ['c', 'cpp'], ], meson_version: '>= 0.56.1') -subdir('libvmaf') +subdir('libvmaf/include') +subdir('libvmaf/src') +subdir('libvmaf/tools') +subdir('libvmaf/doc') +subdir('libvmaf/test')