summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-06-28 16:14:45 -0400
committerDavid Robillard <d@drobilla.net>2022-06-28 18:52:19 -0400
commitacb8ea62ac287efcfb50f20cd419b70f6c5a15a9 (patch)
tree657337f0bf6566b40e3a07002697347b5e35a0d9
parent58d7fe43076a9825cf1f99d94ce224445ab9e405 (diff)
downloadzix-acb8ea62ac287efcfb50f20cd419b70f6c5a15a9.tar.gz
zix-acb8ea62ac287efcfb50f20cd419b70f6c5a15a9.tar.bz2
zix-acb8ea62ac287efcfb50f20cd419b70f6c5a15a9.zip
Clean up build configuration
-rw-r--r--.clang-tidy3
-rw-r--r--benchmark/.clang-tidy3
-rw-r--r--benchmark/bench.h2
-rw-r--r--benchmark/warnings.h3
-rw-r--r--meson.build57
-rw-r--r--meson/suppressions/meson.build1
-rw-r--r--meson_options.txt6
-rw-r--r--src/.clang-tidy3
-rw-r--r--src/allocator.c7
-rw-r--r--src/ring.c4
-rw-r--r--src/zix_config.h46
-rw-r--r--test/.clang-tidy3
12 files changed, 94 insertions, 44 deletions
diff --git a/.clang-tidy b/.clang-tidy
index 6fe5d7a..db23eed 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -3,9 +3,6 @@ Checks: >
-*-magic-numbers,
-*-uppercase-literal-suffix,
-altera-*,
- -bugprone-reserved-identifier,
- -cert-dcl37-c,
- -cert-dcl51-cpp,
-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,
-hicpp-multiway-paths-covered,
-llvmlibc-*,
diff --git a/benchmark/.clang-tidy b/benchmark/.clang-tidy
index 3ebd18e..2aa1e4f 100644
--- a/benchmark/.clang-tidy
+++ b/benchmark/.clang-tidy
@@ -5,9 +5,6 @@ Checks: >
-altera-*,
-android-cloexec-fopen,
-bugprone-easily-swappable-parameters,
- -bugprone-reserved-identifier,
- -cert-dcl37-c,
- -cert-dcl51-cpp,
-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,
-hicpp-multiway-paths-covered,
-llvm-header-guard,
diff --git a/benchmark/bench.h b/benchmark/bench.h
index c07e211..bcfe077 100644
--- a/benchmark/bench.h
+++ b/benchmark/bench.h
@@ -4,8 +4,6 @@
#ifndef BENCH_H
#define BENCH_H
-#define _POSIX_C_SOURCE 199309L
-
#include <time.h>
typedef struct timespec BenchmarkTime;
diff --git a/benchmark/warnings.h b/benchmark/warnings.h
index 59f479d..43e740e 100644
--- a/benchmark/warnings.h
+++ b/benchmark/warnings.h
@@ -9,7 +9,8 @@
# define ZIX_DISABLE_GLIB_WARNINGS \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wdocumentation-unknown-command\"") \
- _Pragma("clang diagnostic ignored \"-Wdocumentation\"")
+ _Pragma("clang diagnostic ignored \"-Wdocumentation\"") \
+ _Pragma("clang diagnostic ignored \"-Wreserved-id-macro\"")
# define ZIX_RESTORE_WARNINGS _Pragma("clang diagnostic pop")
diff --git a/meson.build b/meson.build
index e6f17b4..92525e8 100644
--- a/meson.build
+++ b/meson.build
@@ -26,20 +26,49 @@ cc = meson.get_compiler('c')
# Set global warning flags
if get_option('strict') and not meson.is_subproject()
subdir('meson/warnings')
+ add_project_arguments(all_c_warnings, language: ['c'])
endif
subdir('meson/suppressions')
+add_project_arguments(c_suppressions, language: ['c'])
-add_project_arguments(all_c_warnings + c_suppressions, language: ['c'])
+##########################
+# Platform Configuration #
+##########################
-################
-# Dependencies #
-################
+platform_c_args = []
-# Check for mlock() (used by ZixRing)
-mlock_fragment = '''#include <sys/mman.h>
- int main(void) { return mlock(0, 0); }'''
-if cc.compiles(mlock_fragment, name: 'mlock')
- add_project_arguments(['-DHAVE_MLOCK'], language: 'c')
+# Determine whether to use POSIX
+no_posix = get_option('posix').disabled() or host_machine.system() == 'windows'
+if no_posix
+ platform_c_args += ['-DZIX_NO_POSIX']
+else
+ platform_c_args += ['-D_POSIX_C_SOURCE=200809L']
+endif
+
+# Check for platform features with the build system
+if get_option('checks')
+ platform_c_args += ['-DZIX_NO_DEFAULT_CONFIG']
+
+ mlock_code = '''#include <sys/mman.h>
+int main(void) { return mlock(0, 0); }'''
+
+ posix_memalign_code = '''#include <stdlib.h>
+int main(void) { void* mem; posix_memalign(&mem, 8, 8); }'''
+
+ platform_c_args += '-DHAVE_MLOCK=@0@'.format(
+ cc.compiles(mlock_code,
+ args: platform_c_args,
+ name: 'mlock').to_int())
+
+ platform_c_args += '-DHAVE_POSIX_MEMALIGN=@0@'.format(
+ cc.compiles(posix_memalign_code,
+ args: platform_c_args,
+ name: 'posix_memalign').to_int())
+endif
+
+# Build as C++ on MSVC
+if cc.get_id() == 'msvc'
+ add_project_arguments(['/TP'], language: ['c'])
endif
###########
@@ -81,7 +110,7 @@ if get_option('default_library') == 'static'
endif
# Set any additional arguments required for building libraries or programs
-library_c_args = ['-DZIX_INTERNAL']
+library_c_args = platform_c_args + ['-DZIX_INTERNAL']
library_link_args = []
program_c_args = []
program_link_args = []
@@ -215,15 +244,15 @@ if not get_option('benchmarks').disabled()
if glib_dep.found()
build_benchmarks = true
+ benchmark_c_args = platform_c_args
- benchmark_c_args = []
if cc.get_id() == 'clang'
- benchmark_c_args += [
+ benchmark_c_suppressions = [
'-Wno-reserved-identifier',
]
- endif
- benchmark_c_args = cc.get_supported_arguments(benchmark_c_args)
+ benchmark_c_args += cc.get_supported_arguments(benchmark_c_suppressions)
+ endif
foreach benchmark : benchmarks
benchmark(benchmark,
diff --git a/meson/suppressions/meson.build b/meson/suppressions/meson.build
index 2f96751..e5d5cf3 100644
--- a/meson/suppressions/meson.build
+++ b/meson/suppressions/meson.build
@@ -21,7 +21,6 @@ if is_variable('cc')
'-Wno-c11-extensions', # Glib
'-Wno-implicit-fallthrough', # Really for clang < 12
'-Wno-padded',
- '-Wno-reserved-id-macro',
]
elif cc.get_id() == 'gcc'
diff --git a/meson_options.txt b/meson_options.txt
index 4f5c9b4..ef032fb 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -1,8 +1,14 @@
option('benchmarks', type: 'feature', value: 'auto', yield: true,
description: 'Build benchmarks')
+option('checks', type: 'boolean', value: true, yield: true,
+ description: 'Check for features with the build system')
+
option('strict', type: 'boolean', value: false, yield: true,
description: 'Enable ultra-strict warnings')
option('tests', type: 'feature', value: 'auto', yield: true,
description: 'Build tests')
+
+option('posix', type: 'feature', value: 'auto', yield: true,
+ description: 'Use POSIX system facilities')
diff --git a/src/.clang-tidy b/src/.clang-tidy
index bcf65be..66ba28d 100644
--- a/src/.clang-tidy
+++ b/src/.clang-tidy
@@ -4,9 +4,6 @@ Checks: >
-*-uppercase-literal-suffix,
-altera-*,
-bugprone-easily-swappable-parameters,
- -bugprone-reserved-identifier,
- -cert-dcl37-c,
- -cert-dcl51-cpp,
-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,
-hicpp-multiway-paths-covered,
-llvm-header-guard,
diff --git a/src/allocator.c b/src/allocator.c
index 2df0b90..ca91803 100644
--- a/src/allocator.c
+++ b/src/allocator.c
@@ -1,13 +1,12 @@
// Copyright 2011-2021 David Robillard <d@drobilla.net>
// SPDX-License-Identifier: ISC
-#define _POSIX_C_SOURCE 200809L
-
-#include "zix_config.h"
-
#include "zix/allocator.h"
+
#include "zix/attributes.h"
+#include "zix_config.h"
+
#ifdef _WIN32
# define WIN32_LEAN_AND_MEAN 1
# include <malloc.h>
diff --git a/src/ring.c b/src/ring.c
index a464428..d5b942b 100644
--- a/src/ring.c
+++ b/src/ring.c
@@ -3,10 +3,12 @@
#include "zix/ring.h"
+#include "zix_config.h"
+
#include <stdlib.h>
#include <string.h>
-#ifdef HAVE_MLOCK
+#if USE_MLOCK
# include <sys/mman.h>
# define ZIX_MLOCK(ptr, size) mlock((ptr), (size))
#elif defined(_WIN32)
diff --git a/src/zix_config.h b/src/zix_config.h
index 832b50f..7be46e4 100644
--- a/src/zix_config.h
+++ b/src/zix_config.h
@@ -1,15 +1,26 @@
-// Copyright 2021 David Robillard <d@drobilla.net>
+// Copyright 2021-2022 David Robillard <d@drobilla.net>
// SPDX-License-Identifier: ISC
/*
Configuration header that defines reasonable defaults at compile time.
- This allows compile-time configuration from the command line (typically via
- the build system) while still allowing the source to be built without any
- configuration. The build system can define ZIX_NO_DEFAULT_CONFIG to disable
- defaults, in which case it must define things like HAVE_FEATURE to enable
- features. The design here ensures that compiler warnings or
- include-what-you-use will catch any mistakes.
+ This allows compile-time configuration from the command line, while still
+ allowing the source to be built "as-is" without any configuration. The idea
+ is to support an advanced build system with configuration checks, while still
+ allowing the code to be simply "thrown at a compiler" with features
+ determined from the compiler or system headers. Everything can be
+ overridden, so it should never be necessary to edit this file to build
+ successfully.
+
+ To ensure that all configure checks are performed, the build system can
+ define ZIX_NO_DEFAULT_CONFIG to disable defaults. In this case, it must
+ define all HAVE_FEATURE symbols below to 1 or 0 to enable or disable
+ features. Any missing definitions will generate a compiler warning.
+
+ To ensure that this header is always included properly, all code that uses
+ configuration variables includes this header and checks their value with #if
+ (not #ifdef). Variables like USE_FEATURE are internal and should never be
+ defined on the command line.
*/
#ifndef ZIX_CONFIG_H
@@ -28,10 +39,21 @@
# endif
# endif
+// POSIX.1-2001: mlock()
+# ifndef HAVE_MLOCK
+# if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L
+# define HAVE_MLOCK 1
+# else
+# define HAVE_MLOCK 0
+# endif
+# endif
+
// POSIX.1-2001: posix_memalign()
# ifndef HAVE_POSIX_MEMALIGN
# if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L
-# define HAVE_POSIX_MEMALIGN
+# define HAVE_POSIX_MEMALIGN 1
+# else
+# define HAVE_POSIX_MEMALIGN 0
# endif
# endif
@@ -45,7 +67,13 @@
if the build system defines them all.
*/
-#ifdef HAVE_POSIX_MEMALIGN
+#if HAVE_MLOCK
+# define USE_MLOCK 1
+#else
+# define USE_MLOCK 0
+#endif
+
+#if HAVE_POSIX_MEMALIGN
# define USE_POSIX_MEMALIGN 1
#else
# define USE_POSIX_MEMALIGN 0
diff --git a/test/.clang-tidy b/test/.clang-tidy
index 9f98471..e490926 100644
--- a/test/.clang-tidy
+++ b/test/.clang-tidy
@@ -5,9 +5,6 @@ Checks: >
-altera-*,
-android-cloexec-fopen,
-bugprone-easily-swappable-parameters,
- -bugprone-reserved-identifier,
- -cert-dcl37-c,
- -cert-dcl51-cpp,
-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,
-cppcoreguidelines-avoid-non-const-global-variables,
-google-readability-casting,