Commit d6df882a authored by Brad King's avatar Brad King 💬 Committed by Kitware Robot
Browse files

Merge topic 'find_dependency-improvements'

ab358d6a

 Improve find_dependency argument handling

Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !872
parents a9b11235 ab358d6a
......@@ -7,38 +7,20 @@
#
# ::
#
# find_dependency(<dep> [<version> [EXACT]])
# find_dependency(<dep> [...])
#
#
# ``find_dependency()`` wraps a :command:`find_package` call for a package
# dependency. It is designed to be used in a <package>Config.cmake file, and it
# forwards the correct parameters for EXACT, QUIET and REQUIRED which were
# passed to the original :command:`find_package` call. It also sets an
# informative diagnostic message if the dependency could not be found.
# forwards the correct parameters for QUIET and REQUIRED which were passed to
# the original :command:`find_package` call. It also sets an informative
# diagnostic message if the dependency could not be found.
#
# Any additional arguments specified are forwarded to :command:`find_package`.
#
macro(find_dependency dep)
if (NOT ${dep}_FOUND)
set(cmake_fd_version)
if (${ARGC} GREATER 1)
if ("${ARGV1}" STREQUAL "")
message(FATAL_ERROR "Invalid arguments to find_dependency. VERSION is empty")
endif()
if ("${ARGV1}" STREQUAL EXACT)
message(FATAL_ERROR "Invalid arguments to find_dependency. EXACT may only be specified if a VERSION is specified")
endif()
set(cmake_fd_version ${ARGV1})
endif()
set(cmake_fd_exact_arg)
if(${ARGC} GREATER 2)
if (NOT "${ARGV2}" STREQUAL EXACT)
message(FATAL_ERROR "Invalid arguments to find_dependency")
endif()
set(cmake_fd_exact_arg EXACT)
endif()
if(${ARGC} GREATER 3)
message(FATAL_ERROR "Invalid arguments to find_dependency")
endif()
set(cmake_fd_quiet_arg)
if(${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)
set(cmake_fd_quiet_arg QUIET)
......@@ -52,10 +34,9 @@ macro(find_dependency dep)
_CMAKE_${dep}_TRANSITIVE_DEPENDENCY
)
find_package(${dep} ${cmake_fd_version}
${cmake_fd_exact_arg}
${cmake_fd_quiet_arg}
${cmake_fd_required_arg}
find_package(${dep} ${ARGN}
${cmake_fd_quiet_arg}
${cmake_fd_required_arg}
)
if(NOT DEFINED cmake_fd_alreadyTransitive OR cmake_fd_alreadyTransitive)
......@@ -67,7 +48,6 @@ macro(find_dependency dep)
set(${CMAKE_FIND_PACKAGE_NAME}_FOUND False)
return()
endif()
set(cmake_fd_version)
set(cmake_fd_required_arg)
set(cmake_fd_quiet_arg)
set(cmake_fd_exact_arg)
......
cmake_minimum_required(VERSION 2.8.4)
project(${RunCMake_TEST} NONE)
set(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
include(${RunCMake_TEST}.cmake)
CMake Error at .*Modules/CMakeFindDependencyMacro.cmake:[0-9]+ \(message\):
Invalid arguments to find_dependency. EXACT may only be specified if a
VERSION is specified
Call Stack \(most recent call first\):
EXACT-no-version.cmake:4 \(find_dependency\)
CMakeLists.txt:4 \(include\)
include(CMakeFindDependencyMacro)
find_dependency(Pack1 EXACT)
include(RunCMake)
run_cmake(EXACT-no-version)
run_cmake(empty-version)
run_cmake(empty-arg-3)
run_cmake(invalid-arg-3)
run_cmake(extra-args)
# Success tests
run_cmake(realistic)
run_cmake(basic)
# Failure tests
run_cmake(invalid-arg)
run_cmake(bad-version-fuzzy)
run_cmake(bad-version-exact)
CMake Error at .*/Modules/CMakeFindDependencyMacro.cmake:[0-9]+ \(find_package\):
Could not find a configuration file for package "Pack1" that exactly
matches requested version "1.1".
The following configuration files were considered but not accepted:
.*/Tests/RunCMake/find_dependency/share/cmake/Pack1/Pack1Config.cmake, version: 1.3
Call Stack \(most recent call first\):
bad-version-exact.cmake:5 \(find_dependency\)
CMakeLists.txt:3 \(include\)
set(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
include(CMakeFindDependencyMacro)
find_dependency(Pack1 1.1 EXACT REQUIRED)
CMake Error at .*/Modules/CMakeFindDependencyMacro.cmake:[0-9]+ \(find_package\):
Could not find a configuration file for package "Pack1" that is compatible
with requested version "1.4".
The following configuration files were considered but not accepted:
.*/Tests/RunCMake/find_dependency/share/cmake/Pack1/Pack1Config.cmake, version: 1.3
Call Stack \(most recent call first\):
bad-version-fuzzy.cmake:5 \(find_dependency\)
CMakeLists.txt:3 \(include\)
set(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
include(CMakeFindDependencyMacro)
find_dependency(Pack1 1.4 REQUIRED)
set(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
include(CMakeFindDependencyMacro)
find_dependency(Pack1 "")
find_dependency(Pack1 1.1)
CMake Error at .*Modules/CMakeFindDependencyMacro.cmake:[0-9]+ \(message\):
Invalid arguments to find_dependency
Call Stack \(most recent call first\):
empty-arg-3.cmake:4 \(find_dependency\)
CMakeLists.txt:4 \(include\)
include(CMakeFindDependencyMacro)
find_dependency(Pack1 1.2 "")
CMake Error at .*/Modules/CMakeFindDependencyMacro.cmake:[0-9]+ \(message\):
Invalid arguments to find_dependency. VERSION is empty
Call Stack \(most recent call first\):
empty-version.cmake:4 \(find_dependency\)
CMakeLists.txt:4 \(include\)
CMake Error at .*Modules/CMakeFindDependencyMacro.cmake:[0-9]+ \(message\):
Invalid arguments to find_dependency
Call Stack \(most recent call first\):
extra-args.cmake:4 \(find_dependency\)
CMakeLists.txt:4 \(include\)
include(CMakeFindDependencyMacro)
find_dependency(Pack1 1.2 EXACT PATHS "${CMAKE_BINARY_DIR}")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment