|
| 1 | +# Copyright 2026 LiveKit, Inc. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
1 | 15 | cmake_minimum_required(VERSION 3.20) |
2 | 16 | project(livekit_cpp_example_collection LANGUAGES CXX) |
3 | 17 | set(CMAKE_CXX_STANDARD 17) |
4 | 18 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 19 | +set(CMAKE_POSITION_INDEPENDENT_CODE ON) |
5 | 20 |
|
6 | 21 | # Make "include(LiveKitSDK)" search in ./cmake |
7 | 22 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") |
8 | 23 |
|
9 | 24 | set(LIVEKIT_SDK_VERSION "latest" CACHE STRING "LiveKit C++ SDK version (e.g. 0.2.0 or latest)") |
| 25 | +set(LIVEKIT_LOCAL_SDK_DIR "" CACHE PATH "Path to a local LiveKit SDK install prefix (skips download)") |
10 | 26 |
|
11 | | -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") |
12 | | -include(LiveKitSDK) |
| 27 | +if(LIVEKIT_LOCAL_SDK_DIR) |
| 28 | + message(STATUS "Using local LiveKit SDK: ${LIVEKIT_LOCAL_SDK_DIR}") |
| 29 | + list(PREPEND CMAKE_PREFIX_PATH "${LIVEKIT_LOCAL_SDK_DIR}") |
| 30 | +else() |
| 31 | + include(LiveKitSDK) |
| 32 | + livekit_sdk_setup( |
| 33 | + VERSION "${LIVEKIT_SDK_VERSION}" |
| 34 | + SDK_DIR "${CMAKE_BINARY_DIR}/_deps/livekit-sdk" |
| 35 | + GITHUB_TOKEN "$ENV{GITHUB_TOKEN}" |
| 36 | + ) |
| 37 | +endif() |
| 38 | +find_package(LiveKit CONFIG REQUIRED) |
13 | 39 |
|
14 | | -livekit_sdk_setup( |
15 | | - VERSION "${LIVEKIT_SDK_VERSION}" |
16 | | - SDK_DIR "${CMAKE_BINARY_DIR}/_deps/livekit-sdk" |
17 | | - GITHUB_TOKEN "$ENV{GITHUB_TOKEN}" |
18 | | -) |
| 40 | +if(TARGET LiveKit::livekit) |
| 41 | + set(LIVEKIT_CORE_TARGET LiveKit::livekit) |
| 42 | +elseif(TARGET livekit) |
| 43 | + set(LIVEKIT_CORE_TARGET livekit) |
| 44 | +else() |
| 45 | + message(FATAL_ERROR "Could not find a LiveKit core target (expected LiveKit::livekit or livekit).") |
| 46 | +endif() |
| 47 | + |
| 48 | +set(LIVEKIT_DATA_DIR "") |
| 49 | +if(DEFINED LIVEKIT_ROOT_DIR AND EXISTS "${LIVEKIT_ROOT_DIR}/data") |
| 50 | + set(LIVEKIT_DATA_DIR "${LIVEKIT_ROOT_DIR}/data") |
| 51 | +endif() |
| 52 | + |
| 53 | +function(livekit_copy_windows_runtime_dlls target_name) |
| 54 | + if(NOT WIN32) |
| 55 | + return() |
| 56 | + endif() |
| 57 | + |
| 58 | + get_filename_component(_lk_cmake_parent "${LiveKit_DIR}" DIRECTORY) |
| 59 | + get_filename_component(_lk_lib_dir "${_lk_cmake_parent}" DIRECTORY) |
| 60 | + get_filename_component(_lk_prefix "${_lk_lib_dir}" DIRECTORY) |
| 61 | + set(_lk_bin_dir "${_lk_prefix}/bin") |
| 62 | + |
| 63 | + foreach(_lk_runtime_dll IN ITEMS livekit.dll livekit_ffi.dll) |
| 64 | + if(EXISTS "${_lk_bin_dir}/${_lk_runtime_dll}") |
| 65 | + add_custom_command(TARGET ${target_name} POST_BUILD |
| 66 | + COMMAND ${CMAKE_COMMAND} -E copy_if_different |
| 67 | + "${_lk_bin_dir}/${_lk_runtime_dll}" |
| 68 | + "$<TARGET_FILE_DIR:${target_name}>" |
| 69 | + ) |
| 70 | + endif() |
| 71 | + endforeach() |
| 72 | + |
| 73 | + if(TARGET SDL3::SDL3) |
| 74 | + add_custom_command(TARGET ${target_name} POST_BUILD |
| 75 | + COMMAND ${CMAKE_COMMAND} -E copy_if_different |
| 76 | + "$<TARGET_FILE:SDL3::SDL3>" |
| 77 | + "$<TARGET_FILE_DIR:${target_name}>" |
| 78 | + ) |
| 79 | + endif() |
| 80 | +endfunction() |
| 81 | + |
| 82 | +include(ExampleDeps) |
19 | 83 |
|
20 | | -find_package(LiveKit CONFIG REQUIRED) |
21 | 84 | add_subdirectory(basic_room) |
| 85 | +add_subdirectory(simple_room) |
| 86 | +add_subdirectory(simple_rpc) |
| 87 | +add_subdirectory(simple_data_stream) |
| 88 | +add_subdirectory(logging_levels_basic_usage) |
| 89 | +add_subdirectory(logging_levels_custom_sinks) |
| 90 | +add_subdirectory(hello_livekit_sender) |
| 91 | +add_subdirectory(hello_livekit_receiver) |
| 92 | +add_subdirectory(simple_joystick_sender) |
| 93 | +add_subdirectory(simple_joystick_receiver) |
| 94 | +add_subdirectory(ping_pong_ping) |
| 95 | +add_subdirectory(ping_pong_pong) |
0 commit comments