@@ -397,8 +397,6 @@ relative_protobuf_generate_cpp(ONNX_PROTO_SRCS
397397 onnx/onnx-operators.in.proto
398398 onnx/onnx-data.in.proto)
399399
400- add_library (onnx_proto_object OBJECT ${ONNX_PROTO_SRCS} )
401-
402400file (GLOB_RECURSE __tmp_srcs "${ONNX_ROOT} /onnx/*.h" "${ONNX_ROOT} /onnx/*.cc" )
403401file (GLOB_RECURSE onnx_gtests_src "${ONNX_ROOT} /onnx/test/cpp/*.h"
404402 "${ONNX_ROOT} /onnx/test/cpp/*.cc"
@@ -414,57 +412,14 @@ if(ONNX_USE_LITE_PROTO)
414412 set (LINKED_PROTOBUF_TARGET protobuf::libprotobuf-lite)
415413 endif ()
416414endif ()
417- add_onnx_global_defines(onnx_proto_object)
418- target_include_directories (onnx_proto_object PUBLIC
419- $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR} >)
420- if (MSVC )
421- # For disabling Protobuf related warnings
422- set (protobuf_warnings
423- /wd4146 # unary minus operator applied to unsigned type,
424- # result still unsigned
425- /wd4244 # 'argument': conversion from 'google::
426- # protobuf::uint64' to 'int', possible
427- # loss of data
428- /wd4267 # Conversion from 'size_t' to 'int',
429- # possible loss of data
430- /wd4141 # 'inline': used more than once
431- )
432- endif ()
433- add_library (onnx_proto)
434- target_link_libraries (onnx_proto PUBLIC $<BUILD_INTERFACE:onnx_proto_object>)
435- if (ONNX_ML)
436- target_compile_definitions (onnx_proto PUBLIC ONNX_ML=1)
437- endif ()
438- target_compile_definitions (onnx_proto PUBLIC ONNX_NAMESPACE=${ONNX_NAMESPACE} )
439-
440- # onnx_object and onnx_proto_object are collections of C++ object files.
441- # They are introduced to help onnx_cpp2py_export bypass library boundaries and use ONNX private symbols.
442- add_library (onnx_object OBJECT ${ONNX_SRCS} )
443- add_dependencies (onnx_object onnx_proto_object)
444- target_include_directories (onnx_object PUBLIC
445- $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR} >)
446- set_target_properties (onnx_object PROPERTIES CXX_VISIBILITY_PRESET hidden)
447- set_target_properties (onnx_object PROPERTIES VISIBILITY_INLINES_HIDDEN ON )
448- target_include_directories (onnx_object PUBLIC $<BUILD_INTERFACE:${ONNX_ROOT} >)
449- add_onnx_global_defines(onnx_object)
450- target_link_libraries (onnx_proto_object PUBLIC ${LINKED_PROTOBUF_TARGET} )
451- target_link_libraries (onnx_object PUBLIC ${LINKED_PROTOBUF_TARGET} )
452- foreach (ABSL_USED_TARGET IN LISTS protobuf_ABSL_USED_TARGETS)
453- if (TARGET ${ABSL_USED_TARGET} )
454- target_link_libraries (onnx_proto_object PUBLIC ${ABSL_USED_TARGET} )
455- target_link_libraries (onnx_object PUBLIC ${ABSL_USED_TARGET} )
456- endif ()
457- endforeach ()
458- add_library (onnx)
459- target_link_libraries (onnx PUBLIC $<BUILD_INTERFACE:onnx_object> $<BUILD_INTERFACE:onnx_proto_object>)
460- target_include_directories (onnx PUBLIC $<INSTALL_INTERFACE:include >)
461- if (ONNX_ML)
462- target_compile_definitions (onnx PUBLIC ONNX_ML=1)
463- endif ()
464- target_compile_definitions (onnx PUBLIC ONNX_NAMESPACE=${ONNX_NAMESPACE} )
415+ add_library (onnx_proto ${ONNX_PROTO_SRCS} )
416+ add_onnx_global_defines(onnx_proto)
465417
466- target_compile_options (onnx_object PUBLIC ${protobuf_warnings} )
467- target_compile_options (onnx_proto_object PUBLIC ${protobuf_warnings} )
418+ add_library (onnx ${ONNX_SRCS} ${ONNX_PROTO_SRCS} )
419+ add_dependencies (onnx onnx_proto)
420+ set_target_properties (onnx PROPERTIES CXX_VISIBILITY_PRESET hidden)
421+ set_target_properties (onnx PROPERTIES VISIBILITY_INLINES_HIDDEN ON )
422+ add_onnx_global_defines(onnx)
468423
469424if (ONNX_BUILD_PYTHON)
470425 # find system nanobind
@@ -485,33 +440,15 @@ if(ONNX_BUILD_PYTHON)
485440 nanobind_add_module(
486441 onnx_cpp2py_export
487442 NB_STATIC NB_DOMAIN onnx STABLE_ABI FREE_THREADED LTO
488- "${ONNX_ROOT} /onnx/cpp2py_export.cc" )
489-
490- target_link_libraries (onnx_cpp2py_export PRIVATE $<BUILD_INTERFACE:onnx_object> $<BUILD_INTERFACE:onnx_proto_object>)
491- # Prevent "undefined symbol: _ZNSt10filesystem7__cxx114path14_M_split_cmptsEv"
492- # (std::filesystem::__cxx11::path::_M_split_cmpts()) on gcc 8
493- if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
494- target_link_libraries (onnx_cpp2py_export PRIVATE "-lstdc++fs" )
495- endif ()
443+ "${ONNX_ROOT} /onnx/cpp2py_export.cc" ${ONNX_SRCS} ${ONNX_PROTO_SRCS} )
444+ add_dependencies (onnx_cpp2py_export onnx)
496445endif ()
497446
498- if (MSVC )
499- add_msvc_runtime_flag(onnx_proto_object)
500- add_msvc_runtime_flag(onnx_object)
501- if (TARGET onnx_cpp2py_export)
502- add_msvc_runtime_flag(onnx_cpp2py_export)
503- endif ()
504- if (ONNX_WERROR)
505- target_compile_options (onnx_object PRIVATE "/WX" )
506- endif ()
507- else ()
508- target_compile_options (onnx_object PRIVATE -Wall -Wextra)
509- if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 13)
510- target_compile_options (onnx_object PRIVATE "-Wno-stringop-overflow" )
511- endif ()
512- if (ONNX_WERROR)
513- target_compile_options (onnx_object PRIVATE "-Werror" )
514- endif ()
447+ add_onnx_compile_options(onnx_proto)
448+ add_onnx_compile_options(onnx)
449+ if (TARGET onnx_cpp2py_export)
450+ add_onnx_global_defines(onnx_cpp2py_export)
451+ add_onnx_compile_options(onnx_cpp2py_export)
515452endif ()
516453if (ONNX_USE_ASAN AND NOT MSVC )
517454 find_package (Sanitizer REQUIRED)
0 commit comments