From dc9c4d454a5106437c58fc4ba1addadfe2aef05c Mon Sep 17 00:00:00 2001 From: Rolf Eike Beer Date: Wed, 2 Aug 2017 14:09:19 +0200 Subject: [PATCH] CMake: detect the presence of entropy functions --- expat/CMakeLists.txt | 4 ++++ expat/ConfigureChecks.cmake | 21 +++++++++++++++++++++ expat/expat_config.h.cmake | 12 ++++++++++++ expat/lib/xmlparse.c | 3 --- 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/expat/CMakeLists.txt b/expat/CMakeLists.txt index 76e99c39..128966be 100644 --- a/expat/CMakeLists.txt +++ b/expat/CMakeLists.txt @@ -15,6 +15,7 @@ option(BUILD_examples "build the examples for expat library" ON) option(BUILD_tests "build the tests for expat library" ON) option(BUILD_shared "build a shared expat library" ON) option(BUILD_doc "build man page for xmlwf" ON) +option(USE_libbsd "utilize libbsd (for arc4random_buf)" OFF) option(INSTALL "install expat files in cmake install target" ON) # configuration options @@ -78,6 +79,9 @@ else(BUILD_shared) endif(BUILD_shared) add_library(expat ${_SHARED} ${expat_SRCS}) +if(USE_libbsd) + target_link_libraries(expat bsd) +endif() set(LIBCURRENT 7) # sync set(LIBREVISION 5) # with diff --git a/expat/ConfigureChecks.cmake b/expat/ConfigureChecks.cmake index 6e440ca0..7d44ec1a 100644 --- a/expat/ConfigureChecks.cmake +++ b/expat/ConfigureChecks.cmake @@ -1,4 +1,5 @@ include(CheckCCompilerFlag) +include(CheckCSourceCompiles) include(CheckIncludeFile) include(CheckIncludeFiles) include(CheckFunctionExists) @@ -21,6 +22,16 @@ check_function_exists("getpagesize" HAVE_GETPAGESIZE) check_function_exists("bcopy" HAVE_BCOPY) check_symbol_exists("memmove" "string.h" HAVE_MEMMOVE) check_function_exists("mmap" HAVE_MMAP) +check_function_exists("getrandom" HAVE_GETRANDOM) + +if(USE_libbsd) + set(CMAKE_REQUIRED_LIBRARIES "bsd") +endif() +check_function_exists("arc4random_buf" HAVE_ARC4RANDOM_BUF) +if(NOT HAVE_ARC4RANDOM_BUF) + check_function_exists("arc4random" HAVE_ARC4RANDOM) +endif() +set(CMAKE_REQUIRED_LIBRARIES) #/* Define to 1 if you have the ANSI C header files. */ check_include_files("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS) @@ -41,6 +52,16 @@ else(HAVE_SYS_TYPES_H) set(SIZE_T "unsigned") endif(HAVE_SYS_TYPES_H) +check_c_source_compiles(" + #include /* for NULL */ + #include /* for syscall */ + #include /* for SYS_getrandom */ + int main() { + syscall(SYS_getrandom, NULL, 0, 0); + return 0; + }" + HAVE_SYSCALL_GETRANDOM) + configure_file(expat_config.h.cmake "${CMAKE_CURRENT_BINARY_DIR}/expat_config.h") add_definitions(-DHAVE_EXPAT_CONFIG_H) diff --git a/expat/expat_config.h.cmake b/expat/expat_config.h.cmake index e5147915..41829c04 100644 --- a/expat/expat_config.h.cmake +++ b/expat/expat_config.h.cmake @@ -3,6 +3,12 @@ /* 1234 = LIL_ENDIAN, 4321 = BIGENDIAN */ #cmakedefine BYTEORDER @BYTEORDER@ +/* Define to 1 if you have the `arc4random' function. */ +#cmakedefine HAVE_ARC4RANDOM + +/* Define to 1 if you have the `arc4random_buf' function. */ +#cmakedefine HAVE_ARC4RANDOM_BUF + /* Define to 1 if you have the `bcopy' function. */ #cmakedefine HAVE_BCOPY @@ -15,6 +21,9 @@ /* Define to 1 if you have the `getpagesize' function. */ #cmakedefine HAVE_GETPAGESIZE +/* Define to 1 if you have the `getrandom' function. */ +#cmakedefine HAVE_GETRANDOM + /* Define to 1 if you have the header file. */ #cmakedefine HAVE_INTTYPES_H @@ -39,6 +48,9 @@ /* Define to 1 if you have the header file. */ #cmakedefine HAVE_STRING_H +/* Define to 1 if you have `syscall' and `SYS_getrandom'. */ +#cmakedefine HAVE_SYSCALL_GETRANDOM + /* Define to 1 if you have the header file. */ #cmakedefine HAVE_SYS_STAT_H diff --git a/expat/lib/xmlparse.c b/expat/lib/xmlparse.c index b703e61a..86c79f26 100644 --- a/expat/lib/xmlparse.c +++ b/expat/lib/xmlparse.c @@ -80,9 +80,6 @@ If insist on not using any of these, bypass this error by defining \ XML_POOR_ENTROPY; you have been warned. \ \ - For CMake, one way to pass the define is: \ - cmake -DCMAKE_C_FLAGS="-pipe -O2 -DHAVE_SYSCALL_GETRANDOM" . \ - \ If you have reasons to patch this detection code away or need changes \ to the build system, please open a bug. Thank you! #endif -- 2.40.0