Edit

kc3-lang/libevent/cmake/Macros.cmake

Branch :

  • Show log

    Commit

  • Author : yuangongji
    Date : 2020-03-20 17:49:37
    Hash : 41d1d75a
    Message : 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

  • cmake/Macros.cmake
  • 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()