RPM packages improvements: part 2 (#14306)

* Updated install_dependencies.sh

* Added Fedora support

* Improvements for RPM generation

* Refactored work with gflags

* Apply suggestions from code review

* Improvements

* Several improvements for Ubuntu 18.04

* Improvements in gflags

* Update thirdparty/CMakeLists.txt

temporary install samples dependencies

* Fixed several mistakes

* Fixed issues with gflags

* Don't install dependencies on Linux

* Added nlohmann findinds on debian9 case

* Added FATAL_ERROR is gflags is not found in samples

* Fixes for samples on CentOS 7

* Cross-compiled debian packakges with proper libraries location

* Fixed include for old nlohman-json versions

* Fixed compilation with old json

* Applied review comments

* Added support of old nlohmann versions via submodule

* Temporary WA for CentOS 7

* Fixed compilation with old gflags

* Fixed compilation of C samples

* Fixed gflags on RHEL8.2 / Debian 9
This commit is contained in:
Ilya Lavrenov
2022-12-01 23:57:23 +04:00
committed by GitHub
parent a246bdb3a0
commit 3ec084074a
15 changed files with 248 additions and 143 deletions

View File

@@ -97,38 +97,43 @@ if(NOT DEFINED CMAKE_CXX_STANDARD)
endif()
####################################
if(NOT TARGET gflags)
if(APPLE OR DEFINED ENV{CONDA_PREFIX} OR DEFINED ENV{HOMEBREW_PREFIX})
# conda-forge and brew contains only shared version of gflags
if(ENV{CONDA_PREFIX} AND WIN32)
# conda-forge windows compiled as gflags
find_package(gflags QUIET COMPONENTS shared)
else()
find_package(gflags QUIET COMPONENTS nothreads_shared)
endif()
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/common/utils")
set(gflags_required ON)
endif()
if(TARGET gflags)
set(GFLAGS_TARGET gflags)
elseif(gflags_required)
if(EXISTS /etc/debian_version)
set(gflags_component nothreads_static)
else()
find_package(gflags QUIET COMPONENTS nothreads_static)
set(gflags_component shared)
endif()
find_package(gflags QUIET OPTIONAL_COMPONENTS ${gflags_component})
if(gflags_FOUND)
if(TARGET ${GFLAGS_TARGET})
# nothing
elseif(TARGET gflags_nothreads-static)
# Debian 9: gflag_component is ignored
set(GFLAGS_TARGET gflags_nothreads-static)
elseif(TARGET gflags-shared)
# gflags shared case for CentOS / RHEL / Fedora
set(GFLAGS_TARGET gflags-shared)
else()
message(FATAL_ERROR "Internal error: failed to find imported target 'gflags' using '${gflags_component}' component")
endif()
message(STATUS "gflags (${gflags_VERSION}) is found at ${gflags_DIR} using '${gflags_component}' component")
endif()
if(gflags_FOUND)
if(NOT TARGET ${GFLAGS_TARGET})
if(TARGET gflags_nothreads-static)
# arm cross-compilation
set(GFLAGS_TARGET gflags_nothreads-static)
elseif(TARGET gflags_nothreads-shared)
# centos/rhel8
set(GFLAGS_TARGET gflags_nothreads-shared)
else()
message(FATAL_ERROR "Failed to set GFLAGS_TARGET target")
endif()
if(NOT gflags_FOUND)
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/gflags")
add_subdirectory(thirdparty/gflags EXCLUDE_FROM_ALL)
set(GFLAGS_TARGET gflags_nothreads_static)
else()
message(FATAL_ERROR "Failed to find 'gflags' library using '${gflags_component}' component")
endif()
message(STATUS "gflags (${gflags_VERSION}) is found at ${gflags_DIR}")
elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/gflags")
add_subdirectory(thirdparty/gflags EXCLUDE_FROM_ALL)
set(GFLAGS_TARGET gflags_nothreads_static)
endif()
else()
set(GFLAGS_TARGET gflags)
endif()
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/common/utils")

View File

@@ -19,7 +19,17 @@ if(NOT ANDROID)
endif()
if(NOT TARGET nlohmann_json::nlohmann_json)
find_package(nlohmann_json QUIET)
find_package(nlohmann_json QUIET
# exception for Ubuntu 18.04, where cmake files for nlohmann_json
# are located in a wrong directory
HINTS /usr/lib/cmake)
if(TARGET nlohmann_json)
# Ubuntu 18.04 case where target 'nlohmann_json' is here, but nlohmann_json_FOUND is OFF
if(NOT TARGET nlohmann_json::nlohmann_json)
add_library(nlohmann_json::nlohmann_json ALIAS nlohmann_json)
endif()
set(nlohmann_json_FOUND ON)
endif()
if(nlohmann_json_FOUND)
message(STATUS "nlohmann_json (${nlohmann_json_VERSION}) is found at ${nlohmann_json_DIR}")
elseif(PkgConfig_FOUND)
@@ -31,12 +41,28 @@ if(NOT TARGET nlohmann_json::nlohmann_json)
endif()
endif()
if(NOT nlohmann_json_FOUND)
# try to find header file json.hpp
# for example, on debian 9 there is no cmake / pkgconfig files
find_file(nlohmann_include_file
NAMES "json.hpp"
"Path to json.hpp (nlohmann-json-dev )")
if(nlohmann_include_file)
add_library(nlohmann_json::nlohmann_json INTERFACE IMPORTED)
get_filename_component(nlohmann_include_dir "${nlohmann_include_file}" PATH)
set_target_properties(nlohmann_json::nlohmann_json PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${nlohmann_include_dir}"
INTERFACE_COMPILE_DEFINITIONS JSON_HEADER)
set(nlohmann_json_FOUND ON)
endif()
endif()
if(NOT nlohmann_json_FOUND)
if(EXISTS "${Samples_SOURCE_DIR}/thirdparty/nlohmann_json")
# suppress shadowing names warning
set(JSON_SystemInclude ON CACHE BOOL "" FORCE)
add_subdirectory("${Samples_SOURCE_DIR}/thirdparty/nlohmann_json"
"${Samples_BINARY_DIR}/thirdparty/nlohmann_json" EXCLUDE_FROM_ALL)
"${Samples_BINARY_DIR}/thirdparty/nlohmann_json" EXCLUDE_FROM_ALL)
else()
message(FATAL_ERROR "Failed to find / build nlohmann_json library")
endif()

