Skip to content

Commit 3335738

Browse files
committed
cmake: refactor check_prototype_definition
Introduce `check_prototype_definition_safe` that is safe for `Werror` usage.
1 parent 767a9a7 commit 3335738

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ include(CheckLibraryExists)
9494
include(CheckFunctionExists)
9595
include(CheckSymbolExists)
9696
include(CheckStructHasMember)
97-
include(CheckPrototypeDefinition)
97+
include(CheckPrototypeDefinitionSafe)
9898
include(AddCFlagIfSupported)
9999
include(FindPkgLibraries)
100100
include(FindThreads)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
include(CheckPrototypeDefinition)
2+
3+
function(check_prototype_definition_safe function prototype return header variable)
4+
# temporarily save CMAKE_C_FLAGS and disable warnings about unused
5+
# unused functions and parameters, otherwise they will always fail
6+
# if ENABLE_WERROR is on
7+
set(SAVED_CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
8+
9+
disable_warnings(unused-function)
10+
disable_warnings(unused-parameter)
11+
12+
check_prototype_definition("${function}" "${prototype}" "${return}" "${header}" "${variable}")
13+
14+
# restore CMAKE_C_FLAGS
15+
set(CMAKE_C_FLAGS "${SAVED_CMAKE_C_FLAGS}")
16+
endfunction()

src/CMakeLists.txt

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,40 +58,30 @@ add_feature_info(futimens GIT_USE_FUTIMENS "futimens support")
5858

5959
# qsort
6060

61-
# for these tests, temporarily save CMAKE_C_FLAGS and disable warnings about
62-
# unused functions and parameters, otherwise they will always fail if
63-
# ENABLE_WERROR is on
64-
set(SAVED_CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
65-
disable_warnings(unused-function)
66-
disable_warnings(unused-parameter)
67-
6861
# old-style FreeBSD qsort_r() has the 'context' parameter as the first argument
6962
# of the comparison function:
70-
check_prototype_definition(qsort_r
63+
check_prototype_definition_safe(qsort_r
7164
"void (qsort_r)(void *base, size_t nmemb, size_t size, void *context, int (*compar)(void *, const void *, const void *))"
7265
"" "stdlib.h" GIT_QSORT_BSD)
7366

7467
# GNU or POSIX qsort_r() has the 'context' parameter as the last argument of the
7568
# comparison function:
76-
check_prototype_definition(qsort_r
69+
check_prototype_definition_safe(qsort_r
7770
"void (qsort_r)(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *, void *), void *context)"
7871
"" "stdlib.h" GIT_QSORT_GNU)
7972

8073
# C11 qsort_s() has the 'context' parameter as the last argument of the
8174
# comparison function, and returns an error status:
82-
check_prototype_definition(qsort_s
75+
check_prototype_definition_safe(qsort_s
8376
"errno_t (qsort_s)(void *base, rsize_t nmemb, rsize_t size, int (*compar)(const void *, const void *, void *), void *context)"
8477
"0" "stdlib.h" GIT_QSORT_C11)
8578

8679
# MSC qsort_s() has the 'context' parameter as the first argument of the
8780
# comparison function, and as the last argument of qsort_s():
88-
check_prototype_definition(qsort_s
81+
check_prototype_definition_safe(qsort_s
8982
"void (qsort_s)(void *base, size_t num, size_t width, int (*compare )(void *, const void *, const void *), void *context)"
9083
"" "stdlib.h" GIT_QSORT_MSC)
9184

92-
# restore CMAKE_C_FLAGS
93-
set(CMAKE_C_FLAGS "${SAVED_CMAKE_C_FLAGS}")
94-
9585
# random / entropy data
9686

9787
check_function_exists(getentropy GIT_RAND_GETENTROPY)

0 commit comments

Comments
 (0)