Skip to content

Commit

Permalink
cmake: look for either static or dynamic libraries
Browse files Browse the repository at this point in the history
On some distro, static libraries are shipped in a separate package.
Look for either a static or dynamic libbpf, and only fail if neither is found.
  • Loading branch information
teknoraver authored and yonghong-song committed Jan 28, 2021
1 parent dca1a81 commit 6b4222c
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions cmake/FindLibBpf.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,43 @@ find_path (LIBBPF_INCLUDE_DIR
/sw/include
ENV CPATH)

find_library (LIBBPF_STATIC_LIBRARIES
find_library (LIBBPF_LIBRARIES
NAMES
libbpf.a
bpf
PATHS
/usr/lib
/usr/local/lib
/opt/local/lib
/sw/lib
ENV LIBRARY_PATH
ENV LD_LIBRARY_PATH)
if(LIBBPF_LIBRARIES)
list(APPEND PATHS LIBBPF_LIBRARIES)
endif()

find_library (LIBBPF_LIBRARIES
find_library (LIBBPF_STATIC_LIBRARIES
NAMES
bpf
libbpf.a
PATHS
/usr/lib
/usr/local/lib
/opt/local/lib
/sw/lib
ENV LIBRARY_PATH
ENV LD_LIBRARY_PATH)
if(LIBBPF_STATIC_LIBRARIES)
list(APPEND PATHS LIBBPF_STATIC_LIBRARIES)
endif()

if(LIBBPF_STATIC_LIBRARIES OR LIBBPF_LIBRARIES)
include (FindPackageHandleStandardArgs)

# handle the QUIETLY and REQUIRED arguments and set LIBBPF_FOUND to TRUE if all listed variables are TRUE
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibBpf "Please install the libbpf development package"
LIBBPF_LIBRARIES
LIBBPF_STATIC_LIBRARIES
${PATHS}
LIBBPF_INCLUDE_DIR)

mark_as_advanced(LIBBPF_INCLUDE_DIR LIBBPF_STATIC_LIBRARIES LIBBPF_LIBRARIES)
mark_as_advanced(LIBBPF_INCLUDE_DIR ${PATHS})
else()
message(Please install the libbpf development package)
endif()

0 comments on commit 6b4222c

Please sign in to comment.