@@ -8,14 +8,20 @@ project(livekit VERSION ${LIVEKIT_VERSION} LANGUAGES C CXX)
88
99set (LIVEKIT_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR} )
1010set (LIVEKIT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} )
11+ list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR} /cmake" )
1112
1213option (LIVEKIT_BUILD_EXAMPLES "Build LiveKit examples" OFF )
1314
1415# vcpkg is only used on Windows; Linux/macOS use system package managers
1516if (WIN32 )
1617 option (LIVEKIT_USE_VCPKG "Use vcpkg for dependency management (Windows only)" ON )
18+ set (LIVEKIT_USE_SYSTEM_PROTOBUF ON CACHE BOOL "Use system protobuf (vcpkg) on Windows" FORCE )
19+ # Force /MD or /MDd for ALL targets (including FetchContent subprojects)
20+ set (CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG :Debug >:Debug >DLL" CACHE STRING "" FORCE )
21+ add_compile_options (/utf-8 )
1722else ()
1823 option (LIVEKIT_USE_VCPKG "Use vcpkg for dependency management" OFF )
24+ set (LIVEKIT_USE_SYSTEM_PROTOBUF OFF CACHE BOOL "Use vendored protobuf on non-Windows" FORCE )
1925endif ()
2026
2127set (CMAKE_CXX_STANDARD 17)
@@ -58,15 +64,6 @@ if(LIVEKIT_IS_TOPLEVEL)
5864 endforeach ()
5965endif ()
6066
61-
62- if (MSVC )
63- # Use dynamic CRT (/MD) for compatibility with Qt and other /MD libraries.
64- # The livekit_ffi.dll isolates the /MT libwebrtc dependency, so livekit.lib
65- # can safely use /MD.
66- set (CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG :Debug >:Debug >DLL" )
67- add_compile_options (/utf-8 )
68- endif ()
69-
7067set (FFI_PROTO_DIR ${LIVEKIT_ROOT_DIR} /client-sdk-rust/livekit-ffi/protocol)
7168set (FFI_PROTO_FILES
7269 ${FFI_PROTO_DIR} /handle.proto
@@ -85,24 +82,33 @@ set(FFI_PROTO_FILES
8582set (PROTO_BINARY_DIR ${LIVEKIT_BINARY_DIR} /generated)
8683file (MAKE_DIRECTORY ${PROTO_BINARY_DIR} )
8784
88- # Try to find Protobuf via CONFIG mode first (vcpkg), then fall back to MODULE mode (apt/brew)
89- find_package (Protobuf CONFIG QUIET )
90- if (NOT Protobuf_FOUND)
91- find_package (Protobuf REQUIRED )
92- endif ()
93-
94- # Ensure protoc executable is found (some systems may not set Protobuf_PROTOC_EXECUTABLE)
95- if (NOT Protobuf_PROTOC_EXECUTABLE)
85+ # Livekit static protobuf.
86+ include (protobuf )
87+ # Ensure protoc executable is found.
88+ if (TARGET protobuf::protoc)
89+ set (Protobuf_PROTOC_EXECUTABLE "$<TARGET_FILE :protobuf ::protoc >" )
90+ elseif (NOT Protobuf_PROTOC_EXECUTABLE)
9691 find_program (Protobuf_PROTOC_EXECUTABLE NAMES protoc REQUIRED )
9792endif ()
9893message (STATUS "Using protoc: ${Protobuf_PROTOC_EXECUTABLE} " )
9994
10095add_library (livekit_proto OBJECT ${FFI_PROTO_FILES} )
96+ if (TARGET protobuf::libprotobuf)
97+ set (LIVEKIT_PROTOBUF_TARGET protobuf::libprotobuf)
98+ else ()
99+ message (FATAL_ERROR "No protobuf library target found (expected protobuf::libprotobuf)" )
100+ endif ()
101101target_include_directories (livekit_proto PRIVATE
102- "$< BUILD_INTERFACE : $ {PROTO_BINARY_DIR}> "
102+ "${PROTO_BINARY_DIR} "
103103 ${Protobuf_INCLUDE_DIRS}
104104)
105- target_link_libraries (livekit_proto PRIVATE protobuf::libprotobuf )
105+ target_link_libraries (livekit_proto PRIVATE ${LIVEKIT_PROTOBUF_TARGET} )
106+ if (TARGET absl::base)
107+ get_target_property (_absl_inc absl::base INTERFACE_INCLUDE_DIRECTORIES )
108+ if (_absl_inc)
109+ target_include_directories (livekit_proto PRIVATE ${_absl_inc} )
110+ endif ()
111+ endif ()
106112
107113# Manually generate protobuf files to avoid path prefix issues
108114set (PROTO_SRCS)
@@ -268,7 +274,7 @@ add_custom_target(build_rust_ffi
268274
269275# Note: protozero_plugin.o removal is no longer needed since we use dynamic libraries on Unix
270276
271- add_library (livekit STATIC
277+ add_library (livekit SHARED
272278 src/audio_frame.cpp
273279 src/audio_source.cpp
274280 src/audio_stream.cpp
@@ -301,6 +307,10 @@ add_library(livekit STATIC
301307 src/video_utils.cpp
302308 src/video_utils.h
303309)
310+ if (WIN32 )
311+ set_target_properties (livekit PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON )
312+ endif ()
313+
304314
305315target_sources (livekit PRIVATE $<TARGET_OBJECTS :livekit_proto >)
306316
@@ -318,8 +328,7 @@ target_include_directories(livekit
318328target_link_libraries (livekit
319329 PRIVATE
320330 livekit_ffi
321- PUBLIC
322- protobuf::libprotobuf
331+ ${LIVEKIT_PROTOBUF_TARGET}
323332)
324333
325334message (STATUS "Protobuf: version=${Protobuf_VERSION} ; protoc=${Protobuf_PROTOC_EXECUTABLE} " )
@@ -386,60 +395,6 @@ if(LIVEKIT_IS_TOPLEVEL)
386395 COMMENT "Copying liblivekit_ffi.so to output directory"
387396 )
388397 endif ()
389-
390- # Copy third-party DLL and LIB dependencies to lib directory (Windows only)
391- if (WIN32 AND LIVEKIT_USE_VCPKG)
392- # Determine vcpkg directories based on configuration
393- set (VCPKG_BIN_DIR_DEBUG "${LIVEKIT_ROOT_DIR} /vcpkg_installed/x64-windows/debug/bin" )
394- set (VCPKG_BIN_DIR_RELEASE "${LIVEKIT_ROOT_DIR} /vcpkg_installed/x64-windows/bin" )
395- set (VCPKG_LIB_DIR_DEBUG "${LIVEKIT_ROOT_DIR} /vcpkg_installed/x64-windows/debug/lib" )
396- set (VCPKG_LIB_DIR_RELEASE "${LIVEKIT_ROOT_DIR} /vcpkg_installed/x64-windows/lib" )
397-
398- # vcpkg uses 'd' suffix for debug builds (e.g., libprotobufd.dll)
399- # We need to copy with the correct source name but keep the output name consistent
400-
401- # abseil_dll.dll (same name for both debug and release)
402- add_custom_command (
403- TARGET livekit POST_BUILD
404- COMMAND ${CMAKE_COMMAND} -E copy_if_different
405- "$<IF :$<CONFIG :Debug >,${VCPKG_BIN_DIR_DEBUG} /abseil_dll .dll ,${VCPKG_BIN_DIR_RELEASE} /abseil_dll .dll >"
406- "$<TARGET_FILE_DIR :livekit >/abseil_dll.dll"
407- COMMENT "Copying abseil_dll.dll to lib directory"
408- VERBATIM
409- )
410-
411- # libprotobuf.dll - debug version has 'd' suffix
412- add_custom_command (
413- TARGET livekit POST_BUILD
414- COMMAND ${CMAKE_COMMAND} -E copy_if_different
415- "$<IF :$<CONFIG :Debug >,${VCPKG_BIN_DIR_DEBUG} /libprotobufd .dll ,${VCPKG_BIN_DIR_RELEASE} /libprotobuf .dll >"
416- "$<TARGET_FILE_DIR :livekit >/$<IF :$<CONFIG :Debug >,libprotobufd .dll ,libprotobuf .dll >"
417- COMMENT "Copying libprotobuf DLL to lib directory"
418- VERBATIM
419- )
420-
421- # abseil_dll.lib (same name for both debug and release)
422- add_custom_command (
423- TARGET livekit POST_BUILD
424- COMMAND ${CMAKE_COMMAND} -E copy_if_different
425- "$<IF :$<CONFIG :Debug >,${VCPKG_LIB_DIR_DEBUG} /abseil_dll .lib ,${VCPKG_LIB_DIR_RELEASE} /abseil_dll .lib >"
426- "$<TARGET_FILE_DIR :livekit >/abseil_dll.lib"
427- COMMENT "Copying abseil_dll.lib to lib directory"
428- VERBATIM
429- )
430-
431- # libprotobuf.lib - debug version has 'd' suffix
432- add_custom_command (
433- TARGET livekit POST_BUILD
434- COMMAND ${CMAKE_COMMAND} -E copy_if_different
435- "$<IF :$<CONFIG :Debug >,${VCPKG_LIB_DIR_DEBUG} /libprotobufd .lib ,${VCPKG_LIB_DIR_RELEASE} /libprotobuf .lib >"
436- "$<TARGET_FILE_DIR :livekit >/$<IF :$<CONFIG :Debug >,libprotobufd .lib ,libprotobuf .lib >"
437- COMMENT "Copying libprotobuf LIB to lib directory"
438- VERBATIM
439- )
440-
441- message (STATUS "Third-party dependencies will be copied to lib directory" )
442- endif ()
443398endif ()
444399
445400if (APPLE )
@@ -465,7 +420,7 @@ if(APPLE)
465420 find_library (FW_METALKIT MetalKit REQUIRED )
466421 find_library (FW_SCREENCAPTUREKIT ScreenCaptureKit REQUIRED )
467422
468- target_link_libraries (livekit PUBLIC
423+ target_link_libraries (livekit PRIVATE
469424 ${FW_COREAUDIO}
470425 ${FW_AUDIOTOOLBOX}
471426 ${FW_COREFOUNDATION}
@@ -485,40 +440,11 @@ if(APPLE)
485440 ${FW_SCREENCAPTUREKIT}
486441 )
487442
488- target_link_options (livekit INTERFACE "LINKER:-ObjC" )
489- endif ()
490-
491- if (Protobuf_VERSION VERSION_GREATER_EQUAL 6.0)
492- find_package (absl CONFIG QUIET )
493- if (NOT absl_FOUND)
494- find_package (Abseil QUIET )
495- endif ()
496-
497- if (absl_FOUND)
498- target_link_libraries (livekit PUBLIC
499- absl::log
500- absl::check
501- absl::strings
502- absl::base
503- )
504- elseif (Abseil_FOUND)
505- target_link_libraries (livekit PUBLIC
506- Abseil::log
507- Abseil::check
508- Abseil::strings
509- Abseil::base
510- )
511- else ()
512- message (FATAL_ERROR
513- "Protobuf ${Protobuf_VERSION} requires Abseil but no CMake package was found.\n "
514- "Install Abseil or use Protobuf < 6." )
515- endif ()
516- else ()
517- message (STATUS "Protobuf < 6 detected; skipping Abseil linking." )
443+ target_link_options (livekit PRIVATE "LINKER:-ObjC" )
518444endif ()
519445
520446if (WIN32 )
521- target_link_libraries (livekit PUBLIC
447+ target_link_libraries (livekit PRIVATE
522448 ntdll
523449 userenv
524450 winmm
@@ -535,7 +461,7 @@ endif()
535461
536462if (UNIX AND NOT APPLE )
537463 find_package (OpenSSL REQUIRED )
538- target_link_libraries (livekit PUBLIC OpenSSL::SSL OpenSSL::Crypto )
464+ target_link_libraries (livekit PRIVATE OpenSSL::SSL OpenSSL::Crypto )
539465endif ()
540466
541467if (MSVC )
@@ -582,42 +508,6 @@ if(WIN32)
582508 CONFIGURATIONS Debug
583509 )
584510 endif ()
585-
586- # Protobuf
587- if (TARGET protobuf::libprotobuf)
588- install (IMPORTED_RUNTIME_ARTIFACTS protobuf::libprotobuf
589- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
590- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
591- )
592- install (FILES
593- $<TARGET_PROPERTY :protobuf ::libprotobuf ,IMPORTED_IMPLIB_RELEASE >
594- DESTINATION ${CMAKE_INSTALL_LIBDIR}
595- CONFIGURATIONS Release RelWithDebInfo MinSizeRel
596- )
597- install (FILES
598- $<TARGET_PROPERTY :protobuf ::libprotobuf ,IMPORTED_IMPLIB_DEBUG >
599- DESTINATION ${CMAKE_INSTALL_LIBDIR}
600- CONFIGURATIONS Debug
601- )
602- endif ()
603-
604- # Abseil
605- if (TARGET absl::abseil_dll)
606- install (IMPORTED_RUNTIME_ARTIFACTS absl::abseil_dll
607- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
608- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
609- )
610- install (FILES
611- $<TARGET_PROPERTY :absl ::abseil_dll ,IMPORTED_IMPLIB_RELEASE >
612- DESTINATION ${CMAKE_INSTALL_LIBDIR}
613- CONFIGURATIONS Release RelWithDebInfo MinSizeRel
614- )
615- install (FILES
616- $<TARGET_PROPERTY :absl ::abseil_dll ,IMPORTED_IMPLIB_DEBUG >
617- DESTINATION ${CMAKE_INSTALL_LIBDIR}
618- CONFIGURATIONS Debug
619- )
620- endif ()
621511endif ()
622512
623513# Install public headers
0 commit comments