Skip to content

Commit

Permalink
fix mnn (#1667)
Browse files Browse the repository at this point in the history
* fix mnn

* fix msvc errors

* fix msvc errors
  • Loading branch information
waruqi authored Dec 1, 2022
1 parent 785c793 commit 3774c70
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions packages/m/mnn/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package("mnn")

add_urls("https://github.com/alibaba/MNN/archive/$(version).zip",
"https://github.com/alibaba/MNN.git")

add_versions("1.2.2", "78698b879f796a84d1aeb02f60ee38f6860dfdd03c27d1649aaaf9e0adfc8630")
add_versions("1.2.1", "485ae09558ff5626a63d1467ca81ebe0e17fbc60222c386d8f0e857f487c74d0")

Expand All @@ -26,31 +26,31 @@ package("mnn")

add_links("")

on_load("windows", "linux", "macosx", "android", function (package)
on_load("windows", "linux", "macosx", "android", function (package)
local mnn_path = package:installdir("include")
local mnn_lib_dir = string.sub(mnn_path, 1, string.len(mnn_path) - 7) .. "lib"
if package:config("shared") then
package:add("ldflags", "-L" .. mnn_lib_dir .. " -lmnn")
package:add("shflags", "-L" .. mnn_lib_dir .. " -lmnn")
else
if package:is_plat("linux", "android", "cross") then
package:add("shflags", " -Wl,--whole-archive " .. mnn_lib_dir .. "/libmnn.a -Wl,--no-whole-archive")
package:add("ldflags", " -Wl,--whole-archive " .. mnn_lib_dir .. "/libmnn.a -Wl,--no-whole-archive")
package:add("shflags", " -Wl,--whole-archive " .. mnn_lib_dir .. "/libMNN.a -Wl,--no-whole-archive")
package:add("ldflags", " -Wl,--whole-archive " .. mnn_lib_dir .. "/libMNN.a -Wl,--no-whole-archive")
elseif package:is_plat("macosx") then
package:add("ldflags", "-Wl,-force_load " .. mnn_lib_dir .. "/libmnn.a")
package:add("shflags", "-Wl,-force_load " .. mnn_lib_dir .. "/libmnn.a")
package:add("ldflags", "-Wl,-force_load " .. mnn_lib_dir .. "/libMNN.a")
package:add("shflags", "-Wl,-force_load " .. mnn_lib_dir .. "/libMNN.a")
elseif package:is_plat("windows") then
package:add("linkdirs", mnn_lib_dir)
package:add("shflags", "/WHOLEARCHIVE:mnn")
package:add("ldflags", "/WHOLEARCHIVE:mnn")
package:add("shflags", "/WHOLEARCHIVE:MNN")
package:add("ldflags", "/WHOLEARCHIVE:MNN")
end
end

if package:is_plat("windows") and package:config("shared") then
package:add("defines", "USING_MNN_DLL")
end

if package:is_plat("macosx", "iphoneos") then
if package:is_plat("macosx", "iphoneos") then
if package:config("MNN_OPENCL") then
package:add("frameworks", "OpenCL")
end
Expand All @@ -65,16 +65,16 @@ package("mnn")

on_install("windows", "linux", "macosx", "android", function (package)
local configs = {"-DMNN_BUILD_TEST=OFF",
"-DMNN_BUILD_DEMO=OFF",
"-DMNN_SUPPORT_TFLITE_QUAN=ON",
"-DMNN_PORTABLE_BUILD=OFF",
"-DMNN_SEP_BUILD=OFF"}
"-DMNN_BUILD_DEMO=OFF",
"-DMNN_SUPPORT_TFLITE_QUAN=ON",
"-DMNN_PORTABLE_BUILD=OFF",
"-DMNN_SEP_BUILD=OFF"}
table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
table.insert(configs, "-DMNN_BUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
table.insert(configs, "-DMNN_USE_SYSTEM_LIB=" .. (package:config("use_system_lib") and "ON" or "OFF"))
table.insert(configs, "-DMNN_USE_THREAD_POOL=" .. (package:config("thread_pool") and "ON" or "OFF"))
table.insert(configs, "-DMNN_OPENMP=" .. (package:config("openmp") and "ON" or "OFF"))
if package:config("thread_pool") and package:config("openmp") then
if package:config("thread_pool") and package:config("openmp") then
print("Warning: You are using mnn's thread pool, it will disable openmp!")
end
for _, name in ipairs({"metal", "opencl", "opengl", "vulkan", "arm82", "onednn", "avx512", "cuda", "tensorrt", "coreml"}) do
Expand All @@ -85,6 +85,12 @@ package("mnn")
end
if package:is_plat("windows") then
table.insert(configs, "-DMNN_WIN_RUNTIME_MT=" .. (package:config("vs_runtime") and "ON" or "OFF"))
io.replace("CMakeLists.txt",
'SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Zi")',
'SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")', {plain = true})
io.replace("CMakeLists.txt",
'SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi")',
'SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")', {plain = true})
end
if package:is_plat("android") then
table.insert(configs, "-DMNN_USE_SSE=OFF")
Expand Down

0 comments on commit 3774c70

Please sign in to comment.