1From 9a6d50b3f355c1e4d72a235aa0bac4856dff1785 Mon Sep 17 00:00:00 2001 2From: Adrian Perez de Castro <aperez@igalia.com> 3Date: Tue, 27 Mar 2018 19:59:23 +0100 4Subject: [PATCH] CMake: Handle multiple libraries being returned for Brotli 5 6Brotli is built as three libraries: libbrotlienc, libbrotlidec, and 7libbrotlicommon. When requesting the linker flags using pkg-config for 8e.g. libbrotlidec, it will return both libbrotlidec and libbrotlicommon. 9The FindBrotli*.cmake files ignore the names of the libraries returned 10by pkg-config, and hardcode only the libbrotli{enc,dec} names. While 11this is fine when using shared libraries (they contain an entry for 12libbrotlicommon as required library in their headers), it will cause 13linker errors when Brotli has been built as static libraries, due to 14the missing symbols from libbrotlicommon being unknown to the linker. 15 16This fixes FindBrotli*.cmake files by using the library names reported 17by pkg-config (instead of hardcoding them), and applying find_library() 18to each of the libraries to find their absolute paths. If any of the 19libraries is missing, the corresponding BROTLI{ENC,DEC}_LIBRARIES is 20unset to let find_package_handle_standard_args() report an error. 21--- 22 cmake/FindBrotliDec.cmake | 13 +++++++++---- 23 cmake/FindBrotliEnc.cmake | 14 ++++++++++---- 24 2 files changed, 19 insertions(+), 8 deletions(-) 25 26Signed-off-by: Adrian Perez de Castro <aperez@igalia.com> 27Upstream-Status: Submitted [https://github.com/google/woff2/pull/112] 28 29diff --git a/cmake/FindBrotliDec.cmake b/cmake/FindBrotliDec.cmake 30index abb06f4..9cbb415 100644 31--- a/cmake/FindBrotliDec.cmake 32+++ b/cmake/FindBrotliDec.cmake 33@@ -18,10 +18,15 @@ find_path(BROTLIDEC_INCLUDE_DIRS 34 HINTS ${PC_BROTLIDEC_INCLUDEDIR} 35 ) 36 37-find_library(BROTLIDEC_LIBRARIES 38- NAMES brotlidec 39- HINTS ${PC_BROTLIDEC_LIBDIR} 40-) 41+set(BROTLIDEC_LIBRARIES "") 42+foreach(_lib ${PC_BROTLIDEC_LIBRARIES}) 43+ find_library(PC_BROTLIDEC_PATH_${_lib} ${_lib} HINTS ${PC_BROTLIDEC_LIBRARY_DIRS}) 44+ if(NOT PC_BROTLIDEC_PATH_${_lib}) 45+ unset(BROTLIDEC_LIBRARIES) 46+ break() 47+ endif() 48+ list(APPEND BROTLIDEC_LIBRARIES "${PC_BROTLIDEC_PATH_${_lib}}") 49+endforeach() 50 51 include(FindPackageHandleStandardArgs) 52 find_package_handle_standard_args(BrotliDec 53diff --git a/cmake/FindBrotliEnc.cmake b/cmake/FindBrotliEnc.cmake 54index 4be347d..55f3932 100644 55--- a/cmake/FindBrotliEnc.cmake 56+++ b/cmake/FindBrotliEnc.cmake 57@@ -18,10 +18,16 @@ find_path(BROTLIENC_INCLUDE_DIRS 58 HINTS ${PC_BROTLIENC_INCLUDEDIR} 59 ) 60 61-find_library(BROTLIENC_LIBRARIES 62- NAMES brotlienc 63- HINTS ${PC_BROTLIENC_LIBDIR} 64-) 65+set(BROTLIENC_LIBRARIES "") 66+foreach(_lib ${PC_BROTLIENC_LIBRARIES}) 67+ find_library(PC_BROTLIENC_PATH_${_lib} ${_lib} 68+ HINTS ${PC_BROTLIENC_LIBRARY_DIRS}) 69+ if(NOT PC_BROTLIENC_PATH_${_lib}) 70+ unset(BROTLIENC_LIBRARIES) 71+ break() 72+ endif() 73+ list(APPEND BROTLIENC_LIBRARIES "${PC_BROTLIENC_PATH_${_lib}}") 74+endforeach() 75 76 include(FindPackageHandleStandardArgs) 77 find_package_handle_standard_args(BrotliEnc 78-- 792.16.3 80 81