cmake: qsort detection in features.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index e780116..f3830ef 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -50,22 +50,13 @@ add_feature_info(futimens GIT_USE_FUTIMENS "futimens support")
check_prototype_definition(qsort_r
"void qsort_r(void *base, size_t nmemb, size_t size, void *thunk, int (*compar)(void *, const void *, const void *))"
- "" "stdlib.h" HAVE_QSORT_R_BSD)
-if(HAVE_QSORT_R_BSD)
- target_compile_definitions(git2internal PRIVATE HAVE_QSORT_R_BSD)
-endif()
+ "" "stdlib.h" GIT_QSORT_R_BSD)
check_prototype_definition(qsort_r
"void qsort_r(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *, void *), void *arg)"
- "" "stdlib.h" HAVE_QSORT_R_GNU)
-if(HAVE_QSORT_R_GNU)
- target_compile_definitions(git2internal PRIVATE HAVE_QSORT_R_GNU)
-endif()
+ "" "stdlib.h" GIT_QSORT_R_GNU)
-check_function_exists(qsort_s HAVE_QSORT_S)
-if(HAVE_QSORT_S)
- target_compile_definitions(git2internal PRIVATE HAVE_QSORT_S)
-endif()
+check_function_exists(qsort_s GIT_QSORT_S)
# Find required dependencies
diff --git a/src/features.h.in b/src/features.h.in
index a40b608..81a8ae0 100644
--- a/src/features.h.in
+++ b/src/features.h.in
@@ -24,6 +24,10 @@
#cmakedefine GIT_REGEX_PCRE2
#cmakedefine GIT_REGEX_BUILTIN 1
+#cmakedefine GIT_QSORT_R_BSD
+#cmakedefine GIT_QSORT_R_GNU
+#cmakedefine GIT_QSORT_S
+
#cmakedefine GIT_SSH 1
#cmakedefine GIT_SSH_MEMORY_CREDENTIALS 1
diff --git a/src/util.c b/src/util.c
index 2b1dadf..e06d4ca 100644
--- a/src/util.c
+++ b/src/util.c
@@ -18,7 +18,7 @@
# endif
# include <windows.h>
-# ifdef HAVE_QSORT_S
+# ifdef GIT_QSORT_S
# include <search.h>
# endif
#endif
@@ -673,7 +673,7 @@ size_t git__unescape(char *str)
return (pos - str);
}
-#if defined(HAVE_QSORT_S) || defined(HAVE_QSORT_R_BSD)
+#if defined(GIT_QSORT_S) || defined(GIT_QSORT_R_BSD)
typedef struct {
git__sort_r_cmp cmp;
void *payload;
@@ -688,9 +688,9 @@ static int GIT_LIBGIT2_CALL git__qsort_r_glue_cmp(
#endif
-#if !defined(HAVE_QSORT_R_BSD) && \
- !defined(HAVE_QSORT_R_GNU) && \
- !defined(HAVE_QSORT_S)
+#if !defined(GIT_QSORT_R_BSD) && \
+ !defined(GIT_QSORT_R_GNU) && \
+ !defined(GIT_QSORT_S)
static void swap(uint8_t *a, uint8_t *b, size_t elsize)
{
char tmp[256];
@@ -721,12 +721,12 @@ static void insertsort(
void git__qsort_r(
void *els, size_t nel, size_t elsize, git__sort_r_cmp cmp, void *payload)
{
-#if defined(HAVE_QSORT_R_BSD)
+#if defined(GIT_QSORT_R_BSD)
git__qsort_r_glue glue = { cmp, payload };
qsort_r(els, nel, elsize, &glue, git__qsort_r_glue_cmp);
-#elif defined(HAVE_QSORT_R_GNU)
+#elif defined(GIT_QSORT_R_GNU)
qsort_r(els, nel, elsize, cmp, payload);
-#elif defined(HAVE_QSORT_S)
+#elif defined(GIT_QSORT_S)
git__qsort_r_glue glue = { cmp, payload };
qsort_s(els, nel, elsize, git__qsort_r_glue_cmp, &glue);
#else