Skip to content
This repository was archived by the owner on Apr 30, 2025. It is now read-only.

Commit 48da75d

Browse files
authored
Fix FindBrotli for static libs (yhirose#593)
It wasn't linking them.
1 parent 4f84eeb commit 48da75d

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

cmake/FindBrotli.cmake

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ endif()
3535
find_package(PkgConfig QUIET)
3636
if(PKG_CONFIG_FOUND)
3737
if(BROTLI_USE_STATIC_LIBS)
38+
# Have to use _STATIC to tell PkgConfig to find the static libs.
3839
pkg_check_modules(Brotli_common_STATIC QUIET IMPORTED_TARGET libbrotlicommon)
3940
pkg_check_modules(Brotli_decoder_STATIC QUIET IMPORTED_TARGET libbrotlidec)
4041
pkg_check_modules(Brotli_encoder_STATIC QUIET IMPORTED_TARGET libbrotlienc)
@@ -53,7 +54,7 @@ find_path(Brotli_INCLUDE_DIR
5354
)
5455

5556
# Also check if Brotli_decoder was defined, as it can be passed by the end-user
56-
if(NOT TARGET PkgConfig::Brotli_decoder AND NOT Brotli_decoder)
57+
if(NOT TARGET PkgConfig::Brotli_decoder AND NOT Brotli_decoder AND NOT TARGET PkgConfig::Brotli_decoder_STATIC)
5758
if(BROTLI_USE_STATIC_LIBS)
5859
list(APPEND _brotli_decoder_lib_names
5960
"brotlidec-static"
@@ -77,7 +78,7 @@ if(NOT TARGET PkgConfig::Brotli_decoder AND NOT Brotli_decoder)
7778
endif()
7879

7980
# Also check if Brotli_encoder was defined, as it can be passed by the end-user
80-
if(NOT TARGET PkgConfig::Brotli_encoder AND NOT Brotli_encoder)
81+
if(NOT TARGET PkgConfig::Brotli_encoder AND NOT Brotli_encoder AND NOT TARGET PkgConfig::Brotli_encoder_STATIC)
8182
if(BROTLI_USE_STATIC_LIBS)
8283
list(APPEND _brotli_encoder_lib_names
8384
"brotlienc-static"
@@ -101,7 +102,7 @@ if(NOT TARGET PkgConfig::Brotli_encoder AND NOT Brotli_encoder)
101102
endif()
102103

103104
# Also check if Brotli_common was defined, as it can be passed by the end-user
104-
if(NOT TARGET PkgConfig::Brotli_common AND NOT Brotli_common)
105+
if(NOT TARGET PkgConfig::Brotli_common AND NOT Brotli_common AND NOT TARGET PkgConfig::Brotli_common_STATIC)
105106
if(BROTLI_USE_STATIC_LIBS)
106107
list(APPEND _brotli_common_lib_names
107108
"brotlicommon-static"
@@ -129,13 +130,18 @@ set(_brotli_req_vars "")
129130
# Note that the case here needs to match the case we used elsewhere in this file.
130131
foreach(_target_name "common" "decoder" "encoder")
131132
# The PkgConfig IMPORTED_TARGET has PkgConfig:: prefixed to it.
132-
if(TARGET PkgConfig::Brotli_${_target_name})
133-
add_library(Brotli::${_target_name} ALIAS PkgConfig::Brotli_${_target_name})
133+
if(TARGET PkgConfig::Brotli_${_target_name} OR TARGET PkgConfig::Brotli_${_target_name}_STATIC)
134+
set(_stat_str "")
135+
if(BROTLI_USE_STATIC_LIBS)
136+
set(_stat_str "_STATIC")
137+
endif()
138+
# Can't use generators for ALIAS targets, so you get this jank
139+
add_library(Brotli::${_target_name} ALIAS PkgConfig::Brotli_${_target_name}${_stat_str})
134140

135-
if(Brotli_FIND_REQUIRED_${_target_name})
136141
# The PkgConfig version of the library has a slightly different path to its lib.
142+
if(Brotli_FIND_REQUIRED_${_target_name})
137143
if(BROTLI_USE_STATIC_LIBS)
138-
list(APPEND _brotli_req_vars "Brotli_${_target_name}_STATIC_LINK_LIBRARIES")
144+
list(APPEND _brotli_req_vars "Brotli_${_target_name}_STATIC_LIBRARIES")
139145
else()
140146
list(APPEND _brotli_req_vars "Brotli_${_target_name}_LINK_LIBRARIES")
141147
endif()

0 commit comments

Comments
 (0)