@@ -31,15 +31,60 @@ add_definitions(-D_GNU_SOURCE -DDWARVES_VERSION="v1.12")
31
31
find_package (DWARF REQUIRED)
32
32
find_package (ZLIB REQUIRED)
33
33
34
+ # make sure git submodule(s) are checked out
35
+ find_package (Git QUIET )
36
+ if (GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR} /.git" )
37
+ # Update submodules as needed
38
+ option (GIT_SUBMODULE "Check submodules during build" ON )
39
+ if (GIT_SUBMODULE)
40
+ message (STATUS "Submodule update" )
41
+ execute_process (COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
42
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
43
+ RESULT_VARIABLE GIT_SUBMOD_RESULT)
44
+ if (NOT GIT_SUBMOD_RESULT EQUAL "0" )
45
+ message (FATAL_ERROR "git submodule update --init failed with ${GIT_SUBMOD_RESULT} , please checkout submodules" )
46
+ else ()
47
+ message (STATUS "Submodule update - done" )
48
+ endif ()
49
+ endif ()
50
+ endif ()
51
+ if (NOT EXISTS "${PROJECT_SOURCE_DIR} /lib/bpf/src/btf.h" )
52
+ message (FATAL_ERROR "The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again." )
53
+ endif ()
54
+
34
55
_set_fancy(LIB_INSTALL_DIR "${EXEC_INSTALL_PREFIX}${CMAKE_INSTALL_PREFIX} /${__LIB} " "libdir" )
35
56
57
+ # libbpf uses reallocarray, which is not available in all versions of glibc
58
+ # libbpf's include/tools/libc_compat.h provides implementation, but needs
59
+ # COMPACT_NEED_REALLOCARRAY to be set
60
+ INCLUDE (CheckCSourceCompiles)
61
+ CHECK_C_SOURCE_COMPILES(
62
+ "
63
+ #define _GNU_SOURCE
64
+ #include <stdlib.h>
65
+ int main(void)
66
+ {
67
+ return !!reallocarray(NULL, 1, 1);
68
+ }
69
+ " HAVE_REALLOCARRAY_SUPPORT)
70
+ if (NOT HAVE_REALLOCARRAY_SUPPORT)
71
+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DCOMPAT_NEED_REALLOCARRAY" )
72
+ endif ()
73
+
74
+ file (GLOB libbpf_sources "lib/bpf/src/*.c" )
75
+ add_library (bpf STATIC ${libbpf_sources} )
76
+ set_target_properties (bpf PROPERTIES OUTPUT_NAME bpf)
77
+ target_include_directories (bpf PRIVATE
78
+ ${CMAKE_CURRENT_SOURCE_DIR} /lib/bpf/include
79
+ ${CMAKE_CURRENT_SOURCE_DIR} /lib/bpf/include /uapi)
80
+
36
81
set (dwarves_LIB_SRCS dwarves.c dwarves_fprintf.c gobuffer strings
37
82
ctf_encoder.c ctf_loader.c libctf.c btf_encoder.c btf_loader.c libbtf.c
38
83
dwarf_loader.c dutil.c elf_symtab.c rbtree.c)
39
84
add_library (dwarves SHARED ${dwarves_LIB_SRCS} )
40
85
set_target_properties (dwarves PROPERTIES VERSION 1.0.0 SOVERSION 1)
41
86
set_target_properties (dwarves PROPERTIES INTERFACE_LINK_LIBRARIES "" )
42
- target_link_libraries (dwarves ${DWARF_LIBRARIES} ${ZLIB_LIBRARIES} )
87
+ target_link_libraries (dwarves ${DWARF_LIBRARIES} ${ZLIB_LIBRARIES} bpf )
43
88
44
89
set (dwarves_emit_LIB_SRCS dwarves_emit.c)
45
90
add_library (dwarves_emit SHARED ${dwarves_emit_LIB_SRCS} )
@@ -75,7 +120,7 @@ set(pglobal_SRCS pglobal.c)
75
120
add_executable (pglobal ${pglobal_SRCS} )
76
121
target_link_libraries (pglobal dwarves)
77
122
78
- set (pfunct_SRCS pfunct.c )
123
+ set (pfunct_SRCS pfunct.c)
79
124
add_executable (pfunct ${pfunct_SRCS} )
80
125
target_link_libraries (pfunct dwarves dwarves_emit ${ELF_LIBRARY} )
81
126
0 commit comments