From 6e1d3edb4d1e1b491df879a2764d8a24442795dc Mon Sep 17 00:00:00 2001 From: Alex Neundorf Date: Thu, 16 Jun 2011 21:11:06 +0200 Subject: [PATCH] Add a switch to disable a find_package() call completely As discussed, this adds a switch CMAKE_DISABLE_FIND_PACKAGE_, which, when set to TRUE, keeps the find_package() command from executing. When the package is REQUIRED at the same time, an error is generated. Alex --- Source/cmFindPackageCommand.cxx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 5f106bce0..554601dcb 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -607,6 +607,24 @@ bool cmFindPackageCommand } } + std::string disableFindPackageVar = "CMAKE_DISABLE_FIND_PACKAGE_"; + disableFindPackageVar += this->Name; + if(this->Makefile->IsOn(disableFindPackageVar.c_str())) + { + if (this->Required) + { + cmOStringStream e; + e << "for module " << this->Name << " called with REQUIRED, but " + << disableFindPackageVar + << " is enabled. A REQUIRED package cannot be disabled."; + this->SetError(e.str().c_str()); + return false; + } + + return true; + } + + this->SetModuleVariables(components); // See if there is a Find.cmake module.