diff --git a/ports/onnx-optimizer/fix-cmakelists.patch b/ports/onnx-optimizer/fix-cmakelists.patch new file mode 100644 index 00000000..860cd1de --- /dev/null +++ b/ports/onnx-optimizer/fix-cmakelists.patch @@ -0,0 +1,36 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 0063385..e9ad9ff 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -12,6 +12,13 @@ set(CMAKE_CXX_STANDARD 17) + + set(CMAKE_POSITION_INDEPENDENT_CODE ON) + ++function(add_msvc_runtime_flag lib) ++ if(${ONNX_USE_MSVC_STATIC_RUNTIME}) ++ target_compile_options(${lib} PRIVATE $<$>:/MT> $<$:/MTd>) ++ else() ++ target_compile_options(${lib} PRIVATE $<$>:/MD> $<$:/MDd>) ++ endif() ++endfunction() + include(cmake/utils.cmake) + + # For integration with onnxruntime_webassembly etc. +@@ -26,7 +33,7 @@ if(NOT ONNX_OPT_USE_SYSTEM_PROTOBUF) + add_subdirectory_if_no_target(${PROJECT_SOURCE_DIR}/third_party/protobuf/cmake libprotobuf) + endif() + +- ++find_package(ONNX CONFIG REQUIRED) # ONNX::onnx + set(ONNX_ROOT ${PROJECT_SOURCE_DIR}/third_party/onnx) + add_subdirectory_if_no_target(${ONNX_ROOT} ${ONNX_TARGET_NAME}) + +diff --git a/cmake/utils.cmake b/cmake/utils.cmake +index 6cca9f3..a735434 100644 +--- a/cmake/utils.cmake ++++ b/cmake/utils.cmake +@@ -1,4 +1,3 @@ +-include(${PROJECT_SOURCE_DIR}/third_party/onnx/cmake/Utils.cmake) + + # Poor man's FetchContent + function(add_subdirectory_if_no_target dir target) diff --git a/ports/onnx-optimizer/portfile.cmake b/ports/onnx-optimizer/portfile.cmake new file mode 100644 index 00000000..100cf851 --- /dev/null +++ b/ports/onnx-optimizer/portfile.cmake @@ -0,0 +1,32 @@ +vcpkg_check_linkage(ONLY_STATIC_LIBRARY) + +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO onnx/optimizer + REF "v${VERSION}" + SHA512 552d6fa261c3ce2db2e0938a5b5261676335bce9bd828b46a1e2631f3b362c748ae9a6cfe7d62072fc3774b3f506bc54aa5827b52241e6f48d78a08dea1d9316 + HEAD_REF master + PATCHES + fix-cmakelists.patch +) + +string(COMPARE EQUAL "${VCPKG_CRT_LINKAGE}" "static" USE_STATIC_RUNTIME) + +vcpkg_cmake_configure( + SOURCE_PATH "${SOURCE_PATH}" + OPTIONS + -DONNX_USE_MSVC_STATIC_RUNTIME=${USE_STATIC_RUNTIME} + -DONNX_OPT_USE_SYSTEM_PROTOBUF=ON + -DONNX_TARGET_NAME=ONNX::onnx + -DBUILD_ONNX_PYTHON=OFF +) +vcpkg_cmake_install() +vcpkg_copy_pdbs() +vcpkg_cmake_config_fixup(PACKAGE_NAME ONNXOptimizer CONFIG_PATH lib/cmake/ONNXOptimizer) + +file(REMOVE_RECURSE + "${CURRENT_PACKAGES_DIR}/debug/include" + "${CURRENT_PACKAGES_DIR}/debug/share" + "${CURRENT_PACKAGES_DIR}/include/onnxoptimizer/test" +) +vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE") diff --git a/ports/onnx-optimizer/vcpkg.json b/ports/onnx-optimizer/vcpkg.json new file mode 100644 index 00000000..bb3c674d --- /dev/null +++ b/ports/onnx-optimizer/vcpkg.json @@ -0,0 +1,18 @@ +{ + "name": "onnx-optimizer", + "version-semver": "0.3.19", + "description": "Actively maintained ONNX Optimizer", + "homepage": "https://github.com/onnx/optimizer", + "license": "Apache-2.0", + "dependencies": [ + "onnx", + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true + } + ] +}