@@ -67,94 +67,10 @@ target_include_directories(onnx_optimizer_c_api PUBLIC
6767 )
6868
6969if (ONNX_BUILD_PYTHON)
70- if ("${PY_EXT_SUFFIX} " STREQUAL "" )
71- if (MSVC )
72- set (PY_EXT_SUFFIX ".pyd" )
73- else ()
74- set (PY_EXT_SUFFIX ".so" )
75- endif ()
76- endif ()
77- find_package (Python COMPONENTS Interpreter REQUIRED )
78-
79- onnxopt_add_library (onnx_opt_cpp2py_export MODULE "onnxoptimizer/cpp2py_export.cc" )
80- set_target_properties (onnx_opt_cpp2py_export PROPERTIES PREFIX "" )
81- set_target_properties (onnx_opt_cpp2py_export
82- PROPERTIES COMPILE_FLAGS "-fvisibility=hidden" )
83- set_target_properties (onnx_opt_cpp2py_export PROPERTIES SUFFIX ${PY_EXT_SUFFIX} )
84- set_target_properties (onnx_opt_cpp2py_export
85- PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} )
86- target_include_directories (onnx_opt_cpp2py_export PRIVATE
87- $<BUILD_INTERFACE :${ONNX_ROOT} >
88- $<INSTALL_INTERFACE :include >
89- ${Python_INCLUDE_DIR} )
90- # pybind11 is a header only lib
91- find_package (pybind11 2.2 )
92- if (pybind11_FOUND)
93- target_include_directories (onnx_opt_cpp2py_export PUBLIC
94- ${pybind11_INCLUDE_DIRS} )
95- else ()
96- if (EXISTS ${ONNX_ROOT} /third_party/pybind11/include/pybind11/pybind11.h)
97- target_include_directories (onnx_opt_cpp2py_export PUBLIC
98- ${ONNX_ROOT} /third_party/pybind11/include )
99- else ()
100- message (FATAL_ERROR "cannot find pybind" )
101- endif ()
102- endif ()
103-
104- if (APPLE )
105- set_target_properties (onnx_opt_cpp2py_export
106- PROPERTIES LINK_FLAGS "-undefined dynamic_lookup" )
107- target_link_libraries (onnx_opt_cpp2py_export
108- PRIVATE -Wl,-force_load,$<TARGET_FILE:onnx_optimizer> )
109- elseif (MSVC )
110- # In MSVC, we will add whole archive in default
111- target_link_libraries (onnx_opt_cpp2py_export
112- PRIVATE -WHOLEARCHIVE:$<TARGET_FILE:onnx_optimizer> )
113- elseif (CMAKE_SYSTEM_NAME STREQUAL "AIX" )
114- # whole-archive linker option not available on AIX
115- target_sources (onnx_opt_cpp2py_export
116- PRIVATE $<TARGET_OBJECTS :onnx_optimizer >)
117- else ()
118- # Assume everything else is like gcc
119- target_link_libraries (onnx_opt_cpp2py_export
120- PRIVATE "-Wl,--whole-archive" $<TARGET_FILE :onnx_optimizer >
121- "-Wl,--no-whole-archive" )
122- set_target_properties (onnx_opt_cpp2py_export
123- PROPERTIES LINK_FLAGS "-Wl,--exclude-libs,ALL" )
124- endif ()
125-
70+ find_package (Python3 REQUIRED COMPONENTS Interpreter Development.Module )
71+ find_package (pybind11 )
72+ pybind11_add_module (onnx_opt_cpp2py_export "onnxoptimizer/cpp2py_export.cc" )
12673 target_link_libraries (onnx_opt_cpp2py_export PRIVATE onnx_optimizer )
127-
128- if (MSVC )
129- find_package (Python COMPONENTS Interpreter Development REQUIRED )
130- target_link_libraries (onnx_opt_cpp2py_export PRIVATE ${Python_LIBRARIES} )
131- target_compile_options (onnx_opt_cpp2py_export
132- PRIVATE /MP
133- /WX
134- /wd4800 # disable warning type' : forcing
135- # value to bool 'true' or 'false'
136- # (performance warning)
137- /wd4503 # identifier' : decorated name length
138- # exceeded, name was truncated
139- /wd4146 # unary minus operator applied to
140- # unsigned type, result still
141- # unsigned from include\google\protob
142- # uf\wire_format_lite.h
143- /wd4244 # 'argument': conversion from 'google::
144- # protobuf::uint64' to 'int', possible
145- # loss of data
146- /wd4267 # Conversion from 'size_t' to 'int',
147- # possible loss of data
148- /wd4996 # The second parameter is ignored.
149- ${EXTRA_FLAGS} )
150- if (ONNX_USE_PROTOBUF_SHARED_LIBS)
151- target_compile_options (onnx_opt_cpp2py_export
152- PRIVATE /wd4251 # 'identifier' : class 'type1' needs to
153- # have dll-interface to be used by
154- # clients of class 'type2'
155- )
156- endif ()
157- endif ()
15874endif ()
15975
16076include (GNUInstallDirs )
0 commit comments