summaryrefslogtreecommitdiffstats
path: root/src
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 /src
parent58d7fe43076a9825cf1f99d94ce224445ab9e405 (diff)
downloadzix-acb8ea62ac287efcfb50f20cd419b70f6c5a15a9.tar.gz
zix-acb8ea62ac287efcfb50f20cd419b70f6c5a15a9.tar.bz2
zix-acb8ea62ac287efcfb50f20cd419b70f6c5a15a9.zip
Clean up build configuration
Diffstat (limited to 'src')
-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
4 files changed, 43 insertions, 17 deletions
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