@@ -9,37 +9,34 @@ set(CMAKE_CXX_STANDARD_REQUIRED YES)
99set (CMAKE_CXX_EXTENSIONS NO )
1010set (CMAKE_POSITION_INDEPENDENT_CODE ON )
1111
12- find_package (Protobuf )
12+ find_package (Protobuf CONFIG )
1313if (NOT Protobuf_FOUND)
1414 message (WARNING "Could NOT find Protobuf" )
1515 return ()
1616endif ()
1717
18+ find_package (ONNX CONFIG )
19+ if (NOT ONNX_FOUND)
20+ message (WARNING "Could NOT find ONNX package config" )
21+ return ()
22+ endif ()
23+
1824find_package (Halide REQUIRED )
1925
20- # Download onnx.proto
21- include (FetchContent )
22- FetchContent_Declare (
23- onnx
24- GIT_REPOSITORY https://github.com/onnx/onnx.git
25- GIT_TAG e709452ef2bbc1d113faf678c24e6d3467696e83 # v1.18.0
26- SOURCE_SUBDIR do-not-load/
27- )
28- FetchContent_MakeAvailable (onnx)
26+ find_path (ONNX_INCLUDE_DIR onnx/onnx_pb.h )
27+ if (NOT ONNX_INCLUDE_DIR)
28+ message (WARNING "Could NOT find ONNX headers" )
29+ return ()
30+ endif ()
31+ set (ONNX_PROTO_FILE "${ONNX_INCLUDE_DIR} /onnx/onnx-ml.proto" )
2932
3033# Add library that converts ONNX models to Halide operators
3134add_library (oclib STATIC )
3235add_library (onnx_app::oclib ALIAS oclib )
3336
34- target_sources (oclib PRIVATE onnx_converter.cc "${onnx_SOURCE_DIR} /onnx/onnx.proto" )
35- protobuf_generate (
36- TARGET oclib
37- LANGUAGE cpp
38- PROTOC_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR} /_protoc_out
39- IMPORT_DIRS ${onnx_SOURCE_DIR}
40- )
41- target_include_directories (oclib PUBLIC "${CMAKE_CURRENT_BINARY_DIR} /_protoc_out" )
42- target_link_libraries (oclib PUBLIC Halide::Halide protobuf::libprotobuf-lite )
37+ target_sources (oclib PRIVATE onnx_converter.cc )
38+ target_include_directories (oclib PUBLIC "${ONNX_INCLUDE_DIR} " )
39+ target_link_libraries (oclib PUBLIC Halide::Halide ONNX::onnx_proto )
4340target_compile_definitions (oclib PUBLIC GOOGLE_PROTOBUF_NO_RTTI )
4441
4542# Add test for the onnx converter library (oclib)
@@ -68,11 +65,11 @@ add_custom_command(
6865 COMMAND
6966 protobuf::protoc
7067 --encode=onnx.ModelProto
71- "--proto_path=${onnx_SOURCE_DIR } "
72- "$<SHELL_PATH :${onnx_SOURCE_DIR} / onnx / onnx . proto >"
68+ "--proto_path=${ONNX_INCLUDE_DIR } "
69+ "$<SHELL_PATH :${ONNX_PROTO_FILE} >"
7370 < "$<SHELL_PATH :${CMAKE_CURRENT_SOURCE_DIR} /test_model_proto .txt >"
7471 > test_model.onnx
75- DEPENDS protobuf::protoc ${onnx_SOURCE_DIR} /onnx/onnx.proto
72+ DEPENDS protobuf::protoc ${ONNX_PROTO_FILE}
7673 COMMENT "Generating test ONNX model from proto content"
7774 MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR} /test_model_proto.txt
7875 VERBATIM
@@ -102,7 +99,7 @@ set_tests_properties(
10299)
103100
104101# Python bindings to convert onnx models to Halide model
105- find_package (Python 3 COMPONENTS Interpreter Development )
102+ find_package (Python 3 COMPONENTS Interpreter Development.Module )
106103if (NOT Python_FOUND)
107104 message (WARNING "Could NOT find Python" )
108105 return ()
0 commit comments