+
+#
+# Search for the library components
+#
+
+foreach(component ${LIBUNWIND_COMPONENTS})
+ find_library(PATH_LIBUNWIND_LIB_${component}
+ NAMES ${component}
+ HINTS
+ $ENV{LIBUNWIND_HINT}
+ $ENV{LD_LIBRARY_PATH}
+ PATH_SUFFIXES lib/ GnuWin32/lib lib/system
+ PATHS /opt /opt/local /opt/csw /sw /usr /usr/lib/)
+ if(PATH_LIBUNWIND_LIB_${component})
+ # message(" ${component} ${PATH_LIBUNWIND_LIB_${component}}")
+ string(REGEX REPLACE "/lib${component}.*[.]${LIB_EXE}$" "" PATH_LIBUNWIND_LIB_${component} "${PATH_LIBUNWIND_LIB_${component}}")
+ message(" Found lib${component}.${LIB_EXE} in ${PATH_LIBUNWIND_LIB_${component}}")
+ link_directories(${PATH_LIBUNWIND_LIB_${component}})
+
+ if(${component} STREQUAL "unwind" AND APPLE)
+ # Apple forbids to link directly against its libunwind implementation
+ # So let's comply to that stupid restriction and link against the System framework
+ SET(LIBUNWIND_LIBRARIES "${LIBUNWIND_LIBRARIES} -lSystem")
+ else()
+ SET(LIBUNWIND_LIBRARIES "${LIBUNWIND_LIBRARIES} -l${component}")
+ endif()
+
+ else()
+ message(" Looking for lib${component}.${LIB_EXE} - not found")
+ SET(HAVE_LIBUNWIND 0)
+ endif()
+ mark_as_advanced(PATH_LIBUNWIND_LIB_${component})
+endforeach()
+unset(component)
+unset(LIBUNWIND_COMPONENTS)
+
+#
+# Conclude and cleanup
+#
+if(HAVE_LIBUNWIND)
+ message(STATUS "Dependencies induced by libunwind: ${LIBUNWIND_LIBRARIES}")
+else()
+ message(STATUS "Some libunwind components are missing")
+ set(LIBUNWIND_LIBRARIES "")
+endif()