Skip to content

Commit 33e56f1

Browse files
authored
Add static libraries to Linux amalgamation (maplibre#3699)
1 parent ca5f79c commit 33e56f1

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
function(find_static_library result_var)
2+
# Usage: find_static_library(VAR_NAME NAMES name1 [name2 ...])
3+
set(options)
4+
set(one_value_args)
5+
set(multi_value_args NAMES)
6+
cmake_parse_arguments(FSL "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN})
7+
8+
if(NOT FSL_NAMES)
9+
message(FATAL_ERROR "find_static_library: NAMES argument required")
10+
endif()
11+
12+
# Clear any previous cached result for this variable
13+
unset(${result_var} CACHE)
14+
15+
# Temporarily force CMake to look only for .a
16+
set(_old_suffixes ${CMAKE_FIND_LIBRARY_SUFFIXES})
17+
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
18+
19+
# Invoke find_library using the caller's var name
20+
find_library(${result_var} NAMES ${FSL_NAMES})
21+
22+
# Restore original suffix list
23+
set(CMAKE_FIND_LIBRARY_SUFFIXES ${_old_suffixes})
24+
25+
# Check result
26+
if(NOT ${result_var})
27+
message(FATAL_ERROR
28+
"find_static_library: could not find any of [${FSL_NAMES}] as a .a")
29+
endif()
30+
31+
message(STATUS
32+
"find_static_library: Found static [${FSL_NAMES}] -> ${${result_var}}")
33+
endfunction()

platform/linux/linux.cmake

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,16 @@ target_link_libraries(
184184
# Bundle system provided libraries
185185
if(MLN_CORE_INCLUDE_DEPS AND NOT MLN_USE_BUILTIN_ICU AND NOT "${ARMERGE}" STREQUAL "ARMERGE-NOTFOUND")
186186
message(STATUS "Found armerge: ${ARMERGE}")
187+
include(${CMAKE_CURRENT_LIST_DIR}/cmake/find_static_library.cmake)
188+
find_static_library(PNG_STATIC_LIB NAMES png)
189+
find_static_library(ZLIB_STATIC_LIB NAMES z)
190+
find_static_library(JPEG_STATIC_LIB NAMES jpeg)
191+
find_static_library(WEBP_STATIC_LIB NAMES webp)
192+
find_static_library(CURL_STATIC_LIB NAMES curl)
193+
find_static_library(UV_STATIC_LIB NAMES uv)
194+
find_static_library(OPENSSL_STATIC_LIB NAMES ssl)
195+
find_static_library(SQLITE_STATIC_LIB NAMES sqlite3)
196+
187197
add_custom_command(
188198
TARGET mbgl-core
189199
POST_BUILD
@@ -192,6 +202,14 @@ if(MLN_CORE_INCLUDE_DEPS AND NOT MLN_USE_BUILTIN_ICU AND NOT "${ARMERGE}" STREQU
192202
${ICUUC_LIBRARY_DIRS}/libicuuc.a
193203
${ICUUC_LIBRARY_DIRS}/libicudata.a
194204
${ICUI18N_LIBRARY_DIRS}/libicui18n.a
205+
${PNG_STATIC_LIB}
206+
${ZLIB_STATIC_LIB}
207+
${JPEG_STATIC_LIB}
208+
${WEBP_STATIC_LIB}
209+
${CURL_STATIC_LIB}
210+
${UV_STATIC_LIB}
211+
${OPENSSL_STATIC_LIB}
212+
${SQLITE_STATIC_LIB}
195213
)
196214
endif()
197215

0 commit comments

Comments
 (0)