CheckFuncs.cmake 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # Check if the system has the specified function; treat glibc "stub"
  2. # functions as nonexistent:
  3. # CHECK_FUNCTION_EXISTS_GLIBC (FUNCTION FUNCVAR)
  4. #
  5. # FUNCTION - the function(s) where the prototype should be declared
  6. # FUNCVAR - variable to define if the function does exist
  7. #
  8. # In particular, this understands the glibc convention of
  9. # defining macros __stub_XXXX or __stub___XXXX if the function
  10. # does appear in the library but is merely a stub that does nothing.
  11. # By detecting this case, we can select alternate behavior on
  12. # platforms that don't support this functionality.
  13. #
  14. # The following variables may be set before calling this macro to
  15. # modify the way the check is run:
  16. #
  17. # CMAKE_REQUIRED_FLAGS = string of compile command line flags
  18. # CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
  19. # CMAKE_REQUIRED_INCLUDES = list of include directories
  20. # Copyright (c) 2009, Michihiro NAKAJIMA
  21. #
  22. # Redistribution and use is allowed according to the terms of the BSD license.
  23. # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
  24. INCLUDE(CheckFunctionExists)
  25. MACRO (CHECK_FUNCTION_EXISTS_GLIBC _FUNC _FUNCVAR)
  26. IF(NOT DEFINED ${_FUNCVAR})
  27. SET(CHECK_STUB_FUNC_1 "__stub_${_FUNC}")
  28. SET(CHECK_STUB_FUNC_2 "__stub___${_FUNC}")
  29. CONFIGURE_FILE( ${libarchive_SOURCE_DIR}/build/cmake/CheckFuncs_stub.c.in
  30. ${CMAKE_BINARY_DIR}/cmake.tmp/CheckFuncs_stub.c IMMEDIATE)
  31. TRY_COMPILE(__stub
  32. ${CMAKE_BINARY_DIR}
  33. ${CMAKE_BINARY_DIR}/cmake.tmp/CheckFuncs_stub.c
  34. COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
  35. CMAKE_FLAGS
  36. -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILE_FLAGS}
  37. "${CHECK_INCLUDE_FILE_C_INCLUDE_DIRS}")
  38. IF (__stub)
  39. SET("${_FUNCVAR}" "" CACHE INTERNAL "Have function ${_FUNC}")
  40. ELSE (__stub)
  41. CHECK_FUNCTION_EXISTS("${_FUNC}" "${_FUNCVAR}")
  42. ENDIF (__stub)
  43. ENDIF(NOT DEFINED ${_FUNCVAR})
  44. ENDMACRO (CHECK_FUNCTION_EXISTS_GLIBC)