summaryrefslogtreecommitdiff
path: root/src/CMakeLists.txt
blob: 19b108bd18d99b2ceede42a2365e82b8ebbad75a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152


include(config.cmake)

set(libunwind_sources_common
    mi/init.c
    mi/flush_cache.c
    mi/mempool.c
    mi/strerror.c
    dwarf/global.c
    mi/backtrace.c
    mi/dyn-cancel.c
    mi/dyn-info-list.c
    mi/dyn-register.c
    mi/Ldyn-extract.c
    mi/Lfind_dynamic_proc_info.c
    mi/Lget_accessors.c
    mi/Lget_proc_info_by_ip.c
    mi/Lget_proc_name.c
    mi/Lput_dynamic_unwind_info.c
    mi/Ldestroy_addr_space.c
    mi/Lget_reg.c
    mi/Lset_reg.c
    mi/Lget_fpreg.c
    mi/Lset_fpreg.c
    mi/Lset_caching_policy.c
    mi/_ReadULEB.c
    mi/_ReadSLEB.c
    unwind/Backtrace.c
    unwind/DeleteException.c
    unwind/FindEnclosingFunction.c
    unwind/ForcedUnwind.c
    unwind/GetBSP.c
    unwind/GetCFA.c
    unwind/GetDataRelBase.c
    unwind/GetGR.c
    unwind/GetIP.c
    unwind/GetLanguageSpecificData.c
    unwind/GetRegionStart.c
    unwind/GetTextRelBase.c
    unwind/RaiseException.c
    unwind/Resume.c
    unwind/Resume_or_Rethrow.c
    unwind/SetGR.c
    unwind/SetIP.c
    unwind/GetIPInfo.c
    dwarf/Lexpr.c
    dwarf/Lfde.c
    dwarf/Lparser.c
    dwarf/Lpe.c
    dwarf/Lstep.c
    dwarf/Lfind_proc_info-lsb.c
   )


if(CMAKE_SYSTEM_NAME MATCHES "Linux")
    list(APPEND libunwind_sources_common os-linux.c)
elseif(CMAKE_SYSTEM_NAME MATCHES "SunOS")
    list(APPEND libunwind_sources_common os-solaris.c)
endif()


set(libunwind_sources_x8664_32
    elf32.c
    x86/is_fpreg.c
    x86/regname.c
    x86/setcontext.c
    x86/Lcreate_addr_space.c
    x86/Lget_save_loc.c
    x86/Lglobal.c
    x86/Linit.c
    x86/Linit_local.c
    x86/Linit_remote.c
    x86/Lget_proc_info.c
    x86/Lregs.c
    x86/Lresume.c
    x86/getcontext.c
    x86/Lstep.c
    x86/Los-linux.c
   )

string(REPLACE " " ";" c_flags "${CMAKE_C_FLAGS}")

add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/getcontext.o
                   COMMAND ${CMAKE_C_COMPILER} ${c_flags}
                           -c ${CMAKE_CURRENT_SOURCE_DIR}/x86_64/getcontext.S
                           -o ${CMAKE_CURRENT_BINARY_DIR}/getcontext.o
                   DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/x86_64/getcontext.S)

add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/setcontext.o
                   COMMAND ${CMAKE_C_COMPILER} ${c_flags}
                           -c ${CMAKE_CURRENT_SOURCE_DIR}/x86_64/setcontext.S
                           -o ${CMAKE_CURRENT_BINARY_DIR}/setcontext.o
                   DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/x86_64/setcontext.S)


set(libunwind_sources_x8664_64
    elf64.c
    x86_64/is_fpreg.c
    x86_64/regname.c
    x86_64/Lcreate_addr_space.c
    x86_64/Lget_save_loc.c
    x86_64/Lglobal.c
    x86_64/Linit.c
    x86_64/Linit_local.c
    x86_64/Linit_remote.c
    x86_64/Lget_proc_info.c
    x86_64/Lregs.c
    x86_64/Lresume.c
    x86_64/Lstep.c
    ${CMAKE_CURRENT_BINARY_DIR}/getcontext.o
    ${CMAKE_CURRENT_BINARY_DIR}/setcontext.o
   )


if(CMAKE_SYSTEM_NAME MATCHES "Linux")
    list(APPEND libunwind_sources_x8664_64 x86_64/Los-linux.c)
elseif(CMAKE_SYSTEM_NAME MATCHES "SunOS")
    list(APPEND libunwind_sources_x8664_64 x86_64/Los-solaris.c)
endif()


add_definitions(-DHAVE_CONFIG_H
                -D_GNU_SOURCE
                -fPIC
                -DPIC
		-fexceptions
               )
        
include_directories(.
                    ../include
                    ${CMAKE_CURRENT_BINARY_DIR}/include
                   )


# TODO: add checks for all platforms
if("${CMAKE_C_FLAGS}" MATCHES "-m32")
    set(target "x8664_32")
elseif("${CMAKE_C_FLAGS}" MATCHES "-m64")
    set(target "x8664_64")
    include_directories(../include/tdep-x86_64)
else()
    message(FATAL_ERROR "Unknown target")
endif()

add_library(unwind STATIC ${libunwind_sources_common} ${libunwind_sources_${target}})
set_property(TARGET unwind PROPERTY COMPILE_DEFINITIONS_DEBUG DEBUG)

add_library(unwind-shared SHARED ${libunwind_sources_common} ${libunwind_sources_${target}})
set_property(TARGET unwind-shared PROPERTY COMPILE_DEFINITIONS_DEBUG DEBUG)
set_property(TARGET unwind-shared PROPERTY OUTPUT_NAME "unwind")