summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2023-05-12 21:49:29 +0100
committerEdward Thomson <ethomson@edwardthomson.com>2023-05-12 21:49:29 +0100
commit333573857960fa7260f01f38a2003bafa2313a87 (patch)
treec6f919f9838b2af376facb64699360ae1b803baa
parent767a9a733ca64928d395318a9cda47822241b879 (diff)
downloadlibgit2-333573857960fa7260f01f38a2003bafa2313a87.tar.gz
cmake: refactor `check_prototype_definition`
Introduce `check_prototype_definition_safe` that is safe for `Werror` usage.
-rw-r--r--CMakeLists.txt2
-rw-r--r--cmake/CheckPrototypeDefinitionSafe.cmake16
-rw-r--r--src/CMakeLists.txt18
3 files changed, 21 insertions, 15 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 30527b928..cfb5a7d6f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -94,7 +94,7 @@ include(CheckLibraryExists)
include(CheckFunctionExists)
include(CheckSymbolExists)
include(CheckStructHasMember)
-include(CheckPrototypeDefinition)
+include(CheckPrototypeDefinitionSafe)
include(AddCFlagIfSupported)
include(FindPkgLibraries)
include(FindThreads)
diff --git a/cmake/CheckPrototypeDefinitionSafe.cmake b/cmake/CheckPrototypeDefinitionSafe.cmake
new file mode 100644
index 000000000..f82603d3d
--- /dev/null
+++ b/cmake/CheckPrototypeDefinitionSafe.cmake
@@ -0,0 +1,16 @@
+include(CheckPrototypeDefinition)
+
+function(check_prototype_definition_safe function prototype return header variable)
+ # temporarily save CMAKE_C_FLAGS and disable warnings about unused
+ # unused functions and parameters, otherwise they will always fail
+ # if ENABLE_WERROR is on
+ set(SAVED_CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
+
+ disable_warnings(unused-function)
+ disable_warnings(unused-parameter)
+
+ check_prototype_definition("${function}" "${prototype}" "${return}" "${header}" "${variable}")
+
+ # restore CMAKE_C_FLAGS
+ set(CMAKE_C_FLAGS "${SAVED_CMAKE_C_FLAGS}")
+endfunction()
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index bdf513842..88d616cec 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -58,40 +58,30 @@ add_feature_info(futimens GIT_USE_FUTIMENS "futimens support")
# qsort
-# for these tests, temporarily save CMAKE_C_FLAGS and disable warnings about
-# unused functions and parameters, otherwise they will always fail if
-# ENABLE_WERROR is on
-set(SAVED_CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
-disable_warnings(unused-function)
-disable_warnings(unused-parameter)
-
# old-style FreeBSD qsort_r() has the 'context' parameter as the first argument
# of the comparison function:
-check_prototype_definition(qsort_r
+check_prototype_definition_safe(qsort_r
"void (qsort_r)(void *base, size_t nmemb, size_t size, void *context, int (*compar)(void *, const void *, const void *))"
"" "stdlib.h" GIT_QSORT_BSD)
# GNU or POSIX qsort_r() has the 'context' parameter as the last argument of the
# comparison function:
-check_prototype_definition(qsort_r
+check_prototype_definition_safe(qsort_r
"void (qsort_r)(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *, void *), void *context)"
"" "stdlib.h" GIT_QSORT_GNU)
# C11 qsort_s() has the 'context' parameter as the last argument of the
# comparison function, and returns an error status:
-check_prototype_definition(qsort_s
+check_prototype_definition_safe(qsort_s
"errno_t (qsort_s)(void *base, rsize_t nmemb, rsize_t size, int (*compar)(const void *, const void *, void *), void *context)"
"0" "stdlib.h" GIT_QSORT_C11)
# MSC qsort_s() has the 'context' parameter as the first argument of the
# comparison function, and as the last argument of qsort_s():
-check_prototype_definition(qsort_s
+check_prototype_definition_safe(qsort_s
"void (qsort_s)(void *base, size_t num, size_t width, int (*compare )(void *, const void *, const void *), void *context)"
"" "stdlib.h" GIT_QSORT_MSC)
-# restore CMAKE_C_FLAGS
-set(CMAKE_C_FLAGS "${SAVED_CMAKE_C_FLAGS}")
-
# random / entropy data
check_function_exists(getentropy GIT_RAND_GETENTROPY)