summaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authoryuangongji <yuangongji@foxmail.com>2020-03-20 17:49:37 +0800
committeryuangongji <yuangongji@foxmail.com>2020-03-22 22:22:51 +0800
commit41d1d75a84e03219ec037b0f7982a67fb031eae7 (patch)
treeb7d5b840d3e56fb55e34aaae19cd4b5c46639f7b /cmake
parent1675a55620e6f0bbba5776f2df72cd48920421c2 (diff)
downloadlibevent-41d1d75a84e03219ec037b0f7982a67fb031eae7.tar.gz
cmake: replace CheckFunctionExists with CheckSymbolExists
Checking functions with `CheckFunctionExists` may get wrong results, we should replace it with `CheckSymbolExists`, which is recommended by the cmake official documentation. Before using `CheckSymbolExists`, we use `CheckIncludeFiles` to check header files and save the available header files in a variable that guarantees `CheckSymbolExists` and `CheckTypeSize` to work correctly. This approach is modeled after the cmake scripts of `curl`. The following functions or files were not found before modification, they can now be found: - msys2 + mingw-8.1.0 on Windows10 or mingw-7.3.0 on Ubuntu-18.04 timerclear timercmp timerisset - windows10 getaddrinfo getnameinfo getprotobynumber getservbyname putenv strtoll timerclear timercmp timerisset - ubuntu-18.04 sys/sysctl.h timeradd timerclear timercmp timerisset - MacOS 10.13 sys/random.h timeradd timerclear timercmp timerisset
Diffstat (limited to 'cmake')
-rw-r--r--cmake/CheckSymbolsExist.cmake20
-rw-r--r--cmake/Macros.cmake36
2 files changed, 36 insertions, 20 deletions
diff --git a/cmake/CheckSymbolsExist.cmake b/cmake/CheckSymbolsExist.cmake
deleted file mode 100644
index 2c3c5dc3..00000000
--- a/cmake/CheckSymbolsExist.cmake
+++ /dev/null
@@ -1,20 +0,0 @@
-# Check if each symbol in the symbol list exists,
-# and define PREFIX__HAVE_SYMNAME to 1 if yes.
-#
-
-include(CheckSymbolExists)
-
-# SYMLIST: list of symbols to check
-# HEADERS: header files to be included in check code
-# PREFIX: the prefix of definition
-macro(CHECK_SYMBOLS_EXIST SYMLIST HEADERS PREFIX)
- foreach(SYMNAME ${SYMLIST})
- string(TOUPPER "${SYMNAME}" SYMNAME_UPPER)
- if("${PREFIX}" STREQUAL "")
- set(HAVE_SYM_DEF "HAVE_${SYMNAME_UPPER}")
- else()
- set(HAVE_SYM_DEF "${PREFIX}__HAVE_${SYMNAME_UPPER}")
- endif()
- CHECK_SYMBOL_EXISTS(${SYMNAME} "${HEADERS}" ${HAVE_SYM_DEF})
- endforeach()
-endmacro()
diff --git a/cmake/Macros.cmake b/cmake/Macros.cmake
new file mode 100644
index 00000000..e480bbfd
--- /dev/null
+++ b/cmake/Macros.cmake
@@ -0,0 +1,36 @@
+include(CheckSymbolExists)
+include(CheckIncludeFiles)
+
+# Check if each symbol in the symbol list exists,
+# and define PREFIX__HAVE_SYMNAME to 1 if yes.
+#
+# SYMLIST: list of symbols to check
+# HEADERS: header files to be included in check code
+# PREFIX: the prefix of definition
+macro(CHECK_SYMBOLS_EXIST SYMLIST HEADERS PREFIX)
+ foreach(SYMNAME ${SYMLIST})
+ string(TOUPPER "${SYMNAME}" SYMNAME_UPPER)
+ if ("${PREFIX}" STREQUAL "")
+ set(HAVE_SYM_DEF "HAVE_${SYMNAME_UPPER}")
+ else()
+ set(HAVE_SYM_DEF "${PREFIX}__HAVE_${SYMNAME_UPPER}")
+ endif()
+ CHECK_SYMBOL_EXISTS(${SYMNAME} "${HEADERS}" ${HAVE_SYM_DEF})
+ endforeach()
+endmacro()
+
+# Check if file exists, define PREFIX__HAVE_FILE to 1 if yes,
+# and collect file to EVENT_INCLUDES
+macro(CHECK_INCLUDE_FILE_CONCAT FILE PREFIX)
+ string(REGEX REPLACE "[./]" "_" FILE_UL ${FILE})
+ string(TOUPPER "${FILE_UL}" FILE_UL_UPPER)
+ if ("${PREFIX}" STREQUAL "")
+ set(HAVE_FILE_DEF "HAVE_${FILE_UL_UPPER}")
+ else()
+ set(HAVE_FILE_DEF "${PREFIX}__HAVE_${FILE_UL_UPPER}")
+ endif()
+ CHECK_INCLUDE_FILES("${EVENT_INCLUDES};${FILE}" ${HAVE_FILE_DEF})
+ if(${HAVE_FILE_DEF})
+ set(EVENT_INCLUDES ${EVENT_INCLUDES} ${FILE})
+ endif()
+endmacro()