-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
170 lines (135 loc) · 5.56 KB
/
CMakeLists.txt
File metadata and controls
170 lines (135 loc) · 5.56 KB
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
cmake_minimum_required(VERSION 3.10)
set(PSTACK_SOVERSION 2.17)
set(PSTACK_VERSION 2.17.5)
project(pstack LANGUAGES C CXX VERSION "${PSTACK_VERSION}" )
include (GNUInstallDirs)
enable_testing()
option(PYTHON3 "Compile with python 3 support" OFF)
option(PYTHON2 "Compile with python 2 support" ON)
option(PTRACE_TESTS "Run extra tests that require unrestricted access to ptrace" OFF)
math(EXPR PLATFORM_BITS "${CMAKE_SIZEOF_VOID_P} * 8")
set(PSTACK_BIN "pstack" CACHE STRING "Name of the 'pstack' binary")
# Generate position independent code, even for static libs - that way we can
# link them to shared libs.
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/" CACHE STRING "Rpath to install for binaries or the empty string")
option(TIDY "Run clang-tidy on the source" False)
find_package(LibLZMA REQUIRED)
find_package(ZLIB REQUIRED)
if (PYTHON2)
find_package(Python2 COMPONENTS Development)
endif()
if (PYTHON3)
find_package(Python3 COMPONENTS Development)
endif()
find_package(Git)
if (GIT_FOUND AND EXISTS ${CMAKE_SOURCE_DIR}/.git)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
OUTPUT_VARIABLE GIT_TAG
OUTPUT_STRIP_TRAILING_WHITESPACE
)
message(STATUS "Version from git tag: ${GIT_TAG}")
else()
set(GIT_TAG "unknown")
message(STATUS "git version information unavailable - defaulting to 'unknown'")
endif()
set(VERSION_TAG ${GIT_TAG} CACHE STRING "Version tag (defaults to git commit)")
message(STATUS "Version: ${VERSION_TAG}")
add_definitions(-DVERSION=${VERSION_TAG})
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_EXTENSIONS ON)
add_definitions("-Wall -Wextra -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE")
# Adding frame pointers makes things easy to run performance measurements with,
# and doesn't cost much itself.
add_definitions("-fno-omit-frame-pointer")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Make sure to use the local libpstack headers rather than what's installed.
include_directories(${CMAKE_SOURCE_DIR})
include_directories(${ZLIB_INCLUDE_DIRS})
include_directories(${LIBLZMA_INCLUDE_DIRS})
if (Python3_Development_FOUND OR Python2_Development_FOUND)
set(pysrc python.cc)
endif()
if (PYTHON3 AND Python3_Development_FOUND)
set(pyinc "-I${Python3_INCLUDE_DIRS}")
message(STATUS "Python3_INCLUDE_DIRS are ${pyinc}")
add_definitions("-DWITH_PYTHON3")
set(pysrc ${pysrc} python3.cc pythonc.c)
set_source_files_properties(python3.cc PROPERTIES COMPILE_FLAGS ${pyinc})
set_source_files_properties(pythonc.c PROPERTIES COMPILE_FLAGS ${pyinc})
set_source_files_properties(canal.cc PROPERTIES COMPILE_FLAGS ${pyinc})
endif()
if (Python2_Development_FOUND)
set(pysrc ${pysrc} python2.cc)
add_definitions("-DWITH_PYTHON2")
set_source_files_properties(python2.cc PROPERTIES COMPILE_FLAGS -I${Python2_INCLUDE_DIRS})
endif()
add_definitions("-g3")
add_library(dwelf_objects OBJECT
dwarf_die.cc
dwarf_frame.cc
dwarf_info.cc
dwarf_lines.cc
dwarf_macros.cc
dwarf_pubnames.cc
dwarf_reader.cc
dwarf_unit.cc
dump.cc
context.cc
elf.cc
flags.cc
reader.cc
inflate.cc
lzma.cc
)
add_library(procman_objects OBJECT dead.cc self.cc live.cc process.cc proc_service.cc
dwarfproc.cc procdump.cc threaddb.cc ${pysrc})
add_library(dwelf SHARED $<TARGET_OBJECTS:dwelf_objects>)
add_library(dwelf_static STATIC $<TARGET_OBJECTS:dwelf_objects>)
set_target_properties(dwelf_static PROPERTIES OUTPUT_NAME dwelf_s)
add_library(procman SHARED $<TARGET_OBJECTS:procman_objects>)
add_library(procman_static STATIC $<TARGET_OBJECTS:procman_objects>)
set_target_properties(procman_static PROPERTIES OUTPUT_NAME procman_s)
option(LINK_STATIC "Link binaries against static libraries" OFF)
if (LINK_STATIC)
set(PSTACK_LINK_LIBS procman_static dwelf_static)
else()
set(PSTACK_LINK_LIBS dwelf procman)
endif()
add_executable(canal canal.cc)
add_executable(${PSTACK_BIN} pstack.cc)
target_link_libraries(procman dwelf dl)
target_link_libraries(procman_static dwelf_static dl)
target_link_libraries(${PSTACK_BIN} ${PSTACK_LINK_LIBS})
target_link_libraries(canal ${PSTACK_LINK_LIBS})
target_link_options(${PSTACK_BIN} PRIVATE -Wl,--export-dynamic)
target_link_options(canal PRIVATE -Wl,--export-dynamic)
set_target_properties(dwelf PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION "${PSTACK_SOVERSION}")
set_target_properties(procman PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION "${PSTACK_SOVERSION}")
if ((NOT (Python3_Development_FOUND)) AND PYTHON3)
message(WARNING "no python3 support found")
endif()
if (NOT (Python2_Development_FOUND) AND PYTHON2)
message(WARNING "no python2 support found")
endif()
# bonus: heap debugger
add_library(hdbg SHARED heap.c)
add_executable(hdmp hdmp.cc)
add_executable(stackusers stackusers.cc)
target_link_libraries(hdmp ${PSTACK_LINK_LIBS})
target_link_libraries(hdbg dl)
target_link_libraries(stackusers ${PSTACK_LINK_LIBS})
install(TARGETS ${PSTACK_BIN} canal)
install(TARGETS hdmp)
install(TARGETS dwelf procman dwelf_static procman_static hdbg)
install(FILES ${CMAKE_SOURCE_DIR}/pstack.1 DESTINATION share/man/man1 RENAME ${PSTACK_BIN}.1 )
install(DIRECTORY libpstack DESTINATION include)
install(CODE "execute_process (COMMAND setcap cap_sys_ptrace+ep ${DESTDIR}${CMAKE_INSTALL_PREFIX}/bin/${PSTACK_BIN} RESULT_VARIABLE ret)
if (NOT ret EQUAL \"0\")
message(\"(setcap failed - you might need to use sudo to use pstack: \${ret})\")
endif()
")
add_subdirectory(tests)
# for automake and rpmbuild
add_custom_target(check COMMAND make test)