onnxruntime/cmake/onnxruntime_server.cmake
Colin Versteeg a8ff209ab6 Refactor Onnx runtime Server to only use public APIs (#1271)
* replace log sinks

* limit headers to include dir

* first changes to do dynamic linking

* wip for using cxx api

* remove weird dangling dependency

* building with tests failing

* finish updating converters

* fix const

* intital introduction of typedef

* change logging to use spdlog

* get tests passing

* clang format

* map logging levels better

* clean up unused imports

* trent cr comments

* clang-format

* code review comments

* changing buffer use to reserve

* Dynamically link

* revert tvm

* update binary uploading

* catch exceptions by const-ref

* Revert "revert tvm"

This reverts commit 387676dd1018134d15eb71fa126f7caf94380800.

* fix typo

* update versioning of lib
2019-07-04 01:08:14 -07:00

133 lines
5.3 KiB
CMake
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
set(SERVER_APP_NAME "onnxruntime_server")
# Generate .h and .cc files from protobuf file
add_library(server_proto ${ONNXRUNTIME_ROOT}/server/protobuf/predict.proto ${ONNXRUNTIME_ROOT}/server/protobuf/onnx-ml.proto)
if(WIN32)
target_compile_options(server_proto PRIVATE "/wd4125" "/wd4456")
endif()
target_include_directories(server_proto PUBLIC $<TARGET_PROPERTY:protobuf::libprotobuf,INTERFACE_INCLUDE_DIRECTORIES> "${CMAKE_CURRENT_BINARY_DIR}/.." ${CMAKE_CURRENT_BINARY_DIR}/onnx)
target_compile_definitions(server_proto PUBLIC $<TARGET_PROPERTY:protobuf::libprotobuf,INTERFACE_COMPILE_DEFINITIONS>)
onnxruntime_protobuf_generate(APPEND_PATH IMPORT_DIRS ${REPO_ROOT}/cmake/external/protobuf/src ${ONNXRUNTIME_ROOT}/server/protobuf ${ONNXRUNTIME_ROOT}/core/protobuf TARGET server_proto)
add_dependencies(server_proto ${onnxruntime_EXTERNAL_DEPENDENCIES})
if(NOT WIN32)
if(HAS_UNUSED_PARAMETER)
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/predict.pb.cc PROPERTIES COMPILE_FLAGS -Wno-unused-parameter)
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/onnx-ml.pb.cc PROPERTIES COMPILE_FLAGS -Wno-unused-parameter)
endif()
endif()
# Setup dependencies
include(get_boost.cmake)
set(re2_src ${REPO_ROOT}/cmake/external/re2)
set(SPDLOG_BUILD_EXAMPLES OFF)
add_subdirectory(${REPO_ROOT}/cmake/external/spdlog)
# Setup source code
set(onnxruntime_server_lib_srcs
"${ONNXRUNTIME_ROOT}/server/http/json_handling.cc"
"${ONNXRUNTIME_ROOT}/server/http/predict_request_handler.cc"
"${ONNXRUNTIME_ROOT}/server/http/util.cc"
"${ONNXRUNTIME_ROOT}/server/environment.cc"
"${ONNXRUNTIME_ROOT}/server/executor.cc"
"${ONNXRUNTIME_ROOT}/server/converter.cc"
"${ONNXRUNTIME_ROOT}/server/util.cc"
"${ONNXRUNTIME_ROOT}/server/serializing/tensorprotoutils.cc"
)
if(NOT WIN32)
if(HAS_UNUSED_PARAMETER)
set_source_files_properties(${ONNXRUNTIME_ROOT}/server/http/json_handling.cc PROPERTIES COMPILE_FLAGS -Wno-unused-parameter)
set_source_files_properties(${ONNXRUNTIME_ROOT}/server/http/predict_request_handler.cc PROPERTIES COMPILE_FLAGS -Wno-unused-parameter)
set_source_files_properties(${ONNXRUNTIME_ROOT}/server/executor.cc PROPERTIES COMPILE_FLAGS -Wno-unused-parameter)
set_source_files_properties(${ONNXRUNTIME_ROOT}/server/converter.cc PROPERTIES COMPILE_FLAGS -Wno-unused-parameter)
set_source_files_properties(${ONNXRUNTIME_ROOT}/server/util.cc PROPERTIES COMPILE_FLAGS -Wno-unused-parameter)
set_source_files_properties(${ONNXRUNTIME_ROOT}/server/serializing/tensorprotoutils.cc PROPERTIES COMPILE_FLAGS -Wno-unused-parameter)
endif()
endif()
file(GLOB_RECURSE onnxruntime_server_http_core_lib_srcs
"${ONNXRUNTIME_ROOT}/server/http/core/*.cc"
)
file(GLOB_RECURSE onnxruntime_server_srcs
"${ONNXRUNTIME_ROOT}/server/main.cc"
)
# HTTP core library
add_library(onnxruntime_server_http_core_lib STATIC
${onnxruntime_server_http_core_lib_srcs})
target_include_directories(onnxruntime_server_http_core_lib
PUBLIC
${ONNXRUNTIME_ROOT}/server/http/core
${Boost_INCLUDE_DIR}
${re2_src}
)
add_dependencies(onnxruntime_server_http_core_lib Boost)
target_link_libraries(onnxruntime_server_http_core_lib PRIVATE
${Boost_LIBRARIES}
)
# Server library
add_library(onnxruntime_server_lib ${onnxruntime_server_lib_srcs})
onnxruntime_add_include_to_target(onnxruntime_server_lib gsl onnx_proto server_proto)
target_include_directories(onnxruntime_server_lib PRIVATE
${ONNXRUNTIME_INCLUDE_DIR}
${ONNXRUNTIME_ROOT}/server
${ONNXRUNTIME_ROOT}/server/http
${ONNXRUNTIME_ROOT}/server/logging
PUBLIC
${Boost_INCLUDE_DIR}
${re2_src}
)
target_link_libraries(onnxruntime_server_lib PRIVATE
server_proto
${Boost_LIBRARIES}
onnxruntime_server_http_core_lib
PUBLIC
protobuf::libprotobuf
${onnxruntime_EXTERNAL_DEPENDENCIES}
spdlog::spdlog
onnxruntime
)
if (onnxruntime_USE_SYSLOG)
target_compile_definitions(onnxruntime_server_lib PUBLIC USE_SYSLOG="1")
endif()
# For IDE only
source_group(TREE ${REPO_ROOT} FILES ${onnxruntime_server_srcs} ${onnxruntime_server_lib_srcs} ${onnxruntime_server_lib})
# Server Application
add_executable(${SERVER_APP_NAME} ${onnxruntime_server_srcs})
add_dependencies(${SERVER_APP_NAME} onnx server_proto onnx_proto ${onnxruntime_EXTERNAL_DEPENDENCIES})
if(NOT WIN32)
if(HAS_UNUSED_PARAMETER)
set_source_files_properties("${ONNXRUNTIME_ROOT}/server/main.cc" PROPERTIES COMPILE_FLAGS -Wno-unused-parameter)
endif()
endif()
set(onnxruntime_SERVER_VERSION "local-build" CACHE STRING "Sever version")
target_compile_definitions(${SERVER_APP_NAME} PUBLIC SRV_VERSION="${onnxruntime_SERVER_VERSION}")
message(STATUS "ONNX Runtime Server version set to: ${onnxruntime_SERVER_VERSION}")
set(onnxruntime_LATEST_COMMIT_ID "default" CACHE STRING "The latest commit id")
target_compile_definitions(${SERVER_APP_NAME} PUBLIC LATEST_COMMIT_ID="${onnxruntime_LATEST_COMMIT_ID}")
message(STATUS "ONNX Runtime Server latest commit id is: ${onnxruntime_LATEST_COMMIT_ID}")
onnxruntime_add_include_to_target(${SERVER_APP_NAME} onnxruntime_session onnxruntime_server_lib gsl onnx onnx_proto server_proto)
target_include_directories(${SERVER_APP_NAME} PRIVATE
${ONNXRUNTIME_INCLUDE_DIR}
${ONNXRUNTIME_ROOT}/server/http
)
target_link_libraries(${SERVER_APP_NAME} PRIVATE
onnxruntime_server_http_core_lib
onnxruntime_server_lib
)