FindUnwind.cmake 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # - Try to find libunwind
  2. # Once done this will define
  3. #
  4. # Unwind_FOUND - system has libunwind
  5. # unwind::unwind - cmake target for libunwind
  6. include (FindPackageHandleStandardArgs)
  7. find_path (Unwind_INCLUDE_DIR NAMES unwind.h libunwind.h DOC "unwind include directory")
  8. find_library (Unwind_LIBRARY NAMES unwind DOC "unwind library")
  9. mark_as_advanced (Unwind_INCLUDE_DIR Unwind_LIBRARY)
  10. # Extract version information
  11. if (Unwind_LIBRARY)
  12. set (_Unwind_VERSION_HEADER ${Unwind_INCLUDE_DIR}/libunwind-common.h)
  13. if (EXISTS ${_Unwind_VERSION_HEADER})
  14. file (READ ${_Unwind_VERSION_HEADER} _Unwind_VERSION_CONTENTS)
  15. string (REGEX REPLACE ".*#define UNW_VERSION_MAJOR[ \t]+([0-9]+).*" "\\1"
  16. Unwind_VERSION_MAJOR "${_Unwind_VERSION_CONTENTS}")
  17. string (REGEX REPLACE ".*#define UNW_VERSION_MINOR[ \t]+([0-9]+).*" "\\1"
  18. Unwind_VERSION_MINOR "${_Unwind_VERSION_CONTENTS}")
  19. string (REGEX REPLACE ".*#define UNW_VERSION_EXTRA[ \t]+([0-9]+).*" "\\1"
  20. Unwind_VERSION_PATCH "${_Unwind_VERSION_CONTENTS}")
  21. set (Unwind_VERSION ${Unwind_VERSION_MAJOR}.${Unwind_VERSION_MINOR})
  22. if (CMAKE_MATCH_0)
  23. # Third version component may be empty
  24. set (Unwind_VERSION ${Unwind_VERSION}.${Unwind_VERSION_PATCH})
  25. set (Unwind_VERSION_COMPONENTS 3)
  26. else (CMAKE_MATCH_0)
  27. set (Unwind_VERSION_COMPONENTS 2)
  28. endif (CMAKE_MATCH_0)
  29. endif (EXISTS ${_Unwind_VERSION_HEADER})
  30. endif (Unwind_LIBRARY)
  31. # handle the QUIETLY and REQUIRED arguments and set Unwind_FOUND to TRUE
  32. # if all listed variables are TRUE
  33. find_package_handle_standard_args (Unwind
  34. REQUIRED_VARS Unwind_INCLUDE_DIR Unwind_LIBRARY
  35. VERSION_VAR Unwind_VERSION
  36. )
  37. if (Unwind_FOUND)
  38. if (NOT TARGET unwind::unwind)
  39. add_library (unwind::unwind INTERFACE IMPORTED)
  40. set_property (TARGET unwind::unwind PROPERTY
  41. INTERFACE_INCLUDE_DIRECTORIES ${Unwind_INCLUDE_DIR}
  42. )
  43. set_property (TARGET unwind::unwind PROPERTY
  44. INTERFACE_LINK_LIBRARIES ${Unwind_LIBRARY}
  45. )
  46. set_property (TARGET unwind::unwind PROPERTY
  47. IMPORTED_CONFIGURATIONS RELEASE
  48. )
  49. endif (NOT TARGET unwind::unwind)
  50. endif (Unwind_FOUND)