onnxruntime
165 строк · 6.3 Кб
1# Copyright (c) Microsoft Corporation. All rights reserved.
2# Licensed under the MIT License.
3
4file(GLOB_RECURSE onnxruntime_graph_src CONFIGURE_DEPENDS
5"${ONNXRUNTIME_INCLUDE_DIR}/core/graph/*.h"
6"${ONNXRUNTIME_ROOT}/core/graph/*.h"
7"${ONNXRUNTIME_ROOT}/core/graph/*.cc"
8)
9
10# start with empty training srcs list
11set(orttraining_graph_src)
12
13if (onnxruntime_ENABLE_TRAINING_OPS AND NOT onnxruntime_ENABLE_TRAINING)
14set(orttraining_graph_src
15"${ORTTRAINING_SOURCE_DIR}/core/graph/training_op_defs.cc"
16"${ORTTRAINING_SOURCE_DIR}/core/graph/training_op_defs.h"
17)
18endif()
19
20if (onnxruntime_ENABLE_TRAINING)
21file(GLOB_RECURSE orttraining_graph_src CONFIGURE_DEPENDS
22"${ORTTRAINING_SOURCE_DIR}/core/graph/*.h"
23"${ORTTRAINING_SOURCE_DIR}/core/graph/*.cc"
24)
25endif()
26
27# create empty lists for any excludes
28set(onnxruntime_graph_src_exclude_patterns)
29set(orttraining_graph_src_exclude_patterns)
30
31if (onnxruntime_MINIMAL_BUILD)
32# remove schema registration support
33list(APPEND onnxruntime_graph_src_exclude_patterns
34"${ONNXRUNTIME_INCLUDE_DIR}/core/graph/schema_registry.h"
35"${ONNXRUNTIME_ROOT}/core/graph/schema_registry.cc"
36"${ONNXRUNTIME_ROOT}/core/graph/contrib_ops/*defs.h"
37"${ONNXRUNTIME_ROOT}/core/graph/contrib_ops/*defs.cc"
38"${ONNXRUNTIME_ROOT}/core/graph/contrib_ops/onnx_deprecated_operators.cc"
39"${ONNXRUNTIME_ROOT}/core/graph/contrib_ops/onnx_function_util.h"
40"${ONNXRUNTIME_ROOT}/core/graph/contrib_ops/onnx_function_util.cc"
41"${ONNXRUNTIME_ROOT}/core/graph/contrib_ops/shape_inference_functions.h"
42"${ONNXRUNTIME_ROOT}/core/graph/contrib_ops/shape_inference_functions.cc"
43"${ONNXRUNTIME_ROOT}/core/graph/dml_ops/dml_defs.h"
44"${ONNXRUNTIME_ROOT}/core/graph/dml_ops/dml_defs.cc"
45"${ONNXRUNTIME_ROOT}/core/graph/function_template.h"
46"${ONNXRUNTIME_ROOT}/core/graph/function_utils.h"
47"${ONNXRUNTIME_ROOT}/core/graph/function_utils.cc"
48)
49
50list(APPEND orttraining_graph_src_exclude_patterns
51"${ORTTRAINING_SOURCE_DIR}/core/graph/training_op_defs.h"
52"${ORTTRAINING_SOURCE_DIR}/core/graph/training_op_defs.cc"
53)
54
55# no Function support initially
56list(APPEND onnxruntime_graph_src_exclude_patterns
57"${ONNXRUNTIME_ROOT}/core/graph/function*"
58)
59
60# remove graph proto serializer
61list(APPEND onnxruntime_graph_src_exclude_patterns
62"${ONNXRUNTIME_ROOT}/core/graph/graph_proto_serializer.cc"
63"${ONNXRUNTIME_ROOT}/core/graph/graph_proto_serializer.h"
64)
65
66# no optimizer support in base minimal build
67# some optimizer support in extended minimal build
68if (NOT onnxruntime_EXTENDED_MINIMAL_BUILD)
69list(APPEND onnxruntime_graph_src_exclude_patterns
70"${ONNXRUNTIME_ROOT}/core/graph/graph_utils.*"
71)
72endif()
73endif()
74
75if (onnxruntime_DISABLE_CONTRIB_OPS)
76list(APPEND onnxruntime_graph_src_exclude_patterns
77"${ONNXRUNTIME_ROOT}/core/graph/contrib_ops/*.h"
78"${ONNXRUNTIME_ROOT}/core/graph/contrib_ops/*.cc"
79)
80endif()
81
82if(NOT onnxruntime_USE_DML)
83list(APPEND onnxruntime_graph_src_exclude_patterns
84"${ONNXRUNTIME_ROOT}/core/graph/dml_ops/*.h"
85"${ONNXRUNTIME_ROOT}/core/graph/dml_ops/*.cc"
86)
87endif()
88
89file(GLOB onnxruntime_graph_src_exclude ${onnxruntime_graph_src_exclude_patterns})
90list(REMOVE_ITEM onnxruntime_graph_src ${onnxruntime_graph_src_exclude})
91
92if (onnxruntime_ENABLE_TRAINING_OPS)
93file(GLOB orttraining_graph_src_exclude ${orttraining_graph_src_exclude_patterns})
94list(REMOVE_ITEM orttraining_graph_src ${orttraining_graph_src_exclude})
95endif()
96
97onnxruntime_add_static_library(onnxruntime_graph ${onnxruntime_graph_src} ${orttraining_graph_src})
98add_dependencies(onnxruntime_graph onnx_proto flatbuffers::flatbuffers)
99onnxruntime_add_include_to_target(onnxruntime_graph onnxruntime_common ${WIL_TARGET} onnx onnx_proto ${PROTOBUF_LIB} flatbuffers::flatbuffers safeint_interface Boost::mp11)
100
101if (MSVC)
102set(ONNX_PROTOBUF_NATVIS_FILE "onnx_protobuf.natvis")
103target_sources(
104onnxruntime_graph
105INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/external/${ONNX_PROTOBUF_NATVIS_FILE}>
106)
107endif()
108
109if(NOT MSVC)
110target_compile_options(onnxruntime_graph PRIVATE "-Wno-parentheses" "-Wno-deprecated-declarations")
111endif()
112if (onnxruntime_ENABLE_TRAINING)
113#TODO: the graph library should focus on ONNX IR, it shouldn't depend on math libraries like MKLML/OpenBlas
114target_include_directories(onnxruntime_graph PRIVATE ${MKLML_INCLUDE_DIR})
115target_link_libraries(onnxruntime_graph PRIVATE nlohmann_json::nlohmann_json)
116endif()
117
118target_include_directories(onnxruntime_graph PRIVATE ${ONNXRUNTIME_ROOT})
119
120if (onnxruntime_ENABLE_TRAINING_OPS)
121target_include_directories(onnxruntime_graph PRIVATE ${ORTTRAINING_ROOT})
122
123if (onnxruntime_USE_NCCL)
124target_include_directories(onnxruntime_graph PRIVATE ${NCCL_INCLUDE_DIRS})
125endif()
126endif()
127
128set_target_properties(onnxruntime_graph PROPERTIES FOLDER "ONNXRuntime")
129set_target_properties(onnxruntime_graph PROPERTIES LINKER_LANGUAGE CXX)
130source_group(TREE ${REPO_ROOT} FILES ${onnxruntime_graph_src})
131if (onnxruntime_ENABLE_TRAINING_OPS)
132source_group(TREE ${ORTTRAINING_ROOT} FILES ${orttraining_graph_src})
133endif()
134
135if (onnxruntime_BUILD_MS_EXPERIMENTAL_OPS)
136target_compile_definitions(onnxruntime_graph PRIVATE BUILD_MS_EXPERIMENTAL_OPS=1)
137endif()
138
139if (WIN32)
140set(onnxruntime_graph_static_library_flags
141-IGNORE:4221 # LNK4221: This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library
142)
143
144set_target_properties(onnxruntime_graph PROPERTIES
145STATIC_LIBRARY_FLAGS "${onnxruntime_graph_static_library_flags}")
146
147if (NOT onnxruntime_DISABLE_EXCEPTIONS)
148target_compile_options(onnxruntime_graph PRIVATE
149/EHsc # exception handling - C++ may throw, extern "C" will not
150)
151endif()
152endif()
153
154if (onnxruntime_ENABLE_ATEN)
155target_compile_definitions(onnxruntime_graph PRIVATE ENABLE_ATEN)
156endif()
157
158if (NOT onnxruntime_BUILD_SHARED_LIB)
159install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/graph DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core)
160install(TARGETS onnxruntime_graph
161ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
162LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
163RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
164FRAMEWORK DESTINATION ${CMAKE_INSTALL_BINDIR})
165endif()
166