aboutsummaryrefslogtreecommitdiff
path: root/vcpkg/ports/mnn
diff options
context:
space:
mode:
authorEthan Morgan <ethan@gweithio.com>2026-02-14 16:44:06 +0000
committerEthan Morgan <ethan@gweithio.com>2026-02-14 16:44:06 +0000
commit54409423f767d8b1cf30cb7d0efca6b4ca138823 (patch)
treed915ac7828703ce4b963efdd9728a1777ba18c1e /vcpkg/ports/mnn
move to own git serverHEADmaster
Diffstat (limited to 'vcpkg/ports/mnn')
-rw-r--r--vcpkg/ports/mnn/fix-linux.patch44
-rw-r--r--vcpkg/ports/mnn/portfile.cmake124
-rw-r--r--vcpkg/ports/mnn/use-package-and-install.patch192
-rw-r--r--vcpkg/ports/mnn/vcpkg.json88
4 files changed, 448 insertions, 0 deletions
diff --git a/vcpkg/ports/mnn/fix-linux.patch b/vcpkg/ports/mnn/fix-linux.patch
new file mode 100644
index 0000000..af63ee5
--- /dev/null
+++ b/vcpkg/ports/mnn/fix-linux.patch
@@ -0,0 +1,44 @@
+diff --git a/source/backend/cpu/CPUFixedPoint.hpp b/source/backend/cpu/CPUFixedPoint.hpp
+index a5c44f9..fd2e979 100644
+--- a/source/backend/cpu/CPUFixedPoint.hpp
++++ b/source/backend/cpu/CPUFixedPoint.hpp
+@@ -17,7 +17,7 @@ limitations under the License.
+ #define CPUFixedPoint_HPP
+
+ #include <math.h>
+-#include <stdint.h>
++#include <cstdint>
+ #include <limits>
+ #include <stdexcept>
+ #include <algorithm>
+diff --git a/source/backend/opencl/schema/current/CLCache_generated.h b/source/backend/opencl/schema/current/CLCache_generated.h
+index 434a666..fc972b5 100644
+--- a/source/backend/opencl/schema/current/CLCache_generated.h
++++ b/source/backend/opencl/schema/current/CLCache_generated.h
+@@ -403,7 +403,7 @@ inline const flatbuffers::TypeTable *ShaderTypeTable() {
+ "buildInfo"
+ };
+ static const flatbuffers::TypeTable tt = {
+- flatbuffers::ST_TABLE, 3, type_codes, nullptr, nullptr, names
++ flatbuffers::ST_TABLE, 3, type_codes, nullptr, nullptr, nullptr, names
+ };
+ return &tt;
+ }
+@@ -420,7 +420,7 @@ inline const flatbuffers::TypeTable *AutotuningTypeTable() {
+ "localSize"
+ };
+ static const flatbuffers::TypeTable tt = {
+- flatbuffers::ST_TABLE, 3, type_codes, nullptr, nullptr, names
++ flatbuffers::ST_TABLE, 3, type_codes, nullptr, nullptr, nullptr, names
+ };
+ return &tt;
+ }
+@@ -439,7 +439,7 @@ inline const flatbuffers::TypeTable *CacheTypeTable() {
+ "tunings"
+ };
+ static const flatbuffers::TypeTable tt = {
+- flatbuffers::ST_TABLE, 2, type_codes, type_refs, nullptr, names
++ flatbuffers::ST_TABLE, 2, type_codes, type_refs, nullptr, nullptr, names
+ };
+ return &tt;
+ }
diff --git a/vcpkg/ports/mnn/portfile.cmake b/vcpkg/ports/mnn/portfile.cmake
new file mode 100644
index 0000000..816a7f8
--- /dev/null
+++ b/vcpkg/ports/mnn/portfile.cmake
@@ -0,0 +1,124 @@
+if(VCPKG_TARGET_IS_WINDOWS)
+ vcpkg_check_linkage(ONLY_STATIC_LIBRARY)
+endif()
+
+vcpkg_from_github(
+ OUT_SOURCE_PATH SOURCE_PATH
+ REPO alibaba/MNN
+ REF 1.1.0
+ SHA512 3e31eec9a876be571cb2d29e0a2bcdb8209a43a43a5eeae19b295fadfb1252dd5bd4ed5b7c584706171e1b531710248193bc04520a796963e2b21546acbedae0
+ HEAD_REF master
+ PATCHES
+ use-package-and-install.patch
+ fix-linux.patch
+)
+
+vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
+ FEATURES
+ test MNN_BUILD_TEST
+ test MNN_BUILD_BENCHMARK
+ cuda MNN_CUDA
+ vulkan MNN_VULKAN
+ opencl MNN_OPENCL
+ metal MNN_METAL
+ tools MNN_BUILD_TOOLS
+ tools MNN_BUILD_QUANTOOLS
+ tools MNN_BUILD_TRAIN
+ tools MNN_EVALUATION
+ tools MNN_BUILD_CONVERTER
+ gpu MNN_GPU_TRACE
+ system MNN_USE_SYSTEM_LIB
+)
+
+# 'cuda' feature in Windows failes with Ninja because of parallel PDB access. Make it optional
+set(NINJA_OPTION WINDOWS_USE_MSBUILD)
+if(NOT "cuda" IN_LIST FEATURES)
+ unset(NINJA_OPTION)
+endif()
+
+set(FLATC_EXEC "${CURRENT_HOST_INSTALLED_DIR}/tools/flatbuffers/flatc${VCPKG_HOST_EXECUTABLE_SUFFIX}")
+if (NOT EXISTS "${FLATC_EXEC}")
+ message(FATAL_ERROR "Expected ${FLATC_EXEC} to exist.")
+endif()
+
+# regenerate some code files by schemes and flatbuffers
+vcpkg_execute_build_process(
+ COMMAND "${FLATC_EXEC}" "-c" "-b" "--gen-object-api" "--reflect-names"
+ "../default/BasicOptimizer.fbs"
+ "../default/CaffeOp.fbs"
+ "../default/GpuLibrary.fbs"
+ "../default/MNN.fbs"
+ "../default/Tensor.fbs"
+ "../default/TensorflowOp.fbs"
+ "../default/TFQuantizeOp.fbs"
+ "../default/Type.fbs"
+ "../default/UserDefine.fbs"
+ WORKING_DIRECTORY "${SOURCE_PATH}/schema/current/"
+ LOGNAME flatc-${TARGET_TRIPLET}
+ )
+
+if(VCPKG_TARGET_IS_WINDOWS)
+ string(COMPARE EQUAL "${VCPKG_CRT_LINKAGE}" "static" USE_RUNTIME_MT)
+ list(APPEND PLATFORM_OPTIONS -DMNN_WIN_RUNTIME_MT=${USE_RUNTIME_MT})
+endif()
+
+string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "dynamic" BUILD_SHARED)
+
+vcpkg_cmake_configure(
+ SOURCE_PATH "${SOURCE_PATH}"
+ ${NINJA_OPTION}
+ OPTIONS
+ ${FEATURE_OPTIONS} ${PLATFORM_OPTIONS}
+ -DMNN_BUILD_SHARED_LIBS=${BUILD_SHARED}
+ # 1.1.0.0-${commit}
+ -DMNN_VERSION_MAJOR=1 -DMNN_VERSION_MINOR=1 -DMNN_VERSION_PATCH=0 -DMNN_VERSION_BUILD=0 -DMNN_VERSION_SUFFIX=-d6795ad
+ OPTIONS_DEBUG
+ -DMNN_DEBUG_MEMORY=ON -DMNN_DEBUG_TENSOR_SIZE=ON
+)
+vcpkg_cmake_install()
+vcpkg_copy_pdbs()
+
+vcpkg_download_distfile(COPYRIGHT_PATH
+ URLS "https://apache.org/licenses/LICENSE-2.0.txt"
+ FILENAME 98f6b79b778f7b0a1541.txt
+ SHA512 98f6b79b778f7b0a15415bd750c3a8a097d650511cb4ec8115188e115c47053fe700f578895c097051c9bc3dfb6197c2b13a15de203273e1a3218884f86e90e8
+)
+
+file(MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/share/${PORT}")
+file(INSTALL "${COPYRIGHT_PATH}" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)
+
+if(VCPKG_TARGET_IS_OSX OR VCPKG_TARGET_IS_IOS)
+ if("metal" IN_LIST FEATURES)
+ file(RENAME "${CURRENT_PACKAGES_DIR}/bin/mnn.metallib"
+ "${CURRENT_PACKAGES_DIR}/share/${PORT}/mnn.metallib")
+ endif()
+else()
+ file(MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/share/${PORT}")
+endif()
+
+file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
+if("test" IN_LIST FEATURES)
+ # no install(TARGETS) for the following binaries. check the buildtrees...
+ # vcpkg_copy_tools(
+ # TOOL_NAMES run_test.out benchmark.out benchmarkExprModels.out # test/
+ # AUTO_CLEAN
+ # )
+endif()
+if("tools" IN_LIST FEATURES)
+ vcpkg_copy_tools(
+ TOOL_NAMES MNNV2Basic.out mobilenetTest.out backendTest.out testModel.out testModelWithDescrisbe.out getPerformance.out checkInvalidValue.out timeProfile.out # tools/cpp
+ quantized.out # tools/quantization
+ classficationTopkEval.out # tools/evaluation
+ MNNDump2Json MNNConvert # tools/converter
+ transformer.out train.out dataTransformer.out runTrainDemo.out # tools/train
+ AUTO_CLEAN
+ )
+ if(BUILD_SHARED)
+ vcpkg_copy_tools(TOOL_NAMES TestConvertResult AUTO_CLEAN) # tools/converter
+ endif()
+endif()
+if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
+ # remove the others. ex) mnn.metallib
+ file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/bin
+ ${CURRENT_PACKAGES_DIR}/debug/bin)
+endif()
diff --git a/vcpkg/ports/mnn/use-package-and-install.patch b/vcpkg/ports/mnn/use-package-and-install.patch
new file mode 100644
index 0000000..be53291
--- /dev/null
+++ b/vcpkg/ports/mnn/use-package-and-install.patch
@@ -0,0 +1,192 @@
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -270,18 +270,24 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "^Linux")
+ include_directories(${aarch64_linux_include})
+ endif()
+ endif()
++
++if(MNN_OPENCL)
++ find_package(OpenCL REQUIRED)
++endif()
++find_package(RapidJSON CONFIG REQUIRED)
++find_path(STB_INCLUDE_DIRS stb_image.h)
++find_package(Flatbuffers CONFIG REQUIRED)
+ include_directories(${CMAKE_CURRENT_LIST_DIR}/include/
+ ${CMAKE_CURRENT_LIST_DIR}/source/
+ ${CMAKE_CURRENT_LIST_DIR}/express/
+ ${CMAKE_CURRENT_LIST_DIR}/tools/
+ ${CMAKE_CURRENT_LIST_DIR}/schema/current/
+- ${CMAKE_CURRENT_LIST_DIR}/3rd_party/
+- ${CMAKE_CURRENT_LIST_DIR}/3rd_party/flatbuffers/include
+ ${CMAKE_CURRENT_LIST_DIR}/3rd_party/half
+- ${CMAKE_CURRENT_LIST_DIR}/3rd_party/imageHelper
+- ${CMAKE_CURRENT_LIST_DIR}/3rd_party/OpenCLHeaders/
++ ${RAPIDJSON_INCLUDE_DIRS}
++ ${STB_INCLUDE_DIRS}
++ ${OpenCL_INCLUDE_DIRS}
+ )
+-
++link_libraries(flatbuffers::flatbuffers ${OpenCL_LIBRARIES})
+
+ set(MNN_OBJECTS_TO_LINK "")
+ set(MNN_TARGETS "")
+@@ -631,10 +637,14 @@ ELSEIF(NOT APPLE)
+ INSTALL(FILES ${MNN_PUB_HDRS} DESTINATION include/MNN/)
+ INSTALL(FILES ${MNN_EXPR_PUB_HDRS} DESTINATION include/MNN/expr/)
+ install(TARGETS MNN
++ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib
+ ARCHIVE DESTINATION lib
+ )
++
+ ELSE()
++ INSTALL(FILES ${MNN_PUB_HDRS} DESTINATION include/MNN/)
++ INSTALL(FILES ${MNN_EXPR_PUB_HDRS} DESTINATION include/MNN/expr/)
+ install(TARGETS MNN
+ LIBRARY DESTINATION lib
+ ARCHIVE DESTINATION lib
+@@ -648,5 +658,6 @@ ELSE()
+ ENDFOREACH()
+ IF(MNN_METAL)
+ SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_BINARY_DIR}/mnn.metallib PROPERTIES MACOSX_PACKAGE_LOCATION Resources/)
++ INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/mnn.metallib DESTINATION bin)
+ ENDIF()
+ ENDIF()
+diff --git a/source/backend/cuda/CMakeLists.txt b/source/backend/cuda/CMakeLists.txt
+index f9a24cc..8b1f96f 100644
+--- a/source/backend/cuda/CMakeLists.txt
++++ b/source/backend/cuda/CMakeLists.txt
+@@ -16,9 +16,26 @@ endif()
+ file(GLOB_RECURSE MNN_CUDA_SRC ${CMAKE_CURRENT_LIST_DIR}/core/* ${CMAKE_CURRENT_SOURCE_DIR}/execution/*)
+ message(STATUS "message ${CUDA_NVCC_FLAGS} !!!!!!!!!!!")
+
++# see https://github.com/microsoft/vcpkg/blob/master/ports/cudnn/FindCUDNN.cmake
++find_package(CUDNN REQUIRED)
++message(STATUS "using cudnn: ${CUDNN_LIBRARIES}")
++
++if(WIN32)
++ find_library(CUBLAS_LIB NAMES cublas PATHS $ENV{CUDA_PATH}/lib/x64)
++else()
++ find_library(CUBLAS_LIB cublas)
++endif()
++if(NOT CUBLAS_LIB)
++ message(FATAL_ERROR "cublas not found")
++else()
++ message(STATUS "using cublas: ${CUBLAS_LIB}")
++endif()
++
+ # add_library(MNN_Cuda SHARED ${MNN_CUDA_SRC} )
+-cuda_add_library(MNN_Cuda_Main SHARED ${MNN_CUDA_SRC} )
+-set(MNN_CUDA_LIBS MNN_Cuda_Main cudnn cublas PARENT_SCOPE)
++cuda_add_library(MNN_Cuda_Main STATIC ${MNN_CUDA_SRC} )
++target_link_libraries(MNN_Cuda_Main CuDNN::CuDNN ${CUBLAS_LIB})
++
++set(MNN_CUDA_LIBS MNN_Cuda_Main ${CUDNN_LIB} PARENT_SCOPE)
+ add_library(MNN_CUDA OBJECT Register.cpp)
+
+ include_directories(
+diff --git a/source/backend/tensorrt/CMakeLists.txt b/source/backend/tensorrt/CMakeLists.txt
+index aadabd6..3a0d81e 100644
+--- a/source/backend/tensorrt/CMakeLists.txt
++++ b/source/backend/tensorrt/CMakeLists.txt
+@@ -7,7 +7,7 @@ FIND_PACKAGE(CUDA REQUIRED)
+
+ add_library( MNN_TRT OBJECT ${MNN_TRT_SRCS})
+
+-include_directories(/usr/local/cuda/include/)
++include_directories(${CUDA_INCLUDE_DIRS})
+ include_directories(${CMAKE_CURRENT_LIST_DIR}/backend/)
+ include_directories(${CMAKE_CURRENT_LIST_DIR}/execution/)
+ include_directories(${CMAKE_CURRENT_LIST_DIR}/execution/plugin/)
+diff --git a/tools/converter/CMakeLists.txt b/tools/converter/CMakeLists.txt
+index 2d5133a..d39977a 100644
+--- a/tools/converter/CMakeLists.txt
++++ b/tools/converter/CMakeLists.txt
+@@ -38,11 +38,12 @@ IF(MNN_BUILD_CONVERTER)
+ ${CMAKE_CURRENT_LIST_DIR}/source/cli.cpp
+ ${CMAKE_CURRENT_LIST_DIR}/source/config.cpp
+ )
+- IF(MNN_BUILD_SHARED_LIBS)
+- add_library(MNNConvertDeps SHARED ${COMMON_SRC} ${MNN_CONVERTER_BACKENDS_OBJECTS} ${CMAKE_CURRENT_LIST_DIR}/../../3rd_party/flatbuffers/src/util.cpp $<TARGET_OBJECTS:MNNUtils>)
++ # if Windows, meld MNNConvertDeps(lib) into MNNConvert(exe)
++ IF(MNN_BUILD_SHARED_LIBS AND NOT WIN32)
++ add_library(MNNConvertDeps SHARED ${COMMON_SRC} ${MNN_CONVERTER_BACKENDS_OBJECTS} $<TARGET_OBJECTS:MNNUtils>)
+ add_dependencies(MNNConvertDeps MNN)
+ ELSE()
+- add_library(MNNConvertDeps STATIC ${COMMON_SRC} ${MNN_CONVERTER_BACKENDS_OBJECTS} ${CMAKE_CURRENT_LIST_DIR}/../../3rd_party/flatbuffers/src/util.cpp)
++ add_library(MNNConvertDeps STATIC ${COMMON_SRC} ${MNN_CONVERTER_BACKENDS_OBJECTS})
+ ENDIF()
+
+
+@@ -68,5 +69,7 @@ IF(MNN_BUILD_CONVERTER)
+ add_executable(TestConvertResult ${CMAKE_CURRENT_LIST_DIR}/source/TestConvertResult.cpp)
+ target_link_libraries(TestConvertResult MNNConvertDeps)
+ target_link_libraries(MNNConvert MNNConvertDeps)
++ install(TARGETS TestConvertResult RUNTIME DESTINATION bin)
+ ENDIF()
++ install(TARGETS MNNDump2Json MNNConvert RUNTIME DESTINATION bin)
+ ENDIF()
+diff --git a/tools/cpp/CMakeLists.txt b/tools/cpp/CMakeLists.txt
+index def574c..f4e48c6 100644
+--- a/tools/cpp/CMakeLists.txt
++++ b/tools/cpp/CMakeLists.txt
+@@ -53,3 +53,5 @@ if (MSVC)
+ endif()
+ endforeach()
+ endif()
++
++install(TARGETS ${MNN_CPP_TOOLS} RUNTIME DESTINATION bin)
+diff --git a/tools/evaluation/CMakeLists.txt b/tools/evaluation/CMakeLists.txt
+index 8773372..e40b66d 100644
+--- a/tools/evaluation/CMakeLists.txt
++++ b/tools/evaluation/CMakeLists.txt
+@@ -7,4 +7,5 @@ IF(MNN_EVALUATION)
+ target_link_options(classficationTopkEval.out PRIVATE /WHOLEARCHIVE:$<TARGET_FILE:${DEPEND}>)
+ endforeach ()
+ endif()
++ install(TARGETS classficationTopkEval.out RUNTIME DESTINATION bin)
+ ENDIF()
+diff --git a/tools/quantization/CMakeLists.txt b/tools/quantization/CMakeLists.txt
+index 1e84ee0..86f3cbc 100644
+--- a/tools/quantization/CMakeLists.txt
++++ b/tools/quantization/CMakeLists.txt
+@@ -1,3 +1,5 @@
+ file(GLOB QUANFILES ${CMAKE_CURRENT_LIST_DIR}/*.cpp)
+ add_executable(quantized.out ${QUANFILES})
+ target_link_libraries(quantized.out ${MNN_DEPS})
++
++install(TARGETS quantized.out RUNTIME DESTINATION bin)
+diff --git a/tools/train/CMakeLists.txt b/tools/train/CMakeLists.txt
+index 48f355b..026dc24 100644
+--- a/tools/train/CMakeLists.txt
++++ b/tools/train/CMakeLists.txt
+@@ -27,6 +27,10 @@ if (MNN_BUILD_TRAIN_MINI)
+ else()
+ add_library(MNNTrain ${MNN_LIBARY_TYPE} ${GRAD} ${BASIC_INCLUDE} ${OPTIMIZER} ${DATALOADER} ${TRANSFORMER} ${MODELS} ${DATASETS})
+ endif()
++IF(MNN_BUILD_SHARED_LIBS)
++ target_compile_definitions(MNNTrain PRIVATE BUILDING_MNN_DLL)
++ENDIF()
++
+ target_link_libraries(MNNTrain ${MNN_DEPS})
+
+ add_executable(transformer.out ${CMAKE_CURRENT_LIST_DIR}/source/exec/transformerExecution.cpp)
+@@ -38,7 +42,7 @@ target_link_libraries(train.out MNN)
+
+ add_executable(rawDataTransform.out ${CMAKE_CURRENT_LIST_DIR}/source/exec/rawDataTransform.cpp ${SCHEMA} ${BASIC_INCLUDE})
+
+-include_directories(../../3rd_party/imageHelper/)
++# include_directories(../../3rd_party/imageHelper/)
+ add_executable(dataTransformer.out ${CMAKE_CURRENT_LIST_DIR}/source/exec/dataTransformer.cpp ${SCHEMA} ${BASIC_INCLUDE})
+ target_link_libraries(dataTransformer.out MNN)
+
+@@ -59,3 +63,9 @@ if (MNN_USE_OPENCV)
+ add_definitions(-D MNN_USE_OPENCV)
+ target_link_libraries(runTrainDemo.out ${OpenCV_LIBS})
+ endif()
++
++install(TARGETS MNNTrain transformer.out train.out dataTransformer.out runTrainDemo.out
++ RUNTIME DESTINATION bin
++ LIBRARY DESTINATION lib
++ ARCHIVE DESTINATION lib
++)
diff --git a/vcpkg/ports/mnn/vcpkg.json b/vcpkg/ports/mnn/vcpkg.json
new file mode 100644
index 0000000..e2e528f
--- /dev/null
+++ b/vcpkg/ports/mnn/vcpkg.json
@@ -0,0 +1,88 @@
+{
+ "name": "mnn",
+ "version": "1.1.0",
+ "port-version": 7,
+ "description": "MNN is a blazing fast, lightweight deep learning framework, battle-tested by business-critical use cases in Alibaba",
+ "homepage": "https://www.mnn.zone/",
+ "license": "Apache-2.0",
+ "supports": "!(arm | uwp | ios | android)",
+ "dependencies": [
+ "flatbuffers",
+ {
+ "name": "flatbuffers",
+ "host": true
+ },
+ "rapidjson",
+ "stb",
+ {
+ "name": "vcpkg-cmake",
+ "host": true
+ }
+ ],
+ "features": {
+ "cuda": {
+ "description": "Enable CUDA API backend",
+ "dependencies": [
+ "cuda",
+ "cudnn",
+ {
+ "name": "mnn",
+ "features": [
+ "gpu"
+ ]
+ }
+ ]
+ },
+ "gpu": {
+ "description": "Enable MNN Gpu Debug"
+ },
+ "metal": {
+ "description": "Enable Metal API backend for Apple platforms",
+ "dependencies": [
+ {
+ "name": "mnn",
+ "features": [
+ "gpu"
+ ]
+ }
+ ]
+ },
+ "opencl": {
+ "description": "Enable OpenCL API backend",
+ "dependencies": [
+ {
+ "name": "mnn",
+ "features": [
+ "system"
+ ]
+ },
+ "opencl"
+ ]
+ },
+ "system": {
+ "description": "For opencl and vulkan, use system lib or use dlopen"
+ },
+ "test": {
+ "description": "Build MNN test programs"
+ },
+ "tools": {
+ "description": "Build MNN tools",
+ "dependencies": [
+ "protobuf"
+ ]
+ },
+ "vulkan": {
+ "description": "Enable Vulkan API backend",
+ "dependencies": [
+ {
+ "name": "mnn",
+ "features": [
+ "gpu",
+ "system"
+ ]
+ },
+ "vulkan"
+ ]
+ }
+ }
+}