summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NEWS3
-rw-r--r--src/sord_config.h61
-rw-r--r--src/sord_validate.c11
-rw-r--r--wscript2
4 files changed, 70 insertions, 7 deletions
diff --git a/NEWS b/NEWS
index 35dcf0b..298cba4 100644
--- a/NEWS
+++ b/NEWS
@@ -3,8 +3,9 @@ sord (0.16.7) unstable;
* Clean up code
* Fix potential undefined behavior
* Fix potentially incorrect search results
+ * Remove the need for a generated configuration header
- -- David Robillard <d@drobilla.net> Wed, 11 Nov 2020 21:04:28 +0000
+ -- David Robillard <d@drobilla.net> Fri, 01 Jan 2021 16:59:03 +0000
sord (0.16.6) stable;
diff --git a/src/sord_config.h b/src/sord_config.h
new file mode 100644
index 0000000..f4b54c1
--- /dev/null
+++ b/src/sord_config.h
@@ -0,0 +1,61 @@
+/*
+ Copyright 2021 David Robillard <http://drobilla.net>
+
+ Permission to use, copy, modify, and/or distribute this software for any
+ purpose with or without fee is hereby granted, provided that the above
+ copyright notice and this permission notice appear in all copies.
+
+ THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*/
+
+/*
+ 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 SORD_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 SORD_CONFIG_H
+#define SORD_CONFIG_H
+
+// Define version unconditionally so a warning will catch a mismatch
+#define SORD_VERSION "0.16.7"
+
+#if !defined(SORD_NO_DEFAULT_CONFIG)
+
+// The validator uses PCRE for literal pattern matching
+# ifndef HAVE_PCRE
+# ifdef __has_include
+# if __has_include(<pcre.h>)
+# define HAVE_PCRE 1
+# endif
+# endif
+# endif
+
+#endif // !defined(SORD_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_PCRE
+# define USE_PCRE 1
+#else
+# define USE_PCRE 0
+#endif
+
+#endif // SORD_CONFIG_H
diff --git a/src/sord_validate.c b/src/sord_validate.c
index 0acb0a4..fffc6a1 100644
--- a/src/sord_validate.c
+++ b/src/sord_validate.c
@@ -1,5 +1,5 @@
/*
- Copyright 2012-2017 David Robillard <http://drobilla.net>
+ Copyright 2012-2021 David Robillard <http://drobilla.net>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@@ -21,9 +21,10 @@
#include "sord/sord.h"
#include "sord_config.h"
-#ifdef HAVE_PCRE
+#if USE_PCRE
# include <pcre.h>
#endif
+
#ifdef _WIN32
# include <windows.h>
#endif
@@ -190,7 +191,7 @@ is_descendant_of(SordModel* model,
static bool
regexp_match(const uint8_t* pat, const char* str)
{
-#ifdef HAVE_PCRE
+#if USE_PCRE
// Append a $ to the pattern so we only match if the entire string matches
const size_t len = strlen((const char*)pat);
char* const regx = (char*)malloc(len + 2);
@@ -211,7 +212,7 @@ regexp_match(const uint8_t* pat, const char* str)
const bool ret = pcre_exec(re, NULL, str, strlen(str), 0, 0, NULL, 0) >= 0;
pcre_free(re);
return ret;
-#endif // HAVE_PCRE
+#endif // USE_PCRE
return true;
}
@@ -785,7 +786,7 @@ main(int argc, char** argv)
URI(xsd, pattern);
URI(xsd, string);
-#ifndef HAVE_PCRE
+#if !USE_PCRE
fprintf(stderr, "warning: Built without PCRE, datatypes not checked.\n");
#endif
diff --git a/wscript b/wscript
index b7507cd..6a5aaf5 100644
--- a/wscript
+++ b/wscript
@@ -154,7 +154,7 @@ def configure(conf):
sord_validate_node = conf.path.get_bld().make_node('sord_validate')
conf.env.SORD_VALIDATE = [sord_validate_node.abspath()]
- conf.write_config_header('sord_config.h', remove=False)
+ conf.define('SORD_NO_DEFAULT_CONFIG', 1)
autowaf.display_summary(
conf,