Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,20 @@ else()
set(RUST_TARGET_DIR "${RUST_ROOT}/target")
endif()

# Detect the GCC toolchain's library directory so cargo can find the matching libstdc++.
# This is needed when using a non-system GCC (e.g. GCC 14) on an older distro whose
# system libstdc++ lacks symbols like __cxa_call_terminate.
set(GCC_LIB_DIR "")
if(NOT WIN32)
get_filename_component(_gcc_bin_dir "${CMAKE_C_COMPILER}" DIRECTORY)
get_filename_component(_gcc_root "${_gcc_bin_dir}" DIRECTORY)
if(IS_DIRECTORY "${_gcc_root}/lib64")
set(GCC_LIB_DIR "${_gcc_root}/lib64")
elseif(IS_DIRECTORY "${_gcc_root}/lib")
set(GCC_LIB_DIR "${_gcc_root}/lib")
endif()
endif()

set(RUN_CARGO_SCRIPT ${LIVEKIT_BINARY_DIR}/run_cargo.cmake)
file(WRITE ${RUN_CARGO_SCRIPT}
"if(NOT DEFINED CFG)
Expand All @@ -204,6 +218,11 @@ endif()
message(STATUS \"[run_cargo.cmake] CFG=\${CFG} CARGO=\${CARGO} PROTOC=\${PROTOC_PATH}\")
set(ENV{PROTOC} \"\${PROTOC_PATH}\")

if(DEFINED GCC_LIB_DIR AND NOT GCC_LIB_DIR STREQUAL \"\")
set(ENV{RUSTFLAGS} \"-L \${GCC_LIB_DIR} \$ENV{RUSTFLAGS}\")
set(ENV{LD_LIBRARY_PATH} \"\${GCC_LIB_DIR}:\$ENV{LD_LIBRARY_PATH}\")
endif()

execute_process(
COMMAND \"\${CARGO}\" \${ARGS}
WORKING_DIRECTORY \"\${RUST_ROOT}\"
Expand Down Expand Up @@ -286,6 +305,7 @@ add_custom_command(
-DCARGO=${CARGO_EXECUTABLE}
-DPROTOC_PATH=${Protobuf_PROTOC_EXECUTABLE}
-DRUST_TARGET=${RUST_TARGET_TRIPLE}
-DGCC_LIB_DIR=${GCC_LIB_DIR}
-P "${RUN_CARGO_SCRIPT}"
WORKING_DIRECTORY "${RUST_ROOT}"
DEPENDS ${RUST_SOURCES}
Expand Down
42 changes: 21 additions & 21 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,46 +117,46 @@ target_link_libraries(SimpleRpc
spdlog::spdlog
)

# --- SimpleRobot example (robot + human executables with shared json_utils) ---
# --- SimpleJoystick example (sender + receiver executables with shared json_utils) ---

add_library(simple_robot_json_utils STATIC
simple_robot/json_utils.cpp
simple_robot/json_utils.h
simple_robot/utils.cpp
simple_robot/utils.h
add_library(simple_joystick_json_utils STATIC
simple_joystick/json_utils.cpp
simple_joystick/json_utils.h
simple_joystick/utils.cpp
simple_joystick/utils.h
)

target_include_directories(simple_robot_json_utils PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/simple_robot
target_include_directories(simple_joystick_json_utils PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/simple_joystick
)

target_link_libraries(simple_robot_json_utils
target_link_libraries(simple_joystick_json_utils
PUBLIC
nlohmann_json::nlohmann_json
)

add_executable(SimpleRobot
simple_robot/robot.cpp
add_executable(SimpleJoystickReceiver
simple_joystick/receiver.cpp
)

target_include_directories(SimpleRobot PRIVATE ${EXAMPLES_PRIVATE_INCLUDE_DIRS})
target_include_directories(SimpleJoystickReceiver PRIVATE ${EXAMPLES_PRIVATE_INCLUDE_DIRS})

target_link_libraries(SimpleRobot
target_link_libraries(SimpleJoystickReceiver
PRIVATE
simple_robot_json_utils
simple_joystick_json_utils
livekit
spdlog::spdlog
)

add_executable(SimpleHuman
simple_robot/human.cpp
add_executable(SimpleJoystickSender
simple_joystick/sender.cpp
)

target_include_directories(SimpleHuman PRIVATE ${EXAMPLES_PRIVATE_INCLUDE_DIRS})
target_include_directories(SimpleJoystickSender PRIVATE ${EXAMPLES_PRIVATE_INCLUDE_DIRS})

target_link_libraries(SimpleHuman
target_link_libraries(SimpleJoystickSender
PRIVATE
simple_robot_json_utils
simple_joystick_json_utils
livekit
spdlog::spdlog
)
Expand Down Expand Up @@ -269,7 +269,7 @@ if(WIN32)
)

# Copy DLLs to each example's output directory
foreach(EXAMPLE SimpleRoom SimpleRpc SimpleRobot SimpleHuman SimpleDataStream LoggingLevelsBasicUsage LoggingLevelsCustomSinks BridgeRobot BridgeHuman)
foreach(EXAMPLE SimpleRoom SimpleRpc SimpleJoystickSender SimpleJoystickReceiver SimpleDataStream LoggingLevelsBasicUsage LoggingLevelsCustomSinks BridgeRobot BridgeHuman)
foreach(DLL ${REQUIRED_DLLS})
add_custom_command(TARGET ${EXAMPLE} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
Expand Down Expand Up @@ -304,7 +304,7 @@ if(UNIX)
endif()

# Copy shared library to each example's output directory
foreach(EXAMPLE SimpleRoom SimpleRpc SimpleRobot SimpleHuman SimpleDataStream LoggingLevelsBasicUsage LoggingLevelsCustomSinks BridgeRobot BridgeHuman)
foreach(EXAMPLE SimpleRoom SimpleRpc SimpleJoystickSender SimpleJoystickReceiver SimpleDataStream LoggingLevelsBasicUsage LoggingLevelsCustomSinks BridgeRobot BridgeHuman)
add_custom_command(TARGET ${EXAMPLE} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${LIVEKIT_LIB_DIR}/${FFI_SHARED_LIB}"
Expand Down
22 changes: 19 additions & 3 deletions examples/bridge_human_robot/human.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
* Run alongside the "robot" example (which publishes with identity "robot").
*/

#include "lk_log.h"
#include "livekit/audio_frame.h"
#include "livekit/track.h"
#include "livekit/video_frame.h"
#include "livekit_bridge/livekit_bridge.h"
#include "lk_log.h"
#include "sdl_media.h"

#include <SDL3/SDL.h>
Expand Down Expand Up @@ -115,9 +115,25 @@ int main(int argc, char *argv[]) {
}

std::string url, token;
auto is_ws_url = [](const std::string &s) {
return (s.size() >= 5 && s.compare(0, 5, "ws://") == 0) ||
(s.size() >= 6 && s.compare(0, 6, "wss://") == 0);
};
if (positional.size() >= 2) {
url = positional[0];
token = positional[1];
for (const auto &arg : positional) {
if (is_ws_url(arg)) {
url = arg;
break;
}
}
for (const auto &arg : positional) {
if (arg != url) {
token = arg;
break;
}
}
if (url.empty())
url = positional[0], token = positional[1]; // fallback by position
} else {
const char *e = std::getenv("LIVEKIT_URL");
if (e)
Expand Down
Loading
Loading