|
| 1 | +# Copyright 2026 LiveKit, Inc. |
| 2 | +# |
| 3 | +# Standalone CMake build for the data-track throughput experiment. |
| 4 | +# All paths are relative to CMAKE_CURRENT_SOURCE_DIR so this directory |
| 5 | +# can be moved or renamed freely. |
| 6 | + |
| 7 | +cmake_minimum_required(VERSION 3.20) |
| 8 | +project(DataTrackThroughput LANGUAGES CXX) |
| 9 | + |
| 10 | +set(CMAKE_CXX_STANDARD 17) |
| 11 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 12 | + |
| 13 | +# ---- Dependencies -------------------------------------------------------- |
| 14 | + |
| 15 | +find_package(LiveKit CONFIG REQUIRED) |
| 16 | + |
| 17 | +find_package(nlohmann_json 3.11 QUIET) |
| 18 | +if(NOT nlohmann_json_FOUND) |
| 19 | + include(FetchContent) |
| 20 | + FetchContent_Declare( |
| 21 | + nlohmann_json |
| 22 | + GIT_REPOSITORY https://github.com/nlohmann/json.git |
| 23 | + GIT_TAG v3.11.3 |
| 24 | + GIT_SHALLOW TRUE |
| 25 | + ) |
| 26 | + FetchContent_MakeAvailable(nlohmann_json) |
| 27 | +endif() |
| 28 | + |
| 29 | +# ---- Targets ------------------------------------------------------------- |
| 30 | + |
| 31 | +set(_targets DataTrackThroughputProducer DataTrackThroughputConsumer) |
| 32 | + |
| 33 | +add_executable(DataTrackThroughputProducer producer.cpp) |
| 34 | +add_executable(DataTrackThroughputConsumer consumer.cpp) |
| 35 | + |
| 36 | +foreach(_target ${_targets}) |
| 37 | + target_include_directories(${_target} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}") |
| 38 | + target_link_libraries(${_target} PRIVATE LiveKit::livekit nlohmann_json::nlohmann_json) |
| 39 | +endforeach() |
| 40 | + |
| 41 | +# ---- RPATH --------------------------------------------------------------- |
| 42 | + |
| 43 | +if(UNIX) |
| 44 | + if(APPLE) |
| 45 | + set_target_properties(${_targets} PROPERTIES |
| 46 | + BUILD_RPATH "@loader_path" |
| 47 | + INSTALL_RPATH "@loader_path" |
| 48 | + ) |
| 49 | + else() |
| 50 | + set_target_properties(${_targets} PROPERTIES |
| 51 | + BUILD_RPATH "$ORIGIN" |
| 52 | + INSTALL_RPATH "$ORIGIN" |
| 53 | + BUILD_RPATH_USE_ORIGIN TRUE |
| 54 | + ) |
| 55 | + endif() |
| 56 | +endif() |
| 57 | + |
| 58 | +# ---- Copy SDK shared libraries next to executables ----------------------- |
| 59 | + |
| 60 | +get_target_property(_lk_location LiveKit::livekit IMPORTED_LOCATION) |
| 61 | +if(NOT _lk_location) |
| 62 | + get_target_property(_lk_location LiveKit::livekit IMPORTED_LOCATION_RELEASE) |
| 63 | +endif() |
| 64 | +if(NOT _lk_location) |
| 65 | + get_target_property(_lk_location LiveKit::livekit IMPORTED_LOCATION_DEBUG) |
| 66 | +endif() |
| 67 | +if(_lk_location) |
| 68 | + get_filename_component(_lk_lib_dir "${_lk_location}" DIRECTORY) |
| 69 | +endif() |
| 70 | + |
| 71 | +if(_lk_lib_dir) |
| 72 | + if(WIN32) |
| 73 | + file(GLOB _sdk_shared_libs "${_lk_lib_dir}/../bin/*.dll" "${_lk_lib_dir}/*.dll") |
| 74 | + elseif(APPLE) |
| 75 | + file(GLOB _sdk_shared_libs "${_lk_lib_dir}/*.dylib") |
| 76 | + else() |
| 77 | + file(GLOB _sdk_shared_libs "${_lk_lib_dir}/*.so" "${_lk_lib_dir}/*.so.*") |
| 78 | + endif() |
| 79 | + |
| 80 | + foreach(_target ${_targets}) |
| 81 | + foreach(_lib ${_sdk_shared_libs}) |
| 82 | + get_filename_component(_lib_name "${_lib}" NAME) |
| 83 | + add_custom_command(TARGET ${_target} POST_BUILD |
| 84 | + COMMAND ${CMAKE_COMMAND} -E copy_if_different |
| 85 | + "${_lib}" "$<TARGET_FILE_DIR:${_target}>/${_lib_name}" |
| 86 | + COMMENT "Copying ${_lib_name} next to ${_target}" |
| 87 | + ) |
| 88 | + endforeach() |
| 89 | + endforeach() |
| 90 | +endif() |
0 commit comments