Skip to content

Commit

Permalink
[onnx-optimizer] create a new port with 0.3.19
Browse files Browse the repository at this point in the history
  • Loading branch information
luncliff committed Oct 21, 2024
1 parent 476da81 commit ff99c47
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
36 changes: 36 additions & 0 deletions ports/onnx-optimizer/fix-cmakelists.patch
Original file line number Diff line number Diff line change
@@ -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 $<$<NOT:$<CONFIG:Debug>>:/MT> $<$<CONFIG:Debug>:/MTd>)
+ else()
+ target_compile_options(${lib} PRIVATE $<$<NOT:$<CONFIG:Debug>>:/MD> $<$<CONFIG:Debug>:/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)
32 changes: 32 additions & 0 deletions ports/onnx-optimizer/portfile.cmake
Original file line number Diff line number Diff line change
@@ -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")
18 changes: 18 additions & 0 deletions ports/onnx-optimizer/vcpkg.json
Original file line number Diff line number Diff line change
@@ -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
}
]
}

0 comments on commit ff99c47

Please sign in to comment.