summaryrefslogtreecommitdiffstats
path: root/src/zix_config.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/zix_config.h')
-rw-r--r--src/zix_config.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/zix_config.h b/src/zix_config.h
new file mode 100644
index 0000000..832b50f
--- /dev/null
+++ b/src/zix_config.h
@@ -0,0 +1,54 @@
+// Copyright 2021 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.
+*/
+
+#ifndef ZIX_CONFIG_H
+#define ZIX_CONFIG_H
+
+#if !defined(ZIX_NO_DEFAULT_CONFIG)
+
+// We need unistd.h to check _POSIX_VERSION
+# ifndef ZIX_NO_POSIX
+# ifdef __has_include
+# if __has_include(<unistd.h>)
+# include <unistd.h>
+# endif
+# elif defined(__unix__)
+# include <unistd.h>
+# endif
+# endif
+
+// POSIX.1-2001: posix_memalign()
+# ifndef HAVE_POSIX_MEMALIGN
+# if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L
+# define HAVE_POSIX_MEMALIGN
+# endif
+# endif
+
+#endif // !defined(ZIX_NO_DEFAULT_CONFIG)
+
+/*
+ Make corresponding USE_FEATURE defines based on the HAVE_FEATURE defines from
+ above or the command line. The code checks for these using #if (not #ifdef),
+ so there will be an undefined warning if it checks for an unknown feature,
+ and this header is always required by any code that checks for features, even
+ if the build system defines them all.
+*/
+
+#ifdef HAVE_POSIX_MEMALIGN
+# define USE_POSIX_MEMALIGN 1
+#else
+# define USE_POSIX_MEMALIGN 0
+#endif
+
+#endif // ZIX_CONFIG_H