aboutsummaryrefslogtreecommitdiff
Arrange so that onnx-optimizer uses our own ONNX build, and links against the
shared libraries of ONNX.

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 00633856..76a73853 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -27,8 +27,6 @@ if(NOT ONNX_OPT_USE_SYSTEM_PROTOBUF)
 endif()
 
 
-set(ONNX_ROOT ${PROJECT_SOURCE_DIR}/third_party/onnx)
-add_subdirectory_if_no_target(${ONNX_ROOT} ${ONNX_TARGET_NAME})
 
 file(READ "${PROJECT_SOURCE_DIR}/VERSION_NUMBER" ONNX_OPTIMIZER_VERSION)
 string(STRIP "${ONNX_OPTIMIZER_VERSION}" ONNX_OPTIMIZER_VERSION)
@@ -41,14 +39,14 @@ file(GLOB onnx_opt_srcs "onnxoptimizer/*.cc"
 list(REMOVE_ITEM onnx_opt_srcs "${PROJECT_SOURCE_DIR}/onnxoptimizer/cpp2py_export.cc")
 
 onnxopt_add_library(onnx_optimizer ${onnx_opt_srcs})
-target_link_libraries(onnx_optimizer PUBLIC ${ONNX_TARGET_NAME})
+target_link_libraries(onnx_optimizer PUBLIC ${ONNX_TARGET_NAME} onnx_proto)
 target_include_directories(onnx_optimizer PUBLIC
     $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
     $<INSTALL_INTERFACE:include>
     )
 
 onnxopt_add_executable(onnx_optimizer_exec examples/onnx_optimizer_exec.cpp)
-target_link_libraries(onnx_optimizer_exec onnx_optimizer)
+target_link_libraries(onnx_optimizer_exec onnx_optimizer onnx_proto)
 
 
 file(GLOB onnx_opt_c_api_srcs "onnxoptimizer/c_api/*.cc"
@@ -116,7 +114,8 @@ if(BUILD_ONNX_PYTHON)
                           PRIVATE "-Wl,--whole-archive" $<TARGET_FILE:onnx_optimizer>
                                   "-Wl,--no-whole-archive")
     set_target_properties(onnx_opt_cpp2py_export
-                          PROPERTIES LINK_FLAGS "-Wl,--exclude-libs,ALL")
+                          PROPERTIES LINK_FLAGS "-Wl,--exclude-libs,ALL,-rpath=${CMAKE_INSTALL_PREFIX}/lib")
+
   endif()
 
   target_link_libraries(onnx_opt_cpp2py_export PRIVATE onnx_optimizer)
diff --git a/cmake/utils.cmake b/cmake/utils.cmake
index 6cca9f36..8e39d5c4 100644
--- a/cmake/utils.cmake
+++ b/cmake/utils.cmake
@@ -1,4 +1,4 @@
-include(${PROJECT_SOURCE_DIR}/third_party/onnx/cmake/Utils.cmake)
+include(${ONNX_ROOT}/cmake/Utils.cmake)
 
 # Poor man's FetchContent
 function(add_subdirectory_if_no_target dir target)
' href='#n45'>45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
Upstream status: This patch was taken from leptonica upstream.

Backported to ghostscripts bundled leptonica.

From f04da7c816feb1d5f689c34f3d0e7e3621edf1f5 Mon Sep 17 00:00:00 2001
From: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date: Wed, 1 Feb 2023 19:35:43 +0100
Subject: [PATCH] Fix GNU/Hurd build

There is no PATH_MAX limitation on GNU/Hurd, and realpath() can be
safely be used with its second parameter set to NULL (as required by
posix since its version 2001).
---
 src/sarray1.c | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)

--- a/src/sarray1.c	2023-06-13 12:31:13.393672916 +0200
+++ a/src/sarray1.c	2023-06-13 12:34:13.574237149 +0200
@@ -1953,7 +1953,11 @@
 SARRAY *
 getFilenamesInDirectory(const char  *dirname)
 {
+#if _POSIX_VERSION >= 200112 || defined(__GLIBC__)
+char           *dir;
+#else
 char            dir[PATH_MAX + 1];
+#endif
 char           *realdir, *stat_path, *ignore;
 size_t          size;
 SARRAY         *safiles;
@@ -1976,17 +1980,28 @@
             * If the file or directory exists, realpath returns its path;
               else it returns NULL.
             * If the second arg to realpath is passed in, the canonical path
-              is returned there.  Use a buffer of sufficient size.  If the
-              second arg is NULL, the path is malloc'd and returned if the
-              file or directory exists.
-           We pass in a buffer for the second arg, and check that the canonical
-           directory path was made.  The existence of the directory is checked
-           later, after its actual path is returned by genPathname().  */
+              is returned there.  Use a buffer of sufficient size.
+              We pass in a buffer for the second arg, and check that the
+              canonical directory path was made.  The existence of the
+              directory is checked later, after its actual path is returned by
+              genPathname().
+              With GNU libc or Posix 2001, if the second arg is NULL, the path
+              is malloc'd and returned if the file or directory exists.
+           */
+#if _POSIX_VERSION >= 200112 || defined(__GLIBC__)
+    dir = realpath(dirname, NULL);
+    if (dir == NULL)
+        return (SARRAY *)ERROR_PTR("dir not made", __func__, NULL);
+#else
     dir[0] = '\0';  /* init empty in case realpath() fails to write it */
     ignore = realpath(dirname, dir);
     if (dir[0] == '\0')
         return (SARRAY *)ERROR_PTR("dir not made", procName, NULL);
+#endif
     realdir = genPathname(dir, NULL);
+#if _POSIX_VERSION >= 200112 || defined(__GLIBC__)
+    LEPT_FREE(dir);
+#endif
     if ((pdir = opendir(realdir)) == NULL) {
         LEPT_FREE(realdir);
         return (SARRAY *)ERROR_PTR("pdir not opened", procName, NULL);
@@ -1998,10 +2013,12 @@
         stat_ret = fstatat(dfd, pdirentry->d_name, &st, 0);
 #else
         size = strlen(realdir) + strlen(pdirentry->d_name) + 2;
+#if _POSIX_VERSION < 200112 && !defined(__GLIBC__)
         if (size > PATH_MAX) {
             L_ERROR("size = %zu too large; skipping\n", procName, size);
             continue;
         }
+#endif
         stat_path = (char *)LEPT_CALLOC(size, 1);
         snprintf(stat_path, size, "%s/%s", realdir, pdirentry->d_name);
         stat_ret = stat(stat_path, &st);