Skip to content

Commit 30e191a

Browse files
committed
CMake: make libebl independent of libdw
Commit 720ed9b("Include DWARF support in static build") added a search for libebl into FindLibDw.cmake. The problem is that distros only provide libebl as a static library which makes the search for libdw fail when linking dynamically. Since libebl is necessary for static builds only, separate its search into FindLibEbl.cmake and require it from static builds. In addition, libebl is not necessary on all systems (e.g. Alpine doesn't have it), so make its requirement optional. This may cause some trouble when running a static build on a system with libdw but without libebl but since those two are usually packaged in the same package, that shouldn't occur often.
1 parent a025200 commit 30e191a

File tree

3 files changed

+37
-17
lines changed

3 files changed

+37
-17
lines changed

cmake/FindLibDw.cmake

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,11 @@ find_library (LIBDW_LIBRARIES
3131
ENV LIBRARY_PATH
3232
ENV LD_LIBRARY_PATH)
3333

34-
find_library (LIBEBL_LIBRARIES
35-
NAMES
36-
ebl
37-
PATH_SUFFIXES
38-
libebl
39-
PATHS
40-
ENV LIBRARY_PATH
41-
ENV LD_LIBRARY_PATH)
42-
4334
include (FindPackageHandleStandardArgs)
4435

4536
# handle the QUIETLY and REQUIRED arguments and set LIBDW_FOUND to TRUE if all listed variables are TRUE
4637
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibDw "Please install the libdw development package"
4738
LIBDW_LIBRARIES
48-
LIBEBL_LIBRARIES
4939
LIBDW_INCLUDE_DIRS)
5040

51-
mark_as_advanced(LIBDW_INCLUDE_DIRS LIBEBL_LIBRARIES LIBDW_LIBRARIES)
41+
mark_as_advanced(LIBDW_INCLUDE_DIRS LIBDW_LIBRARIES)

cmake/FindLibEbl.cmake

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# - Try to find libebl static library
2+
# Once done this will define
3+
#
4+
# LIBEBL_FOUND - system has libebl
5+
# LIBEBL_LIBRARIES - Link these to use libebl
6+
7+
find_library(LIBEBL_LIBRARIES
8+
NAMES
9+
ebl
10+
PATH_SUFFIXES
11+
libebl
12+
PATHS
13+
ENV LIBRARY_PATH
14+
ENV LD_LIBRARY_PATH)
15+
16+
include (FindPackageHandleStandardArgs)
17+
18+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibEbl "Please install the libebl static library"
19+
LIBEBL_LIBRARIES)
20+
21+
mark_as_advanced(LIBEBL_LIBRARIES)

src/CMakeLists.txt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,19 +171,28 @@ endif(STATIC_BPF_BCC)
171171
if (LIBDW_FOUND)
172172
if(STATIC_LINKING)
173173
find_package(LibBz2)
174+
find_package(LibLzma)
175+
find_package(LibEbl)
176+
174177
add_library(LIBBZ2 STATIC IMPORTED)
175178
set_property(TARGET LIBBZ2 PROPERTY IMPORTED_LOCATION ${LIBBZ2_LIBRARIES})
176179

177-
find_package(LibLzma)
178180
add_library(LIBLZMA STATIC IMPORTED)
179181
set_property(TARGET LIBLZMA PROPERTY IMPORTED_LOCATION ${LIBLZMA_LIBRARIES})
180182

181-
add_library(LIBEBL STATIC IMPORTED)
182-
set_property(TARGET LIBEBL PROPERTY IMPORTED_LOCATION ${LIBEBL_LIBRARIES})
183-
184183
add_library(LIBDW STATIC IMPORTED)
185184
set_property(TARGET LIBDW PROPERTY IMPORTED_LOCATION ${LIBDW_LIBRARIES})
186-
target_link_libraries(LIBDW INTERFACE LIBBZ2 LIBELF LIBLZMA LIBEBL)
185+
186+
set(LIBDW_LIBS LIBBZ2 LIBELF LIBLZMA)
187+
188+
if (${LIBEBL_FOUND})
189+
# libebl is not necessary on some systems (e.g. Alpine)
190+
add_library(LIBEBL STATIC IMPORTED)
191+
set_property(TARGET LIBEBL PROPERTY IMPORTED_LOCATION ${LIBEBL_LIBRARIES})
192+
set(LIBDW_LIBS ${LIBDW_LIBS} LIBEBL)
193+
endif()
194+
195+
target_link_libraries(LIBDW INTERFACE ${LIBDW_LIBS})
187196

188197
target_link_libraries(runtime LIBDW)
189198
else()
@@ -221,7 +230,7 @@ if (STATIC_LINKING)
221230
target_link_libraries(libbpftrace "-Wl,-Bdynamic" "-lrt" "-lpthread" "-ldl" "-lm")
222231
target_link_libraries(libbpftrace "-Wl,-Bstatic" "-lz")
223232
target_link_libraries(runtime "-Wl,-Bdynamic" "-lrt" "-lpthread" "-ldl" "-lm")
224-
target_link_libraries(runtime "-Wl,-Bstatic" "-lz")
233+
target_link_libraries(runtime "-Wl,-Bstatic" "-lz")
225234
endif()
226235
elseif(STATIC_BPF_BCC)
227236
# partial static build, libbpf needs zlib

0 commit comments

Comments
 (0)