1 # Search for libunwind and components, both includes and libraries
3 # Copyright (C) 2003-2018 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)
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 # For some reason, some archs have an arch-specific while other do not.
33 if (CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")
34 SET(LIBUNWIND_COMPONENTS ${LIBUNWIND_COMPONENTS} unwind-arm)
35 elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "amd64")
36 SET(LIBUNWIND_COMPONENTS ${LIBUNWIND_COMPONENTS} unwind-x86_64)
37 elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^i.86$")
38 SET(LIBUNWIND_COMPONENTS ${LIBUNWIND_COMPONENTS} unwind-x86)
42 message(STATUS "Looking for libunwind:")
43 # Let's assume we have it, and invalidate if parts are missing
47 # Search for the header file
50 find_path(PATH_LIBUNWIND_H "libunwind.h"
54 PATH_SUFFIXES include/ GnuWin32/include
55 PATHS /opt /opt/local /opt/csw /sw /usr)
57 string(REGEX REPLACE "/libunwind.h" "" PATH_LIBUNWIND_H "${PATH_LIBUNWIND_H}")
58 message(" Found libunwind.h in ${PATH_LIBUNWIND_H}")
59 include_directories(${PATH_LIBUNWIND_H})
61 message(" NOT FOUND libunwind.h")
64 mark_as_advanced(PATH_LIBUNWIND_H)
67 # Search for the library components
70 foreach(component ${LIBUNWIND_COMPONENTS})
71 find_library(PATH_LIBUNWIND_LIB_${component}
76 PATH_SUFFIXES lib/ GnuWin32/lib lib/system
77 PATHS /opt /opt/local /opt/csw /sw /usr /usr/lib/)
78 if(PATH_LIBUNWIND_LIB_${component})
79 # message(" ${component} ${PATH_LIBUNWIND_LIB_${component}}")
80 string(REGEX REPLACE "/lib${component}.*[.]${LIB_EXE}$" "" PATH_LIBUNWIND_LIB_${component} "${PATH_LIBUNWIND_LIB_${component}}")
81 message(" Found lib${component}.${LIB_EXE} in ${PATH_LIBUNWIND_LIB_${component}}")
82 link_directories(${PATH_LIBUNWIND_LIB_${component}})
84 if(${component} STREQUAL "unwind" AND APPLE)
85 # Apple forbids to link directly against its libunwind implementation
86 # So let's comply to that stupid restriction and link against the System framework
87 SET(LIBUNWIND_LIBRARIES "${LIBUNWIND_LIBRARIES} -lSystem")
89 SET(LIBUNWIND_LIBRARIES "${LIBUNWIND_LIBRARIES} -l${component}")
93 message(" Looking for lib${component}.${LIB_EXE} - not found")
96 mark_as_advanced(PATH_LIBUNWIND_LIB_${component})
99 unset(LIBUNWIND_COMPONENTS)
102 # Conclude and cleanup
105 message(STATUS "Dependencies induced by libunwind: ${LIBUNWIND_LIBRARIES}")
107 message(STATUS "Some libunwind components are missing")
108 set(LIBUNWIND_LIBRARIES "")