From bd1f6ced7166d213bf8d99ea86d63c1430f00033 Mon Sep 17 00:00:00 2001 From: mid-kid Date: Tue, 6 Dec 2022 23:59:43 +0100 Subject: [PATCH] CMake: Allow building with external crc32c Ported from gentoo: https://github.com/gentoo/gentoo/blob/795a0a5/media-libs/tg_owt/files/tg_owt-0_pre20220507-unbundle-crc32c.patch --- CMakeLists.txt | 6 ++++-- cmake/external.cmake | 14 ++++++++++++++ cmake/libcrc32c.cmake | 4 +++- cmake/tg_owtConfig.cmake | 5 ++++- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d3f674f..19f97000 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -139,7 +139,6 @@ set_target_properties(tg_owt PROPERTIES SOVERSION 0 VERSION 0.0.0) target_link_libraries(tg_owt PRIVATE - tg_owt::libcrc32c tg_owt::libpffft tg_owt::librnnoise tg_owt::libsrtp @@ -177,6 +176,7 @@ link_opus(tg_owt) link_libabsl(tg_owt) link_libopenh264(tg_owt) link_libvpx(tg_owt) +link_crc32c(tg_owt) if (TG_OWT_BUILD_AUDIO_BACKENDS AND (UNIX AND NOT APPLE)) link_libalsa(tg_owt) @@ -2627,7 +2627,6 @@ endif() set(export_targets ${tg_owt_export} - libcrc32c libpffft librnnoise libsrtp @@ -2645,6 +2644,9 @@ endif() if (NOT LIBOPENH264_FOUND) list(APPEND export_targets libopenh264) endif() +if (NOT Crc32c_FOUND) + list(APPEND export_targets libcrc32c) +endif() export( TARGETS ${export_targets} diff --git a/cmake/external.cmake b/cmake/external.cmake index 9328861e..6c4aa752 100644 --- a/cmake/external.cmake +++ b/cmake/external.cmake @@ -166,6 +166,20 @@ function(link_libvpx target_name) endif() endfunction() +# crc32c +function(link_crc32c target_name) + if (TG_OWT_PACKAGED_BUILD) + find_package(Crc32c) + set(Crc32c_FOUND ${Crc32c_FOUND} PARENT_SCOPE) + if (Crc32c_FOUND) + target_link_libraries(${target_name} INTERFACE Crc32c::crc32c) + endif() + endif() + if (NOT Crc32c_FOUND) + target_link_libraries(${target_name} PRIVATE tg_owt::libcrc32c) + endif() +endfunction() + function(link_glib target_name) find_package(PkgConfig REQUIRED) pkg_check_modules(GLIB2 REQUIRED glib-2.0) diff --git a/cmake/libcrc32c.cmake b/cmake/libcrc32c.cmake index 9e1643ae..42d2d1cd 100644 --- a/cmake/libcrc32c.cmake +++ b/cmake/libcrc32c.cmake @@ -28,6 +28,8 @@ target_sources(libcrc32c PRIVATE ${PROJECT_BINARY_DIR}/include/crc32c/crc32c_con target_include_directories(libcrc32c PRIVATE - ${libcrc32c_loc}/include ${PROJECT_BINARY_DIR}/include +PUBLIC + $ + $ ) diff --git a/cmake/tg_owtConfig.cmake b/cmake/tg_owtConfig.cmake index e9f43880..431deaf4 100644 --- a/cmake/tg_owtConfig.cmake +++ b/cmake/tg_owtConfig.cmake @@ -1,6 +1,9 @@ +include(CMakeFindDependencyMacro) if (@absl_FOUND@) - include(CMakeFindDependencyMacro) find_dependency(absl REQUIRED) endif() +if (@Crc32c_FOUND@) + find_dependency(Crc32c) +endif() include("${CMAKE_CURRENT_LIST_DIR}/tg_owtTargets.cmake")