From 169e219154873be30faaa026d09847f438bbea51 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Mon, 17 Aug 2020 11:05:21 +0200 Subject: [PATCH] cmake: check for GNU style strerror_r --- CMake/CheckCompiles.cmake | 16 ++++++++++++++++ CMake/_Include.cmake | 4 +++- src/mem_config.h.in | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 CMake/CheckCompiles.cmake diff --git a/CMake/CheckCompiles.cmake b/CMake/CheckCompiles.cmake new file mode 100644 index 00000000..f03f1da4 --- /dev/null +++ b/CMake/CheckCompiles.cmake @@ -0,0 +1,16 @@ +include(CheckCXXSourceCompiles) + +function(check_compiles RESULT_VAR TEST) + + unset(SOURCE) + foreach(HEADER IN LISTS ARGN) + string(APPEND SOURCE "#include <${HEADER}>\n") + endforeach() + string(APPEND SOURCE " + int main() { + ${TEST} + return 0; + } + ") + check_cxx_source_compiles("${SOURCE}" ${RESULT_VAR}) +endfunction() diff --git a/CMake/_Include.cmake b/CMake/_Include.cmake index 0f25ab48..67963844 100644 --- a/CMake/_Include.cmake +++ b/CMake/_Include.cmake @@ -14,6 +14,7 @@ include(CheckDebug) include(CheckDecl) include(CheckDependency) include(CheckHeader) +include(CheckCompiles) include(CheckType) include(CheckStdatomic) @@ -34,7 +35,7 @@ if(ENABLE_DTRACE) set(HAVE_DTRACE 1) endif() -##uuid +## uuid if(BUILD_TESTING) check_dependency(LIBUUID uuid uuid/uuid.h) endif() @@ -91,6 +92,7 @@ check_decl(MSG_NOSIGNAL sys/socket.h) check_decl(rcvtimeo sys/socket.h) check_decl(sndtimeo sys/socket.h) check_decl(strerror_r string.h) +check_compiles(HAVE_STRERROR_R_CHAR_P "char x, y = *strerror_r(0,&x,1);" string.h) check_decl(strerror string.h) check_decl(abi::__cxa_demangle cxxabi.h) set(HAVE_GCC_ABI_DEMANGLE ${HAVE_ABI____CXA_DEMANGLE}) diff --git a/src/mem_config.h.in b/src/mem_config.h.in index de2cdb7a..d2704095 100644 --- a/src/mem_config.h.in +++ b/src/mem_config.h.in @@ -39,6 +39,7 @@ #cmakedefine HAVE_STDLIB_H 1 #cmakedefine HAVE_STRERROR 1 #cmakedefine HAVE_STRERROR_R 1 +#cmakedefine HAVE_STRERROR_R_CHAR_P 1 #cmakedefine HAVE_STRINGS_H 1 #cmakedefine HAVE_SYS_SOCKET_H 1 #cmakedefine HAVE_SYS_TIME_H 1 -- 2.30.2