|
3 | 3 |
|
4 | 4 | cmake_minimum_required (VERSION 3.0)
|
5 | 5 |
|
| 6 | +option(BUILD_SHARED_LIBS "Build using shared libraries" OFF) |
| 7 | + |
6 | 8 | if(ESP_PLATFORM)
|
7 | 9 | include (${COMPONENT_DIR}/build-scripts/esp-idf/wamr/CMakeLists.txt)
|
8 | 10 | return()
|
9 | 11 | endif()
|
10 | 12 |
|
11 |
| -project (iwasm) |
| 13 | +project (iwasm LANGUAGES C) |
| 14 | + |
| 15 | +set(CMAKE_CXX_STANDARD 17) |
12 | 16 |
|
13 | 17 | set (CMAKE_VERBOSE_MAKEFILE OFF)
|
14 | 18 |
|
15 | 19 | if (NOT DEFINED WAMR_BUILD_PLATFORM)
|
16 | 20 | string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM)
|
17 | 21 | endif ()
|
18 | 22 |
|
19 |
| -if (NOT DEFINED WAMR_BUILD_STATIC) |
20 |
| - set (WAMR_BUILD_STATIC 1) |
21 |
| -endif () |
22 |
| -if (NOT DEFINED WAMR_BUILD_SHARED) |
23 |
| - set (WAMR_BUILD_SHARED 1) |
24 |
| -endif () |
25 |
| - |
26 | 23 | # Reset default linker flags
|
27 | 24 | set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
|
28 | 25 | set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
|
@@ -113,8 +110,8 @@ if (NOT DEFINED WAMR_BUILD_SIMD)
|
113 | 110 | endif ()
|
114 | 111 |
|
115 | 112 | if (NOT DEFINED WAMR_BUILD_REF_TYPES)
|
116 |
| - # Disable reference types by default |
117 |
| - set (WAMR_BUILD_REF_TYPES 0) |
| 113 | + # Enable reference types by default |
| 114 | + set (WAMR_BUILD_REF_TYPES 1) |
118 | 115 | endif ()
|
119 | 116 |
|
120 | 117 | set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
@@ -154,52 +151,40 @@ if (MSVC)
|
154 | 151 | add_definitions(-DCOMPILING_WASM_RUNTIME_API=1)
|
155 | 152 | endif ()
|
156 | 153 |
|
157 |
| -# STATIC LIBRARY |
158 |
| -if (WAMR_BUILD_STATIC) |
159 |
| - add_library(iwasm_static STATIC ${WAMR_RUNTIME_LIB_SOURCE}) |
160 |
| - set_target_properties (iwasm_static PROPERTIES OUTPUT_NAME vmlib) |
161 |
| - target_include_directories(iwasm_static INTERFACE ${WAMR_ROOT_DIR}/core/iwasm/include) |
162 |
| - target_link_libraries (iwasm_static INTERFACE ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl ${CMAKE_THREAD_LIBS_INIT}) |
163 |
| - if (WAMR_BUILD_WASM_CACHE EQUAL 1) |
164 |
| - target_link_libraries(iwasm_static INTERFACE boringssl_crypto) |
165 |
| - endif () |
| 154 | +add_library (vmlib ${WAMR_RUNTIME_LIB_SOURCE}) |
| 155 | +set_target_properties (vmlib PROPERTIES OUTPUT_NAME iwasm) |
| 156 | +target_include_directories(vmlib INTERFACE |
| 157 | + $<BUILD_INTERFACE:${WAMR_ROOT_DIR}/core/iwasm/include> |
| 158 | + $<INSTALL_INTERFACE:include/iwasm> |
| 159 | +) |
166 | 160 |
|
167 |
| - if (MINGW) |
168 |
| - target_link_libraries (iwasm_static PRIVATE ws2_32) |
169 |
| - endif () |
170 |
| - |
171 |
| - if (WIN32) |
172 |
| - target_link_libraries(iwasm_static PRIVATE ntdll) |
173 |
| - endif() |
| 161 | +target_link_libraries (vmlib PUBLIC ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl ${CMAKE_THREAD_LIBS_INIT}) |
| 162 | +if (WAMR_BUILD_WASM_CACHE EQUAL 1) |
| 163 | + target_link_libraries(vmlib INTERFACE boringssl_crypto) |
| 164 | +endif () |
174 | 165 |
|
175 |
| - install (TARGETS iwasm_static ARCHIVE DESTINATION lib) |
| 166 | +if (MINGW) |
| 167 | + target_link_libraries(vmlib INTERFACE -lWs2_32 -lwsock32) |
| 168 | + target_link_libraries(vmlib PRIVATE ws2_32) |
176 | 169 | endif ()
|
177 | 170 |
|
178 |
| -# SHARED LIBRARY |
179 |
| -if (WAMR_BUILD_SHARED) |
180 |
| - add_library (iwasm_shared SHARED ${WAMR_RUNTIME_LIB_SOURCE}) |
181 |
| - set_target_properties (iwasm_shared PROPERTIES OUTPUT_NAME iwasm) |
182 |
| - target_include_directories(iwasm_shared INTERFACE ${WAMR_ROOT_DIR}/core/iwasm/include) |
183 |
| - target_link_libraries (iwasm_shared INTERFACE ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl ${CMAKE_THREAD_LIBS_INIT}) |
184 |
| - if (WAMR_BUILD_WASM_CACHE EQUAL 1) |
185 |
| - target_link_libraries(iwasm_shared INTERFACE boringssl_crypto) |
186 |
| - endif () |
| 171 | +if (WIN32) |
| 172 | + target_link_libraries(vmlib PRIVATE ntdll) |
| 173 | +endif() |
187 | 174 |
|
188 |
| - if (MINGW) |
189 |
| - target_link_libraries(iwasm_shared INTERFACE -lWs2_32 -lwsock32) |
190 |
| - target_link_libraries(iwasm_shared PRIVATE ws2_32) |
191 |
| - endif () |
| 175 | +set (WAMR_PUBLIC_HEADERS |
| 176 | + ${WAMR_ROOT_DIR}/core/iwasm/include/wasm_c_api.h |
| 177 | + ${WAMR_ROOT_DIR}/core/iwasm/include/wasm_export.h |
| 178 | + ${WAMR_ROOT_DIR}/core/iwasm/include/lib_export.h |
| 179 | +) |
| 180 | +set_target_properties (vmlib PROPERTIES PUBLIC_HEADER "${WAMR_PUBLIC_HEADERS}") |
192 | 181 |
|
193 |
| - if (WIN32) |
194 |
| - target_link_libraries(iwasm_shared PRIVATE ntdll) |
195 |
| - endif() |
| 182 | +set_version_info (vmlib) |
196 | 183 |
|
197 |
| - install (TARGETS iwasm_shared LIBRARY DESTINATION lib) |
198 |
| -endif () |
| 184 | +install (TARGETS vmlib |
| 185 | + EXPORT iwasmTargets |
| 186 | + LIBRARY DESTINATION lib |
| 187 | + PUBLIC_HEADER DESTINATION include/iwasm |
| 188 | +) |
199 | 189 |
|
200 |
| -# HEADERS |
201 |
| -install (FILES |
202 |
| - ${WAMR_ROOT_DIR}/core/iwasm/include/wasm_c_api.h |
203 |
| - ${WAMR_ROOT_DIR}/core/iwasm/include/wasm_export.h |
204 |
| - ${WAMR_ROOT_DIR}/core/iwasm/include/lib_export.h |
205 |
| - DESTINATION include) |
| 190 | +install_iwasm_package () |
0 commit comments