Hi Brad, thanks for helping me out with the patch. Your wording of the message is better than my proposal. Please find attached an improved patch.
Bye Christoph -- [..] Mathematicians are like theologians: we regard existence as the prime attribute of what we study. But unlike theologians, we need not always rely upon faith alone. [Lawrence Evans]
>From 2e2ce0fb59461842947d6f3cc58c7a266a6cd33c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20Gr=C3=83=C2=83=C3=82=C2=BCninger?= <gruen...@dune-project.org> Date: Tue, 25 Apr 2017 06:41:31 +0200 Subject: [PATCH] cmFindPackageCommand: Add OPTIONAL If OPTIONAL is set and the package is not found, just a single line of output is written and despite QUIET the package appears in the feature summary. --- Help/command/find_package.rst | 18 ++++++++++++------ Source/cmFindPackageCommand.cxx | 23 +++++++++++++++++++++-- Source/cmFindPackageCommand.h | 1 + 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/Help/command/find_package.rst b/Help/command/find_package.rst index 60a77b85e..61b31ac46 100644 --- a/Help/command/find_package.rst +++ b/Help/command/find_package.rst @@ -5,8 +5,8 @@ Load settings for an external project. :: - find_package(<package> [version] [EXACT] [QUIET] [MODULE] - [REQUIRED] [[COMPONENTS] [components...]] + find_package(<package> [version] [EXACT] [OPTIONAL] [QUIET] + [MODULE] [REQUIRED] [[COMPONENTS] [components...]] [OPTIONAL_COMPONENTS components...] [NO_POLICY_SCOPE]) @@ -14,7 +14,10 @@ Finds and loads settings from an external project. ``<package>_FOUND`` will be set to indicate whether the package was found. When the package is found package-specific information is provided through variables and :ref:`Imported Targets` documented by the package itself. The -``QUIET`` option disables messages if the package cannot be found. The +``OPTIONAL`` option reduces the lengthy warning message to a single +line of output if the package cannot be found. The ``QUIET`` option +disables messages if the package cannot be found and suppresses the +feature summary for this package. The ``MODULE`` option disables the second signature documented below. The ``REQUIRED`` option stops processing with an error message if the package cannot be found. @@ -54,7 +57,7 @@ option is not given the command proceeds to Config mode. The complete Config mode command signature is:: - find_package(<package> [version] [EXACT] [QUIET] + find_package(<package> [version] [EXACT] [OPTIONAL] [QUIET] [REQUIRED] [[COMPONENTS] [components...]] [CONFIG|NO_MODULE] [NO_POLICY_SCOPE] @@ -100,8 +103,11 @@ version are stored in the cmake variable ``<package>_CONSIDERED_CONFIGS``, the associated versions in ``<package>_CONSIDERED_VERSIONS``. If the package configuration file cannot be found CMake will generate -an error describing the problem unless the ``QUIET`` argument is -specified. If ``REQUIRED`` is specified and the package is not found a +an error describing the problem. When the ``OPTIONAL`` argument is +specified, the error is reduced to a single line containing the package +status. When the ``QUIET`` argument is specified, the error and +possible feature summary entries are suppressed. +If ``REQUIRED`` is specified and the package is not found a fatal error is generated and the configure step stops executing. If ``<package>_DIR`` has been set to a directory not containing a configuration file CMake will ignore it and search from scratch. diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 17fa92ccd..b0d8433d9 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -83,6 +83,7 @@ void cmFindPackageCommand::Sort(std::vector<std::string>::iterator begin, cmFindPackageCommand::cmFindPackageCommand() { this->CMakePathName = "PACKAGE"; + this->Optional = false; this->Quiet = false; this->Required = false; this->NoUserRegistry = false; @@ -242,7 +243,10 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args, std::set<unsigned int> configArgs; std::set<unsigned int> moduleArgs; for (unsigned int i = 1; i < args.size(); ++i) { - if (args[i] == "QUIET") { + if (args[i] == "OPTIONAL") { + this->Optional = true; + doing = DoingNone; + } else if (args[i] == "QUIET") { this->Quiet = true; doing = DoingNone; } else if (args[i] == "EXACT") { @@ -546,6 +550,14 @@ void cmFindPackageCommand::SetModuleVariables(const std::string& components) std::string components_var = this->Name + "_FIND_COMPONENTS"; this->AddFindDefinition(components_var, components.c_str()); + if (this->Optional) { + // Tell the module that is about to be read that it should find + // an optional package. + std::string optional = this->Name; + optional += "_FIND_OPTIONAL"; + this->AddFindDefinition(optional, "1"); + } + if (this->Quiet) { // Tell the module that is about to be read that it should find // quietly. @@ -727,7 +739,7 @@ bool cmFindPackageCommand::HandlePackageMode() } } - if (result && !found && (!this->Quiet || this->Required)) { + if (result && !found && ((!this->Quiet && !this->Optional) || this->Required)) { // The variable is not set. std::ostringstream e; std::ostringstream aw; @@ -827,6 +839,13 @@ bool cmFindPackageCommand::HandlePackageMode() this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, aw.str()); } } + else if (result && !found && !this->Quiet && this->Optional) { + std::ostringstream aw; + aw << "Could NOT find " << this->Name + << " (missing: " << this->Name + << "-config.cmake)"; + this->Makefile->DisplayStatus(aw.str().c_str(), -1); + } // Set a variable marking whether the package was found. this->Makefile->AddDefinition(foundVar, found ? "1" : "0"); diff --git a/Source/cmFindPackageCommand.h b/Source/cmFindPackageCommand.h index c42eccee3..376a9cbba 100644 --- a/Source/cmFindPackageCommand.h +++ b/Source/cmFindPackageCommand.h @@ -161,6 +161,7 @@ private: unsigned int VersionFoundTweak; unsigned int VersionFoundCount; KWIML_INT_uint64_t RequiredCMakeVersion; + bool Optional; bool Quiet; bool Required; bool UseConfigFiles; -- 2.12.0
-- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers