From f7ed978beeee3117fcbb30354e47f40da060f23a Mon Sep 17 00:00:00 2001 From: HaseenaSainul <41037131+HaseenaSainul@users.noreply.github.com> Date: Tue, 26 Oct 2021 09:14:02 +0530 Subject: [PATCH] FindPackage.cmake:Added support to handle REQUIRED and QUIET (#103) --- DeviceIdentification/CMakeLists.txt | 2 +- DeviceIdentification/cmake/FindBCM_HOST.cmake | 20 +++++++----- .../cmake/FindMFRFWLibs.cmake | 31 ++++++++++--------- DeviceIdentification/cmake/FindNEXUS.cmake | 10 ++---- DeviceIdentification/cmake/FindNXCLIENT.cmake | 8 ++--- Packager/cmake/FindGLIB.cmake | 10 ++++-- Packager/cmake/FindLibOPKG.cmake | 12 +++++-- Packager/cmake/FindSqlite.cmake | 8 +++-- Packager/cmake/FindSqliteSee.cmake | 7 ++++- WebKitBrowser/cmake/FindAampJSBindings.cmake | 2 +- WebKitBrowser/cmake/FindWPEBackend.cmake | 27 ++++++++-------- WebKitBrowser/cmake/FindWPEWebKit.cmake | 8 ++--- 12 files changed, 82 insertions(+), 63 deletions(-) diff --git a/DeviceIdentification/CMakeLists.txt b/DeviceIdentification/CMakeLists.txt index ca2e42540e..88282477bd 100644 --- a/DeviceIdentification/CMakeLists.txt +++ b/DeviceIdentification/CMakeLists.txt @@ -50,7 +50,7 @@ if (PLUGIN_DEVICEIDENTIFICATION_USE_MFR AND MFRFWLIBS_FOUND) Implementation/MFR/MFR.cpp) target_link_libraries(${MODULE_NAME} PRIVATE - mfrfwlibs::mfrfwlibs) + MFRFWLibs::MFRFWLibs) elseif (BUILD_BROADCOM) target_sources(${MODULE_NAME} PRIVATE diff --git a/DeviceIdentification/cmake/FindBCM_HOST.cmake b/DeviceIdentification/cmake/FindBCM_HOST.cmake index ab7c47d979..b5a1062ed0 100644 --- a/DeviceIdentification/cmake/FindBCM_HOST.cmake +++ b/DeviceIdentification/cmake/FindBCM_HOST.cmake @@ -27,22 +27,26 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -find_package(PkgConfig) -pkg_check_modules(PC_BCM_HOST bcm_host) - -include(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(PC_BCM_HOST DEFAULT_MSG PC_BCM_HOST_FOUND) +if(BCM_HOST_FIND_QUIETLY) + set(_BCM_HOST_MODE QUIET) +elseif(BCM_HOST_FIND_REQUIRED) + set(_BCM_HOST_MODE REQUIRED) +endif() -mark_as_advanced(PC_BCM_HOST_INCLUDE_DIRS PC_BCM_HOST_LIBRARIES) +find_package(PkgConfig) +pkg_check_modules(PC_BCM_HOST ${_BCM_HOST_MODE} bcm_host) if(${PC_BCM_HOST_FOUND}) find_library(BCM_HOST_LIBRARY bcm_host HINTS ${PC_BCM_LIBDIR} ${PC_BCM_LIBRARY_DIRS} ) set(BCM_LIBRARIES ${PC_BCM_HOST_LIBRARIES}) - set(BCM_HOST_FOUND ${PC_BCM_HOST_FOUND}) - if(NOT TARGET BCM_HOST::BCM_HOST) + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(BCM_HOST DEFAULT_MSG PC_BCM_HOST_FOUND PC_BCM_HOST_INCLUDE_DIRS BCM_HOST_LIBRARY PC_BCM_HOST_LIBRARIES) + mark_as_advanced(PC_BCM_HOST_INCLUDE_DIRS PC_BCM_HOST_LIBRARIES) + + if(BCM_HOST_FOUND AND NOT TARGET BCM_HOST::BCM_HOST) add_library(BCM_HOST::BCM_HOST UNKNOWN IMPORTED) set_target_properties(BCM_HOST::BCM_HOST diff --git a/DeviceIdentification/cmake/FindMFRFWLibs.cmake b/DeviceIdentification/cmake/FindMFRFWLibs.cmake index 541ac454b3..287b072655 100644 --- a/DeviceIdentification/cmake/FindMFRFWLibs.cmake +++ b/DeviceIdentification/cmake/FindMFRFWLibs.cmake @@ -1,8 +1,8 @@ # - Try to find MFRFWLIBS # Once done this will define -# MFRFWLIBS_FOUND - System has mfrfwlibs -# MFRFWLIBS_INCLUDE_DIRS - The mfrfwlibs include directories -# MFRFWLIBS_LIBRARIES - The libraries needed to use mfrfwlibs +# MFRFWLIBS_FOUND - System has MFRFWLibs +# MFRFWLIBS_INCLUDE_DIRS - The MFRFWLibs include directories +# MFRFWLIBS_LIBRARIES - The libraries needed to use MFRFWLibs # # Copyright (C) 2019 Metrological. # @@ -27,22 +27,25 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE -find_package(PkgConfig) -pkg_check_modules(MFRFWLIBS fwupgrade) - -include(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(mfrfwlibs DEFAULT_MSG MFRFWLIBS_LIBRARIES) - -mark_as_advanced(MFRFWLIBS_INCLUDE_DIRS MFRFWLIBS_LIBRARIES) - +if(MFRFWLibs_FIND_QUIETLY) + set(_MFRFWLIBS_MODE QUIET) +elseif(MFRFWLibs_FIND_REQUIRED) + set(_MFRFWLIBS_MODE REQUIRED) +endif() +find_package(PkgConfig) +pkg_check_modules(MFRFWLIBS ${_MFRFWLIBS_MODE} fwupgrade) find_library(MFRFWLIBS_LIBRARY NAMES ${MFRFWLIBS_LIBRARIES} HINTS ${MFRFWLIBS_LIBDIR} ${MFRFWLIBS_LIBRARY_DIRS} ) -if(MFRFWLIBS_LIBRARY AND NOT TARGET mfrfwlibs::mfrfwlibs) - add_library(mfrfwlibs::mfrfwlibs UNKNOWN IMPORTED) - set_target_properties(mfrfwlibs::mfrfwlibs PROPERTIES +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(MFRFWLibs DEFAULT_MSG MFRFWLIBS_LIBRARY MFRFWLIBS_LIBRARIES) +mark_as_advanced(MFRFWLIBS_INCLUDE_DIRS MFRFWLIBS_LIBRARIES) + +if(MFRFWLibs_FOUND AND NOT TARGET MFRFWLibs::MFRFWLibs) + add_library(MFRFWLibs::MFRFWLibs UNKNOWN IMPORTED) + set_target_properties(MFRFWLibs::MFRFWLibs PROPERTIES IMPORTED_LOCATION "${MFRFWLIBS_LIBRARY}" INTERFACE_LINK_LIBRARIES "${MFRFWLIBS_LIBRARIES}" INTERFACE_COMPILE_OPTIONS "${MFRFWLIBS_DEFINITIONS}" diff --git a/DeviceIdentification/cmake/FindNEXUS.cmake b/DeviceIdentification/cmake/FindNEXUS.cmake index 65ccaf98fb..0df19eb6ad 100644 --- a/DeviceIdentification/cmake/FindNEXUS.cmake +++ b/DeviceIdentification/cmake/FindNEXUS.cmake @@ -32,21 +32,15 @@ find_path(LIBNEXUS_INCLUDE nexus_config.h find_library(LIBNEXUS_LIBRARY nexus) if(EXISTS "${LIBNEXUS_LIBRARY}") - set(NEXUS_FOUND TRUE) - find_library(LIBB_OS_LIBRARY b_os) - find_library(LIBNEXUS_CLIENT_LIBRARY nexus_client) - find_library(LIBNXCLIENT_LIBRARY nxclient) include(FindPackageHandleStandardArgs) - - find_package_handle_standard_args(LIBNEXUS DEFAULT_MSG LIBNEXUS_INCLUDE LIBNEXUS_LIBRARY) - + find_package_handle_standard_args(NEXUS DEFAULT_MSG LIBNEXUS_INCLUDE LIBNEXUS_LIBRARY) mark_as_advanced(LIBNEXUS_INCLUDE LIBNEXUS_LIBRARY) - if(NOT TARGET NEXUS::NEXUS) + if(NEXUS_FOUND AND NOT TARGET NEXUS::NEXUS) add_library(NEXUS::NEXUS UNKNOWN IMPORTED) set_target_properties(NEXUS::NEXUS PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C" diff --git a/DeviceIdentification/cmake/FindNXCLIENT.cmake b/DeviceIdentification/cmake/FindNXCLIENT.cmake index a5feb1c0ea..a718dbc24b 100644 --- a/DeviceIdentification/cmake/FindNXCLIENT.cmake +++ b/DeviceIdentification/cmake/FindNXCLIENT.cmake @@ -33,15 +33,11 @@ find_library(LIBNXCLIENT_LIBRARY nxclient) if(EXISTS "${LIBNXCLIENT_LIBRARY}") include(FindPackageHandleStandardArgs) - - set(NXCLIENT_FOUND TRUE) - - find_package_handle_standard_args(LIBNXCLIENT DEFAULT_MSG NXCLIENT_FOUND LIBNXCLIENT_INCLUDE LIBNXCLIENT_LIBRARY) + find_package_handle_standard_args(NXCLIENT DEFAULT_MSG LIBNXCLIENT_INCLUDE LIBNXCLIENT_LIBRARY) mark_as_advanced(LIBNXCLIENT_LIBRARY) - if(NOT TARGET NXCLIENT::NXCLIENT) + if(NXCLIENT_FOUND AND NOT TARGET NXCLIENT::NXCLIENT) add_library(NXCLIENT::NXCLIENT UNKNOWN IMPORTED) - set_target_properties(NXCLIENT::NXCLIENT PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C" IMPORTED_LOCATION "${LIBNXCLIENT_LIBRARY}" diff --git a/Packager/cmake/FindGLIB.cmake b/Packager/cmake/FindGLIB.cmake index 93d3ec5479..a04991af0e 100644 --- a/Packager/cmake/FindGLIB.cmake +++ b/Packager/cmake/FindGLIB.cmake @@ -41,8 +41,14 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +if(GLIB_FIND_QUIETLY) + set(_GLIB_MODE QUIET) +elseif(GLIB_FIND_REQUIRED) + set(_GLIB_MODE REQUIRED) +endif() + find_package(PkgConfig) -pkg_check_modules(PC_GLIB QUIET glib-2.0) +pkg_check_modules(PC_GLIB ${_GLIB_MODE} glib-2.0) find_library(GLIB_LIBRARIES NAMES glib-2.0 @@ -106,7 +112,7 @@ foreach (_component ${GLIB_FIND_COMPONENTS}) endforeach () include(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLIB REQUIRED_VARS GLIB_INCLUDE_DIRS GLIB_LIBRARIES ${ADDITIONAL_REQUIRED_VARS} +find_package_handle_standard_args(GLIB REQUIRED_VARS GLIB_INCLUDE_DIRS GLIB_LIBRARIES ${ADDITIONAL_REQUIRED_VARS} VERSION_VAR GLIB_VERSION) mark_as_advanced( diff --git a/Packager/cmake/FindLibOPKG.cmake b/Packager/cmake/FindLibOPKG.cmake index e948d98283..224a30851a 100644 --- a/Packager/cmake/FindLibOPKG.cmake +++ b/Packager/cmake/FindLibOPKG.cmake @@ -21,8 +21,15 @@ # LIBOPKG_INCLUDE_DIRS - The libopkg include directories # LIBOPKG_LIBRARIES - The libraries needed to use libopkg # + +if(LibOPKG_FIND_QUIETLY) + set(_LIBOPKG_MODE QUIET) +elseif(LibOPKG_FIND_REQUIRED) + set(_LIBOPKG_MODE REQUIRED) +endif() + find_package(PkgConfig) -pkg_check_modules(PC_LIBOPKG libopkg) +pkg_check_modules(PC_LIBOPKG ${_LIBOPKG_MODE} libopkg) if(PC_LIBOPKG_FOUND) if(LIBOPKG_FIND_VERSION AND PC_LIBOPKG_VERSION) @@ -43,7 +50,8 @@ set(LIBOPKG_LIBRARIES ${PC_LIBOPKG_LIBRARIES}) set(LIBOPKG_LIBRARY_DIRS ${PC_LIBOPKG_LIBRARY_DIRS} ${PC_LIBOPKG_LIBDIR}) find_library(OPKG_LIBRARY_LOCATION "${LIBOPKG_LIBRARIES}") - +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(LibOPKG DEFAULT_MSG OPKG_LIBRARY_LOCATION LIBOPKG_INCLUDE_DIRS LIBOPKG_LIBRARIES) mark_as_advanced(LIBOPKG_DEFINITIONS LIBOPKG_INCLUDE_DIRS LIBOPKG_LIBRARIES) if(NOT TARGET LibOPKG::LibOPKG) diff --git a/Packager/cmake/FindSqlite.cmake b/Packager/cmake/FindSqlite.cmake index af0e2591f6..5888ca329f 100644 --- a/Packager/cmake/FindSqlite.cmake +++ b/Packager/cmake/FindSqlite.cmake @@ -1,3 +1,7 @@ find_package(PkgConfig) - -pkg_search_module(SQLITE REQUIRED sqlite3) +if(Sqlite_FIND_QUIETLY) + set(_SQLITE_MODE QUIET) +elseif(Sqlite_FIND_REQUIRED) + set(_SQLITE_MODE REQUIRED) +endif() +pkg_search_module(SQLITE ${_SQLITE_MODE} sqlite3) diff --git a/Packager/cmake/FindSqliteSee.cmake b/Packager/cmake/FindSqliteSee.cmake index a9baf61a10..eb94aeeeba 100644 --- a/Packager/cmake/FindSqliteSee.cmake +++ b/Packager/cmake/FindSqliteSee.cmake @@ -1,3 +1,8 @@ find_package(PkgConfig) -pkg_search_module(SQLITE REQUIRED sqlite3see) +if(SqliteSee_FIND_QUIETLY) + set(_SQLITE_SEE_MODE QUIET) +elseif(SqliteSee_FIND_REQUIRED) + set(_SQLITE_SEE_MODE REQUIRED) +endif() +pkg_search_module(SQLITE_SEE ${_SQLITE_SEE_MODE} sqlite3see) diff --git a/WebKitBrowser/cmake/FindAampJSBindings.cmake b/WebKitBrowser/cmake/FindAampJSBindings.cmake index 2d8ad50dda..fea3dea2cc 100644 --- a/WebKitBrowser/cmake/FindAampJSBindings.cmake +++ b/WebKitBrowser/cmake/FindAampJSBindings.cmake @@ -19,6 +19,6 @@ find_library(AAMP_JSBINDINGS_LIBRARIES aampjsbindings) include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(AAMP_JSBINDINGS DEFAULT_MSG AAMP_JSBINDINGS_LIBRARIES) +find_package_handle_standard_args(AampJSBindings DEFAULT_MSG AAMP_JSBINDINGS_LIBRARIES) mark_as_advanced(AAMP_JSBINDINGS_LIBRARIES) diff --git a/WebKitBrowser/cmake/FindWPEBackend.cmake b/WebKitBrowser/cmake/FindWPEBackend.cmake index aaf0e9ef7f..b86d0dfe3f 100644 --- a/WebKitBrowser/cmake/FindWPEBackend.cmake +++ b/WebKitBrowser/cmake/FindWPEBackend.cmake @@ -47,19 +47,18 @@ if(PC_WPE_BACKEND_FOUND) NAMES ${PC_WPE_BACKEND_LIBRARIES} HINTS ${PC_WPE_BACKEND_LIBDIR} ${PC_WPE_BACKEND_LIBRARY_DIRS} ) +endif() - include(FindPackageHandleStandardArgs) - find_package_handle_standard_args(WPEBackend - VERSION_VAR PC_WPE_BACKEND_VERSION - REQUIRED_VARS WPE_BACKEND_LIBRARY WPE_BACKEND_INCLUDE_DIR WPE_BACKEND_LIBRARY) - - if(PC_WPE_BACKEND_FOUND AND NOT TARGET WPEBackend::WPEBackend) - add_library(WPEBackend::WPEBackend SHARED IMPORTED) - set_target_properties(WPEBackend::WPEBackend PROPERTIES - IMPORTED_LOCATION "${WPE_BACKEND_LIBRARY}" - INTERFACE_INCLUDE_DIRECTORIES "${WPE_BACKEND_INCLUDE_DIR}" - ) - endif() - +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(WPEBackend + VERSION_VAR PC_WPE_BACKEND_VERSION + REQUIRED_VARS WPE_BACKEND_LIBRARY WPE_BACKEND_INCLUDE_DIR) mark_as_advanced(WPE_BACKEND_INCLUDE_DIR WPE_BACKEND_LIBRARY) -endif() \ No newline at end of file + +if(WPEBackend_FOUND AND NOT TARGET WPEBackend::WPEBackend) + add_library(WPEBackend::WPEBackend SHARED IMPORTED) + set_target_properties(WPEBackend::WPEBackend PROPERTIES + IMPORTED_LOCATION "${WPE_BACKEND_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${WPE_BACKEND_INCLUDE_DIR}" + ) +endif() diff --git a/WebKitBrowser/cmake/FindWPEWebKit.cmake b/WebKitBrowser/cmake/FindWPEWebKit.cmake index 24295d2a52..40aa37ebb0 100644 --- a/WebKitBrowser/cmake/FindWPEWebKit.cmake +++ b/WebKitBrowser/cmake/FindWPEWebKit.cmake @@ -97,11 +97,13 @@ else() set(WEBKIT_GLIB_API FALSE CACHE INTERNAL "" FORCE) endif() +include(FindPackageHandleStandardArgs) find_package_handle_standard_args(WPEWebKit VERSION_VAR WPE_WEBKIT_VERSION - REQUIRED_VARS WPE_WEBKIT_LIBRARY WPE_WEBKIT_LINK_LIBRARIES WPE_WEBKIT_INCLUDE_DIRS) + REQUIRED_VARS WPE_WEBKIT_FOUND WPE_WEBKIT_LIBRARY WPE_WEBKIT_LINK_LIBRARIES WPE_WEBKIT_INCLUDE_DIRS) +mark_as_advanced(WPE_WEBKIT_LINK_LIBRARIES WPE_WEBKIT_CFLAGS WPE_WEBKIT_INCLUDE_DIRS) -if(WPE_WEBKIT_FOUND AND NOT TARGET WPEWebKit::WPEWebKit) +if(WPEWebKit_FOUND AND NOT TARGET WPEWebKit::WPEWebKit) add_library(WPEWebKit::WPEWebKit SHARED IMPORTED) set_target_properties(WPEWebKit::WPEWebKit PROPERTIES IMPORTED_LOCATION "${WPE_WEBKIT_LIBRARY}" @@ -110,5 +112,3 @@ if(WPE_WEBKIT_FOUND AND NOT TARGET WPEWebKit::WPEWebKit) INTERFACE_INCLUDE_DIRECTORIES "${WPE_WEBKIT_INCLUDE_DIRS}" ) endif() - -mark_as_advanced(WPE_WEBKIT_LINK_LIBRARIES WPE_WEBKIT_CFLAGS WPE_WEBKIT_INCLUDE_DIRS)