1 # Search for libunwind and components, both includes and libraries
3 # Copyright (C) 2003-2022 The SimGrid Team.
4 # This is distributed under the LGPL licence but please contact us for
5 # relicensing if you need. This is merely free software, no matter the licence.
8 # Input environment variables:
9 # LIBUNWIND_HINT: path to libunwind installation (e.g., /usr)
10 # (only needed for non-standard installs)
12 # You can tune the needed components here.
13 # TODO: we should take this as a parameter if I knew how to do so.
15 # SimGrid needs unwind-ptrace on Linux and FreeBSD
16 if("${CMAKE_SYSTEM}" MATCHES "Linux|FreeBSD")
17 set(LIBUNWIND_COMPONENTS ${LIBUNWIND_COMPONENTS} unwind-ptrace unwind-generic)
22 # HAVE_LIBUNWIND : if all components were found was found
23 # LIBUNWIND_LIBRARIES: List of all libraries to load (-lunwind -lunwind-x86_64 and such)
26 # - Calls include_directories() on where libunwind.h lives
27 # - Calls link_directories() on where the libs live
29 # Of course also need the core lib
30 set(LIBUNWIND_COMPONENTS ${LIBUNWIND_COMPONENTS} "unwind")
32 message(STATUS "Looking for libunwind:")
33 # Let's assume we have it, and invalidate if parts are missing
37 # Search for the header file
40 find_path(PATH_LIBUNWIND_H "libunwind.h"
44 PATH_SUFFIXES include/ GnuWin32/include
45 PATHS /opt /opt/local /opt/csw /sw /usr)
47 string(REGEX REPLACE "/libunwind.h" "" PATH_LIBUNWIND_H "${PATH_LIBUNWIND_H}")
48 message(" Found libunwind.h in ${PATH_LIBUNWIND_H}")
49 include_directories(${PATH_LIBUNWIND_H})
51 message(" NOT FOUND libunwind.h")
54 mark_as_advanced(PATH_LIBUNWIND_H)
57 # Search for the library components
60 foreach(component ${LIBUNWIND_COMPONENTS})
61 find_library(PATH_LIBUNWIND_LIB_${component}
66 PATH_SUFFIXES lib/ GnuWin32/lib lib/system
67 PATHS /opt /opt/local /opt/csw /sw /usr /usr/lib/)
68 if(PATH_LIBUNWIND_LIB_${component})
69 # message(" ${component} ${PATH_LIBUNWIND_LIB_${component}}")
70 string(REGEX REPLACE "/lib${component}.*[.]${LIB_EXE}$" "" PATH_LIBUNWIND_LIB_${component} "${PATH_LIBUNWIND_LIB_${component}}")
71 message(" Found lib${component}.${LIB_EXE} in ${PATH_LIBUNWIND_LIB_${component}}")
72 link_directories(${PATH_LIBUNWIND_LIB_${component}})
74 if(${component} STREQUAL "unwind" AND APPLE)
75 # Apple forbids to link directly against its libunwind implementation
76 # So let's comply to that stupid restriction and link against the System framework
77 SET(LIBUNWIND_LIBRARIES "${LIBUNWIND_LIBRARIES} -lSystem")
79 SET(LIBUNWIND_LIBRARIES "${LIBUNWIND_LIBRARIES} -l${component}")
83 message(" Looking for lib${component}.${LIB_EXE} - not found")
86 mark_as_advanced(PATH_LIBUNWIND_LIB_${component})
89 unset(LIBUNWIND_COMPONENTS)
92 # Conclude and cleanup
95 message(STATUS "Dependencies induced by libunwind: ${LIBUNWIND_LIBRARIES}")
97 message(STATUS "Some libunwind components are missing")
98 set(LIBUNWIND_LIBRARIES "")