Merge topic 'FPHSA_exact_version'

ba907f7d FPHSA: fix when requested or found version is exactly 0
4f9bf446 FPHSA: when EXACT version match is requested only compare the components given
This commit is contained in:
Brad King 2014-10-08 10:48:14 -04:00 committed by CMake Topic Stage
commit b3cbb9e188
25 changed files with 89 additions and 7 deletions

View File

@ -284,18 +284,47 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG)
# version handling: # version handling:
set(VERSION_MSG "") set(VERSION_MSG "")
set(VERSION_OK TRUE) set(VERSION_OK TRUE)
set(VERSION ${${FPHSA_VERSION_VAR}} ) set(VERSION ${${FPHSA_VERSION_VAR}})
if (${_NAME}_FIND_VERSION)
if(VERSION) # check with DEFINED here as the requested or found version may be "0"
if (DEFINED ${_NAME}_FIND_VERSION)
if(DEFINED ${FPHSA_VERSION_VAR})
if(${_NAME}_FIND_VERSION_EXACT) # exact version required if(${_NAME}_FIND_VERSION_EXACT) # exact version required
# count the dots in the version string
string(REGEX REPLACE "[^.]" "" _VERSION_DOTS "${VERSION}")
# add one dot because there is one dot more than there are components
string(LENGTH "${_VERSION_DOTS}." _VERSION_DOTS)
if (_VERSION_DOTS GREATER ${_NAME}_FIND_VERSION_COUNT)
# Because of the C++ implementation of find_package() ${_NAME}_FIND_VERSION_COUNT
# is at most 4 here. Therefore a simple lookup table is used.
if (${_NAME}_FIND_VERSION_COUNT EQUAL 1)
set(_VERSION_REGEX "[^.]*")
elseif (${_NAME}_FIND_VERSION_COUNT EQUAL 2)
set(_VERSION_REGEX "[^.]*\\.[^.]*")
elseif (${_NAME}_FIND_VERSION_COUNT EQUAL 3)
set(_VERSION_REGEX "[^.]*\\.[^.]*\\.[^.]*")
else ()
set(_VERSION_REGEX "[^.]*\\.[^.]*\\.[^.]*\\.[^.]*")
endif ()
string(REGEX REPLACE "^(${_VERSION_REGEX})\\..*" "\\1" _VERSION_HEAD "${VERSION}")
unset(_VERSION_REGEX)
if (NOT ${_NAME}_FIND_VERSION VERSION_EQUAL _VERSION_HEAD)
set(VERSION_MSG "Found unsuitable version \"${VERSION}\", but required is exact version \"${${_NAME}_FIND_VERSION}\"")
set(VERSION_OK FALSE)
else ()
set(VERSION_MSG "(found suitable exact version \"${VERSION}\")")
endif ()
unset(_VERSION_HEAD)
else ()
if (NOT "${${_NAME}_FIND_VERSION}" VERSION_EQUAL "${VERSION}") if (NOT "${${_NAME}_FIND_VERSION}" VERSION_EQUAL "${VERSION}")
set(VERSION_MSG "Found unsuitable version \"${VERSION}\", but required is exact version \"${${_NAME}_FIND_VERSION}\"") set(VERSION_MSG "Found unsuitable version \"${VERSION}\", but required is exact version \"${${_NAME}_FIND_VERSION}\"")
set(VERSION_OK FALSE) set(VERSION_OK FALSE)
else () else ()
set(VERSION_MSG "(found suitable exact version \"${VERSION}\")") set(VERSION_MSG "(found suitable exact version \"${VERSION}\")")
endif () endif ()
endif ()
unset(_VERSION_DOTS)
else() # minimum version specified: else() # minimum version specified:
if ("${${_NAME}_FIND_VERSION}" VERSION_GREATER "${VERSION}") if ("${${_NAME}_FIND_VERSION}" VERSION_GREATER "${VERSION}")

View File

@ -0,0 +1,6 @@
# pseudo find_module
set(FOOBAR TRUE)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Pseudo REQUIRED_VARS FOOBAR VERSION_VAR Pseudo_VERSION)

View File

@ -1,3 +1,28 @@
include(RunCMake) include(RunCMake)
run_cmake(BadFoundVar) run_cmake(BadFoundVar)
# The pseudo module will "find" a package with the given version. Check if the
# version selection code in FPHSA works correctly.
set(RunCMake_TEST_OPTIONS "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}" "-DPseudo_VERSION=1.2.3.4.5")
run_cmake(any_version)
# test EXACT mode with every subcomponent
run_cmake(exact_1)
run_cmake(exact_1.2)
run_cmake(exact_1.2.3)
run_cmake(exact_1.2.3.4)
# now test every component with an invalid version
run_cmake(exact_0)
run_cmake(exact_2)
run_cmake(exact_1.1)
run_cmake(exact_1.3)
run_cmake(exact_1.2.2)
run_cmake(exact_1.2.4)
run_cmake(exact_1.2.3.3)
run_cmake(exact_1.2.3.5)
# check if searching for a version 0 works
list(APPEND RunCMake_TEST_OPTIONS "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}" "-DPseudo_VERSION=0")
run_cmake(exact_0_matching)

View File

@ -0,0 +1 @@
find_package(Pseudo REQUIRED)

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1 @@
find_package(Pseudo 0 EXACT REQUIRED)

View File

@ -0,0 +1 @@
find_package(Pseudo 0 EXACT REQUIRED)

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1 @@
find_package(Pseudo 1.1 EXACT REQUIRED)

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1 @@
find_package(Pseudo 1.2.2 EXACT REQUIRED)

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1 @@
find_package(Pseudo 1.2.3.3 EXACT REQUIRED)

View File

@ -0,0 +1 @@
find_package(Pseudo 1.2.3.4 EXACT REQUIRED)

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1 @@
find_package(Pseudo 1.2.3.5 EXACT REQUIRED)

View File

@ -0,0 +1 @@
find_package(Pseudo 1.2.3 EXACT REQUIRED)

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1 @@
find_package(Pseudo 1.2.4 EXACT REQUIRED)

View File

@ -0,0 +1 @@
find_package(Pseudo 1.2 EXACT REQUIRED)

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1 @@
find_package(Pseudo 1.3 EXACT REQUIRED)

View File

@ -0,0 +1 @@
find_package(Pseudo 1 EXACT REQUIRED)

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1 @@
find_package(Pseudo 2 EXACT REQUIRED)