Skip to content

Commit 9a6d50b

Browse files
committed
CMake: Handle multiple libraries being returned for Brotli
Brotli is built as three libraries: libbrotlienc, libbrotlidec, and libbrotlicommon. When requesting the linker flags using pkg-config for e.g. libbrotlidec, it will return both libbrotlidec and libbrotlicommon. The FindBrotli*.cmake files ignore the names of the libraries returned by pkg-config, and hardcode only the libbrotli{enc,dec} names. While this is fine when using shared libraries (they contain an entry for libbrotlicommon as required library in their headers), it will cause linker errors when Brotli has been built as static libraries, due to the missing symbols from libbrotlicommon being unknown to the linker. This fixes FindBrotli*.cmake files by using the library names reported by pkg-config (instead of hardcoding them), and applying find_library() to each of the libraries to find their absolute paths. If any of the libraries is missing, the corresponding BROTLI{ENC,DEC}_LIBRARIES is unset to let find_package_handle_standard_args() report an error.
1 parent 5e5f2cf commit 9a6d50b

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

cmake/FindBrotliDec.cmake

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,15 @@ find_path(BROTLIDEC_INCLUDE_DIRS
1818
HINTS ${PC_BROTLIDEC_INCLUDEDIR}
1919
)
2020

21-
find_library(BROTLIDEC_LIBRARIES
22-
NAMES brotlidec
23-
HINTS ${PC_BROTLIDEC_LIBDIR}
24-
)
21+
set(BROTLIDEC_LIBRARIES "")
22+
foreach(_lib ${PC_BROTLIDEC_LIBRARIES})
23+
find_library(PC_BROTLIDEC_PATH_${_lib} ${_lib} HINTS ${PC_BROTLIDEC_LIBRARY_DIRS})
24+
if(NOT PC_BROTLIDEC_PATH_${_lib})
25+
unset(BROTLIDEC_LIBRARIES)
26+
break()
27+
endif()
28+
list(APPEND BROTLIDEC_LIBRARIES "${PC_BROTLIDEC_PATH_${_lib}}")
29+
endforeach()
2530

2631
include(FindPackageHandleStandardArgs)
2732
find_package_handle_standard_args(BrotliDec

cmake/FindBrotliEnc.cmake

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,16 @@ find_path(BROTLIENC_INCLUDE_DIRS
1818
HINTS ${PC_BROTLIENC_INCLUDEDIR}
1919
)
2020

21-
find_library(BROTLIENC_LIBRARIES
22-
NAMES brotlienc
23-
HINTS ${PC_BROTLIENC_LIBDIR}
24-
)
21+
set(BROTLIENC_LIBRARIES "")
22+
foreach(_lib ${PC_BROTLIENC_LIBRARIES})
23+
find_library(PC_BROTLIENC_PATH_${_lib} ${_lib}
24+
HINTS ${PC_BROTLIENC_LIBRARY_DIRS})
25+
if(NOT PC_BROTLIENC_PATH_${_lib})
26+
unset(BROTLIENC_LIBRARIES)
27+
break()
28+
endif()
29+
list(APPEND BROTLIENC_LIBRARIES "${PC_BROTLIENC_PATH_${_lib}}")
30+
endforeach()
2531

2632
include(FindPackageHandleStandardArgs)
2733
find_package_handle_standard_args(BrotliEnc

0 commit comments

Comments
 (0)