message: Modulize ONNX libraries
diff: @@ -18,6 +18,16 @@ endif()
  add_subdirectory(third_party/pybind11)
  FIND_PACKAGE(Protobuf REQUIRED)
  +# Build the libraries with -fPIC
  +set(CMAKE_POSITION_INDEPENDENT_CODE ON)
  +
  +if(ONNX_NAMESPACE)
  + SET(MY_ONNX_NAMESPACE "-DONNX_NAMESPACE=${ONNX_NAMESPACE}")
  +else()
  + SET(MY_ONNX_NAMESPACE "-DONNX_NAMESPACE=onnx")
  +endif()
  +add_definitions(${MY_ONNX_NAMESPACE})
  +
  # function(RELATIVE_PROTOBUF_GENERATE_CPP SRCS HDRS ROOT_DIR)
  # from https://github.com/tensorflow/tensorflow/blob/d2c3b873c6f8ff999a2e4ee707a84ff00d9c15a5/tensorflow/contrib/cmake/tf_core_framework.cmake
  # to solve the problem that customized dir can't be specified when calling PROTOBUF_GENERATE_CPP.
  @@ -76,6 +86,7 @@ file(GLOB_RECURSE onnx_src
  "${ONNX_ROOT}/onnx/*.h"
  "${ONNX_ROOT}/onnx/*.cc"
  )
  +list(REMOVE_ITEM onnx_src "${ONNX_ROOT}/onnx/cpp2py_export.cc")
  if(MSVC)
  set(DLLEXPORT_OPTION "-DONNX_API=__declspec(dllexport)")
  @@ -87,20 +98,31 @@ add_library(onnx_proto ${PROTO_SRCS} ${PROTO_HDRS})
  target_include_directories(onnx_proto PUBLIC "${CMAKE_CURRENT_BINARY_DIR}" "${PROTOBUF_INCLUDE_DIRS}")
  target_link_libraries(onnx_proto PUBLIC ${PROTOBUF_LIBRARIES})
  -
  if(MSVC)
  target_compile_options(onnx_proto PRIVATE /WX- ${DLLEXPORT_OPTION})
  endif()
  add_library(onnx ${onnx_src})
  -target_include_directories(onnx PUBLIC ${ONNX_ROOT} "${CMAKE_CURRENT_BINARY_DIR}" "${PYBIND11_INCLUDE_DIR}" "${PYTHON_INCLUDE_DIRS}")
  +target_include_directories(onnx PUBLIC ${ONNX_ROOT} "${CMAKE_CURRENT_BINARY_DIR}")
  target_link_libraries(onnx PUBLIC onnx_proto)
  +add_library(onnx_pybind "${ONNX_ROOT}/onnx/cpp2py_export.cc")
  +target_include_directories(onnx_pybind PUBLIC "${CMAKE_CURRENT_BINARY_DIR}" "${PROTOBUF_INCLUDE_DIRS}" "${PYBIND11_INCLUDE_DIR}" "${PYTHON_INCLUDE_DIRS}")
  +target_link_libraries(onnx_pybind PUBLIC onnx_proto onnx)
  +
  +# Export include directories
  +set(ONNX_INCLUDE_DIRS "${ONNX_ROOT}" "${CMAKE_CURRENT_BINARY_DIR}")
  +set(ONNX_INCLUDE_DIRS ${ONNX_INCLUDE_DIRS} PARENT_SCOPE)
  +
  if (WIN32)
  target_compile_options(onnx PRIVATE
  /wd4800 # disable warning type' : forcing value to bool 'true' or 'false' (performance warning)
  /wd4503 # identifier' : decorated name length exceeded, name was truncated
  )
  + target_compile_options(onnx_pybind PRIVATE
  + /wd4800 # disable warning type' : forcing value to bool 'true' or 'false' (performance warning)
  + /wd4503 # identifier' : decorated name length exceeded, name was truncated
  + )
  set(onnx_static_library_flags
  -IGNORE:4221 # LNK4221: This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library
  )
  