diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f6066ad971..3182d126933 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,10 +3,11 @@ # if(DEFINED BUILD_SHARED_LIBS AND NOT BUILD_SHARED_LIBS) - # 'target_link_libraries' does not work correctly when called from + # 3.17: 'target_link_libraries' does not work correctly when called from # different directory where 'add_library' is called: CMake generates # incorrect OpenVINOConfig.cmake in this case - cmake_minimum_required(VERSION 3.17) + # 3.18: add_library cannot create ALIAS for non-GLOBAL targets + cmake_minimum_required(VERSION 3.18) else() if(CPACK_GENERATOR STREQUAL "DEB") # we have to use CPACK_DEBIAN_PACKAGE_SHLIBDEPS_PRIVATE_DIRS variable @@ -120,7 +121,7 @@ if (ENABLE_TESTS) include(cmake/test_model_zoo.cmake) endif() -add_subdirectory(thirdparty) +include(thirdparty/dependencies.cmake) add_subdirectory(src) if(ENABLE_SAMPLES OR ENABLE_TESTS OR ENABLE_COMPILE_TOOL) diff --git a/cmake/templates/OpenVINOConfig.cmake.in b/cmake/templates/OpenVINOConfig.cmake.in index c058e5c7b1e..b186d3a36c2 100644 --- a/cmake/templates/OpenVINOConfig.cmake.in +++ b/cmake/templates/OpenVINOConfig.cmake.in @@ -238,7 +238,15 @@ macro(_ov_find_pugixml) if(_ov_pugixml_pkgconfig_interface AND NOT ANDROID) _ov_find_dependency(PkgConfig) elseif(_ov_pugixml_cmake_interface) - _ov_find_dependency(PugiXML REQUIRED) + _ov_find_dependency(PugiXML NAMES PugiXML pugixml) + endif() + + # see https://cmake.org/cmake/help/latest/command/add_library.html#alias-libraries + # cmake older than 3.18 cannot create an alias for imported non-GLOBAL targets + # so, we have to use 'GLOBAL' property for cases when we call from OpenVINODeveloperPackage + # because the alias openvino::pugixml is created later + if(CMAKE_VERSION VERSION_LESS 3.18 AND OpenVINODeveloperPackage_DIR) + set(_ov_pugixml_visibility GLOBAL) endif() if(PugiXML_FOUND) @@ -248,8 +256,10 @@ macro(_ov_find_pugixml) set(_ov_pugixml_target pugixml::pugixml) endif() if(OpenVINODeveloperPackage_DIR) - set_property(TARGET ${_ov_pugixml_target} PROPERTY IMPORTED_GLOBAL ON) - # align with build tree + # align with build tree and create alias + if(_ov_pugixml_visibility STREQUAL "GLOBAL") + set_target_properties(${_ov_pugixml_target} PROPERTIES IMPORTED_GLOBAL TRUE) + endif() add_library(openvino::pugixml ALIAS ${_ov_pugixml_target}) endif() unset(_ov_pugixml_target) @@ -265,7 +275,7 @@ macro(_ov_find_pugixml) ${pkg_config_quiet_arg} ${pkg_config_required_arg} IMPORTED_TARGET - GLOBAL + ${_ov_pugixml_visibility} pugixml) unset(pkg_config_quiet_arg) @@ -295,6 +305,8 @@ macro(_ov_find_pugixml) message(FATAL_ERROR "Failed to find system pugixml in OpenVINO Developer Package") endif() endif() + + unset(_ov_pugixml_visibility) endif() endmacro() @@ -314,7 +326,7 @@ macro(_ov_find_ade) # whether 'ade' is found via find_package set(_ENABLE_SYSTEM_ADE "@ade_FOUND@") if(_OV_ENABLE_GAPI_PREPROCESSING AND _ENABLE_SYSTEM_ADE) - _ov_find_dependency(ade 0.1.2) + _ov_find_dependency(ade @ade_VERSION@) endif() unset(_OV_ENABLE_GAPI_PREPROCESSING) unset(_ENABLE_SYSTEM_ADE) @@ -375,9 +387,8 @@ endmacro() macro(_ov_find_protobuf_frontend_dependency) set(_OV_ENABLE_SYSTEM_PROTOBUF "@ENABLE_SYSTEM_PROTOBUF@") - # TODO: remove check for target existence - if(_OV_ENABLE_SYSTEM_PROTOBUF AND NOT TARGET protobuf::libprotobuf) - _ov_find_dependency(Protobuf @Protobuf_VERSION@ EXACT) + if(_OV_ENABLE_SYSTEM_PROTOBUF) + _ov_find_dependency(Protobuf @Protobuf_VERSION@ EXACT NAMES Protobuf protobuf) endif() unset(_OV_ENABLE_SYSTEM_PROTOBUF) endmacro() @@ -385,8 +396,7 @@ endmacro() macro(_ov_find_tensorflow_frontend_dependencies) set(_OV_ENABLE_SYSTEM_SNAPPY "@ENABLE_SYSTEM_SNAPPY@") set(_ov_snappy_lib "@ov_snappy_lib@") - # TODO: remove check for target existence - if(_OV_ENABLE_SYSTEM_SNAPPY AND NOT TARGET ${_ov_snappy_lib}) + if(_OV_ENABLE_SYSTEM_SNAPPY) _ov_find_dependency(Snappy @Snappy_VERSION@ EXACT) endif() unset(_OV_ENABLE_SYSTEM_SNAPPY) diff --git a/cmake/templates/OpenVINODeveloperPackageConfig.cmake.in b/cmake/templates/OpenVINODeveloperPackageConfig.cmake.in index 277873a29bc..64dae5d7c28 100644 --- a/cmake/templates/OpenVINODeveloperPackageConfig.cmake.in +++ b/cmake/templates/OpenVINODeveloperPackageConfig.cmake.in @@ -33,7 +33,11 @@ set(ENABLE_PLUGINS_XML ON) # for samples in 3rd party projects if(ENABLE_SAMPLES) - set_and_check(gflags_DIR "@gflags_BINARY_DIR@") + if("@gflags_FOUND@") + set_and_check(gflags_DIR "@gflags_DIR@") + else() + set_and_check(gflags_DIR "@gflags_BINARY_DIR@") + endif() endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") diff --git a/docs/dev/static_libaries.md b/docs/dev/static_libaries.md index 4e0443aacc0..e001b6f24c5 100644 --- a/docs/dev/static_libaries.md +++ b/docs/dev/static_libaries.md @@ -19,7 +19,7 @@ It is possible because not all interface symbols of OpenVINO Runtime libraries a ## System requirements -* CMake version 3.17 or higher must be used to build static OpenVINO libraries. +* CMake version 3.18 or higher must be used to build static OpenVINO libraries. * Supported OSes: * Windows x64 * Linux x64 diff --git a/src/bindings/python/CMakeLists.txt b/src/bindings/python/CMakeLists.txt index 056d578070b..f05013af026 100644 --- a/src/bindings/python/CMakeLists.txt +++ b/src/bindings/python/CMakeLists.txt @@ -64,8 +64,7 @@ function(ov_check_python_build_conditions) endif() # use libraries with the same version as python itself set(PYBIND11_PYTHON_VERSION ${PYTHON_VERSION_STRING}) - find_host_package(PythonLibsNew ${PYBIND11_PYTHON_VERSION} EXACT - ${find_package_mode}) + find_host_package(PythonLibsNew ${PYBIND11_PYTHON_VERSION} EXACT ${find_package_mode}) set(PYTHONLIBSNEW_FOUND ${PYTHONLIBS_FOUND} PARENT_SCOPE) endfunction() # try to find python libraries diff --git a/src/cmake/ie_parallel.cmake b/src/cmake/ie_parallel.cmake index 0268d4d5b8f..caa5e44b9dc 100644 --- a/src/cmake/ie_parallel.cmake +++ b/src/cmake/ie_parallel.cmake @@ -115,7 +115,7 @@ macro(ov_find_package_tbb) IMPORTED_TARGET # we need to set GLOBAL in order to create ALIAS later # ALIAS creation for non-GLOBAL targets is available since cmake 3.18 - GLOBAL + ${OV_PkgConfig_VISILITY} tbb) if(tbb_FOUND) # parse version @@ -190,7 +190,6 @@ macro(ov_find_package_tbb) if(PkgConfig_FOUND) pkg_search_module(HWLOC QUIET IMPORTED_TARGET - GLOBAL hwloc) endif() diff --git a/src/common/itt/CMakeLists.txt b/src/common/itt/CMakeLists.txt index 6e5727cd855..49b63848906 100644 --- a/src/common/itt/CMakeLists.txt +++ b/src/common/itt/CMakeLists.txt @@ -12,7 +12,7 @@ add_library(openvino::itt ALIAS ${TARGET_NAME}) target_link_libraries(${TARGET_NAME} PUBLIC openvino::util) if(ENABLE_PROFILING_ITT) - target_link_libraries(${TARGET_NAME} PUBLIC ittapi::ittnotify) + target_link_libraries(${TARGET_NAME} PUBLIC ittapi::ittapi) if(ENABLE_PROFILING_FILTER STREQUAL "ALL") target_compile_definitions(${TARGET_NAME} PUBLIC ENABLE_PROFILING_ALL diff --git a/src/common/itt/cmake/ITTConfig.cmake b/src/common/itt/cmake/ITTConfig.cmake index 251900ce60e..f2f6fca627b 100644 --- a/src/common/itt/cmake/ITTConfig.cmake +++ b/src/common/itt/cmake/ITTConfig.cmake @@ -47,12 +47,12 @@ find_package_handle_standard_args(ITT if(ITT_FOUND) set(INTEL_ITT_FOUND ${ITT_FOUND}) - add_library(ittapi::ittnotify STATIC IMPORTED GLOBAL) - set_target_properties(ittapi::ittnotify PROPERTIES IMPORTED_LOCATION "${Located_ITT_LIBS}" - INTERFACE_INCLUDE_DIRECTORIES ${Located_ITT_INCLUDE_DIRS} - INTERFACE_COMPILE_DEFINITIONS ENABLE_PROFILING_ITT) + add_library(ittapi::ittapi STATIC IMPORTED GLOBAL) + set_target_properties(ittapi::ittapi PROPERTIES IMPORTED_LOCATION "${Located_ITT_LIBS}" + INTERFACE_INCLUDE_DIRECTORIES ${Located_ITT_INCLUDE_DIRS} + INTERFACE_COMPILE_DEFINITIONS ENABLE_PROFILING_ITT) if(UNIX) - set_target_properties(ittapi::ittnotify PROPERTIES INTERFACE_LINK_LIBRARIES "${CMAKE_DL_LIBS};Threads::Threads") + set_target_properties(ittapi::ittapi PROPERTIES INTERFACE_LINK_LIBRARIES "${CMAKE_DL_LIBS};Threads::Threads") endif() endif() diff --git a/thirdparty/CMakeLists.txt b/thirdparty/dependencies.cmake similarity index 76% rename from thirdparty/CMakeLists.txt rename to thirdparty/dependencies.cmake index a4343cfac2d..29b565b36a9 100644 --- a/thirdparty/CMakeLists.txt +++ b/thirdparty/dependencies.cmake @@ -2,11 +2,20 @@ # SPDX-License-Identifier: Apache-2.0 # +set(_old_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) +set(_old_CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ${CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE}) + # Android toolchain does not provide pkg-config file. So, cmake mistakenly uses # build system pkg-config executable, which finds packages on build system. Such # libraries cannot be linked into Android binaries. if(NOT ANDROID) find_package(PkgConfig QUIET) + # see https://cmake.org/cmake/help/latest/command/add_library.html#alias-libraries + # cmake older than 3.18 cannot create an alias for imported non-GLOBAL targets + # so, we have to use 'IMPORTED_GLOBAL' property + if(CMAKE_VERSION VERSION_LESS 3.18) + set(OV_PkgConfig_VISILITY GLOBAL) + endif() endif() if(SUGGEST_OVERRIDE_SUPPORTED) @@ -21,31 +30,20 @@ if(ENABLE_PROFILING_ITT) find_package(ittapi QUIET) if(ittapi_FOUND) # conan defines 'ittapi::ittapi' target - # create more common alias 'ittapi::ittnotify' set_target_properties(ittapi::ittapi PROPERTIES - IMPORTED_GLOBAL ON INTERFACE_COMPILE_DEFINITIONS ENABLE_PROFILING_ITT) - add_library(ittapi::ittnotify ALIAS ittapi::ittapi) - - # set ittapi_FOUND to parent scope to properly generate OpenVINOConfig.cmake for static build - set(ittapi_FOUND ${ittapi_FOUND} PARENT_SCOPE) else() - add_subdirectory(ittapi) + add_subdirectory(thirdparty/ittapi) endif() - add_subdirectory(itt_collector EXCLUDE_FROM_ALL) -endif() - -if(ENABLE_SAMPLES OR ENABLE_TESTS) - add_subdirectory(cnpy EXCLUDE_FROM_ALL) + add_subdirectory(thirdparty/itt_collector EXCLUDE_FROM_ALL) endif() if(X86_64 OR UNIVERSAL2) find_package(xbyak QUIET) if(xbyak_FOUND) - # conan creates alias xbyak::xbyak, we only need to make it GLOBAL - set_target_properties(xbyak::xbyak PROPERTIES IMPORTED_GLOBAL ON) + # conan creates alias xbyak::xbyak, no extra steps are required else() - add_subdirectory(xbyak EXCLUDE_FROM_ALL) + add_subdirectory(thirdparty/xbyak EXCLUDE_FROM_ALL) # export and install xbyak openvino_developer_export_targets(COMPONENT openvino_common TARGETS xbyak::xbyak) ov_install_static_lib(xbyak ${OV_CPACK_COMP_CORE}) @@ -71,7 +69,6 @@ if(ENABLE_INTEL_GPU) if(NOT OpenCLHeaders_FOUND) message(WARNING "OpenCLHeaders not found, but OpenCLICDLoader is installed. Please, install OpenCL headers") else() - set_target_properties(OpenCL::Headers PROPERTIES IMPORTED_GLOBAL ON) set_property(TARGET OpenCL::OpenCL APPEND PROPERTY INTERFACE_LINK_LIBRARIES OpenCL::Headers) endif() @@ -82,25 +79,20 @@ if(ENABLE_INTEL_GPU) if(NOT OpenCLHeadersCpp_FOUND) message(WARNING "OpenCLHeadersCpp not found, but OpenCLICDLoader is installed. Please, install OpenCL C++ headers") else() - set_target_properties(OpenCL::HeadersCpp PROPERTIES IMPORTED_GLOBAL ON) get_target_property(opencl_cpp_include_dirs OpenCL::HeadersCpp INTERFACE_INCLUDE_DIRECTORIES) set_property(TARGET OpenCL::OpenCL APPEND PROPERTY INTERFACE_LINK_LIBRARIES OpenCL::HeadersCpp) endif() - - # set OpenCLICDLoader_FOUND to parent scope to generate proper OpenVINOConfig.cmake for static libraries case - set(OpenCLICDLoader_FOUND ON PARENT_SCOPE) else() # try to find system OpenCL: # - 'apt-get install opencl-headers ocl-icd-opencl-dev' # - 'yum install ocl-icd-devel opencl-headers' # - 'conda install khronos-opencl-icd-loader -c conda-forge' + # - 'vcpkg install opencl:' find_package(OpenCL QUIET) endif() endif() if(TARGET OpenCL::OpenCL) - set_target_properties(OpenCL::OpenCL PROPERTIES IMPORTED_GLOBAL ON) - # try to find CL/opencl.hpp find_file(OpenCL_HPP NAMES CL/opencl.hpp OpenCL/opencl.hpp @@ -123,8 +115,8 @@ if(ENABLE_INTEL_GPU) # set variables for onednn_gpu if(OpenCLHeaders_FOUND) - set(OpenCL_INCLUDE_DIR "$" PARENT_SCOPE) - set(OpenCL_LIBRARY "$" PARENT_SCOPE) + set(OpenCL_INCLUDE_DIR "$") + set(OpenCL_LIBRARY "$") elseif(OpenCL_FOUND) # find_package(OpenCL) already defines OpenCL_INCLUDE_DIR and OpenCL_LIBRARY # see https://cmake.org/cmake/help/latest/module/FindOpenCL.html @@ -133,14 +125,7 @@ if(ENABLE_INTEL_GPU) message(FATAL_ERROR "Internal error: cannot find OpenCL headers") endif() else() - add_subdirectory(ocl) - - set(OpenCL_INCLUDE_DIR "${OpenCL_INCLUDE_DIR}" PARENT_SCOPE) - set(OpenCL_LIBRARY "${OpenCL_LIBRARY}" PARENT_SCOPE) - set(opencl_root_hints "${opencl_root_hints}" PARENT_SCOPE) - - # system OpenCL is not found: set it explictly for consistent OpenVINOConfig.cmake generation - set(ENABLE_SYSTEM_OPENCL OFF PARENT_SCOPE) + add_subdirectory(thirdparty/ocl) endif() # cmake cannot set properties for imported targets @@ -157,7 +142,8 @@ if(ENABLE_INTEL_GPU) # used in tests add_library(opencl_new_headers INTERFACE) add_library(OpenCL::NewHeaders ALIAS opencl_new_headers) - foreach(opencl_dir "${CMAKE_CURRENT_SOURCE_DIR}/ocl/clhpp_headers/include" "${CMAKE_CURRENT_SOURCE_DIR}/ocl/cl_headers") + foreach(opencl_dir "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/ocl/clhpp_headers/include" + "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/ocl/cl_headers") if(EXISTS "${opencl_dir}") set_property(TARGET opencl_new_headers APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES $) @@ -172,35 +158,44 @@ endif() # if(ENABLE_SAMPLES OR ENABLE_TESTS) - find_package(ZLIB QUIET CONFIG) + find_package(ZLIB QUIET) if(ZLIB_FOUND) - # need to make it global to use outside of the current sub-directory - set_target_properties(ZLIB::ZLIB PROPERTIES IMPORTED_GLOBAL ON) + # FindZLIB module defines ZLIB::ZLIB, no extra steps are required endif() # cmake has failed to find zlib, let's try pkg-config if(NOT ZLIB_FOUND AND PkgConfig_FOUND) pkg_search_module(zlib QUIET - IMPORTED_TARGET GLOBAL + IMPORTED_TARGET zlib) if(zlib_FOUND) - add_library(ZLIB::ZLIB ALIAS PkgConfig::zlib) + add_library(ZLIB::ZLIB INTERFACE IMPORTED) + set_target_properties(ZLIB::ZLIB PROPERTIES INTERFACE_LINK_LIBRARIES PkgConfig::zlib) message(STATUS "${PKG_CONFIG_EXECUTABLE}: zlib (${zlib_VERSION}) is found at ${zlib_PREFIX}") endif() endif() if(NOT (zlib_FOUND OR ZLIB_FOUND)) - add_subdirectory(zlib EXCLUDE_FROM_ALL) + add_subdirectory(thirdparty/zlib EXCLUDE_FROM_ALL) endif() endif() +# +# cnpy +# + +if(ENABLE_SAMPLES OR ENABLE_TESTS) + add_subdirectory(thirdparty/cnpy EXCLUDE_FROM_ALL) +endif() + # # Pugixml # if(ENABLE_SYSTEM_PUGIXML) # try system pugixml first - find_package(PugiXML QUIET) + # Note: we also specify 'pugixml' in NAMES because vcpkg + find_package(PugiXML QUIET NAMES PugiXML pugixml) if(PugiXML_FOUND) # TODO: use static pugixml library in case of BUILD_SHARED_LIBS=OFF if(TARGET pugixml::shared) @@ -216,7 +211,7 @@ if(ENABLE_SYSTEM_PUGIXML) # - 'apt-get install libpugixml-dev' set(pugixml_target pugixml) elseif(TARGET pugixml::static) - # sometimes pugixml::static target already exists, just need to make it global + # sometimes pugixml::static target already exists, just need to create an alias # - 'conda install pugixml -c conda-forge' set(pugixml_target pugixml::static) else() @@ -225,10 +220,10 @@ if(ENABLE_SYSTEM_PUGIXML) # to property generate OpenVINO Developer packages files set(PugiXML_FOUND ${PugiXML_FOUND} CACHE BOOL "" FORCE) elseif(PkgConfig_FOUND) - # U18 case when cmake interface is not available + # Ubuntu 18.04 case when cmake interface is not available pkg_search_module(pugixml QUIET IMPORTED_TARGET - GLOBAL + ${OV_PkgConfig_VISILITY} pugixml) if(pugixml_FOUND) set(pugixml_target PkgConfig::pugixml) @@ -246,10 +241,13 @@ if(ENABLE_SYSTEM_PUGIXML) if(NOT TARGET ${pugixml_target}) find_library(PUGIXML_LIBRARY NAMES pugixml DOC "Path to pugixml library") if(PUGIXML_LIBRARY) - add_library(pugixml INTERFACE IMPORTED GLOBAL) + add_library(pugixml INTERFACE IMPORTED) set_target_properties(pugixml PROPERTIES INTERFACE_LINK_LIBRARIES "${PUGIXML_LIBRARY}") set(pugixml_target pugixml) set(PugiXML_FOUND ON) + # because we don't need to have a dependency on specific cmake targets in this case + # in file OpenVINOConfig.cmake static build case + set(ENABLE_SYSTEM_PUGIXML OFF) endif() endif() @@ -279,13 +277,16 @@ if(ENABLE_SYSTEM_PUGIXML) message(FATAL_ERROR "Debian | RPM package build requires shared Pugixml library") endif() - set_target_properties(${pugixml_target} PROPERTIES IMPORTED_GLOBAL ON) + if(OV_PkgConfig_VISILITY) + # need to set GLOBAL visibility in order to create ALIAS for this target + set_target_properties(${pugixml_target} PROPERTIES IMPORTED_GLOBAL ON) + endif() # create an alias for real target which can be shared or static add_library(openvino::pugixml ALIAS ${pugixml_target}) else() # reset to prevent improper code generation in OpenVINODeveloperPackage.cmake, # and OpenVINOConfig.cmake for static case - set(ENABLE_SYSTEM_PUGIXML OFF PARENT_SCOPE) + set(ENABLE_SYSTEM_PUGIXML OFF) endif() endif() @@ -294,7 +295,7 @@ if(NOT TARGET openvino::pugixml) function(ov_build_pugixml) function(ov_build_pugixml_static) set(BUILD_SHARED_LIBS OFF) - add_subdirectory(pugixml EXCLUDE_FROM_ALL) + add_subdirectory(thirdparty/pugixml EXCLUDE_FROM_ALL) endfunction() ov_build_pugixml_static() set_property(TARGET pugixml-static PROPERTY EXPORT_NAME pugixml) @@ -312,17 +313,17 @@ endif() if(ENABLE_GAPI_PREPROCESSING) add_library(ocv_hal INTERFACE) - target_include_directories(ocv_hal INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/ocv") + target_include_directories(ocv_hal INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/ocv") # ade - find_package(ade 0.1.2 QUIET) + find_package(ade 0.1.0 QUIET) if(ade_FOUND) - # conan creates 'ade' target - - # set ade_FOUND to parent scope to properly generate OpenVINOConfig.cmake for static build - set(ade_FOUND ${ade_FOUND} PARENT_SCOPE) + # conan and vcpkg create 'ade' target + # we just need to remove non-numerical symbols from version, + # because conan defines it as 0.1.2a, which is invalid in cmake + string(REGEX REPLACE "[a-z]" "" ade_VERSION "${ade_VERSION}") else() - add_subdirectory(ade EXCLUDE_FROM_ALL) + add_subdirectory(thirdparty/ade EXCLUDE_FROM_ALL) set_target_properties(ade PROPERTIES FOLDER thirdparty) openvino_developer_export_targets(COMPONENT openvino_common TARGETS ade) @@ -331,7 +332,7 @@ if(ENABLE_GAPI_PREPROCESSING) endif() # fluid - add_subdirectory(fluid/modules/gapi EXCLUDE_FROM_ALL) + add_subdirectory(thirdparty/fluid/modules/gapi EXCLUDE_FROM_ALL) if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 11) target_compile_options(fluid PRIVATE "-Wno-maybe-uninitialized") @@ -351,42 +352,50 @@ endif() # if(ENABLE_SAMPLES OR ENABLE_COMPILE_TOOL OR ENABLE_TESTS) - # on Windows and macOS we don't use gflags, because will be dynamically linked - if(CMAKE_HOST_LINUX AND LINUX) + if(CMAKE_TOOLCHAIN_FILE MATCHES "vcpkg " OR DEFINED VCPKG_VERBOSE OR + CMAKE_TOOLCHAIN_FILE MATCHES "conan_toolchain" OR DEFINED CONAN_EXPORTED) + # vcpkg contains only libs compiled with threads + # conan case + find_package(gflags QUIET) + elseif(APPLE OR WIN32) + # on Windows and macOS we don't use gflags, because will be dynamically linked + elseif(CMAKE_HOST_LINUX AND LINUX) if(OV_OS_RHEL) set(gflag_component nothreads_shared) elseif(OV_OS_DEBIAN) set(gflag_component nothreads_static) endif() find_package(gflags QUIET OPTIONAL_COMPONENTS ${gflag_component}) - else() - # conan case - find_package(gflags QUIET) endif() if(gflags_FOUND) if(TARGET gflags) - set_target_properties(gflags PROPERTIES IMPORTED_GLOBAL ON) + # no extra steps elseif(TARGET gflags_nothreads-static) # Debian 9: gflag_component is ignored - set_target_properties(gflags_nothreads-static PROPERTIES IMPORTED_GLOBAL ON) - add_library(gflags ALIAS gflags_nothreads-static) + set(gflags_target gflags_nothreads-static) elseif(TARGET gflags_nothreads-shared) # CentOS / RHEL / Fedora case - set_target_properties(gflags_nothreads-shared PROPERTIES IMPORTED_GLOBAL ON) - add_library(gflags ALIAS gflags_nothreads-shared) + set(gflags_target gflags_nothreads-shared) elseif(TARGET ${GFLAGS_TARGET}) - set_target_properties(${GFLAGS_TARGET} PROPERTIES IMPORTED_GLOBAL ON) - add_library(gflags ALIAS ${GFLAGS_TARGET}) + set(gflags_target ${GFLAGS_TARGET}) else() message(FATAL_ERROR "Internal error: failed to find imported target 'gflags' using '${gflag_component}' component") endif() + if(gflags_target) + if(OV_PkgConfig_VISILITY) + # need to set GLOBAL visibility in order to create ALIAS for this target + set_target_properties(${gflags_target} PROPERTIES IMPORTED_GLOBAL ON) + endif() + add_library(gflags ALIAS ${gflags_target}) + endif() + message(STATUS "gflags (${gflags_VERSION}) is found at ${gflags_DIR} using '${gflag_component}' component") endif() if(NOT TARGET gflags) - add_subdirectory(gflags EXCLUDE_FROM_ALL) + add_subdirectory(thirdparty/gflags EXCLUDE_FROM_ALL) openvino_developer_export_targets(COMPONENT openvino_common TARGETS gflags) endif() endif() @@ -401,11 +410,14 @@ if(ENABLE_TESTS) if(GTest_FOUND) foreach(gtest_target gtest gtest_main gmock gmock_main) - set_target_properties(GTest::${gtest_target} PROPERTIES IMPORTED_GLOBAL ON) + if(OV_PkgConfig_VISILITY) + # need to set GLOBAL visibility in order to create ALIAS for this target + set_target_properties(GTest::${gtest_target} PROPERTIES IMPORTED_GLOBAL ON) + endif() add_library(${gtest_target} ALIAS GTest::${gtest_target}) endforeach() else() - add_subdirectory(gtest EXCLUDE_FROM_ALL) + add_subdirectory(thirdparty/gtest EXCLUDE_FROM_ALL) openvino_developer_export_targets(COMPONENT tests TARGETS gmock gmock_main gtest gtest_main) endif() @@ -423,25 +435,15 @@ if(ENABLE_OV_PADDLE_FRONTEND OR ENABLE_OV_ONNX_FRONTEND OR ENABLE_OV_TF_FRONTEND if(CMAKE_VERBOSE_MAKEFILE) set(Protobuf_DEBUG ON) endif() - find_package(Protobuf 3.20.3 REQUIRED) + # Note: we also specify 'protobuf' in NAMES because vcpkg + find_package(Protobuf 3.20.3 REQUIRED NAMES Protobuf protobuf) set(PROTOC_EXECUTABLE protobuf::protoc) - - # in case of system protobuf, we have to add version to OpenVINOConfig.cmake for static build - # to ensure no mismatch between versions of protoc and libprotobuf, we need to use exactly - # the same versions - set(Protobuf_VERSION ${Protobuf_VERSION} PARENT_SCOPE) - - foreach(target ${PROTOC_EXECUTABLE} protobuf::libprotobuf protobuf::libprotobuf-lite) - set_target_properties(${target} PROPERTIES IMPORTED_GLOBAL ON) - endforeach() else() - add_subdirectory(protobuf EXCLUDE_FROM_ALL) + add_subdirectory(thirdparty/protobuf EXCLUDE_FROM_ALL) endif() - # forward variables used in the other places - set(PROTOC_DEPENDENCY ${PROTOC_DEPENDENCY} PARENT_SCOPE) - set(PROTOC_EXECUTABLE ${PROTOC_EXECUTABLE} PARENT_SCOPE) - set(Protobuf_IN_FRONTEND ON PARENT_SCOPE) + # forward additional variables used in the other places + set(Protobuf_IN_FRONTEND ON) # set public / interface compile options foreach(target_name protobuf::libprotobuf protobuf::libprotobuf-lite) @@ -489,17 +491,12 @@ if(ENABLE_OV_TF_LITE_FRONTEND) # we don't actually use library files (.so | .dylib | .a) itself, only headers set(flatbuffers_LIBRARY flatbuffers::flatbuffers) set(flatbuffers_COMPILER flatbuffers::flatc) - - foreach(target IN LISTS flatbuffers_LIBRARY flatbuffers_COMPILER) - set_property(TARGET ${target} PROPERTY IMPORTED_GLOBAL ON) - endforeach() else() - add_subdirectory(flatbuffers EXCLUDE_FROM_ALL) + add_subdirectory(thirdparty/flatbuffers EXCLUDE_FROM_ALL) endif() - set(flatbuffers_INCLUDE_DIRECTORIES $ PARENT_SCOPE) - set(flatbuffers_COMPILER ${flatbuffers_COMPILER} PARENT_SCOPE) - set(flatbuffers_DEPENDENCY ${flatbuffers_DEPENDENCY} PARENT_SCOPE) + # set additional variables, used in other places of our cmake scripts + set(flatbuffers_INCLUDE_DIRECTORIES $) endif() # @@ -517,13 +514,12 @@ if(ENABLE_SNAPPY_COMPRESSION) set(ov_snappy_lib Snappy::snappy-static) endif() - set_target_properties(${ov_snappy_lib} PROPERTIES IMPORTED_GLOBAL ON) - add_library(openvino::snappy ALIAS ${ov_snappy_lib}) + if(OV_PkgConfig_VISILITY) + # need to set GLOBAL visibility in order to create ALIAS for this target + set_target_properties(${ov_snappy_lib} PROPERTIES IMPORTED_GLOBAL ON) + endif() - # set Snappy_VERSION to parent scope for consistent OpenVINOConfig.cmake generation - # in case of static build with system dependencies - set(Snappy_VERSION ${Snappy_VERSION} PARENT_SCOPE) - set(ov_snappy_lib ${ov_snappy_lib} PARENT_SCOPE) + add_library(openvino::snappy ALIAS ${ov_snappy_lib}) endif() if(NOT TARGET openvino::snappy) @@ -551,7 +547,7 @@ if(ENABLE_SNAPPY_COMPRESSION) ie_add_compiler_flags(-Wno-sign-compare) endif() - add_subdirectory(snappy EXCLUDE_FROM_ALL) + add_subdirectory(thirdparty/snappy EXCLUDE_FROM_ALL) # need to create alias openvino::snappy add_library(openvino::snappy ALIAS snappy) @@ -574,15 +570,9 @@ if(ENABLE_OV_ONNX_FRONTEND) find_package(ONNX 1.13.1 EXACT QUIET COMPONENTS onnx onnx_proto NO_MODULE) if(ONNX_FOUND) - # conan creates imported targets 'onnx' and 'onnx_proto' - set_target_properties(onnx onnx_proto PROPERTIES IMPORTED_GLOBAL ON) - - # set ONNX_VERSION to parent scope for correct OpenVINOConfig.cmake generation - # in case of static libraries - set(ONNX_VERSION ${ONNX_VERSION} PARENT_SCOPE) - set(ENABLE_SYSTEM_ONNX ON PARENT_SCOPE) + # conan and vcpkg create imported targets 'onnx' and 'onnx_proto' else() - add_subdirectory(onnx) + add_subdirectory(thirdparty/onnx) endif() endif() @@ -594,19 +584,16 @@ if(ENABLE_SAMPLES) # Note: VPUX requires 3.9.0 version, because it contains 'nlohmann::ordered_json' find_package(nlohmann_json 3.9.0 QUIET) if(nlohmann_json_FOUND) - # conan creates imported target nlohmann_json::nlohmann_json - # no needs to make the target global, because samples call find_package(nlohmann_json) as well - # but we need to set nlohmann_json_FOUND to parent scope to properly generate InferenceEngineDeveloperPackageConfig.cmake - set(nlohmann_json_FOUND ${nlohmann_json_FOUND} PARENT_SCOPE) + # conan and vcpkg create imported target nlohmann_json::nlohmann_json else() - add_subdirectory(json) + add_subdirectory(thirdparty/json) # this is required only because of VPUX plugin reused this openvino_developer_export_targets(COMPONENT openvino_common TARGETS nlohmann_json) # for nlohmann library versions older than v3.0.0 if(NOT TARGET nlohmann_json::nlohmann_json) - add_library(nlohmann_json::nlohmann_json INTERFACE IMPORTED GLOBAL) + add_library(nlohmann_json::nlohmann_json INTERFACE IMPORTED) set_target_properties(nlohmann_json::nlohmann_json PROPERTIES INTERFACE_LINK_LIBRARIES nlohmann_json INTERFACE_COMPILE_DEFINITIONS JSON_HEADER) @@ -633,7 +620,7 @@ if(CPACK_GENERATOR MATCHES "^(DEB|RPM|CONDA-FORGE|BREW|CONAN)$") message(FATAL_ERROR "Pugixml must be used as a ${CPACK_GENERATOR} package. Install libpugixml-dev / pugixml-devel") endif() elseif(APPLE OR WIN32) - install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/gflags + install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/gflags DESTINATION ${OV_CPACK_SAMPLESDIR}/cpp/thirdparty COMPONENT ${OV_CPACK_COMP_CPP_SAMPLES} PATTERN bazel EXCLUDE @@ -652,16 +639,16 @@ elseif(APPLE OR WIN32) PATTERN .travis.yml EXCLUDE PATTERN WORKSPACE EXCLUDE) - file(GLOB zlib_sources ${CMAKE_CURRENT_SOURCE_DIR}/zlib/zlib/*.c - ${CMAKE_CURRENT_SOURCE_DIR}/zlib/zlib/*.h) + file(GLOB zlib_sources ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/zlib/zlib/*.c + ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/zlib/zlib/*.h) install(FILES ${zlib_sources} DESTINATION ${OV_CPACK_SAMPLESDIR}/cpp/thirdparty/zlib/zlib COMPONENT ${OV_CPACK_COMP_CPP_SAMPLES}) - install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/zlib/CMakeLists.txt + install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/zlib/CMakeLists.txt DESTINATION ${OV_CPACK_SAMPLESDIR}/cpp/thirdparty/zlib COMPONENT ${OV_CPACK_COMP_CPP_SAMPLES}) - install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/json/nlohmann_json + install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/json/nlohmann_json DESTINATION ${OV_CPACK_SAMPLESDIR}/cpp/thirdparty COMPONENT ${OV_CPACK_COMP_CPP_SAMPLES} PATTERN ChangeLog.md EXCLUDE @@ -682,6 +669,11 @@ elseif(APPLE OR WIN32) PATTERN wsjcpp.yml EXCLUDE) endif() -install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/cnpy +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/cnpy DESTINATION ${OV_CPACK_SAMPLESDIR}/cpp/thirdparty COMPONENT ${OV_CPACK_COMP_CPP_SAMPLES}) + +# restore state + +set(CMAKE_CXX_FLAGS "${_old_CMAKE_CXX_FLAGS}") +set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ${_old_CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE}) diff --git a/thirdparty/itt_collector/sea_itt_lib/CMakeLists.txt b/thirdparty/itt_collector/sea_itt_lib/CMakeLists.txt index 82919fb64b5..3282bd85fd2 100644 --- a/thirdparty/itt_collector/sea_itt_lib/CMakeLists.txt +++ b/thirdparty/itt_collector/sea_itt_lib/CMakeLists.txt @@ -27,7 +27,7 @@ add_library(${TARGET_NAME} SHARED ${SOURCES}) target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) set_target_properties(${TARGET_NAME} PROPERTIES OUTPUT_NAME IntelSEAPI) -target_link_libraries(${TARGET_NAME} PRIVATE ittapi::ittnotify) +target_link_libraries(${TARGET_NAME} PRIVATE ittapi::ittapi) if(UNIX) target_link_libraries(${TARGET_NAME} PRIVATE ${CMAKE_DL_LIBS}) diff --git a/thirdparty/ittapi/CMakeLists.txt b/thirdparty/ittapi/CMakeLists.txt index d30d6f0136c..96f7ae7d604 100644 --- a/thirdparty/ittapi/CMakeLists.txt +++ b/thirdparty/ittapi/CMakeLists.txt @@ -22,9 +22,9 @@ else() $ $) - # create alias ittapi::ittnotify - add_library(ittapi::ittnotify ALIAS ittnotify) + # create alias ittapi::ittapi + add_library(ittapi::ittapi ALIAS ittnotify) - openvino_developer_export_targets(COMPONENT openvino_common TARGETS ittapi::ittnotify) - ov_install_static_lib(ittapi::ittnotify ${OV_CPACK_COMP_CORE}) + openvino_developer_export_targets(COMPONENT openvino_common TARGETS ittapi::ittapi) + ov_install_static_lib(ittapi::ittapi ${OV_CPACK_COMP_CORE}) endif()