| 1 | Arrange so that onnx-optimizer uses our own ONNX build, and links against the
|
| 2 | shared libraries of ONNX.
|
| 3 |
|
| 4 | diff --git a/CMakeLists.txt b/CMakeLists.txt
|
| 5 | index 00633856..76a73853 100644
|
| 6 | |
| 7 | |
| 8 | @@ -27,8 +27,6 @@ if(NOT ONNX_OPT_USE_SYSTEM_PROTOBUF)
|
| 9 | endif()
|
| 10 |
|
| 11 |
|
| 12 | -set(ONNX_ROOT ${PROJECT_SOURCE_DIR}/third_party/onnx)
|
| 13 | -add_subdirectory_if_no_target(${ONNX_ROOT} ${ONNX_TARGET_NAME})
|
| 14 |
|
| 15 | file(READ "${PROJECT_SOURCE_DIR}/VERSION_NUMBER" ONNX_OPTIMIZER_VERSION)
|
| 16 | string(STRIP "${ONNX_OPTIMIZER_VERSION}" ONNX_OPTIMIZER_VERSION)
|
| 17 | @@ -41,14 +39,14 @@ file(GLOB onnx_opt_srcs "onnxoptimizer/*.cc"
|
| 18 | list(REMOVE_ITEM onnx_opt_srcs "${PROJECT_SOURCE_DIR}/onnxoptimizer/cpp2py_export.cc")
|
| 19 |
|
| 20 | onnxopt_add_library(onnx_optimizer ${onnx_opt_srcs})
|
| 21 | -target_link_libraries(onnx_optimizer PUBLIC ${ONNX_TARGET_NAME})
|
| 22 | +target_link_libraries(onnx_optimizer PUBLIC ${ONNX_TARGET_NAME} onnx_proto)
|
| 23 | target_include_directories(onnx_optimizer PUBLIC
|
| 24 | $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
|
| 25 | $<INSTALL_INTERFACE:include>
|
| 26 | )
|
| 27 |
|
| 28 | onnxopt_add_executable(onnx_optimizer_exec examples/onnx_optimizer_exec.cpp)
|
| 29 | -target_link_libraries(onnx_optimizer_exec onnx_optimizer)
|
| 30 | +target_link_libraries(onnx_optimizer_exec onnx_optimizer onnx_proto)
|
| 31 |
|
| 32 |
|
| 33 | file(GLOB onnx_opt_c_api_srcs "onnxoptimizer/c_api/*.cc"
|
| 34 | @@ -116,7 +114,8 @@ if(BUILD_ONNX_PYTHON)
|
| 35 | PRIVATE "-Wl,--whole-archive" $<TARGET_FILE:onnx_optimizer>
|
| 36 | "-Wl,--no-whole-archive")
|
| 37 | set_target_properties(onnx_opt_cpp2py_export
|
| 38 | - PROPERTIES LINK_FLAGS "-Wl,--exclude-libs,ALL")
|
| 39 | + PROPERTIES LINK_FLAGS "-Wl,--exclude-libs,ALL,-rpath=${CMAKE_INSTALL_PREFIX}/lib")
|
| 40 | +
|
| 41 | endif()
|
| 42 |
|
| 43 | target_link_libraries(onnx_opt_cpp2py_export PRIVATE onnx_optimizer)
|
| 44 | diff --git a/cmake/utils.cmake b/cmake/utils.cmake
|
| 45 | index 6cca9f36..8e39d5c4 100644
|
| 46 | |
| 47 | |
| 48 | @@ -1,4 +1,4 @@
|
| 49 | -include(${PROJECT_SOURCE_DIR}/third_party/onnx/cmake/Utils.cmake)
|
| 50 | +include(${ONNX_ROOT}/cmake/Utils.cmake)
|
| 51 |
|
| 52 | # Poor man's FetchContent
|
| 53 | function(add_subdirectory_if_no_target dir target)
|