mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-06-01 23:30:35 +00:00
## Description 1. Convert some git submodules to cmake external projects 2. Update nsync from [1.23.0](https://github.com/google/nsync/releases/tag/1.23.0) to [1.25.0](https://github.com/google/nsync/releases/tag/1.25.0) 3. Update re2 from 2021-06-01 to 2022-06-01 4. Update wil from an old commit to 1.0.220914.1 tag 5. Update gtest to a newer commit so that it can optionally leverage absl/re2 for parsing command line flags. The following git submodules are deleted: 1. FP16 2. safeint 3. XNNPACK 4. cxxopts 5. dlpack 7. flatbuffers 8. googlebenchmark 9. json 10. mimalloc 11. mp11 12. pthreadpool More will come. ## Motivation and Context There are 3 ways of integrating 3rd party C/C++ libraries into ONNX Runtime: 1. Install them to a system location, then use cmake's find_package module to locate them. 2. Use git submodules 6. Use cmake's external projects(externalproject_add). At first when this project was just started, we considered both option 2 and option 3. We preferred option 2 because: 1. It's easier to handle authentication. At first this project was not open source, and it had some other non-public dependencies. If we use git submodule, ADO will handle authentication smoothly. Otherwise we need to manually pass tokens around and be very careful on not exposing them in build logs. 2. At that time, cmake fetched dependencies after "cmake" finished generating vcprojects/makefiles. So it was very difficult to make cflags consistent. Since cmake 3.11, it has a new command: FetchContent, which fetches dependencies when it generates vcprojects/makefiles just before add_subdirectories, so the parent project's variables/settings can be easily passed to the child projects. And when the project went on, we had some new concerns: 1. As we started to have more and more EPs and build configs, the number of submodules grew quickly. For more developers, most ORT submodules are not relevant to them. They shouldn't need to download all of them. 2. It is impossible to let two different build configs use two different versions of the same dependency. For example, right now we have protobuf 3.18.3 in the submodules. Then every EP must use the same version. Whenever we have a need to upgrade protobuf, we need to coordinate across the whole team and many external developers. I can't manage it anymore. 3. Some projects want to manage the dependencies in a different way, either because of their preference or because of compliance requirements. For example, some Microsoft teams want to use vcpkg, but we don't want to force every user of onnxruntime using vcpkg. 7. Someone wants to dynamically link to protobuf, but our build script only does static link. 8. Hard to handle security vulnerabilities. For example, whenever protobuf has a security patch, we have a lot of things to do. But if we allowed people to build ORT with a different version of protobuf without changing ORT"s source code, the customer who build ORT from source will be able to act on such things in a quicker way. They will not need to wait ORT having a patch release. 9. Every time we do a release, github will also publish a source file zip file and a source file tarball for us. But they are not usable, because they miss submodules. ### New features After this change, users will be able to: 1. Build the dependencies in the way they want, then install them to somewhere(for example, /usr or a temp folder). 2. Or download the dependencies by using cmake commands from these dependencies official website 3. Similar to the above, but use your private mirrors to migrate supply chain risks. 4. Use different versions of the dependencies, as long as our source code is compatible with them. For example, you may use you can't use protobuf 3.20.x as they need code changes in ONNX Runtime. 6. Only download the things the current build needs. 10. Avoid building external dependencies again and again in every build. ### Breaking change The onnxruntime_PREFER_SYSTEM_LIB build option is removed you could think from now it is default ON. If you don't like the new behavior, you can set FETCHCONTENT_TRY_FIND_PACKAGE_MODE to NEVER. Besides, for who relied on the onnxruntime_PREFER_SYSTEM_LIB build option, please be aware that this PR will change find_package calls from Module mode to Config mode. For example, in the past if you have installed protobuf from apt-get from ubuntu 20.04's official repo, find_package can find it and use it. But after this PR, it won't. This is because that protobuf version provided by Ubuntu 20.04 is too old to support the "config mode". It can be resolved by getting a newer version of protobuf from somewhere.
209 lines
7.7 KiB
CMake
209 lines
7.7 KiB
CMake
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
# Licensed under the MIT License.
|
|
|
|
set(onnxruntime_common_src_patterns
|
|
"${ONNXRUNTIME_INCLUDE_DIR}/core/common/*.h"
|
|
"${ONNXRUNTIME_INCLUDE_DIR}/core/common/logging/*.h"
|
|
"${ONNXRUNTIME_INCLUDE_DIR}/core/platform/*.h"
|
|
"${ONNXRUNTIME_ROOT}/core/common/*.h"
|
|
"${ONNXRUNTIME_ROOT}/core/common/*.cc"
|
|
"${ONNXRUNTIME_ROOT}/core/common/logging/*.h"
|
|
"${ONNXRUNTIME_ROOT}/core/common/logging/*.cc"
|
|
"${ONNXRUNTIME_ROOT}/core/common/logging/sinks/*.h"
|
|
"${ONNXRUNTIME_ROOT}/core/common/logging/sinks/*.cc"
|
|
"${ONNXRUNTIME_ROOT}/core/platform/env.h"
|
|
"${ONNXRUNTIME_ROOT}/core/platform/env.cc"
|
|
"${ONNXRUNTIME_ROOT}/core/platform/env_time.h"
|
|
"${ONNXRUNTIME_ROOT}/core/platform/env_time.cc"
|
|
"${ONNXRUNTIME_ROOT}/core/platform/path_lib.h"
|
|
"${ONNXRUNTIME_ROOT}/core/platform/path_lib.cc"
|
|
"${ONNXRUNTIME_ROOT}/core/platform/scoped_resource.h"
|
|
"${ONNXRUNTIME_ROOT}/core/platform/telemetry.h"
|
|
"${ONNXRUNTIME_ROOT}/core/platform/telemetry.cc"
|
|
"${ONNXRUNTIME_ROOT}/core/platform/logging/make_platform_default_log_sink.h"
|
|
"${ONNXRUNTIME_ROOT}/core/platform/logging/make_platform_default_log_sink.cc"
|
|
"$(ONNXRUNTIME_ROOT}/core/quantization/*.h"
|
|
"$(ONNXRUNTIME_ROOT}/core/quantization/*.cc"
|
|
)
|
|
|
|
if(WIN32)
|
|
list(APPEND onnxruntime_common_src_patterns
|
|
"${ONNXRUNTIME_ROOT}/core/platform/windows/*.h"
|
|
"${ONNXRUNTIME_ROOT}/core/platform/windows/*.cc"
|
|
"${ONNXRUNTIME_ROOT}/core/platform/windows/logging/*.h"
|
|
"${ONNXRUNTIME_ROOT}/core/platform/windows/logging/*.cc"
|
|
)
|
|
|
|
else()
|
|
list(APPEND onnxruntime_common_src_patterns
|
|
"${ONNXRUNTIME_ROOT}/core/platform/posix/*.h"
|
|
"${ONNXRUNTIME_ROOT}/core/platform/posix/*.cc"
|
|
)
|
|
|
|
if (onnxruntime_USE_SYSLOG)
|
|
list(APPEND onnxruntime_common_src_patterns
|
|
"${ONNXRUNTIME_ROOT}/core/platform/posix/logging/*.h"
|
|
"${ONNXRUNTIME_ROOT}/core/platform/posix/logging/*.cc"
|
|
)
|
|
endif()
|
|
|
|
if (CMAKE_SYSTEM_NAME STREQUAL "Android")
|
|
list(APPEND onnxruntime_common_src_patterns
|
|
"${ONNXRUNTIME_ROOT}/core/platform/android/logging/*.h"
|
|
"${ONNXRUNTIME_ROOT}/core/platform/android/logging/*.cc"
|
|
)
|
|
endif()
|
|
|
|
if (APPLE)
|
|
list(APPEND onnxruntime_common_src_patterns
|
|
"${ONNXRUNTIME_ROOT}/core/platform/apple/logging/*.h"
|
|
"${ONNXRUNTIME_ROOT}/core/platform/apple/logging/*.mm"
|
|
)
|
|
endif()
|
|
endif()
|
|
|
|
if(onnxruntime_target_platform STREQUAL "ARM64EC")
|
|
if (MSVC)
|
|
link_directories("$ENV{VCINSTALLDIR}/Tools/MSVC/$ENV{VCToolsVersion}/lib/ARM64EC")
|
|
link_directories("$ENV{VCINSTALLDIR}/Tools/MSVC/$ENV{VCToolsVersion}/ATLMFC/lib/ARM64EC")
|
|
link_libraries(softintrin.lib)
|
|
add_compile_options("/bigobj")
|
|
endif()
|
|
endif()
|
|
|
|
file(GLOB onnxruntime_common_src CONFIGURE_DEPENDS
|
|
${onnxruntime_common_src_patterns}
|
|
)
|
|
|
|
# Remove new/delete intercept. To deal with memory leaks
|
|
# Use either non-mimalloc build OR use mimalloc built-in features.
|
|
if(WIN32 AND onnxruntime_USE_MIMALLOC)
|
|
list(REMOVE_ITEM onnxruntime_common_src
|
|
"${ONNXRUNTIME_ROOT}/core/platform/windows/debug_alloc.cc"
|
|
"${ONNXRUNTIME_ROOT}/core/platform/windows/debug_alloc.h")
|
|
endif()
|
|
|
|
source_group(TREE ${REPO_ROOT} FILES ${onnxruntime_common_src})
|
|
|
|
onnxruntime_add_static_library(onnxruntime_common ${onnxruntime_common_src})
|
|
|
|
if (onnxruntime_USE_TELEMETRY)
|
|
set_target_properties(onnxruntime_common PROPERTIES COMPILE_FLAGS "/FI${ONNXRUNTIME_INCLUDE_DIR}/core/platform/windows/TraceLoggingConfigPrivate.h")
|
|
endif()
|
|
if (onnxruntime_USE_MIMALLOC)
|
|
list(APPEND onnxruntime_EXTERNAL_LIBRARIES mimalloc-static)
|
|
onnxruntime_add_static_library(onnxruntime_mimalloc_shim "${ONNXRUNTIME_ROOT}/core/platform/windows/mimalloc/mimalloc_overloads.cc")
|
|
target_link_libraries(onnxruntime_mimalloc_shim PRIVATE mimalloc-static)
|
|
target_link_libraries(onnxruntime_common PRIVATE onnxruntime_mimalloc_shim)
|
|
endif()
|
|
|
|
if(NOT onnxruntime_DISABLE_ABSEIL)
|
|
target_include_directories(onnxruntime_common PRIVATE ${ABSEIL_SOURCE_DIR})
|
|
if (MSVC)
|
|
set(ABSEIL_NATVIS_FILE "abseil-cpp.natvis")
|
|
target_sources(
|
|
onnxruntime_common
|
|
INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/external/${ABSEIL_NATVIS_FILE}>)
|
|
endif()
|
|
endif()
|
|
|
|
onnxruntime_add_include_to_target(onnxruntime_common date_interface WIL::WIL)
|
|
target_include_directories(onnxruntime_common
|
|
PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${ONNXRUNTIME_ROOT} ${eigen_INCLUDE_DIRS}
|
|
# propagate include directories of dependencies that are part of public interface
|
|
PUBLIC
|
|
${OPTIONAL_LITE_INCLUDE_DIR})
|
|
|
|
|
|
target_link_libraries(onnxruntime_common PUBLIC safeint_interface ${GSL_TARGET})
|
|
|
|
add_dependencies(onnxruntime_common ${onnxruntime_EXTERNAL_DEPENDENCIES})
|
|
|
|
install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/common DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core)
|
|
set_target_properties(onnxruntime_common PROPERTIES LINKER_LANGUAGE CXX)
|
|
set_target_properties(onnxruntime_common PROPERTIES FOLDER "ONNXRuntime")
|
|
|
|
|
|
if (onnxruntime_WINML_NAMESPACE_OVERRIDE STREQUAL "Windows")
|
|
target_compile_definitions(onnxruntime_common PRIVATE "BUILD_INBOX=1")
|
|
endif()
|
|
|
|
# check if we need to link against libatomic due to std::atomic usage by the threadpool code
|
|
# e.g. Raspberry Pi requires this
|
|
if (onnxruntime_LINK_LIBATOMIC)
|
|
list(APPEND onnxruntime_EXTERNAL_LIBRARIES atomic)
|
|
endif()
|
|
|
|
if(APPLE)
|
|
target_link_libraries(onnxruntime_common PRIVATE "-framework Foundation")
|
|
endif()
|
|
|
|
|
|
if(MSVC)
|
|
if(onnxruntime_target_platform STREQUAL "ARM64")
|
|
set(ARM64 TRUE)
|
|
elseif (onnxruntime_target_platform STREQUAL "ARM")
|
|
set(ARM TRUE)
|
|
elseif(onnxruntime_target_platform STREQUAL "x64")
|
|
set(X64 TRUE)
|
|
elseif(onnxruntime_target_platform STREQUAL "x86")
|
|
set(X86 TRUE)
|
|
endif()
|
|
elseif(APPLE)
|
|
if(CMAKE_OSX_ARCHITECTURES_LEN LESS_EQUAL 1)
|
|
set(X64 TRUE)
|
|
endif()
|
|
elseif(NOT onnxruntime_BUILD_WEBASSEMBLY)
|
|
if (CMAKE_SYSTEM_NAME STREQUAL "Android")
|
|
if (CMAKE_ANDROID_ARCH_ABI STREQUAL "armeabi-v7a")
|
|
set(ARM TRUE)
|
|
elseif (CMAKE_ANDROID_ARCH_ABI STREQUAL "arm64-v8a")
|
|
set(ARM64 TRUE)
|
|
elseif (CMAKE_ANDROID_ARCH_ABI STREQUAL "x86_64")
|
|
set(X86_64 TRUE)
|
|
elseif (CMAKE_ANDROID_ARCH_ABI STREQUAL "x86")
|
|
set(X86 TRUE)
|
|
endif()
|
|
else()
|
|
execute_process(
|
|
COMMAND ${CMAKE_C_COMPILER} -dumpmachine
|
|
OUTPUT_VARIABLE dumpmachine_output
|
|
ERROR_QUIET
|
|
)
|
|
if(dumpmachine_output MATCHES "^arm64.*")
|
|
set(ARM64 TRUE)
|
|
elseif(dumpmachine_output MATCHES "^arm.*")
|
|
set(ARM TRUE)
|
|
elseif(dumpmachine_output MATCHES "^aarch64.*")
|
|
set(ARM64 TRUE)
|
|
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(i.86|x86?)$")
|
|
set(X86 TRUE)
|
|
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|amd64)$")
|
|
set(X86_64 TRUE)
|
|
endif()
|
|
endif()
|
|
endif()
|
|
|
|
|
|
if (ARM64 OR ARM OR X86 OR X64 OR X86_64)
|
|
if((WIN32 AND NOT CMAKE_CXX_STANDARD_LIBRARIES MATCHES kernel32.lib) OR ((ARM64 OR ARM) AND MSVC))
|
|
# msvc compiler report syntax error with cpuinfo arm source files
|
|
# and cpuinfo does not have code for getting arm uarch info under windows
|
|
else()
|
|
# Link cpuinfo if supported
|
|
# Using it mainly in ARM with Android.
|
|
# Its functionality in detecting x86 cpu features are lacking, so is support for Windows.
|
|
if (CPUINFO_SUPPORTED)
|
|
onnxruntime_add_include_to_target(onnxruntime_common cpuinfo)
|
|
list(APPEND onnxruntime_EXTERNAL_LIBRARIES cpuinfo clog)
|
|
endif()
|
|
endif()
|
|
endif()
|
|
|
|
if (NOT onnxruntime_BUILD_SHARED_LIB)
|
|
install(TARGETS onnxruntime_common
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
FRAMEWORK DESTINATION ${CMAKE_INSTALL_BINDIR})
|
|
endif()
|