Skip to content

Commit

Permalink
Disable pkg-config search on Android via CMAKE_DISABLE_FIND_PACKAGE_P…
Browse files Browse the repository at this point in the history
…kgConfig (openvinotoolkit#20179)
  • Loading branch information
ilya-lavrenov authored Oct 3, 2023
1 parent 23e5964 commit d37326b
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 39 deletions.
8 changes: 8 additions & 0 deletions cmake/developer_package/IEDevScriptsConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ if(NOT DEFINED IEDevScripts_DIR)
message(FATAL_ERROR "IEDevScripts_DIR is not defined")
endif()

# disable FindPkgConfig.cmake for Android
if(ANDROID)
# 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.
set(CMAKE_DISABLE_FIND_PACKAGE_PkgConfig ON)
endif()

macro(ov_set_if_not_defined var value)
if(NOT DEFINED ${var})
set(${var} ${value})
Expand Down
6 changes: 1 addition & 5 deletions cmake/features.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ Usage: -DSELECTIVE_BUILD=ON -DSELECTIVE_BUILD_STAT=/path/*.csv" OFF

ie_option (ENABLE_DOCS "Build docs using Doxygen" OFF)

if(NOT ANDROID)
# on Android build FindPkgConfig.cmake finds host system pkg-config, which is not appropriate
find_package(PkgConfig QUIET)
endif()

find_package(PkgConfig QUIET)
ie_dependent_option (ENABLE_PKGCONFIG_GEN "Enable openvino.pc pkg-config file generation" ON "LINUX OR APPLE;PkgConfig_FOUND;BUILD_SHARED_LIBS" OFF)

#
Expand Down
12 changes: 5 additions & 7 deletions docs/snippets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ if(TARGET OpenCL::OpenCL)
endif()

# try to find VA libraries
if(NOT ANDROID)
find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
pkg_search_module(libva QUIET IMPORTED_TARGET libva)
if(libva_FOUND)
message(STATUS "${PKG_CONFIG_EXECUTABLE}: libva (${libva_VERSION}) is found at ${libva_PREFIX}")
endif()
find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
pkg_search_module(libva QUIET IMPORTED_TARGET libva)
if(libva_FOUND)
message(STATUS "${PKG_CONFIG_EXECUTABLE}: libva (${libva_VERSION}) is found at ${libva_PREFIX}")
endif()
endif()

Expand Down
8 changes: 8 additions & 0 deletions samples/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ elseif(NOT OV_GENERATOR_MULTI_CONFIG)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Release;Debug;RelWithDebInfo;MinSizeRel")
endif()

# disable FindPkgConfig.cmake for Android
if(ANDROID)
# 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.
set(CMAKE_DISABLE_FIND_PACKAGE_PkgConfig ON)
endif()

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

if (NOT BIN_FOLDER)
Expand Down
5 changes: 1 addition & 4 deletions samples/cpp/benchmark_app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ ie_add_sample(NAME ${TARGET_NAME}

# Required nlohmann_json dependency

if(NOT ANDROID)
find_package(PkgConfig QUIET)
endif()

if(NOT TARGET nlohmann_json::nlohmann_json)
find_package(PkgConfig QUIET)
find_package(nlohmann_json QUIET
# exception for Ubuntu 18.04, where cmake files for nlohmann_json
# are located in a wrong directory
Expand Down
5 changes: 1 addition & 4 deletions samples/cpp/speech_sample/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ file (GLOB HDR ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp)

# Required zlib and cnpy dependencies

if(NOT ANDROID)
find_package(PkgConfig QUIET)
endif()

find_package(ZLIB QUIET)

if(NOT TARGET ZLIB::ZLIB)
find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
pkg_search_module(zlib QUIET
IMPORTED_TARGET GLOBAL
Expand Down
4 changes: 1 addition & 3 deletions src/cmake/ov_parallel.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
# SPDX-License-Identifier: Apache-2.0
#

if(NOT ANDROID)
find_package(PkgConfig QUIET)
endif()
find_package(PkgConfig QUIET)

function(_ov_get_tbb_location tbb_target _tbb_lib_location_var)
if(NOT TBB_FOUND)
Expand Down
8 changes: 3 additions & 5 deletions src/plugins/intel_gpu/tests/functional/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@ if(ENABLE_PROXY)
endif()

# try to find VA libraries
if(NOT ANDROID)
find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
pkg_search_module(libva QUIET IMPORTED_TARGET libva)
endif()
find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
pkg_search_module(libva QUIET IMPORTED_TARGET libva)
endif()

if(libva_FOUND)
Expand Down
17 changes: 6 additions & 11 deletions thirdparty/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,12 @@ endif()
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()
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()

if(SUGGEST_OVERRIDE_SUPPORTED)
Expand Down

0 comments on commit d37326b

Please sign in to comment.