xref: /freebsd/contrib/libevent/cmake/Macros.cmake (revision 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e)
1include(CheckSymbolExists)
2include(CheckIncludeFiles)
3
4# Check if each symbol in the symbol list exists,
5# and define PREFIX__HAVE_SYMNAME to 1 if yes.
6#
7# SYMLIST: list of symbols to check
8# HEADERS: header files to be included in check code
9# PREFIX: the prefix of definition
10macro(CHECK_SYMBOLS_EXIST SYMLIST HEADERS PREFIX)
11  foreach(SYMNAME ${SYMLIST})
12    string(TOUPPER "${SYMNAME}" SYMNAME_UPPER)
13    if ("${PREFIX}" STREQUAL "")
14      set(HAVE_SYM_DEF "HAVE_${SYMNAME_UPPER}")
15    else()
16      set(HAVE_SYM_DEF "${PREFIX}__HAVE_${SYMNAME_UPPER}")
17    endif()
18    CHECK_SYMBOL_EXISTS(${SYMNAME} "${HEADERS}" ${HAVE_SYM_DEF})
19  endforeach()
20endmacro()
21
22# Check if file exists, define PREFIX__HAVE_FILE to 1 if yes,
23# and collect file to EVENT_INCLUDES
24macro(CHECK_INCLUDE_FILE_CONCAT FILE PREFIX)
25  string(REGEX REPLACE "[./]" "_" FILE_UL ${FILE})
26  string(TOUPPER "${FILE_UL}" FILE_UL_UPPER)
27  if ("${PREFIX}" STREQUAL "")
28    set(HAVE_FILE_DEF "HAVE_${FILE_UL_UPPER}")
29  else()
30    set(HAVE_FILE_DEF "${PREFIX}__HAVE_${FILE_UL_UPPER}")
31  endif()
32  CHECK_INCLUDE_FILES("${EVENT_INCLUDES};${FILE}" ${HAVE_FILE_DEF})
33  if(${HAVE_FILE_DEF})
34    set(EVENT_INCLUDES ${EVENT_INCLUDES} ${FILE})
35  endif()
36endmacro()
37