mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-02-11 09:25:20 +00:00
Strip static and shared libraries of iwasm to reduce the binary size (#2431)
Reduce iwasm static and shared library size when CMAKE_STRIP is set and the build type is "Release". It remains as it is when build type was selected Debug.
This commit is contained in:
parent
51714c41c0
commit
7e3a29d5e4
|
@ -107,6 +107,11 @@ endif ()
|
|||
|
||||
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
# Set the strip command based on the system (GNU or Clang)
|
||||
if (CMAKE_STRIP)
|
||||
set (CMAKE_STRIP_FLAGS "--strip-all")
|
||||
endif ()
|
||||
|
||||
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
|
||||
|
||||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wshadow -Wno-unused-parameter")
|
||||
|
@ -141,6 +146,15 @@ endif ()
|
|||
|
||||
install (TARGETS iwasm_static ARCHIVE DESTINATION lib)
|
||||
|
||||
# If it's a Release build, strip the static library
|
||||
if (CMAKE_STRIP AND CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
# Strip static library
|
||||
message (STATUS "Stripping static library after build!")
|
||||
add_custom_command (TARGET iwasm_static POST_BUILD
|
||||
COMMAND ${CMAKE_STRIP} ${CMAKE_STRIP_FLAGS} $<TARGET_FILE:iwasm_static>
|
||||
)
|
||||
endif ()
|
||||
|
||||
# SHARED LIBRARY
|
||||
add_library (iwasm_shared SHARED ${WAMR_RUNTIME_LIB_SOURCE})
|
||||
set_target_properties (iwasm_shared PROPERTIES OUTPUT_NAME iwasm)
|
||||
|
@ -162,3 +176,12 @@ install (FILES
|
|||
${WAMR_ROOT_DIR}/core/iwasm/include/wasm_export.h
|
||||
${WAMR_ROOT_DIR}/core/iwasm/include/lib_export.h
|
||||
DESTINATION include)
|
||||
|
||||
# If it's a Release build, strip the shared library
|
||||
if (CMAKE_STRIP AND CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
# Strip shared library
|
||||
message (STATUS "Stripping shared library after build!")
|
||||
add_custom_command (TARGET iwasm_shared POST_BUILD
|
||||
COMMAND ${CMAKE_STRIP} ${CMAKE_STRIP_FLAGS} $<TARGET_FILE:iwasm_shared>
|
||||
)
|
||||
endif ()
|
||||
|
|
Loading…
Reference in New Issue
Block a user