-
Notifications
You must be signed in to change notification settings - Fork 53
/
CMakeLists.txt
188 lines (161 loc) · 7.08 KB
/
CMakeLists.txt
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
cmake_minimum_required(VERSION 3.5)
project(pahole C)
cmake_policy(SET CMP0005 NEW)
option(LIBBPF_EMBEDDED "Use the embedded version of libbpf instead of searching it via pkg-config" ON)
if (NOT LIBBPF_EMBEDDED)
find_package(PkgConfig REQUIRED)
if(PKGCONFIG_FOUND)
pkg_check_modules(LIBBPF REQUIRED libbpf>=0.4.0)
endif()
endif()
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR})
if(NOT LIBBPF_FOUND)
# Allows to use 'system' style #include with both embedded and system libbpf
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/lib/include)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/lib/bpf/include/uapi)
else()
INCLUDE_DIRECTORIES(${LIBBPF_INCLUDE_DIRS})
LINK_DIRECTORIES(${LIBBPF_LIBRARY_DIRS})
endif()
# Use the standard library installation directory
include(GNUInstallDirs)
set(CMAKE_INSTALL_LIBDIR "lib" CACHE STRING "libdir name")
# where to look first for cmake modules,
# before ${CMAKE_ROOT}/Modules/ is checked
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
if (NOT CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE Debug CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
FORCE)
endif (NOT CMAKE_BUILD_TYPE)
set(CMAKE_C_FLAGS_DEBUG "-Wall -Werror -ggdb -O0")
set(CMAKE_C_FLAGS_RELEASE "-Wall -O2")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")
if (NOT DEFINED BUILD_SHARED_LIBS)
set (BUILD_SHARED_LIBS ON)
message(STATUS "Setting BUILD_SHARED_LIBS = ${BUILD_SHARED_LIBS}")
endif (NOT DEFINED BUILD_SHARED_LIBS)
# Just for grepping, DWARVES_VERSION isn't used anywhere anymore
# add_definitions(-D_GNU_SOURCE -DDWARVES_VERSION="v1.28")
add_definitions(-D_GNU_SOURCE -DDWARVES_MAJOR_VERSION=1)
add_definitions(-D_GNU_SOURCE -DDWARVES_MINOR_VERSION=28)
find_package(DWARF REQUIRED)
find_package(ZLIB REQUIRED)
find_package(argp REQUIRED)
find_package(obstack REQUIRED)
find_package(Python3 QUIET)
# make sure git submodule(s) are checked out
find_package(Git QUIET)
if(LIBBPF_EMBEDDED AND GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
# Update submodules as needed
option(GIT_SUBMODULE "Check submodules during build" ON)
if(GIT_SUBMODULE)
message(STATUS "Submodule update")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
else()
message(STATUS "Submodule update - done")
endif()
endif()
endif()
if(NOT LIBBPF_FOUND AND NOT EXISTS "${PROJECT_SOURCE_DIR}/lib/bpf/src/btf.h")
message(FATAL_ERROR "The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
endif()
if (NOT DEFINED LIB_INSTALL_DIR)
set(LIB_INSTALL_DIR "${EXEC_INSTALL_PREFIX}${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
endif()
# libbpf uses reallocarray, which is not available in all versions of glibc
# libbpf's include/tools/libc_compat.h provides implementation, but needs
# COMPACT_NEED_REALLOCARRAY to be set
INCLUDE(CheckCSourceCompiles)
CHECK_C_SOURCE_COMPILES(
"
#define _GNU_SOURCE
#include <stdlib.h>
int main(void)
{
return !!reallocarray(NULL, 1, 1);
}
" HAVE_REALLOCARRAY_SUPPORT)
if (NOT HAVE_REALLOCARRAY_SUPPORT)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DCOMPAT_NEED_REALLOCARRAY")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64")
if (NOT LIBBPF_FOUND)
file(GLOB libbpf_sources "lib/bpf/src/*.c")
add_library(bpf OBJECT ${libbpf_sources})
set_property(TARGET bpf PROPERTY POSITION_INDEPENDENT_CODE 1)
target_include_directories(bpf PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/lib/bpf/include
${CMAKE_CURRENT_SOURCE_DIR}/lib/bpf/include/uapi)
endif()
set(dwarves_LIB_SRCS dwarves.c dwarves_fprintf.c gobuffer.c
ctf_loader.c libctf.c btf_encoder.c btf_loader.c
dwarf_loader.c dutil.c elf_symtab.c rbtree.c)
if (NOT LIBBPF_FOUND)
list(APPEND dwarves_LIB_SRCS $<TARGET_OBJECTS:bpf>)
endif()
add_library(dwarves ${dwarves_LIB_SRCS})
set_target_properties(dwarves PROPERTIES VERSION 1.0.0 SOVERSION 1)
set_target_properties(dwarves PROPERTIES INTERFACE_LINK_LIBRARIES "")
target_link_libraries(dwarves ${DWARF_LIBRARIES} ${ZLIB_LIBRARIES} ${LIBBPF_LIBRARIES} ${ARGP_LIBRARY} ${OBSTACK_LIBRARY})
set(dwarves_emit_LIB_SRCS dwarves_emit.c)
add_library(dwarves_emit ${dwarves_emit_LIB_SRCS})
set_target_properties(dwarves_emit PROPERTIES VERSION 1.0.0 SOVERSION 1)
target_link_libraries(dwarves_emit dwarves)
set(dwarves_reorganize_LIB_SRCS dwarves_reorganize.c)
add_library(dwarves_reorganize ${dwarves_reorganize_LIB_SRCS})
set_target_properties(dwarves_reorganize PROPERTIES VERSION 1.0.0 SOVERSION 1)
target_link_libraries(dwarves_reorganize dwarves)
set(codiff_SRCS codiff.c)
add_executable(codiff ${codiff_SRCS})
target_link_libraries(codiff dwarves)
set(ctracer_SRCS ctracer.c)
add_executable(ctracer ${ctracer_SRCS})
target_link_libraries(ctracer dwarves dwarves_emit dwarves_reorganize ${ELF_LIBRARY})
set(dtagnames_SRCS dtagnames.c)
add_executable(dtagnames ${dtagnames_SRCS})
target_link_libraries(dtagnames dwarves)
set(pahole_SRCS pahole.c)
add_executable(pahole ${pahole_SRCS})
target_link_libraries(pahole dwarves dwarves_emit dwarves_reorganize)
set(pdwtags_SRCS pdwtags.c)
add_executable(pdwtags ${pdwtags_SRCS})
target_link_libraries(pdwtags dwarves)
set(pglobal_SRCS pglobal.c)
add_executable(pglobal ${pglobal_SRCS})
target_link_libraries(pglobal dwarves)
set(pfunct_SRCS pfunct.c)
add_executable(pfunct ${pfunct_SRCS})
target_link_libraries(pfunct dwarves dwarves_emit ${ELF_LIBRARY})
set(prefcnt_SRCS prefcnt.c)
add_executable(prefcnt ${prefcnt_SRCS})
target_link_libraries(prefcnt dwarves)
set(scncopy_SRCS scncopy.c elfcreator.c)
add_executable(scncopy ${scncopy_SRCS})
target_link_libraries(scncopy dwarves ${ELF_LIBRARY})
set(syscse_SRCS syscse.c)
add_executable(syscse ${syscse_SRCS})
target_link_libraries(syscse dwarves)
install(TARGETS codiff ctracer dtagnames pahole pdwtags
pfunct pglobal prefcnt scncopy syscse RUNTIME DESTINATION
${CMAKE_INSTALL_PREFIX}/bin)
install(TARGETS dwarves LIBRARY DESTINATION ${LIB_INSTALL_DIR} ARCHIVE DESTINATION ${LIB_INSTALL_DIR})
install(TARGETS dwarves dwarves_emit dwarves_reorganize LIBRARY DESTINATION ${LIB_INSTALL_DIR} ARCHIVE DESTINATION ${LIB_INSTALL_DIR})
install(FILES dwarves.h dwarves_emit.h dwarves_reorganize.h
dutil.h gobuffer.h list.h rbtree.h
btf_encoder.h config.h ctf.h
elfcreator.h elf_symtab.h hash.h libctf.h
DESTINATION ${CMAKE_INSTALL_PREFIX}/include/dwarves/)
install(FILES man-pages/pahole.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man1/)
if(Python3_FOUND)
install(PROGRAMS ostra/ostra-cg DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
install(FILES ostra/python/ostra.py DESTINATION ${CMAKE_INSTALL_PREFIX}/share/dwarves/runtime/python)
endif()
install(PROGRAMS btfdiff fullcircle DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
install(FILES lib/Makefile lib/ctracer_relay.c lib/ctracer_relay.h lib/linux.blacklist.cu
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/dwarves/runtime)