2018-11-20 00:48:22 +00:00
|
|
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
|
# Licensed under the MIT License.
|
|
|
|
|
|
|
|
|
|
if(UNIX)
|
|
|
|
|
set(SYMBOL_FILE ${CMAKE_CURRENT_BINARY_DIR}/onnxruntime.lds)
|
2021-10-27 10:07:07 +00:00
|
|
|
if(APPLE)
|
|
|
|
|
set(OUTPUT_STYLE xcode)
|
|
|
|
|
else()
|
|
|
|
|
set(OUTPUT_STYLE gcc)
|
2022-02-11 03:17:08 +00:00
|
|
|
endif()
|
2018-11-20 00:48:22 +00:00
|
|
|
else()
|
|
|
|
|
set(SYMBOL_FILE ${CMAKE_CURRENT_BINARY_DIR}/onnxruntime_dll.def)
|
|
|
|
|
set(OUTPUT_STYLE vc)
|
|
|
|
|
endif()
|
|
|
|
|
|
2020-09-14 17:32:39 +00:00
|
|
|
if (${CMAKE_SYSTEM_NAME} STREQUAL "iOS")
|
|
|
|
|
set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
|
2020-09-15 06:59:41 +00:00
|
|
|
set(OUTPUT_STYLE xcode)
|
2020-09-14 17:32:39 +00:00
|
|
|
endif()
|
2018-11-20 00:48:22 +00:00
|
|
|
|
2021-05-28 00:07:48 +00:00
|
|
|
# This macro is to get the path of header files for mobile packaging, for iOS and Android
|
|
|
|
|
macro(get_mobile_api_headers _HEADERS)
|
2021-08-27 21:10:14 +00:00
|
|
|
# include both c and cxx api
|
2021-05-28 00:07:48 +00:00
|
|
|
set(${_HEADERS}
|
|
|
|
|
"${REPO_ROOT}/include/onnxruntime/core/session/onnxruntime_c_api.h"
|
|
|
|
|
"${REPO_ROOT}/include/onnxruntime/core/session/onnxruntime_cxx_api.h"
|
|
|
|
|
"${REPO_ROOT}/include/onnxruntime/core/session/onnxruntime_cxx_inline.h"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# need to add header files for enabled EPs
|
|
|
|
|
foreach(f ${ONNXRUNTIME_PROVIDER_NAMES})
|
|
|
|
|
file(GLOB _provider_headers CONFIGURE_DEPENDS
|
|
|
|
|
"${REPO_ROOT}/include/onnxruntime/core/providers/${f}/*.h"
|
|
|
|
|
)
|
|
|
|
|
list(APPEND ${_HEADERS} "${_provider_headers}")
|
|
|
|
|
unset(_provider_headers)
|
|
|
|
|
endforeach()
|
|
|
|
|
endmacro()
|
|
|
|
|
|
2018-11-23 04:56:43 +00:00
|
|
|
#If you want to verify if there is any extra line in symbols.txt, run
|
|
|
|
|
# nm -C -g --defined libonnxruntime.so |grep -v '\sA\s' | cut -f 3 -d ' ' | sort
|
|
|
|
|
# after build
|
|
|
|
|
|
2018-11-20 00:48:22 +00:00
|
|
|
list(APPEND SYMBOL_FILES "${REPO_ROOT}/tools/ci_build/gen_def.py")
|
|
|
|
|
foreach(f ${ONNXRUNTIME_PROVIDER_NAMES})
|
|
|
|
|
list(APPEND SYMBOL_FILES "${ONNXRUNTIME_ROOT}/core/providers/${f}/symbols.txt")
|
|
|
|
|
endforeach()
|
|
|
|
|
|
2019-08-20 19:04:10 +00:00
|
|
|
add_custom_command(OUTPUT ${SYMBOL_FILE} ${CMAKE_CURRENT_BINARY_DIR}/generated_source.c
|
2021-06-03 06:36:49 +00:00
|
|
|
COMMAND ${Python_EXECUTABLE} "${REPO_ROOT}/tools/ci_build/gen_def.py"
|
2020-09-29 20:53:11 +00:00
|
|
|
--version_file "${ONNXRUNTIME_ROOT}/../VERSION_NUMBER" --src_root "${ONNXRUNTIME_ROOT}"
|
|
|
|
|
--config ${ONNXRUNTIME_PROVIDER_NAMES} --style=${OUTPUT_STYLE} --output ${SYMBOL_FILE}
|
|
|
|
|
--output_source ${CMAKE_CURRENT_BINARY_DIR}/generated_source.c
|
2018-11-20 00:48:22 +00:00
|
|
|
DEPENDS ${SYMBOL_FILES}
|
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
|
|
2019-08-20 19:04:10 +00:00
|
|
|
add_custom_target(onnxruntime_generate_def ALL DEPENDS ${SYMBOL_FILE} ${CMAKE_CURRENT_BINARY_DIR}/generated_source.c)
|
2020-02-04 03:33:14 +00:00
|
|
|
if(WIN32)
|
2021-04-15 23:47:53 +00:00
|
|
|
onnxruntime_add_shared_library(onnxruntime
|
|
|
|
|
${SYMBOL_FILE}
|
|
|
|
|
"${ONNXRUNTIME_ROOT}/core/dll/dllmain.cc"
|
|
|
|
|
"${ONNXRUNTIME_ROOT}/core/dll/onnxruntime.rc"
|
|
|
|
|
)
|
|
|
|
|
elseif(onnxruntime_BUILD_APPLE_FRAMEWORK)
|
2021-05-28 00:07:48 +00:00
|
|
|
get_mobile_api_headers(APPLE_FRAMEWORK_HEADERS)
|
2021-04-15 23:47:53 +00:00
|
|
|
|
|
|
|
|
# apple framework requires the header file be part of the library
|
|
|
|
|
onnxruntime_add_shared_library(onnxruntime
|
|
|
|
|
${APPLE_FRAMEWORK_HEADERS}
|
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/generated_source.c"
|
|
|
|
|
)
|
|
|
|
|
|
2021-06-02 18:30:05 +00:00
|
|
|
# create Info.plist for the framework and podspec for CocoaPods (optional)
|
2021-04-15 23:47:53 +00:00
|
|
|
set(MACOSX_FRAMEWORK_NAME "onnxruntime")
|
|
|
|
|
set(MACOSX_FRAMEWORK_IDENTIFIER "com.microsoft.onnxruntime")
|
2021-07-14 23:39:17 +00:00
|
|
|
# Need to include CoreML as a weaklink for CocoaPods package if the EP is enabled
|
|
|
|
|
if(onnxruntime_USE_COREML)
|
|
|
|
|
set(APPLE_WEAK_FRAMEWORK "\\\"CoreML\\\"")
|
|
|
|
|
endif()
|
|
|
|
|
set(INFO_PLIST_PATH "${CMAKE_CURRENT_BINARY_DIR}/Info.plist")
|
|
|
|
|
configure_file(${REPO_ROOT}/cmake/Info.plist.in ${INFO_PLIST_PATH})
|
2021-06-02 18:30:05 +00:00
|
|
|
configure_file(
|
2021-07-02 13:21:59 +00:00
|
|
|
${REPO_ROOT}/tools/ci_build/github/apple/framework_info.json.template
|
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/framework_info.json)
|
2021-04-15 23:47:53 +00:00
|
|
|
set_target_properties(onnxruntime PROPERTIES
|
|
|
|
|
FRAMEWORK TRUE
|
|
|
|
|
FRAMEWORK_VERSION A
|
|
|
|
|
PUBLIC_HEADER "${APPLE_FRAMEWORK_HEADERS}"
|
|
|
|
|
MACOSX_FRAMEWORK_INFO_PLIST ${CMAKE_CURRENT_BINARY_DIR}/Info.plist
|
|
|
|
|
VERSION ${ORT_VERSION}
|
|
|
|
|
SOVERSION ${ORT_VERSION}
|
|
|
|
|
)
|
2020-02-04 03:33:14 +00:00
|
|
|
else()
|
2021-04-15 23:47:53 +00:00
|
|
|
onnxruntime_add_shared_library(onnxruntime ${CMAKE_CURRENT_BINARY_DIR}/generated_source.c)
|
2021-05-26 00:36:15 +00:00
|
|
|
if (onnxruntime_USE_CUDA)
|
|
|
|
|
set_property(TARGET onnxruntime APPEND_STRING PROPERTY LINK_FLAGS " -Xlinker -rpath=\\$ORIGIN")
|
|
|
|
|
endif()
|
2020-02-04 03:33:14 +00:00
|
|
|
endif()
|
|
|
|
|
|
2018-11-20 00:48:22 +00:00
|
|
|
add_dependencies(onnxruntime onnxruntime_generate_def ${onnxruntime_EXTERNAL_DEPENDENCIES})
|
2019-01-07 21:15:24 +00:00
|
|
|
target_include_directories(onnxruntime PRIVATE ${ONNXRUNTIME_ROOT})
|
2018-11-20 00:48:22 +00:00
|
|
|
|
2020-02-07 19:00:28 +00:00
|
|
|
target_compile_definitions(onnxruntime PRIVATE VER_MAJOR=${VERSION_MAJOR_PART})
|
|
|
|
|
target_compile_definitions(onnxruntime PRIVATE VER_MINOR=${VERSION_MINOR_PART})
|
|
|
|
|
target_compile_definitions(onnxruntime PRIVATE VER_BUILD=${VERSION_BUILD_PART})
|
|
|
|
|
target_compile_definitions(onnxruntime PRIVATE VER_PRIVATE=${VERSION_PRIVATE_PART})
|
|
|
|
|
target_compile_definitions(onnxruntime PRIVATE VER_STRING=\"${VERSION_STRING}\")
|
2022-06-17 21:49:04 +00:00
|
|
|
target_compile_definitions(onnxruntime PRIVATE FILE_NAME=\"onnxruntime.dll\")
|
2020-02-07 19:00:28 +00:00
|
|
|
|
2018-11-20 00:48:22 +00:00
|
|
|
if(UNIX)
|
2019-02-06 23:27:37 +00:00
|
|
|
if (APPLE)
|
2020-02-04 03:33:14 +00:00
|
|
|
set(ONNXRUNTIME_SO_LINK_FLAG " -Xlinker -dead_strip")
|
2019-02-06 23:27:37 +00:00
|
|
|
else()
|
2020-02-04 03:33:14 +00:00
|
|
|
set(ONNXRUNTIME_SO_LINK_FLAG " -Xlinker --version-script=${SYMBOL_FILE} -Xlinker --no-undefined -Xlinker --gc-sections -z noexecstack")
|
2019-02-06 23:27:37 +00:00
|
|
|
endif()
|
2018-11-20 00:48:22 +00:00
|
|
|
else()
|
2020-02-04 03:33:14 +00:00
|
|
|
set(ONNXRUNTIME_SO_LINK_FLAG " -DEF:${SYMBOL_FILE}")
|
2018-11-20 00:48:22 +00:00
|
|
|
endif()
|
|
|
|
|
|
2019-01-25 18:45:39 +00:00
|
|
|
if (NOT WIN32)
|
2020-09-14 17:32:39 +00:00
|
|
|
if (APPLE OR ${CMAKE_SYSTEM_NAME} MATCHES "^iOS")
|
2021-10-27 10:07:07 +00:00
|
|
|
set(ONNXRUNTIME_SO_LINK_FLAG " -Wl,-exported_symbols_list,${SYMBOL_FILE}")
|
2020-09-14 17:32:39 +00:00
|
|
|
if (${CMAKE_SYSTEM_NAME} STREQUAL "iOS")
|
|
|
|
|
set_target_properties(onnxruntime PROPERTIES
|
|
|
|
|
SOVERSION ${ORT_VERSION}
|
|
|
|
|
MACOSX_RPATH TRUE
|
|
|
|
|
INSTALL_RPATH_USE_LINK_PATH FALSE
|
|
|
|
|
BUILD_WITH_INSTALL_NAME_DIR TRUE
|
|
|
|
|
INSTALL_NAME_DIR @rpath)
|
|
|
|
|
else()
|
|
|
|
|
set_target_properties(onnxruntime PROPERTIES INSTALL_RPATH "@loader_path")
|
|
|
|
|
endif()
|
build ONNXRuntime into WebAssembly (#6478)
* Simplified version of WebAssembly support to keep most of existing data structures and add cmake using Ninja and emcmake
* Clean up CMakeLists.txt and add an example to create and compute a kernel
* Load a model from bytes and remove graph building steps
* Add all cpu and contrib ops with mlas library
* WebAssembly build with Onnxruntime C/CXX API
* Use protobuf cmakefile directory instead of adding every necessary source file
* Fix invalid output at example
* add missing files
* Change an example to use Teams model and support ort mobile format
* add API for javascript
* fix input releasing in _ort_run()
* update API
* Let onnxruntime cmake build WebAssembly with option '--wasm'
* allow one-step building for wasm
* Make build script working on Linux and MacOS
* Fix broken build from Windows command
* Enable unit test on building WebAssembly
* Resolve comments
* update build flags
* wasm conv improvement from: 1) GemmV; 2) Depthwise direct convolution 3x3; 3) Direct convolution 3x3
* Cleaned mlas unittest.
* use glob
* update comments
* Update baseline due to loss scale fix (#6948)
* fix stream sync issue (#6954)
* Enable type reduction in EyeLike, Mod, random.cc CPU kernels. (#6960)
* Update EyeLike CPU kernel.
* Update Mod CPU kernel.
* Update Multinomial CPU kernel.
* Slight improvement to Pad CPU kernel binary size.
* Update RandomNormal[Like], RandomUniform[Like] CPU kernels.
* Fix warning from setting multiple MSVC warning level options. (#6917)
Fix warning from setting multiple MSVC warning level options. Replace an existing /Wn flag instead of always appending a new one.
* MLAS: quantized GEMM update (#6916)
Various updates to the int8_t GEMMs:
1) Add ARM64 udot kernel to take advantage of dot product instructions available in newer cores. Some models run 4x faster than the stock implementation we used before.
2) Refactor the x64 kernels to share common code for AVX2(u8u8/u8s8/avxvnni) vs AVX512(u8u8/u8s8/avx512vnni) to reduce binary size.
3) Extend kernels to support per-column zero points for matrix B. This is not currently wired to an operator.
* Implement QLinearAveragePool with unit tests. (#6896)
Implement QLinearAveragePool with unit tests.
* Attention fusion detect num_heads and hidden_size automatically (#6920)
* fixed type to experimental session constructor (#6950)
* fixed type to experimental session constructor
Co-authored-by: David Medine <david.medine@brainproducts.com>
* Update onnxruntime_perf_test.exe to accept free dimension overrides (#6962)
Co-authored-by: Ori Levari <orlevari@microsoft.com>
* Fix possible fd leak in NNAPI (#6966)
* Release buffers for prepacked tensors (#6820)
Unsolved problems:
1. One test failure was caused by a bug in Cudnn rnn kernels, when they can allocate a buffer and partially initialize it, the garbage data near tail of the buffer caused problem in some of the hardware. To attack this problem in a broader sense, should we add code in our allocators, and during a memory fuzzing test, fill an allocated buffer with garbage before returning to the caller?
2. Prepacking is used more widely than we know. For instance, Cudnn rnn kernels also cache their weights. They mix several weight tensors together into a single buffer, and never touch the original weight tensor anymore. This is the same idea with pre-pack, but they didn't override the virtual function, and they never tried to release those weight tensors, leading to memory waste. It also seems to me that there are some other kernels have similar behavior. Wonder how much memory we can save if we try to cleanup those too.
3. Turning off memory pattern planning does increase memory fragmentation, leading to out of memory error in some training test cases. Perhaps we can revisit the idea of pushing kernels-creation stage earlier, and then during initializer deserialization, we only avoid tracing those that will be prepacked.
* Enable type reduction for Range, ReverseSequence, ScatterND, Split, and Unique CPU kernels. (#6963)
* add CI
* fix test in ci
* fix flags for nsync in wasm build
* add copyright banner
* fix wasm source glob
* add missing exports
* resolve comments
* Perf gain by make packb wide to 4 from 16 on GEMM for WASM.
Remove no need direct conv in previous perf tuning.
* fix buildbreak introduced from latest master merge
* fix buildbreak in mlasi.h
* resolve all comments except MLAS
* rewrite packb related 3 functions for WASM_SCALAR seperately rather than using #ifdef in each.
and other changes according to PR feedback in mlas.
* More complete scalar path in sgemm from Tracy.
* Fix edge case handling in depthwise conv2d kernel 3x3. where:
*) support input W==1 and H==1
*) recalc in accurate pad_right and pad_bottom
*) support hidden pad_right == 2 or pad_bottom == 2 when W == 1 or H==1 and no pad left/top
* Add more test coverage for conv depthwise from Tracy.
Fix one typo according to PR.
* resolve comments
* replace typedef by using
* do not use throw in OrtRun()
* output error message
Co-authored-by: Sunghoon <35605090+hanbitmyths@users.noreply.github.com>
Co-authored-by: Lei Zhang <zhang.huanning@hotmail.com>
Co-authored-by: Wei-Sheng Chin <wschin@outlook.com>
Co-authored-by: Tianlei Wu <tlwu@microsoft.com>
Co-authored-by: Edward Chen <18449977+edgchen1@users.noreply.github.com>
Co-authored-by: Tracy Sharpe <42477615+tracysh@users.noreply.github.com>
Co-authored-by: David Medine <david.eric.medine@gmail.com>
Co-authored-by: David Medine <david.medine@brainproducts.com>
Co-authored-by: Ori Levari <ori.levari@microsoft.com>
Co-authored-by: Ori Levari <orlevari@microsoft.com>
Co-authored-by: Guoyu Wang <62914304+gwang-msft@users.noreply.github.com>
Co-authored-by: Chen Fu <chenfucs@gmail.com>
2021-04-06 23:18:10 +00:00
|
|
|
elseif (NOT onnxruntime_BUILD_WEBASSEMBLY)
|
2019-02-06 23:27:37 +00:00
|
|
|
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-rpath='$ORIGIN'")
|
|
|
|
|
endif()
|
2019-01-25 18:45:39 +00:00
|
|
|
endif()
|
|
|
|
|
|
2020-09-09 11:38:34 +00:00
|
|
|
|
2022-04-20 16:11:10 +00:00
|
|
|
if(CMAKE_SYSTEM_NAME STREQUAL "Android" AND onnxruntime_MINIMAL_BUILD)
|
|
|
|
|
# target onnxruntime is a shared library, the dummy __cxa_demangle is only attach to it to avoid
|
|
|
|
|
# affecting downstream ort library users with the behaviour of dummy __cxa_demangle. So the dummy
|
|
|
|
|
# __cxa_demangle must not expose to libonnxruntime_common.a. It works as when the linker is
|
|
|
|
|
# creating the DSO, our dummy __cxa_demangle always comes before libc++abi.a so the
|
|
|
|
|
# __cxa_demangle in libc++abi.a is discarded, thus, huge binary size reduction.
|
|
|
|
|
target_sources(onnxruntime PRIVATE "${ONNXRUNTIME_ROOT}/core/platform/android/cxa_demangle.cc")
|
|
|
|
|
target_compile_definitions(onnxruntime PRIVATE USE_DUMMY_EXA_DEMANGLE=1)
|
|
|
|
|
endif()
|
|
|
|
|
|
2020-09-09 11:38:34 +00:00
|
|
|
# strip binary on Android, or for a minimal build on Unix
|
|
|
|
|
if(CMAKE_SYSTEM_NAME STREQUAL "Android" OR (onnxruntime_MINIMAL_BUILD AND UNIX))
|
2020-09-10 20:50:28 +00:00
|
|
|
if (onnxruntime_MINIMAL_BUILD AND ADD_DEBUG_INFO_TO_MINIMAL_BUILD)
|
|
|
|
|
# don't strip
|
|
|
|
|
else()
|
|
|
|
|
set_target_properties(onnxruntime PROPERTIES LINK_FLAGS_RELEASE -s)
|
|
|
|
|
set_target_properties(onnxruntime PROPERTIES LINK_FLAGS_MINSIZEREL -s)
|
|
|
|
|
endif()
|
2020-05-19 02:20:23 +00:00
|
|
|
endif()
|
|
|
|
|
|
2021-05-28 00:07:48 +00:00
|
|
|
# we need to copy C/C++ API headers to be packed into Android AAR package
|
|
|
|
|
if(CMAKE_SYSTEM_NAME STREQUAL "Android" AND onnxruntime_BUILD_JAVA)
|
|
|
|
|
get_mobile_api_headers(ANDROID_AAR_HEADERS)
|
|
|
|
|
set(ANDROID_HEADERS_DIR ${CMAKE_CURRENT_BINARY_DIR}/android/headers)
|
|
|
|
|
file(MAKE_DIRECTORY ${ANDROID_HEADERS_DIR})
|
|
|
|
|
# copy the header files one by one
|
|
|
|
|
foreach(h_ ${ANDROID_AAR_HEADERS})
|
|
|
|
|
get_filename_component(HEADER_NAME_ ${h_} NAME)
|
2021-07-14 23:39:17 +00:00
|
|
|
add_custom_command(TARGET onnxruntime POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${h_} ${ANDROID_HEADERS_DIR}/${HEADER_NAME_})
|
2021-05-28 00:07:48 +00:00
|
|
|
endforeach()
|
|
|
|
|
endif()
|
|
|
|
|
|
2022-02-11 03:17:08 +00:00
|
|
|
# This list is a reversed topological ordering of library dependencies.
|
|
|
|
|
# Earlier entries may depend on later ones. Later ones should not depend on earlier ones.
|
2021-07-14 23:39:17 +00:00
|
|
|
set(onnxruntime_INTERNAL_LIBRARIES
|
|
|
|
|
onnxruntime_session
|
|
|
|
|
${onnxruntime_libs}
|
|
|
|
|
${PROVIDERS_ACL}
|
|
|
|
|
${PROVIDERS_ARMNN}
|
|
|
|
|
${PROVIDERS_COREML}
|
|
|
|
|
${PROVIDERS_DML}
|
|
|
|
|
${PROVIDERS_NNAPI}
|
2022-06-03 21:10:02 +00:00
|
|
|
${PROVIDERS_SNPE}
|
2021-07-14 23:39:17 +00:00
|
|
|
${PROVIDERS_NUPHAR}
|
2022-02-15 09:21:02 +00:00
|
|
|
${PROVIDERS_TVM}
|
2021-07-14 23:39:17 +00:00
|
|
|
${PROVIDERS_RKNPU}
|
|
|
|
|
${PROVIDERS_ROCM}
|
|
|
|
|
${PROVIDERS_VITISAI}
|
2022-06-03 10:22:34 +00:00
|
|
|
${PROVIDERS_XNNPACK}
|
2021-07-14 23:39:17 +00:00
|
|
|
${PROVIDERS_INTERNAL_TESTING}
|
|
|
|
|
${onnxruntime_winml}
|
|
|
|
|
onnxruntime_optimizer
|
|
|
|
|
onnxruntime_providers
|
|
|
|
|
${onnxruntime_tvm_libs}
|
|
|
|
|
onnxruntime_framework
|
|
|
|
|
onnxruntime_graph
|
2022-02-11 03:17:08 +00:00
|
|
|
onnxruntime_util
|
2021-09-04 20:30:33 +00:00
|
|
|
${ONNXRUNTIME_MLAS_LIBS}
|
2021-07-14 23:39:17 +00:00
|
|
|
onnxruntime_common
|
|
|
|
|
onnxruntime_flatbuffers
|
|
|
|
|
)
|
2018-11-20 00:48:22 +00:00
|
|
|
|
2019-06-07 18:50:23 +00:00
|
|
|
if (onnxruntime_ENABLE_LANGUAGE_INTEROP_OPS)
|
2021-07-14 23:39:17 +00:00
|
|
|
list(APPEND onnxruntime_INTERNAL_LIBRARIES
|
|
|
|
|
onnxruntime_language_interop
|
|
|
|
|
onnxruntime_pyop
|
|
|
|
|
)
|
2019-06-07 18:50:23 +00:00
|
|
|
endif()
|
|
|
|
|
|
2021-07-14 23:39:17 +00:00
|
|
|
# If you are linking a new library, please add it to the list onnxruntime_INTERNAL_LIBRARIES or onnxruntime_EXTERNAL_LIBRARIES,
|
|
|
|
|
# Please do not add a library directly to the target_link_libraries command
|
|
|
|
|
target_link_libraries(onnxruntime PRIVATE
|
|
|
|
|
${onnxruntime_INTERNAL_LIBRARIES}
|
|
|
|
|
${onnxruntime_EXTERNAL_LIBRARIES}
|
|
|
|
|
)
|
|
|
|
|
|
2020-02-04 03:33:14 +00:00
|
|
|
set_property(TARGET onnxruntime APPEND_STRING PROPERTY LINK_FLAGS ${ONNXRUNTIME_SO_LINK_FLAG} ${onnxruntime_DELAYLOAD_FLAGS})
|
2018-11-20 00:48:22 +00:00
|
|
|
set_target_properties(onnxruntime PROPERTIES LINK_DEPENDS ${SYMBOL_FILE})
|
2021-02-04 16:38:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
set_target_properties(onnxruntime PROPERTIES VERSION ${ORT_VERSION})
|
|
|
|
|
|
2018-11-20 00:48:22 +00:00
|
|
|
install(TARGETS onnxruntime
|
2021-04-15 23:47:53 +00:00
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
|
|
|
FRAMEWORK DESTINATION ${CMAKE_INSTALL_BINDIR})
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
set_target_properties(onnxruntime PROPERTIES FOLDER "ONNXRuntime")
|
2020-02-26 01:47:02 +00:00
|
|
|
|
2021-09-17 00:45:29 +00:00
|
|
|
if (WIN32 AND NOT CMAKE_CXX_STANDARD_LIBRARIES MATCHES kernel32.lib)
|
|
|
|
|
# Workaround STL bug https://github.com/microsoft/STL/issues/434#issuecomment-921321254
|
|
|
|
|
# Note that the workaround makes std::system_error crash before Windows 10
|
|
|
|
|
|
|
|
|
|
# The linker warns "LNK4199: /DELAYLOAD:api-ms-win-core-heapl2-1-0.dll ignored; no imports found from api-ms-win-core-heapl2-1-0.dll"
|
|
|
|
|
# when you're not using imports directly, even though the import exists in the STL and the DLL would have been linked without DELAYLOAD
|
|
|
|
|
target_link_options(onnxruntime PRIVATE /DELAYLOAD:api-ms-win-core-heapl2-1-0.dll /ignore:4199)
|
|
|
|
|
endif()
|
2021-07-14 23:39:17 +00:00
|
|
|
|
2021-12-07 20:39:46 +00:00
|
|
|
if (winml_is_inbox)
|
|
|
|
|
# Apply linking flags required by inbox static analysis tools
|
|
|
|
|
target_link_options(onnxruntime PRIVATE ${os_component_link_flags_list})
|
|
|
|
|
# Link *_x64/*_arm64 DLLs for the ARM64X forwarder
|
|
|
|
|
function(duplicate_shared_library target new_target)
|
|
|
|
|
get_target_property(sources ${target} SOURCES)
|
|
|
|
|
get_target_property(compile_definitions ${target} COMPILE_DEFINITIONS)
|
|
|
|
|
get_target_property(compile_options ${target} COMPILE_OPTIONS)
|
|
|
|
|
get_target_property(include_directories ${target} INCLUDE_DIRECTORIES)
|
|
|
|
|
get_target_property(link_libraries ${target} LINK_LIBRARIES)
|
|
|
|
|
get_target_property(link_flags ${target} LINK_FLAGS)
|
|
|
|
|
get_target_property(link_options ${target} LINK_OPTIONS)
|
|
|
|
|
add_library(${new_target} SHARED ${sources})
|
|
|
|
|
add_dependencies(${target} ${new_target})
|
|
|
|
|
target_compile_definitions(${new_target} PRIVATE ${compile_definitions})
|
|
|
|
|
target_compile_options(${new_target} PRIVATE ${compile_options})
|
|
|
|
|
target_include_directories(${new_target} PRIVATE ${include_directories})
|
|
|
|
|
target_link_libraries(${new_target} PRIVATE ${link_libraries})
|
|
|
|
|
set_property(TARGET ${new_target} PROPERTY LINK_FLAGS "${link_flags}")
|
|
|
|
|
target_link_options(${new_target} PRIVATE ${link_options})
|
|
|
|
|
endfunction()
|
|
|
|
|
if (WAI_ARCH STREQUAL x64 OR WAI_ARCH STREQUAL arm64)
|
|
|
|
|
duplicate_shared_library(onnxruntime onnxruntime_${WAI_ARCH})
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
2021-07-14 23:39:17 +00:00
|
|
|
# Assemble the Apple static framework (iOS and macOS)
|
|
|
|
|
if(onnxruntime_BUILD_APPLE_FRAMEWORK)
|
|
|
|
|
set(STATIC_LIB_DIR ${CMAKE_CURRENT_BINARY_DIR}/static_libraries)
|
|
|
|
|
file(MAKE_DIRECTORY ${STATIC_LIB_DIR})
|
|
|
|
|
|
|
|
|
|
# Remove the existing files in the STATIC_LIB_DIR folder
|
|
|
|
|
file(GLOB _OLD_STATIC_LIBS ${STATIC_LIB_DIR}/*.a)
|
|
|
|
|
file(REMOVE "${_OLD_STATIC_LIBS}")
|
|
|
|
|
|
|
|
|
|
# Go through all the static libraries, and create symbolic links
|
|
|
|
|
foreach(_LIB ${onnxruntime_INTERNAL_LIBRARIES} ${onnxruntime_EXTERNAL_LIBRARIES})
|
|
|
|
|
GET_TARGET_PROPERTY(_LIB_TYPE ${_LIB} TYPE)
|
|
|
|
|
if(_LIB_TYPE STREQUAL "STATIC_LIBRARY")
|
|
|
|
|
add_custom_command(TARGET onnxruntime POST_BUILD COMMAND ${CMAKE_COMMAND} -E create_symlink $<TARGET_FILE:${_LIB}> ${STATIC_LIB_DIR}/$<TARGET_LINKER_FILE_NAME:${_LIB}>)
|
|
|
|
|
endif()
|
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
|
|
if(${CMAKE_SYSTEM_NAME} STREQUAL "iOS")
|
|
|
|
|
set(STATIC_FRAMEWORK_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}-${CMAKE_OSX_SYSROOT})
|
|
|
|
|
else() # macOS
|
|
|
|
|
set(STATIC_FRAMEWORK_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Assemble the static framework
|
|
|
|
|
set(STATIC_FRAMEWORK_DIR ${STATIC_FRAMEWORK_OUTPUT_DIR}/static_framework/onnxruntime.framework)
|
|
|
|
|
set(STATIC_FRAMEWORK_HEADER_DIR ${STATIC_FRAMEWORK_DIR}/Headers)
|
|
|
|
|
file(MAKE_DIRECTORY ${STATIC_FRAMEWORK_DIR})
|
|
|
|
|
# Remove all files under STATIC_FRAMEWORK_DIR (if any)
|
|
|
|
|
file(GLOB_RECURSE _OLD_STATIC_FRAMEWORK ${STATIC_FRAMEWORK_DIR}/*.*)
|
|
|
|
|
file(REMOVE "${_OLD_STATIC_FRAMEWORK}")
|
|
|
|
|
|
|
|
|
|
file(MAKE_DIRECTORY ${STATIC_FRAMEWORK_HEADER_DIR})
|
|
|
|
|
|
|
|
|
|
# copy the header files one by one, and the Info.plist
|
|
|
|
|
foreach(h_ ${APPLE_FRAMEWORK_HEADERS})
|
|
|
|
|
get_filename_component(HEADER_NAME_ ${h_} NAME)
|
|
|
|
|
add_custom_command(TARGET onnxruntime POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${h_} ${STATIC_FRAMEWORK_HEADER_DIR}/${HEADER_NAME_})
|
|
|
|
|
endforeach()
|
|
|
|
|
add_custom_command(TARGET onnxruntime POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${INFO_PLIST_PATH} ${STATIC_FRAMEWORK_DIR}/Info.plist)
|
|
|
|
|
|
|
|
|
|
# link the static library
|
|
|
|
|
add_custom_command(TARGET onnxruntime POST_BUILD COMMAND libtool -static -o ${STATIC_FRAMEWORK_DIR}/onnxruntime *.a WORKING_DIRECTORY ${STATIC_LIB_DIR})
|
|
|
|
|
endif()
|