From d37326b37eec21501fe0177deaa71239ede656ef Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Tue, 3 Oct 2023 09:16:56 +0400 Subject: [PATCH] Disable pkg-config search on Android via CMAKE_DISABLE_FIND_PACKAGE_PkgConfig (#20179) --- .../developer_package/IEDevScriptsConfig.cmake | 8 ++++++++ cmake/features.cmake | 6 +----- docs/snippets/CMakeLists.txt | 12 +++++------- samples/cpp/CMakeLists.txt | 8 ++++++++ samples/cpp/benchmark_app/CMakeLists.txt | 5 +---- samples/cpp/speech_sample/CMakeLists.txt | 5 +---- src/cmake/ov_parallel.cmake | 4 +--- .../intel_gpu/tests/functional/CMakeLists.txt | 8 +++----- thirdparty/dependencies.cmake | 17 ++++++----------- 9 files changed, 34 insertions(+), 39 deletions(-) diff --git a/cmake/developer_package/IEDevScriptsConfig.cmake b/cmake/developer_package/IEDevScriptsConfig.cmake index e1ccba489fc..6a3bd84b465 100644 --- a/cmake/developer_package/IEDevScriptsConfig.cmake +++ b/cmake/developer_package/IEDevScriptsConfig.cmake @@ -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}) diff --git a/cmake/features.cmake b/cmake/features.cmake index 5f5a58d2daf..455db56d28a 100644 --- a/cmake/features.cmake +++ b/cmake/features.cmake @@ -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) # diff --git a/docs/snippets/CMakeLists.txt b/docs/snippets/CMakeLists.txt index 273f5a4ffae..d9c87955266 100644 --- a/docs/snippets/CMakeLists.txt +++ b/docs/snippets/CMakeLists.txt @@ -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() diff --git a/samples/cpp/CMakeLists.txt b/samples/cpp/CMakeLists.txt index 714cc0a3016..ea3448522de 100644 --- a/samples/cpp/CMakeLists.txt +++ b/samples/cpp/CMakeLists.txt @@ -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) diff --git a/samples/cpp/benchmark_app/CMakeLists.txt b/samples/cpp/benchmark_app/CMakeLists.txt index 1ec22b20cb0..c79615130c2 100644 --- a/samples/cpp/benchmark_app/CMakeLists.txt +++ b/samples/cpp/benchmark_app/CMakeLists.txt @@ -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 diff --git a/samples/cpp/speech_sample/CMakeLists.txt b/samples/cpp/speech_sample/CMakeLists.txt index f37ef003341..092ebf14807 100644 --- a/samples/cpp/speech_sample/CMakeLists.txt +++ b/samples/cpp/speech_sample/CMakeLists.txt @@ -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 diff --git a/src/cmake/ov_parallel.cmake b/src/cmake/ov_parallel.cmake index 2d66146c699..f669b7b1562 100644 --- a/src/cmake/ov_parallel.cmake +++ b/src/cmake/ov_parallel.cmake @@ -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) diff --git a/src/plugins/intel_gpu/tests/functional/CMakeLists.txt b/src/plugins/intel_gpu/tests/functional/CMakeLists.txt index d37f2abb20d..e784d57d291 100644 --- a/src/plugins/intel_gpu/tests/functional/CMakeLists.txt +++ b/src/plugins/intel_gpu/tests/functional/CMakeLists.txt @@ -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) diff --git a/thirdparty/dependencies.cmake b/thirdparty/dependencies.cmake index eb4cd25aaf5..8ef6c5bf1c5 100644 --- a/thirdparty/dependencies.cmake +++ b/thirdparty/dependencies.cmake @@ -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)