-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
79 lines (68 loc) · 2.39 KB
/
CMakeLists.txt
File metadata and controls
79 lines (68 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
cmake_minimum_required(VERSION 3.25)
project(onnxinfo CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(ABSL_PROPAGATE_CXX_STD ON)
set(protobuf_BUILD_TESTS OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${onnxinfo_SOURCE_DIR}/tests)
# protobuf
include(FetchContent)
FetchContent_Declare(
protobuf
GIT_REPOSITORY https://github.com/protocolbuffers/protobuf.git
GIT_TAG e6ab258b7ca407ed1bad8a2f04971e72b16f5409 # v28.2
)
FetchContent_MakeAvailable(protobuf)
# pybind11
FetchContent_Declare(
pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11.git
GIT_TAG a2e59f0e7065404b44dfe92a28aca47ba1378dc4 # v2.13.6
)
FetchContent_MakeAvailable(pybind11)
# generate onnx.proto3.pb.h and onnx.proto3.pb.cc
if (NOT EXISTS ${onnxinfo_SOURCE_DIR}/third_party/onnx/onnx.proto3)
file(MAKE_DIRECTORY ${onnxinfo_SOURCE_DIR}/third_party/onnx)
execute_process(
COMMAND wget "https://raw.githubusercontent.com/onnx/onnx/main/onnx/onnx.proto3" -O ${onnxinfo_SOURCE_DIR}/third_party/onnx/onnx.proto3
)
endif()
add_custom_command(
OUTPUT ${onnxinfo_SOURCE_DIR}/third_party/onnx/onnx.proto3.pb.h
${onnxinfo_SOURCE_DIR}/third_party/onnx/onnx.proto3.pb.cc
COMMAND protobuf::protoc --cpp_out=${onnxinfo_SOURCE_DIR}/third_party/onnx -I${onnxinfo_SOURCE_DIR}/third_party/onnx onnx.proto3
)
# start building onnxinfo library for pybind11
include_directories(
${protobuf_SOURCE_DIR}/third_party/abseil-cpp
${protobuf_SOURCE_DIR}
${pybind11_SOURCE_DIR}/include
${onnxinfo_SOURCE_DIR}/include
${onnxinfo_SOURCE_DIR}/third_party/onnx
)
link_directories(
${protobuf_BINARY_DIR}
${protobuf_BINARY_DIR}/third_party/abseil-cpp/absl
)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Wall -fPIC -flto=auto")
file(GLOB_RECURSE SOURCES "${onnxinfo_SOURCE_DIR}/src/*.cpp")
list(REMOVE_ITEM SOURCES "${onnxinfo_SOURCE_DIR}/src/pybind.cpp")
add_library(
_onnxinfo STATIC
${SOURCES}
${onnxinfo_SOURCE_DIR}/third_party/onnx/onnx.proto3.pb.cc
)
add_dependencies(_onnxinfo protobuf::protoc)
target_link_libraries(_onnxinfo
protobuf::libprotobuf
)
pybind11_add_module(${PROJECT_NAME} src/pybind.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE _onnxinfo)
# custom cmake target for test
# add_custom_target(test ALL)
# add_custom_command(
# TARGET test
# COMMAND python3 -m pytest -v
# )