From 86f7acbbb977cedaa7ea8e931029880fe10aa395 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Mon, 6 Sep 2021 15:39:20 -0700 Subject: [PATCH] CMake: Add version checking in find_feature --- src/platform/cmake/FindFeature.cmake | 47 ++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/src/platform/cmake/FindFeature.cmake b/src/platform/cmake/FindFeature.cmake index 50e0c57d3..4a3fa5276 100644 --- a/src/platform/cmake/FindFeature.cmake +++ b/src/platform/cmake/FindFeature.cmake @@ -7,22 +7,57 @@ function(find_feature FEATURE_NAME FEATURE_REQUIRES) set(${FEATURE_NAME} OFF PARENT_SCOPE) return() endif() + if(ARGV2) + set(VERSION "${ARGV2}") + set(FIND_VERSION "${VERSION}" EXACT) + set(PKG_CONFIG_VERSION_CHECK " >=${VERSION}") + else() + set(VERSION) + set(FIND_VERSION) + set(PKG_CONFIG_VERSION_CHECK) + endif() foreach(NAMES ${FEATURE_REQUIRES}) string(REPLACE "|" ";" NAMELIST "${NAMES}") set(FOUND OFF) foreach(REQUIRE ${NAMELIST}) if(NOT ${REQUIRE}_FOUND) - find_package(${REQUIRE} QUIET) + find_package(${REQUIRE} ${FIND_VERSION} QUIET) if(NOT ${REQUIRE}_FOUND) - pkg_search_module(${REQUIRE} ${REQUIRE}) + pkg_search_module(${REQUIRE} "${REQUIRE}${PKG_CONFIG_VERSION_CHECK}") endif() endif() if(${REQUIRE}_FOUND) string(TOUPPER ${REQUIRE} UREQUIRE) - set(${UREQUIRE}_CFLAGS_OTHER ${${REQUIRE}_CFLAGS_OTHER} PARENT_SCOPE) - set(${UREQUIRE}_FOUND ${${REQUIRE}_FOUND} PARENT_SCOPE) - set(${UREQUIRE}_INCLUDE_DIRS ${${REQUIRE}_INCLUDE_DIRS} PARENT_SCOPE) - set(${UREQUIRE}_VERSION_STRING ${${REQUIRE}_VERSION_STRING} PARENT_SCOPE) + if(DEFINED ${REQUIRE}_CFLAGS_OTHER) + set(${UREQUIRE}_CFLAGS_OTHER ${${REQUIRE}_CFLAGS_OTHER} PARENT_SCOPE) + elseif(DEFINED ${UREQUIRE}_CFLAGS_OTHER) + set(${UREQUIRE}_CFLAGS_OTHER ${${UREQUIRE}_CFLAGS_OTHER} PARENT_SCOPE) + endif() + if(DEFINED ${REQUIRE}_FOUND) + set(${UREQUIRE}_FOUND ${${REQUIRE}_FOUND} PARENT_SCOPE) + elseif(DEFINED ${UREQUIRE}_FOUND) + set(${UREQUIRE}_FOUND ${${UREQUIRE}_FOUND} PARENT_SCOPE) + endif() + if(DEFINED ${REQUIRE}_INCLUDE_DIRS) + set(${UREQUIRE}_INCLUDE_DIRS ${${REQUIRE}_INCLUDE_DIRS} PARENT_SCOPE) + elseif(DEFINED ${UREQUIRE}_INCLUDE_DIRS) + set(${UREQUIRE}_INCLUDE_DIRS ${${UREQUIRE}_INCLUDE_DIRS} PARENT_SCOPE) + endif() + if(DEFINED ${REQUIRE}_VERSION_STRING) + set(${UREQUIRE}_VERSION_STRING ${${REQUIRE}_VERSION_STRING} PARENT_SCOPE) + elseif(DEFINED ${UREQUIRE}_VERSION_STRING) + set(${UREQUIRE}_VERSION_STRING ${${UREQUIRE}_VERSION_STRING} PARENT_SCOPE) + endif() + if(DEFINED ${REQUIRE}_VERSION_MAJOR) + set(${UREQUIRE}_VERSION_MAJOR ${${REQUIRE}_VERSION_MAJOR} PARENT_SCOPE) + elseif(DEFINED ${UREQUIRE}_VERSION_MAJOR) + set(${UREQUIRE}_VERSION_MAJOR ${${UREQUIRE}_VERSION_MAJOR} PARENT_SCOPE) + endif() + if(DEFINED ${REQUIRE}_VERSION_MINOR) + set(${UREQUIRE}_VERSION_MINOR ${${REQUIRE}_VERSION_MINOR} PARENT_SCOPE) + elseif(DEFINED ${UREQUIRE}_VERSION_MINOR) + set(${UREQUIRE}_VERSION_MINOR ${${UREQUIRE}_VERSION_MINOR} PARENT_SCOPE) + endif() if (APPLE) set(IS_FRAMEWORK OFF) set(LIBS)