onnxruntime/cmake/onnxruntime_opschema_lib.cmake
G. Ramalingam 8079c76383
Create ORT opschema library (#7903)
* Op schema library

* Create ORT opschema library and sample app

* delete message in cmake

* Fix cmake

* Address PR feedback and add dependency

* Add cmake dependency

* Cmake fix

* Add dependency for nsync

* Add dependency for nsync

* Reorder dependencies

* Testing for dependencies on all platforms

* Resolve dependencies on GetStackTrace, floatToHalf

* Compiler strict-aliasing warning

* Merge with master

* Minor cleanup
2021-06-14 14:02:33 -07:00

46 lines
2 KiB
CMake

# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# Schema library (for contrib ops and training ops)
set (CONTRIB_OPS_DIR ${ONNXRUNTIME_ROOT}/core/graph/contrib_ops)
set (TRAINING_OPS_DIR ${ORTTRAINING_ROOT}/orttraining/core/graph)
file(GLOB_RECURSE contrib_ops_schema_src
"${CONTRIB_OPS_DIR}/*.cc"
"${TRAINING_OPS_DIR}/training_op_defs.cc"
"${ORTTRAINING_ROOT}/orttraining/training_ops/cpu/aten_ops/aten_op_config.cc"
)
# The nchwc op schemas are platform-specific and not currently required.
list(REMOVE_ITEM contrib_ops_schema_src ${CONTRIB_OPS_DIR}/nchwc_schema_defs.cc)
# Use of ORT_ENFORCE introduces a dependency on GetStackTrace.
# Currently, we just use an empty implementation to avoid bringing in other dependencies.
if(WIN32)
list(APPEND contrib_ops_schema_src "${ONNXRUNTIME_ROOT}/core/platform/windows/stacktrace.cc")
else()
list(APPEND contrib_ops_schema_src "${ONNXRUNTIME_ROOT}/core/platform/posix/stacktrace.cc")
endif()
onnxruntime_add_static_library(ort_opschema_lib ${contrib_ops_schema_src})
target_compile_options(ort_opschema_lib PRIVATE -D_OPSCHEMA_LIB_=1)
set (OPSCHEMA_LIB_DEPENDENCIES onnx onnx_proto protobuf::libprotobuf flatbuffers)
# ${CMAKE_CURRENT_BINARY_DIR} is so that #include "onnxruntime_config.h" is found
target_include_directories(ort_opschema_lib PRIVATE ${ONNXRUNTIME_ROOT} ${ORTTRAINING_ROOT} ${CMAKE_CURRENT_BINARY_DIR})
onnxruntime_add_include_to_target(ort_opschema_lib onnxruntime_common onnx onnx_proto protobuf::libprotobuf flatbuffers)
add_dependencies(ort_opschema_lib ${OPSCHEMA_LIB_DEPENDENCIES})
# Test schema library using toy application
set(OPSCHEMA_LIB_TEST ${REPO_ROOT}/samples/c_cxx/opschema_lib_use)
file(GLOB_RECURSE opschema_lib_test_src "${OPSCHEMA_LIB_TEST}/main.cc")
add_executable(opschema_lib_test ${opschema_lib_test_src})
target_include_directories(opschema_lib_test PRIVATE ${ORTTRAINING_ROOT})
target_link_libraries(opschema_lib_test ort_opschema_lib ${OPSCHEMA_LIB_DEPENDENCIES})