Skip to content

Commit c4734c6

Browse files
bddppqhouseroad
authored andcommitted
[cmake] Allow adding extra source files to the onnx lib (#1439)
* [cmake] Allow adding extra source files to the onnx lib By setting ONNX_SRCS before including onnx's cmake files * fix
1 parent bf9dec2 commit c4734c6

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

CMakeLists.txt

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -243,29 +243,33 @@ function(RELATIVE_PROTOBUF_GENERATE_CPP NAME SRCS HDRS ROOT_DIR DEPEND)
243243
endfunction()
244244

245245
relative_protobuf_generate_cpp(gen_onnx_proto
246-
PROTO_SRCS
247-
PROTO_HDRS
246+
__tmp_srcs
247+
__tmp_hdrs
248248
${ONNX_ROOT}
249249
""
250250
onnx/onnx.in.proto)
251+
list(APPEND ONNX_PROTO_SRCS ${__tmp_srcs})
252+
list(APPEND ONNX_PROTO_HDRS ${__tmp_hdrs})
253+
251254
relative_protobuf_generate_cpp(gen_onnx_operators_proto
252-
PROTO_SRCS2
253-
PROTO_HDRS2
255+
__tmp_srcs
256+
__tmp_hdrs
254257
${ONNX_ROOT}
255258
gen_onnx_proto
256259
onnx/onnx-operators.in.proto)
257-
list(APPEND PROTO_SRCS ${PROTO_SRCS2})
258-
list(APPEND PROTO_HDRS ${PROTO_HDRS2})
260+
list(APPEND ONNX_PROTO_SRCS ${__tmp_srcs})
261+
list(APPEND ONNX_PROTO_HDRS ${__tmp_hdrs})
259262

260-
file(GLOB_RECURSE onnx_src "${ONNX_ROOT}/onnx/*.h" "${ONNX_ROOT}/onnx/*.cc")
263+
file(GLOB_RECURSE __tmp_srcs "${ONNX_ROOT}/onnx/*.h" "${ONNX_ROOT}/onnx/*.cc")
261264
file(GLOB_RECURSE onnx_gtests_src "${ONNX_ROOT}/onnx/test/cpp/*.h"
262265
"${ONNX_ROOT}/onnx/test/cpp/*.cc"
263266
"${ONNX_ROOT}/onnx/backend/test/cpp/*.cc"
264267
"${ONNX_ROOT}/onnx/backend/test/cpp/*.h")
265-
list(REMOVE_ITEM onnx_src "${ONNX_ROOT}/onnx/cpp2py_export.cc")
266-
list(REMOVE_ITEM onnx_src ${onnx_gtests_src})
268+
list(REMOVE_ITEM __tmp_srcs "${ONNX_ROOT}/onnx/cpp2py_export.cc")
269+
list(REMOVE_ITEM __tmp_srcs ${onnx_gtests_src})
270+
list(APPEND ONNX_SRCS ${__tmp_srcs})
267271

268-
add_library(onnx_proto ${PROTO_SRCS} ${PROTO_HDRS})
272+
add_library(onnx_proto ${ONNX_PROTO_SRCS} ${ONNX_PROTO_HDRS})
269273
target_include_directories(onnx_proto PUBLIC
270274
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
271275
$<INSTALL_INTERFACE:include>
@@ -297,7 +301,7 @@ else()
297301
endif()
298302
add_onnx_global_defines(onnx_proto)
299303

300-
add_library(onnx ${onnx_src})
304+
add_library(onnx ${ONNX_SRCS})
301305
target_include_directories(onnx PUBLIC
302306
$<BUILD_INTERFACE:${ONNX_ROOT}>
303307
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>

0 commit comments

Comments
 (0)