Added support of pugixml search via pkg-config (#12958)

* Added support of pugixml search via pkg-config

* Updated old InferencEngineDEveloperPackage.cmake.in

* Removed debug print

* Fixed cmake stage for U18

* Added WA for pugixml on U18 for DevPackage as well

* Disable pkg-config generation for OpenVINO for U18

* Added option for pkg-config

* Now triplet is aut-detected

* Fixed U18 case
This commit is contained in:
Ilya Lavrenov authored and GitHub committed 2022-09-10 01:10:24 +03:00
1 parent ee8575134a
commit 53542ded57
6 files changed
+150 -63

No files matched your search

+4
View File
@@ -45,6 +45,10 @@ ie_option(ENABLE_ERROR_HIGHLIGHT "Highlight errors and warnings during compile t
ie_option (ENABLE_DOCS "Build docs using Doxygen" OFF)
# TODO: fix apple later
find_package(PkgConfig QUIET)
ie_dependent_option (ENABLE_PKGCONFIG_GEN "Enable openvino.pc pkg-config file generation" ON "LINUX;PkgConfig_FOUND;BUILD_SHARED_LIBS" OFF)
#
# Inference Engine specific options
#
@@ -79,9 +79,43 @@ if(TARGET IE::runtime::dev AND NOT TARGET openvino::runtime::dev)
endif()
if(ENABLE_SYSTEM_PUGIXML)
find_dependency(PugiXML)
set_property(TARGET pugixml PROPERTY IMPORTED_GLOBAL TRUE)
add_library(IE::pugixml ALIAS pugixml)
set(_ov_pugixml_pkgconfig_interface "@pugixml_FOUND@")
if(_ov_pugixml_pkgconfig_interface)
find_dependency(PkgConfig)
else()
find_dependency(PugiXML)
endif()
if(PugiXML_FOUND)
set_property(TARGET pugixml PROPERTY IMPORTED_GLOBAL TRUE)
add_library(IE::pugixml ALIAS pugixml)
elseif(PkgConfig_FOUND)
if(${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)
set(pkg_config_quiet_arg QUIET)
endif()
if(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED)
set(pkg_config_required_arg REQUIRED)
endif()
pkg_search_module(pugixml
${pkg_config_quiet_arg}
${pkg_config_required_arg}
IMPORTED_TARGET GLOBAL
pugixml)
unset(pkg_config_quiet_arg)
unset(pkg_config_required_arg)
if(pugixml_FOUND)
add_library(IE::pugixml ALIAS PkgConfig::pugixml)
# PATCH: on Ubuntu 18.04 pugixml.pc contains incorrect include directories
get_target_property(interface_include_dir PkgConfig::pugixml INTERFACE_INCLUDE_DIRECTORIES)
if(interface_include_dir AND NOT EXISTS "${interface_include_dir}")
set_target_properties(PkgConfig::pugixml PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "")
endif()
endif()
endif()
endif()
# inherit OpenCV from main IE project if enabled
@@ -50,9 +50,43 @@ foreach(component @openvino_export_components@)
endforeach()
if(ENABLE_SYSTEM_PUGIXML)
find_dependency(PugiXML)
set_property(TARGET pugixml PROPERTY IMPORTED_GLOBAL TRUE)
add_library(openvino::pugixml ALIAS pugixml)
set(_ov_pugixml_pkgconfig_interface "@pugixml_FOUND@")
if(_ov_pugixml_pkgconfig_interface)
find_dependency(PkgConfig)
else()
find_dependency(PugiXML)
endif()
if(PugiXML_FOUND)
set_property(TARGET pugixml PROPERTY IMPORTED_GLOBAL TRUE)
add_library(openvino::pugixml ALIAS pugixml)
elseif(PkgConfig_FOUND)
if(${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)
set(pkg_config_quiet_arg QUIET)
endif()
if(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED)
set(pkg_config_required_arg REQUIRED)
endif()
pkg_search_module(pugixml
${pkg_config_quiet_arg}
${pkg_config_required_arg}
IMPORTED_TARGET GLOBAL
pugixml)
unset(pkg_config_quiet_arg)
unset(pkg_config_required_arg)
if(pugixml_FOUND)
add_library(openvino::pugixml ALIAS PkgConfig::pugixml)
# PATCH: on Ubuntu 18.04 pugixml.pc contains incorrect include directories
get_target_property(interface_include_dir PkgConfig::pugixml INTERFACE_INCLUDE_DIRECTORIES)
if(interface_include_dir AND NOT EXISTS "${interface_include_dir}")
set_target_properties(PkgConfig::pugixml PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "")
endif()
endif()
endif()
endif()
# inherit OpenCV from main OpenVINO project if enabled
+1 -1
View File
@@ -6,7 +6,7 @@ pc_path=${pcfiledir}
prefix=${pc_path}/@PKGCONFIG_OpenVINO_PREFIX@
exec_prefix=${prefix}/@OV_CPACK_RUNTIMEDIR@
libdir=${exec_prefix}/@PKGCONFIG_OpenVINO_TRIPLET@
libdir=${exec_prefix}
include_prefix=${prefix}/@OV_CPACK_INCLUDEDIR@
includedir_old=${include_prefix}/ie
+23 -47
View File
@@ -183,18 +183,7 @@ install(FILES "${CMAKE_BINARY_DIR}/share/OpenVINOConfig.cmake"
# Generate and install openvino.pc pkg-config file
# TODO: fix apple later
if(LINUX)
find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
set(generate_pkgconfig ON)
endif()
# temporary skip generator of pkg-config file for static libraries
if(NOT BUILD_SHARED_LIBS)
set(generate_pkgconfig OFF)
endif()
if(ENABLE_PKGCONFIG_GEN)
# fill in PKGCONFIG_OpenVINO_FRONTENDS
get_target_property(PKGCONFIG_OpenVINO_FRONTENDS_LIST ov_frontends MANUALLY_ADDED_DEPENDENCIES)
if(ENABLE_OV_IR_FRONTEND)
@@ -224,55 +213,42 @@ if(LINUX)
set(PKGCONFIG_OpenVINO_PRIVATE_DEPS "-L\${prefix}/${pkg_config_tbb_lib_dir} -ltbb")
endif()
if(ENABLE_SYSTEM_PUGIXML AND PkgConfig_FOUND)
if(ENABLE_SYSTEM_PUGIXML)
pkg_check_modules(PKGCONFIG_pugixml QUIET
NO_CMAKE_PATH
NO_CMAKE_ENVIRONMENT_PATH
pugixml)
set(pugixml_dep "pugixml = ${PKGCONFIG_pugixml_VERSION}")
if(PKGCONFIG_OpenVINO_REQUIRES_PRIVATE)
set(PKGCONFIG_OpenVINO_REQUIRES_PRIVATE "${PKGCONFIG_OpenVINO_REQUIRES_PRIVATE}, ${pugixml_dep}")
else()
set(PKGCONFIG_OpenVINO_REQUIRES_PRIVATE "${pugixml_dep}")
endif()
endif()
# detect <multiarch-triplet>
if(CPACK_GENERATOR STREQUAL "DEB")
# TODO: find a better way to detect <multiarch-triplet>
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# note: clang provides different output like 'x86_64-pc-linux-gnu', so it's not used
execute_process(COMMAND "${CMAKE_C_COMPILER}" -dumpmachine
OUTPUT_VARIABLE PKGCONFIG_OpenVINO_TRIPLET
ERROR_VARIABLE error_message
RESULT_VARIABLE exit_code
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT exit_code EQUAL 0)
message(WARNING "Internal error: failed to detect library <multiarch-triplet> ${error_message}")
set(generate_pkgconfig OFF)
if(pugixml_buggy_pkgconfig)
if(PKGCONFIG_OpenVINO_PRIVATE_DEPS)
set(PKGCONFIG_OpenVINO_PRIVATE_DEPS "${PKGCONFIG_OpenVINO_PRIVATE_DEPS} -lpugixml")
else()
set(PKGCONFIG_OpenVINO_PRIVATE_DEPS "-lpugixml")
endif()
else()
# cannot detect <multiarch-triplet>
set(generate_pkgconfig OFF)
if(PKGCONFIG_OpenVINO_REQUIRES_PRIVATE)
set(PKGCONFIG_OpenVINO_REQUIRES_PRIVATE "${PKGCONFIG_OpenVINO_REQUIRES_PRIVATE}, ${pugixml_dep}")
else()
set(PKGCONFIG_OpenVINO_REQUIRES_PRIVATE "${pugixml_dep}")
endif()
endif()
endif()
# define relative paths
file(RELATIVE_PATH PKGCONFIG_OpenVINO_PREFIX "/${OV_CPACK_RUNTIMEDIR}/pkgconfig" "/")
if(generate_pkgconfig)
set(pkgconfig_in "${OpenVINO_SOURCE_DIR}/cmake/templates/openvino.pc.in")
set(pkgconfig_out "${OpenVINO_BINARY_DIR}/share/openvino.pc")
configure_file("${pkgconfig_in}" "${pkgconfig_out}" @ONLY)
set(pkgconfig_in "${OpenVINO_SOURCE_DIR}/cmake/templates/openvino.pc.in")
set(pkgconfig_out "${OpenVINO_BINARY_DIR}/share/openvino.pc")
configure_file("${pkgconfig_in}" "${pkgconfig_out}" @ONLY)
install(FILES "${pkgconfig_out}"
DESTINATION "${OV_CPACK_RUNTIMEDIR}/pkgconfig"
COMPONENT ${OV_CPACK_COMP_CORE_DEV})
install(FILES "${pkgconfig_out}"
DESTINATION "${OV_CPACK_RUNTIMEDIR}/pkgconfig"
COMPONENT ${OV_CPACK_COMP_CORE_DEV})
add_custom_command(TARGET openvino PRE_BUILD
COMMAND "${PKG_CONFIG_EXECUTABLE}" --validate "${pkgconfig_out}"
COMMENT "[pkg-config] validating openvino.pc"
VERBATIM)
endif()
add_custom_command(TARGET openvino PRE_BUILD
COMMAND "${PKG_CONFIG_EXECUTABLE}" --validate "${pkgconfig_out}"
COMMAND cat "${pkgconfig_out}"
COMMENT "[pkg-config] validating openvino.pc"
VERBATIM)
endif()
+48 -9
View File
@@ -47,36 +47,72 @@ endif()
#
if(ENABLE_SYSTEM_PUGIXML)
find_package(PkgConfig QUIET)
# try system pugixml first
find_package(PugiXML QUIET)
if(PugiXML_FOUND)
if(TARGET pugixml::shared)
# example: cross-compilation on debian
set(pugixml_target pugixml::shared)
elseif(TARGET pugixml::static)
# sometimes pugixml::static target already exists, just need to make it global
# example: building using conda environment
set(pugixml_target pugixml::static)
elseif(TARGET pugixml)
# or create an alias for pugixml shared library
# example: libpugixml-dev debian package
set(pugixml_target pugixml)
elseif(TARGET pugixml::static)
# sometimes pugixml::static target already exists, just need to make it global
# example: building using conda environment
set(pugixml_target pugixml::static)
else()
message(FATAL_ERROR "Failed to detect pugixml library target name")
endif()
elseif(PkgConfig_FOUND)
# U18 case when cmake interface is not available
pkg_search_module(pugixml QUIET
IMPORTED_TARGET GLOBAL
pugixml)
if(pugixml_FOUND)
set(pugixml_target PkgConfig::pugixml)
# PATCH: on Ubuntu 18.04 pugixml.pc contains incorrect include directories
get_target_property(interface_include_dir ${pugixml_target} INTERFACE_INCLUDE_DIRECTORIES)
if(interface_include_dir AND NOT EXISTS "${interface_include_dir}")
set_target_properties(${pugixml_target} PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "")
# buggy pugixml.pc does not allow to work with openvino.pc well
set(pugixml_buggy_pkgconfig ON CACHE INTERNAL "" FORCE)
message(WARNING "openvino.pc pkg-config file generation has turned off because it should have to depend on pugixml.pc")
endif()
message(STATUS "${PKG_CONFIG_EXECUTABLE}: pugixml (${pugixml_VERSION}) is found at ${pugixml_PREFIX}")
endif()
endif()
if(TARGET ${pugixml_target})
# we need to install dynamic library for wheel package
get_target_property(target_type ${pugixml_target} TYPE)
if(target_type STREQUAL "SHARED_LIBRARY")
ie_cpack_add_component(pugixml HIDDEN)
get_target_property(imported_config ${pugixml_target} IMPORTED_CONFIGURATIONS)
get_target_property(pugixml_loc ${pugixml_target} IMPORTED_LOCATION_${imported_config})
get_target_property(pugixml_soname_loc ${pugixml_target} IMPORTED_SONAME_${imported_config})
get_filename_component(pugixml_dir "${pugixml_loc}" DIRECTORY)
install(FILES "${pugixml_loc}"
"${pugixml_dir}/${pugixml_soname_loc}"
get_target_property(pugixml_soname_loc ${pugixml_target} IMPORTED_SONAME_${imported_config})
set(pugixml_libs "${pugixml_loc}" "${pugixml_dir}/${pugixml_soname_loc}")
elseif(target_type STREQUAL "INTERFACE_LIBRARY")
get_target_property(pugixml_loc ${pugixml_target} INTERFACE_LINK_LIBRARIES)
file(GLOB pugixml_libs_all "${pugixml_loc}.*")
foreach(pugixml_lib IN LISTS pugixml_libs_all)
if(pugixml_lib MATCHES "^${pugixml_loc}(\.[0-9]+)+$")
list(APPEND pugixml_libs "${pugixml_lib}")
endif()
endforeach()
endif()
# if dynamic libpugixml.so.1 and libpugixml.so.1.X are found
if(pugixml_libs)
ie_cpack_add_component(pugixml HIDDEN)
install(FILES ${pugixml_libs}
DESTINATION runtime/3rdparty/pugixml/lib
COMPONENT pugixml EXCLUDE_FROM_ALL)
COMPONENT pugixml
EXCLUDE_FROM_ALL)
elseif(CPACK_GENERATOR STREQUAL "DEB")
message(FATAL_ERROR "Debian package build requires shared Pugixml library")
endif()
set_target_properties(${pugixml_target} PROPERTIES IMPORTED_GLOBAL ON)
@@ -235,6 +271,9 @@ if(CPACK_GENERATOR STREQUAL "DEB")
if(NOT zlib_FOUND)
message(FATAL_ERROR "zlib must be used as a debian package. Install zlib1g-dev")
endif()
if(NOT ENABLE_SYSTEM_PUGIXML)
message(FATAL_ERROR "Pugixml must be used as a debian package. Install libpugixml-dev")
endif()
else()
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/gflags
DESTINATION ${OV_CPACK_SAMPLESDIR}/cpp/thirdparty