Skip to content

Commit b38a2e8

Browse files
authored
Fix building iwasm_shared and iwasm_static libs on win32 (#3762)
Fixes to enable building iwasm_shared and iwasm_static libraries on win32.
1 parent 6f97822 commit b38a2e8

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

CMakeLists.txt

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,14 @@ set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
121121

122122
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
123123

124-
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wshadow -Wno-unused-parameter -fvisibility=hidden")
125-
# set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wsign-conversion")
126-
127-
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wno-unused")
124+
if (NOT WIN32)
125+
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security \
126+
-ffunction-sections -fdata-sections \
127+
-Wno-unused-parameter -Wno-pedantic")
128+
# Remove the extra spaces for better make log
129+
string (REGEX REPLACE " *" " " CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
130+
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wno-unused")
131+
endif()
128132

129133
if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
130134
if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
@@ -145,6 +149,10 @@ include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
145149
set (THREADS_PREFER_PTHREAD_FLAG ON)
146150
find_package(Threads REQUIRED)
147151

152+
if (MSVC)
153+
add_definitions(-DCOMPILING_WASM_RUNTIME_API=1)
154+
endif ()
155+
148156
# STATIC LIBRARY
149157
if (WAMR_BUILD_STATIC)
150158
add_library(iwasm_static STATIC ${WAMR_RUNTIME_LIB_SOURCE})
@@ -155,6 +163,14 @@ if (WAMR_BUILD_STATIC)
155163
target_link_libraries(iwasm_static INTERFACE boringssl_crypto)
156164
endif ()
157165

166+
if (MINGW)
167+
target_link_libraries (iwasm_static PRIVATE ws2_32)
168+
endif ()
169+
170+
if (WIN32)
171+
target_link_libraries(iwasm_static PRIVATE ntdll)
172+
endif()
173+
158174
install (TARGETS iwasm_static ARCHIVE DESTINATION lib)
159175
endif ()
160176

@@ -169,9 +185,14 @@ if (WAMR_BUILD_SHARED)
169185
endif ()
170186

171187
if (MINGW)
172-
target_link_libraries (iwasm_shared INTERFACE -lWs2_32 -lwsock32)
188+
target_link_libraries(iwasm_shared INTERFACE -lWs2_32 -lwsock32)
189+
target_link_libraries(iwasm_shared PRIVATE ws2_32)
173190
endif ()
174191

192+
if (WIN32)
193+
target_link_libraries(iwasm_shared PRIVATE ntdll)
194+
endif()
195+
175196
install (TARGETS iwasm_shared LIBRARY DESTINATION lib)
176197
endif ()
177198

0 commit comments

Comments
 (0)