View File

@@ -5,11 +5,16 @@
#pragma once
#include <map>
#include <nlohmann/json.hpp>
#include <string>
#include <utility>
#include <vector>
#ifdef JSON_HEADER
# include <json.hpp>
#else
# include <nlohmann/json.hpp>
#endif
// clang-format off
#include "samples/common.hpp"
#include "samples/csv_dumper.hpp"

View File

@@ -6,7 +6,6 @@
#include <algorithm>
#include <map>
#include <nlohmann/json.hpp>
#include <regex>
#include <string>
#include <utility>
@@ -20,6 +19,12 @@
#include "utils.hpp"
// clang-format on
#ifdef JSON_HEADER
# include <json.hpp>
#else
# include <nlohmann/json.hpp>
#endif
#ifdef USE_OPENCV
# include <opencv2/core.hpp>
#endif
@@ -767,21 +772,28 @@ void load_config(const std::string& filename, std::map<std::string, ov::AnyMap>&
nlohmann::json jsonConfig;
try {
ifs >> jsonConfig;
} catch (const nlohmann::json::parse_error& e) {
} catch (const std::exception& e) {
throw std::runtime_error("Can't parse config file \"" + filename + "\".\n" + e.what());
}
for (const auto& item : jsonConfig.items()) {
std::string deviceName = item.key();
for (const auto& option : item.value().items()) {
for (auto item = jsonConfig.cbegin(), end = jsonConfig.cend(); item != end; ++item) {
const std::string& deviceName = item.key();
const auto& itemValue = item.value();
for (auto option = itemValue.cbegin(), itemValueEnd = itemValue.cend(); option != itemValueEnd; ++option) {
if (option.key() != "DEVICE_PROPERTIES") {
config[deviceName][option.key()] = option.value().get<std::string>();
continue;
}
for (const auto& hw_properties : option.value().items()) {
auto hw_device_name = hw_properties.key();
const auto& optionValue = option.value();
for (auto hw_properties = optionValue.cbegin(), optionValueEnd = optionValue.cend();
hw_properties != optionValueEnd;
++hw_properties) {
const std::string& hw_device_name = hw_properties.key();
std::map<std::string, ov::Any> hw_device_properties;
for (const auto& property : hw_properties.value().items())
const auto& hw_propertiesValue = hw_properties.value();
for (auto property = hw_propertiesValue.cbegin(), hw_propertiesEnd = hw_propertiesValue.cend();
property != hw_propertiesEnd;
++property)
hw_device_properties[property.key()] = property.value().get<std::string>();
config[deviceName][hw_device_name] = hw_device_properties;
}

View File

@@ -14,7 +14,7 @@ target_include_directories(${TARGET_NAME}
find_package(OpenVINO REQUIRED COMPONENTS Runtime)
target_link_libraries(${TARGET_NAME} PUBLIC openvino::runtime PRIVATE gflags)
target_link_libraries(${TARGET_NAME} PUBLIC openvino::runtime PRIVATE ${GFLAGS_TARGET})
if(COMMAND add_clang_format_target)
add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME})