From 5878c5d919a206b9a54f48f386ab98b5cff09e08 Mon Sep 17 00:00:00 2001 From: Alex Merry Date: Sat, 22 Feb 2014 13:35:14 +0000 Subject: [PATCH 1/3] Always set version variable of find_dependency macro If there is no ARGV1, that is fine; version will be made empty, and no version will be passed to find_package(). This is relevant when find_dependency is invoked multiple times, sometimes with a version specified and sometimes without. find_dependency(dep1 3.4) find_dependency(dep2) # version still set to 3.4. --- Modules/CMakeFindDependencyMacro.cmake | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Modules/CMakeFindDependencyMacro.cmake b/Modules/CMakeFindDependencyMacro.cmake index 0f1f56da9..c0a0ef780 100644 --- a/Modules/CMakeFindDependencyMacro.cmake +++ b/Modules/CMakeFindDependencyMacro.cmake @@ -29,9 +29,7 @@ macro(find_dependency dep) if (NOT ${dep}_FOUND) - if (${ARGV1}) - set(version ${ARGV1}) - endif() + set(version ${ARGV1}) set(exact_arg) if(${CMAKE_FIND_PACKAGE_NAME}_FIND_VERSION_EXACT) set(exact_arg EXACT) From a35ce7235b94ce040b605d87ee326e8d354a5ecb Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 24 Feb 2014 18:27:35 +0100 Subject: [PATCH 2/3] find_dependency: Add namespacing for variables in the macro. Avoid setting a variable called 'version' etc. --- Modules/CMakeFindDependencyMacro.cmake | 30 +++++++++++++++----------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/Modules/CMakeFindDependencyMacro.cmake b/Modules/CMakeFindDependencyMacro.cmake index c0a0ef780..142130dcf 100644 --- a/Modules/CMakeFindDependencyMacro.cmake +++ b/Modules/CMakeFindDependencyMacro.cmake @@ -29,27 +29,31 @@ macro(find_dependency dep) if (NOT ${dep}_FOUND) - set(version ${ARGV1}) - set(exact_arg) + set(cmake_fd_version ${ARGV1}) + set(cmake_fd_exact_arg) if(${CMAKE_FIND_PACKAGE_NAME}_FIND_VERSION_EXACT) - set(exact_arg EXACT) + set(cmake_fd_exact_arg EXACT) endif() - set(quiet_arg) + set(cmake_fd_quiet_arg) if(${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY) - set(quiet_arg QUIET) + set(cmake_fd_quiet_arg QUIET) endif() - set(required_arg) + set(cmake_fd_required_arg) if(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED) - set(required_arg REQUIRED) + set(cmake_fd_required_arg REQUIRED) endif() - get_property(alreadyTransitive GLOBAL PROPERTY + get_property(cmake_fd_alreadyTransitive GLOBAL PROPERTY _CMAKE_${dep}_TRANSITIVE_DEPENDENCY ) - find_package(${dep} ${version} ${exact_arg} ${quiet_arg} ${required_arg}) + find_package(${dep} ${version} + ${cmake_fd_exact_arg} + ${cmake_fd_quiet_arg} + ${cmake_fd_required_arg} + ) - if(NOT DEFINED alreadyTransitive OR alreadyTransitive) + if(NOT DEFINED cmake_fd_alreadyTransitive OR cmake_fd_alreadyTransitive) set_property(GLOBAL PROPERTY _CMAKE_${dep}_TRANSITIVE_DEPENDENCY TRUE) endif() @@ -58,8 +62,8 @@ macro(find_dependency dep) set(${CMAKE_FIND_PACKAGE_NAME}_FOUND False) return() endif() - set(required_arg) - set(quiet_arg) - set(exact_arg) + set(cmake_fd_required_arg) + set(cmake_fd_quiet_arg) + set(cmake_fd_exact_arg) endif() endmacro() From 2be6dbe4207cda39b479e7c81d172d49dd67cc38 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 24 Feb 2014 18:59:11 +0100 Subject: [PATCH 3/3] find_dependency: Ensure that ARGV1 has valid local content The ARGV1 value could come from a wrapping context if find_dependency is called from a function. --- Modules/CMakeFindDependencyMacro.cmake | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Modules/CMakeFindDependencyMacro.cmake b/Modules/CMakeFindDependencyMacro.cmake index 142130dcf..08c4990c2 100644 --- a/Modules/CMakeFindDependencyMacro.cmake +++ b/Modules/CMakeFindDependencyMacro.cmake @@ -29,7 +29,10 @@ macro(find_dependency dep) if (NOT ${dep}_FOUND) - set(cmake_fd_version ${ARGV1}) + set(cmake_fd_version) + if (${ARGC} GREATER 1) + set(cmake_fd_version ${ARGV1}) + endif() set(cmake_fd_exact_arg) if(${CMAKE_FIND_PACKAGE_NAME}_FIND_VERSION_EXACT) set(cmake_fd_exact_arg EXACT)