Add cmake static/shared library build settings (#3443)

Allow builds to target either static library only, shared library only, or both (default).
This commit is contained in:
Benbuck Nason 2024-05-18 06:15:11 -07:00 committed by GitHub
parent ec44f494cc
commit 0ceffe74a7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -16,6 +16,13 @@ if (NOT DEFINED WAMR_BUILD_PLATFORM)
string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM)
endif ()
if (NOT DEFINED WAMR_BUILD_STATIC)
set (WAMR_BUILD_STATIC 1)
endif ()
if (NOT DEFINED WAMR_BUILD_SHARED)
set (WAMR_BUILD_SHARED 1)
endif ()
# Reset default linker flags
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
@ -136,6 +143,7 @@ endif ()
include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
# STATIC LIBRARY
if (WAMR_BUILD_STATIC)
add_library(iwasm_static STATIC ${WAMR_RUNTIME_LIB_SOURCE})
set_target_properties (iwasm_static PROPERTIES OUTPUT_NAME vmlib)
target_include_directories(iwasm_static INTERFACE ${WAMR_ROOT_DIR}/core/iwasm/include)
@ -145,8 +153,10 @@ if (WAMR_BUILD_WASM_CACHE EQUAL 1)
endif ()
install (TARGETS iwasm_static ARCHIVE DESTINATION lib)
endif ()
# SHARED LIBRARY
if (WAMR_BUILD_SHARED)
add_library (iwasm_shared SHARED ${WAMR_RUNTIME_LIB_SOURCE})
set_target_properties (iwasm_shared PROPERTIES OUTPUT_NAME iwasm)
target_include_directories(iwasm_shared INTERFACE ${WAMR_ROOT_DIR}/core/iwasm/include)
@ -160,6 +170,7 @@ if (MINGW)
endif ()
install (TARGETS iwasm_shared LIBRARY DESTINATION lib)
endif ()
# HEADERS
install (FILES