OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
Update "Building OpenVINO static libraries" instructions. (#37313)
Oleg Pipikine97007fc7480
diff --git a/cmake/features.cmake b/cmake/features.cmakeindex 681b69e0585..382245e3ce7 100644--- a/cmake/features.cmake+++ b/cmake/features.cmake@@ -55,7 +55,8 @@ ov_dependent_option (ENABLE_ONEDNN_FOR_GPU "Enable oneDNN with GPU support" ${ENov_dependent_option (ENABLE_CM_FOR_GPU "Enable C for Metal (CM) kernels at GPU runtime" ON "ENABLE_INTEL_GPU" OFF)ov_dependent_option (ENABLE_INTEL_NPU "NPU plugin for OpenVINO runtime" ON "X86_64;WIN32 OR LINUX OR ANDROID" OFF)-ov_dependent_option (ENABLE_INTEL_NPU_INTERNAL "NPU plugin internal components for OpenVINO runtime" ON "ENABLE_INTEL_NPU" OFF)+# matches ENABLE_INTEL_NPU_COMPILER default: internal NPU tools aren't built for static libs+ov_dependent_option (ENABLE_INTEL_NPU_INTERNAL "NPU plugin internal components for OpenVINO runtime" ${BUILD_SHARED_LIBS} "ENABLE_INTEL_NPU" OFF)ov_option (ENABLE_DEBUG_CAPS "enable OpenVINO debug capabilities at runtime" OFF)ov_dependent_option (ENABLE_NPU_DEBUG_CAPS "enable NPU debug capabilities at runtime" ON "ENABLE_DEBUG_CAPS;ENABLE_INTEL_NPU" OFF)diff --git a/docs/articles_en/openvino-workflow/deployment-locally.rst b/docs/articles_en/openvino-workflow/deployment-locally.rstindex d5a5553636b..b30df22335f 100644--- a/docs/articles_en/openvino-workflow/deployment-locally.rst+++ b/docs/articles_en/openvino-workflow/deployment-locally.rst@@ -33,7 +33,7 @@ Local Deployment Options- Grab a necessary functionality of OpenVINO together with your application, also called "local distribution":- using the :doc:`local distribution <deployment-locally/local-distribution-libraries>` approach;- - using `a static version of OpenVINO Runtime linked to the final app <https://github.com/openvinotoolkit/openvino/blob/master/docs/dev/static_libaries.md>`__.+ - using `a static version of OpenVINO Runtime linked to the final app <https://github.com/openvinotoolkit/openvino/blob/master/docs/dev/static_libraries.md>`__.The table below shows which distribution type can be used for what target operating system:@@ -52,7 +52,7 @@ The table below shows which distribution type can be used for what target operat- See https://pypi.org/project/openvino* - :doc:`Libraries for Local Distribution <deployment-locally/local-distribution-libraries>`- All operating systems- * - `Build OpenVINO statically and link to the final app <https://github.com/openvinotoolkit/openvino/blob/master/docs/dev/static_libaries.md>`__+ * - `Build OpenVINO statically and link to the final app <https://github.com/openvinotoolkit/openvino/blob/master/docs/dev/static_libraries.md>`__- All operating systemsdiff --git a/docs/articles_en/openvino-workflow/deployment-locally/local-distribution-libraries.rst b/docs/articles_en/openvino-workflow/deployment-locally/local-distribution-libraries.rstindex 5f51fe180e8..2fe45620d7f 100644--- a/docs/articles_en/openvino-workflow/deployment-locally/local-distribution-libraries.rst+++ b/docs/articles_en/openvino-workflow/deployment-locally/local-distribution-libraries.rst@@ -16,7 +16,7 @@ what minimal set of libraries is required to deploy the application.Local distribution is also suitable for OpenVINO binaries built from source using`Build instructions <https://github.com/openvinotoolkit/openvino/wiki#how-to-build>`__,but this guide assumes that OpenVINO Runtime is built dynamically.-For `Static OpenVINO Runtime <https://github.com/openvinotoolkit/openvino/blob/master/docs/dev/static_libaries.md>`__,+For `Static OpenVINO Runtime <https://github.com/openvinotoolkit/openvino/blob/master/docs/dev/static_libraries.md>`__,select the required OpenVINO capabilities at the CMake configuration stage using`CMake Options for Custom Compilation <https://github.com/openvinotoolkit/openvino/blob/master/docs/dev/cmake_options_for_custom_compilation.md>`__,then build and link the OpenVINO components to the final application.diff --git a/docs/articles_en/openvino-workflow/deployment-locally/optimial-binary-size-conditional-compilation.rst b/docs/articles_en/openvino-workflow/deployment-locally/optimial-binary-size-conditional-compilation.rstindex 6485160db3c..f5ac9ec0a66 100644--- a/docs/articles_en/openvino-workflow/deployment-locally/optimial-binary-size-conditional-compilation.rst+++ b/docs/articles_en/openvino-workflow/deployment-locally/optimial-binary-size-conditional-compilation.rst@@ -224,7 +224,7 @@ Perform the above steps for each SKUs information (CPUID, L1/L2/L3 cache size, cHow to Enable Conditional Compilation on Windows################################################-Find detailed information in the Building OpenVINO static libraries `document <https://github.com/openvinotoolkit/openvino/blob/master/docs/dev/static_libaries.md>`__ .+Find detailed information in the Building OpenVINO static libraries `document <https://github.com/openvinotoolkit/openvino/blob/master/docs/dev/static_libraries.md>`__ .Stage 1: Selective build analyzed stagediff --git a/docs/dev/build.md b/docs/dev/build.mdindex fcd129f20fd..1de9a203cae 100644--- a/docs/dev/build.md+++ b/docs/dev/build.md@@ -24,7 +24,7 @@ The articles below provide the basic informations about the process of building* [Docker Image](https://github.com/openvinotoolkit/docker_ci/tree/master/dockerfiles/ubuntu20/build_custom)* [Linux RISC-V](./build_riscv64.md)-> **NOTE**: For the details on how to build static OpenVINO, refer to [Building static OpenVINO libraries](static_libaries.md)+> **NOTE**: For the details on how to build static OpenVINO, refer to [Building static OpenVINO libraries](static_libraries.md)## See alsodiff --git a/docs/dev/static_libaries.md b/docs/dev/static_libraries.mdsimilarity index 51%rename from docs/dev/static_libaries.mdrename to docs/dev/static_libraries.mdindex 72d5b19b4f1..6835039a40b 100644--- a/docs/dev/static_libaries.md+++ b/docs/dev/static_libraries.md@@ -9,6 +9,8 @@- [Link static OpenVINO runtime](#link-static-openvino-runtime)- [Static OpenVINO libraries + Conditional compilation for particular models](#static-openvino-libraries--conditional-compilation-for-particular-models)- [Building with static MSVC Runtime](#building-with-static-msvc-runtime)+- [Building static OpenVINO for a specific device](#building-static-openvino-for-a-specific-device)+- [Validating a static build](#validating-a-static-build)- [Limitations](#limitations)- [See also](#see-also)@@ -56,7 +58,7 @@ cmake -DENABLE_INTEL_GPU=OFF \> **NOTE**: Inference backends located in external repositories can also be used in a static build. Use `-DOPENVINO_EXTRA_MODULES=<path to external plugin root>` to enable them. `OpenVINODeveloperPackage.cmake` must not be used to build external plugins, only `OPENVINO_EXTRA_MODULES` is a working solution.> **NOTE**: The `ENABLE_LTO` CMake option can also be passed to enable link time optimizations to reduce the binary size. But such property should also be enabled on the target which links with static OpenVINO libraries via `set_target_properties(<target_name> PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ON)`--+## Build static OpenVINO librariesTo build OpenVINO Runtime in a static mode, you need to specify the additional CMake option:@@ -68,9 +70,15 @@ cmake -DBUILD_SHARED_LIBS=OFF <all other CMake options> <openvino_sources root>Then, use the usual CMake 'build' command:```sh-cmake --build . --target openvino --config Release -j12+cmake --build . --config Release -j12```+> **NOTE**: Do not restrict the build to `--target openvino` — the install step below expects other components too (such as `openvino_c`), and fails if they were not built:+> ```+> file INSTALL cannot find ".../bin/intel64/Release/openvino_c.lib": No error.+> ```+> To build only a subset of targets, disable the components you don't need at configure time (e.g. `-DENABLE_JS=OFF`), or use a component-scoped install: `cmake --install . --component core`.+Then, the installation step:```sh@@ -79,6 +87,8 @@ cmake -DCMAKE_INSTALL_PREFIX=<install_root> -P cmake_install.cmakeThe OpenVINO runtime is located in `<install_root>/runtime/lib`+> **NOTE**: Build artifacts default to the *source* tree, not the build directory. If you build more than one static configuration from the same checkout (e.g. per-device, or `/MD` vs `/MT`), pass a separate `-DOUTPUT_ROOT=<build_dir>` per configuration, or they will clobber each other's generated files.+## Link static OpenVINO RuntimeOnce you build static OpenVINO Runtime libraries and install them, you can use one of the two ways to add them to your project:@@ -129,16 +139,77 @@ cmake -DCMAKE_TOOLCHAIN_FILE=<openvino source dir>/cmake/toolchains/mt.runtime.w> **NOTE**: all other dependent application and libraries must be built with the same `mt.runtime.win32.toolchain.cmake ` toolchain to have conformed values of the `MSVC_RUNTIME_LIBRARY` target property.-## Limitations+## Building static OpenVINO for a specific device++The general instructions above apply to every device. The notes below cover additional, device-specific behavior of `-DBUILD_SHARED_LIBS=OFF` that is not obvious from CMake errors alone.++### CPU++No additional options are required; CPU builds statically the same way as the common runtime described above.++### GPU++GPU builds statically with the default `-DGPU_RT_TYPE=OCL` runtime, no extra flags needed.++> **NOTE**: `OV_GPU_WITH_SYCL` (SYCL-enabled GPU runtime) is not compatible with `-DENABLE_LTO=ON` and fails CMake configuration with `FATAL_ERROR: Intel GPU plugin with SYCL is not supported with ENABLE_LTO=ON`. If SYCL is enabled for GPU, do not enable `ENABLE_LTO`.++### NPU++No additional options are required. `ENABLE_INTEL_NPU_INTERNAL`, which controls internal NPU tooling such as `compile_tool`, follows `BUILD_SHARED_LIBS` and is disabled by default in a static build, so the install manifest does not expect those tools ([cmake/features.cmake](../../cmake/features.cmake)). If you explicitly re-enable it with `-DENABLE_INTEL_NPU_INTERNAL=ON`, build the corresponding targets as well (or build the default target as described above), otherwise the install step will fail looking for binaries that were never built.++The NPU offline compiler is a prebuilt shared library and is **not available in static builds**: `ENABLE_INTEL_NPU_COMPILER` defaults to `${BUILD_SHARED_LIBS}` and cannot be forced `ON` for a static build. When it's unavailable, `CompilerAdapterFactory` falls back to the driver compiler (`NPU_COMPILER_TYPE=DRIVER`) instead of the plugin compiler (`NPU_COMPILER_TYPE=PLUGIN`) used by default in shared builds — see [compiler_adapter_factory.cpp](../../src/plugins/intel_npu/src/compiler_adapter/src/compiler_adapter_factory.cpp).++### Building multiple device configurations from one checkout-* The enabled and tested capabilities of OpenVINO Runtime in a static build:- * OpenVINO common runtime - work with `ov::Model`, perform model loading on particular device- * MULTI, HETERO, AUTO, and BATCH inference modes- * IR, ONNX, PDPD, TF and TF Lite frontends to read `ov::Model`-* Static build support for building static libraries only for OpenVINO Runtime libraries. All other third-party prebuilt dependencies remain in the same format:- * `TBB` is a shared library; to provide your own TBB build from [[oneTBB source code|https://github.com/oneapi-src/oneTBB]] use `export TBBROOT=<tbb_root>` before OpenVINO CMake scripts are run.+This only applies if you deliberately build *separate* static packages per device (for example, to validate each device independently, or to ship a smaller single-device binary) — not to a single build with several devices enabled together. Give each configuration its own `OUTPUT_ROOT` and install prefix (see the note above):++```sh+cmake -S . -B build_cpu -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DOUTPUT_ROOT=$PWD/build_cpu+cmake --build build_cpu --config Release -j12+cmake --install build_cpu --config Release --prefix install_cpu++cmake -S . -B build_npu -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DOUTPUT_ROOT=$PWD/build_npu+cmake --build build_npu --config Release -j12+cmake --install build_npu --config Release --prefix install_npu+```++## Validating a static build++The existing OpenVINO samples can be used to validate a static build:++* `hello_query_device` reports the devices and plugins compiled into the binary; use it to confirm that the plugins you enabled (for example CPU, GPU, NPU) are present and loadable.+* `hello_classification` (or `benchmark_app`) loads a model and runs inference on a selected device, verifying that the statically-linked plugin and frontend also work correctly at run time, not just that they link successfully.++```sh+cmake -S samples/cpp -B samples_build -DOpenVINO_DIR=<install_root>/runtime/cmake+cmake --build samples_build --config Release+samples_build/intel64/Release/hello_query_device+samples_build/intel64/Release/hello_classification <model.xml> <image> <DEVICE>+```++These samples link against the static package the same way any consuming application would, following the steps described in [Link static OpenVINO Runtime](#link-static-openvino-runtime).++## Limitations- > **NOTE**: The TBB team does not recommend using oneTBB as a static library, see [[Why onetbb does not like a static library?|https://github.com/uxlfoundation/oneTBB/issues/646]]+* Device support in a static build:++ | Device | Builds statically | Notes |+ |---|---|---|+ | CPU | Yes | |+ | GPU | Yes | See [GPU](#gpu) notes above |+ | NPU | Yes | See [NPU](#npu) notes above |+ | MULTI, HETERO, AUTO, BATCH | Yes | |+ | IR, ONNX, PDPD, TF, TF Lite frontends | Yes | |++* Static build support means building static libraries only for OpenVINO Runtime libraries. All other third-party prebuilt dependencies remain in the same format:+ * `TBB` is a shared library and is not rebuilt as part of a static OpenVINO build; the prebuilt shared TBB package is copied to `<install_root>/runtime/3rdparty/tbb/bin` and must be available to your application at run time (on `PATH` on Windows, or `LD_LIBRARY_PATH` on Linux).+ > **NOTE**: The prebuilt TBB package can also be downloaded directly:+ > * Linux x64: `https://storage.openvinotoolkit.org/dependencies/thirdparty/linux/oneapi-tbb-2021.13.1-lin-release.tgz`+ > * Windows x64: `https://storage.openvinotoolkit.org/dependencies/thirdparty/windows/oneapi-tbb-2021.13.2-win.zip`+ >+ > The TBB version differs per OS and changes between OpenVINO releases; check [cmake/dependencies.cmake](../../cmake/dependencies.cmake) for the version matching your checkout before downloading.+ * To use your own oneTBB build instead of the prebuilt package (for example, to build oneTBB as a static library), follow the official [oneTBB installation instructions](https://github.com/uxlfoundation/oneTBB/blob/master/INSTALL.md) and set `TBBROOT` to the installation directory before configuring OpenVINO.+ > **NOTE**: The oneTBB team does not recommend using oneTBB as a static library, see [[Why onetbb does not like a static library?|https://github.com/uxlfoundation/oneTBB/issues/646]].* `TBBBind_2_5` is not available on Windows x64 during a static OpenVINO build (see description for `ENABLE_TBBBIND_2_5` CMake option [[here|CMakeOptionsForCustomCompilation]] to understand what this library is responsible for). So, capabilities enabled by `TBBBind_2_5` are not available. To enable them, build [[oneTBB from source code|https://github.com/oneapi-src/oneTBB]] and provide the path to built oneTBB artifacts via `TBBROOT` environment variable before OpenVINO CMake scripts are run.