CheckFuncs.cmake 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. GET_FILENAME_COMPONENT(_selfdir_CheckFunctionExistsGlibc
  26. "${CMAKE_CURRENT_LIST_FILE}" PATH)
  27. MACRO (CHECK_FUNCTION_EXISTS_GLIBC _FUNC _FUNCVAR)
  28. IF(NOT DEFINED ${_FUNCVAR})
  29. SET(CHECK_STUB_FUNC_1 "__stub_${_FUNC}")
  30. SET(CHECK_STUB_FUNC_2 "__stub___${_FUNC}")
  31. CONFIGURE_FILE( ${_selfdir_CheckFunctionExistsGlibc}/CheckFuncs_stub.c.in
  32. ${CMAKE_CURRENT_BINARY_DIR}/cmake.tmp/CheckFuncs_stub.c)
  33. TRY_COMPILE(__stub
  34. ${CMAKE_CURRENT_BINARY_DIR}
  35. ${CMAKE_CURRENT_BINARY_DIR}/cmake.tmp/CheckFuncs_stub.c
  36. COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
  37. CMAKE_FLAGS
  38. -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILE_FLAGS}
  39. "${CHECK_INCLUDE_FILE_C_INCLUDE_DIRS}")
  40. IF (__stub)
  41. SET("${_FUNCVAR}" "" CACHE INTERNAL "Have function ${_FUNC}")
  42. ELSE (__stub)
  43. CHECK_FUNCTION_EXISTS("${_FUNC}" "${_FUNCVAR}")
  44. ENDIF (__stub)
  45. ENDIF(NOT DEFINED ${_FUNCVAR})
  46. ENDMACRO (CHECK_FUNCTION_EXISTS_GLIBC)