Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
8e9be6de049caa7ab375bbd42536124c1c06ac0f
[simgrid.git] / tools / cmake / Modules / FindLibunwind.cmake
1 message(STATUS "Looking for libunwind")
2
3 if(PROCESSOR_x86_64)
4   find_library(PATH_LIBUNWIND_LIB
5     NAMES unwind-x86_64
6     HINTS
7     $ENV{SIMGRID_LIBUNWIND_LIBRARY_PATH}
8     $ENV{LD_LIBRARY_PATH}
9     $ENV{LIBUNWIND_LIBRARY_PATH}
10     PATH_SUFFIXES lib/ GnuWin32/lib lib/system
11     PATHS
12     /opt
13     /opt/local
14     /opt/csw
15     /sw
16     /usr)
17   message(STATUS "Looking for libunwind-x86_64 - found")
18 endif()
19
20 if(NOT PATH_LIBUNWIND_LIB)
21   find_library(PATH_LIBUNWIND_LIB
22     NAMES unwind
23     HINTS
24       $ENV{SIMGRID_LIBUNWIND_LIBRARY_PATH}
25       $ENV{LD_LIBRARY_PATH}
26       $ENV{LIBUNWIND_LIBRARY_PATH}
27       PATH_SUFFIXES lib/ GnuWin32/lib lib/system
28       PATHS
29       /opt
30       /opt/local
31       /opt/csw
32       /sw
33       /usr
34       /usr/lib/)
35       
36   # Mac OSX has a libunwind that is not the one we need, so double check
37   if (PATH_LIBUNWIND_LIB)
38     message(STATUS "Looking for libunwind - found")
39
40     string(REGEX REPLACE "/libunwind.*[.]${LIB_EXE}$" "" PATH_LIBUNWIND_LIB "${PATH_LIBUNWIND_LIB}")
41     CHECK_LIBRARY_EXISTS(unwind unw_init_local "${PATH_LIBUNWIND_LIB}" RIGHT_LIBUNWIND)
42
43     if (NOT RIGHT_LIBUNWIND)
44       message(STATUS "libunwind in ${PATH_LIBUNWIND_LIB} is unusable. Disable it.")
45       set(PATH_LIBUNWIND_LIB 0)
46     endif()
47     
48   else()
49     message(STATUS "Looking for libunwind - not found")
50   endif()
51
52 endif()
53
54 find_path(PATH_LIBUNWIND_H "libunwind.h"
55   HINTS
56   $ENV{SIMGRID_LIBUNWIND_LIBRARY_PATH}
57   $ENV{LD_LIBRARY_PATH}
58   $ENV{LIBUNWIND_LIBRARY_PATH}
59   PATH_SUFFIXES include/ GnuWin32/include
60   PATHS
61   /opt
62   /opt/local
63   /opt/csw
64   /sw
65   /usr)
66
67 message(STATUS "Looking for libunwind.h")
68 if(PATH_LIBUNWIND_H)
69   message(STATUS "Looking for libunwind.h - found")
70 else()
71   message(STATUS "Looking for libunwind.h - not found")
72 endif()
73
74 if(PATH_LIBUNWIND_LIB AND PATH_LIBUNWIND_H)
75   string(REGEX REPLACE "/libunwind.*[.]${LIB_EXE}$" "" PATH_LIBUNWIND_LIB "${PATH_LIBUNWIND_LIB}")
76   string(REGEX REPLACE "/libunwind.h"               "" PATH_LIBUNWIND_H   "${PATH_LIBUNWIND_H}")
77       
78   include_directories(${PATH_LIBUNWIND_H})
79   link_directories(${PATH_LIBUNWIND_LIB})
80   SET(HAVE_LIBUNWIND 1)
81 else()
82   SET(HAVE_LIBUNWIND 0)
83 endif()
84
85 mark_as_advanced(PATH_LIBDW_H)
86 mark_as_advanced(PATH_LIBDW_LIB)
87 mark_as_advanced(PATH_LIBUNWIND_LIB)
88 mark_as_advanced(PATH_LIBUNWIND_H)