|
2 | 2 | # Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved. |
3 | 3 |
|
4 | 4 | cmake_minimum_required(VERSION 3.10...4.0) |
5 | | -if (POLICY CMP0144) |
6 | | - message("--using CMP0144 for Protobuf checking") |
7 | | - cmake_policy(SET CMP0144 NEW) |
8 | | -else (POLICY CMP0144) |
9 | | - message("--CMP0144 is not supported, skipping xbtracer") |
10 | | - return() |
11 | | -endif () |
12 | 5 |
|
13 | | -find_package(Protobuf) |
| 6 | +include(${XRT_SOURCE_DIR}/CMake/protobuf.cmake) |
14 | 7 | if (NOT Protobuf_FOUND) |
15 | | - message("Protobuf is not found, skipping xbtracer") |
| 8 | + message("Protobuf was not found, skip xbtracer.") |
16 | 9 | return() |
17 | | -endif (NOT Protobuf_FOUND) |
18 | | - |
19 | | -# Protobuf 22+ uses abseil for logging, need to link against it |
20 | | -# Note: Protobuf versioning changed - version 22.0 may report as 4.22.0 or 6.22.0 |
21 | | -# We check for abseil linking if protobuf version >= 4.0 (corresponds to protobuf 22+) |
22 | | -find_package(absl QUIET) |
23 | | -if (absl_FOUND AND Protobuf_VERSION VERSION_GREATER_EQUAL 4.0) |
24 | | - set(XBTRACER_ABSL_LIBS absl::log_internal_check_op absl::log_internal_message) |
25 | | - message(STATUS "Found abseil, will link xbtracer against abseil logging libraries") |
26 | | -endif() |
27 | | -message("Protobuf version is ${Protobuf_VERSION}.") |
| 10 | +endif () |
28 | 11 | if (Protobuf_VERSION VERSION_LESS 3.0) |
29 | | - # we use timestamp feature of protobuf |
30 | | - message("Protobuf version ${Protobuf_VERSION} is less than 3.0, skip xbtracer.") |
| 12 | + message("Protobuf ${Protobuf_VERSION} < 3.0, skip xbtracer.") |
31 | 13 | return() |
32 | | -endif (Protobuf_VERSION VERSION_LESS 3.0) |
33 | | - |
34 | | -# Imported targets should link the .lib (not the .dll) when compiling with MSVC |
35 | | -set(XBTRACER_PROTOBUF_LINK "") |
36 | | -if (TARGET protobuf::libprotobuf) |
37 | | - set(XBTRACER_PROTOBUF_LINK protobuf::libprotobuf) |
38 | | -elseif (TARGET Protobuf::libprotobuf) |
39 | | - set(XBTRACER_PROTOBUF_LINK Protobuf::libprotobuf) |
40 | | -else() |
41 | | - set(XBTRACER_PROTOBUF_LINK ${Protobuf_LIBRARIES}) |
42 | | -endif() |
43 | | - |
44 | | -include_directories ( |
45 | | -${Protobuf_INCLUDE_DIR} |
46 | | -${CMAKE_CURRENT_BINARY_DIR} |
47 | | -) |
48 | | -# Generate Cpp files from Proto file |
49 | | -file(GLOB PROTO_SRC_FILES |
50 | | - "${CMAKE_CURRENT_SOURCE_DIR}/src/*.proto" |
51 | | -) |
52 | | - |
53 | | -PROTOBUF_GENERATE_CPP(ProtoSources ProtoHeaders ${PROTO_SRC_FILES}) |
54 | | - |
55 | | -add_custom_target(xbtracer_generated_code DEPENDS ${ProtoSources} ${ProtoHeaders}) |
| 14 | +endif () |
56 | 15 |
|
57 | | -add_library(xbtracer_protobuf STATIC ${ProtoSources} ${ProtoHeaders}) |
58 | | -add_dependencies(xbtracer_protobuf xbtracer_generated_code) |
| 16 | +################################################################ |
| 17 | +# Generate C++ from .proto and create xbtracer proto library |
| 18 | +################################################################ |
| 19 | +set(XBTRACER_PROTO_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/func.proto) |
| 20 | +add_library(xbtracer_protobuf STATIC) |
| 21 | +protobuf_generate_cpp(xbtracer_protobuf ${XBTRACER_PROTO_FILES}) |
| 22 | +target_include_directories(xbtracer_protobuf PRIVATE |
| 23 | + ${Protobuf_INCLUDE_DIR} |
| 24 | + ${CMAKE_CURRENT_BINARY_DIR} |
| 25 | + ${CMAKE_CURRENT_BINARY_DIR}/src |
| 26 | + ) |
59 | 27 | if (MSVC) |
60 | | - target_compile_options(xbtracer_protobuf PRIVATE /wd4244 /wd4267 /wd4100) |
61 | | -endif(MSVC) |
62 | | -# Link protobuf static library against abseil if needed |
63 | | -if (XBTRACER_ABSL_LIBS) |
64 | | - target_link_libraries(xbtracer_protobuf PUBLIC ${XBTRACER_ABSL_LIBS}) |
65 | | -endif() |
66 | | - |
67 | | -include_directories( |
68 | | - "${CMAKE_CURRENT_SOURCE_DIR}/src" |
69 | | - ${XRT_BINARY_DIR}/gen |
70 | | -) |
71 | | - |
72 | | -file(GLOB XBTRACER_COMMON_SRC_FILES |
73 | | - "${CMAKE_CURRENT_SOURCE_DIR}/src/common/*.cpp" |
74 | | -) |
| 28 | + target_compile_options(xbtracer_protobuf PRIVATE /wd4244 /wd4267 /wd4100 /wd4141 /wd4189) |
| 29 | +endif () |
| 30 | +target_link_libraries(xbtracer_protobuf PUBLIC protobuf::libprotobuf) |
75 | 31 |
|
| 32 | +################################################################ |
| 33 | +# Create xbtracer common library |
| 34 | +################################################################ |
| 35 | +file(GLOB XBTRACER_COMMON_SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/common/*.cpp) |
76 | 36 | add_library(xbtracer_common STATIC ${XBTRACER_COMMON_SRC_FILES}) |
| 37 | +target_include_directories(xbtracer_common PRIVATE |
| 38 | + ${CMAKE_CURRENT_SOURCE_DIR}/src |
| 39 | + ) |
77 | 40 | if (NOT WIN32) |
78 | 41 | target_link_libraries(xbtracer_common PRIVATE dl) |
79 | 42 | endif (NOT WIN32) |
80 | 43 |
|
81 | | -file(GLOB XBTRACER_WRAPPER_SRC_FILES |
82 | | - "${CMAKE_CURRENT_SOURCE_DIR}/src/wrapper/*.cpp" |
83 | | -) |
84 | | - |
85 | | -add_library(xrt_trace SHARED ${XBTRACER_WRAPPER_SRC_FILES} ${ProtoHeaders}) |
| 44 | +################################################################ |
| 45 | +# Create xbtracer wrapper library |
| 46 | +################################################################ |
| 47 | +file(GLOB XBTRACER_WRAPPER_SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/wrapper/*.cpp) |
| 48 | +add_library(xrt_trace SHARED ${XBTRACER_WRAPPER_SRC_FILES}) |
86 | 49 | set_target_properties(xrt_trace PROPERTIES VERSION ${XRT_VERSION_STRING} SOVERSION ${XRT_SOVERSION}) |
87 | 50 | target_compile_definitions(xrt_trace PRIVATE XRT_ABI_VERSION=${XRT_VERSION_MAJOR}) |
88 | | - |
89 | | -target_link_libraries(xrt_trace PRIVATE xbtracer_common xbtracer_protobuf ${XBTRACER_PROTOBUF_LINK} xrt_coreutil) |
| 51 | +target_include_directories(xrt_trace PRIVATE |
| 52 | + ${CMAKE_CURRENT_SOURCE_DIR}/src |
| 53 | + ${CMAKE_CURRENT_BINARY_DIR} |
| 54 | + ${CMAKE_CURRENT_BINARY_DIR}/src |
| 55 | + ) |
| 56 | +target_link_libraries(xrt_trace PRIVATE xbtracer_common xbtracer_protobuf protobuf::libprotobuf xrt_coreutil) |
90 | 57 | add_dependencies(xrt_trace xbtracer_common xbtracer_protobuf xrt_coreutil) |
91 | 58 |
|
| 59 | +################################################################ |
| 60 | +# Create xbtracer tracer executable |
| 61 | +################################################################ |
92 | 62 | file(GLOB XBTRACER_CAPTURE_SRC_FILES |
93 | 63 | "${CMAKE_CURRENT_SOURCE_DIR}/src/capture/*.cpp" |
94 | 64 | ) |
95 | 65 |
|
96 | 66 | add_executable(xrt-tracer ${XBTRACER_CAPTURE_SRC_FILES}) |
97 | 67 | target_link_libraries(xrt-tracer PRIVATE xbtracer_common) |
| 68 | +target_include_directories(xrt-tracer PRIVATE |
| 69 | + ${CMAKE_CURRENT_SOURCE_DIR}/src |
| 70 | + ) |
98 | 71 | add_dependencies(xrt-tracer xbtracer_common) |
99 | 72 |
|
| 73 | +################################################################ |
| 74 | +# Create xbtracer replay executable |
| 75 | +################################################################ |
100 | 76 | file(GLOB XBREPLAY_SRC_FILES |
101 | 77 | "${CMAKE_CURRENT_SOURCE_DIR}/src/replay/*.cpp" |
102 | 78 | ) |
103 | 79 | add_executable(xrt-replay ${XBREPLAY_SRC_FILES}) |
104 | | -target_link_libraries(xrt-replay PRIVATE xbtracer_common xbtracer_protobuf ${XBTRACER_PROTOBUF_LINK} xrt_coreutil) |
| 80 | +target_include_directories(xrt-replay PRIVATE |
| 81 | + ${CMAKE_CURRENT_SOURCE_DIR}/src |
| 82 | + ${CMAKE_CURRENT_BINARY_DIR} |
| 83 | + ${CMAKE_CURRENT_BINARY_DIR}/src |
| 84 | + ) |
| 85 | +target_link_libraries(xrt-replay PRIVATE xbtracer_common xbtracer_protobuf protobuf::libprotobuf xrt_coreutil) |
105 | 86 | if (NOT WIN32) |
106 | 87 | target_link_libraries(xrt-replay PRIVATE pthread) |
107 | 88 | endif (NOT WIN32) |
108 | 89 | add_dependencies(xrt-replay xbtracer_common xbtracer_protobuf xrt_coreutil) |
109 | | -# TODO: when buiding with yocto for APU in CI, the status return from message to jason convertion function |
110 | | -# provided from protobuf built from yocto doesn't match the one in the absl library, which results in |
111 | | -# build failure. After fixing this issue in yocto APU build, we can always print message as JSON. |
112 | | -# for now, we by default disable it, as it is not the key feature in the tracer/replay prototype, and replay |
| 90 | + |
| 91 | +# TODO: when buiding with yocto for APU in CI, the status return from |
| 92 | +# message to jason convertion function provided from protobuf built |
| 93 | +# from yocto doesn't match the one in the absl library, which results |
| 94 | +# in build failure. After fixing this issue in yocto APU build, we can |
| 95 | +# always print message as JSON. for now, we by default disable it, as |
| 96 | +# it is not the key feature in the tracer/replay prototype, and replay |
113 | 97 | # only tries to dump JSON message when it fails to replay a function. |
114 | 98 | if (XRT_XBTRACER_ENABLE_JSON) |
115 | 99 | target_compile_options(xrt-replay PRIVATE XBTRACER_PROTOBUF_HAS_JASON) |
116 | 100 |
|
117 | 101 | add_executable(xbtracer_dump |
118 | 102 | src/misc/xbtracer_dump.cpp |
119 | 103 | ) |
120 | | - target_link_libraries(xbtracer_dump PRIVATE xbtracer_common xbtracer_protobuf ${XBTRACER_PROTOBUF_LINK}) |
| 104 | + target_link_libraries(xbtracer_dump PRIVATE xbtracer_common xbtracer_protobuf protobuf::libprotobuf) |
121 | 105 | add_dependencies(xbtracer_dump xbtracer_common xbtracer_protobuf xrt_coreutil) |
122 | 106 | endif (XRT_XBTRACER_ENABLE_JSON) |
123 | 107 |
|
|
0 commit comments