cmake/Source/cmFindPackageCommand.h

271 lines
7.5 KiB
C
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
2021-09-14 00:13:48 +02:00
#pragma once
2018-01-26 17:06:56 +01:00
#include "cmConfigure.h" // IWYU pragma: keep
2017-07-20 19:35:53 +02:00
2018-08-09 18:06:22 +02:00
#include <cstddef>
2018-10-28 12:09:07 +01:00
#include <functional>
2017-04-14 19:02:05 +02:00
#include <map>
#include <set>
#include <string>
2022-08-04 22:12:04 +02:00
#include <utility>
2017-04-14 19:02:05 +02:00
#include <vector>
2021-09-14 00:13:48 +02:00
#include <cm/string_view>
2020-08-30 11:54:41 +02:00
#include <cm3p/kwiml/int.h>
2020-02-01 23:06:01 +01:00
#include "cmFindCommon.h"
#include "cmPolicies.h"
2018-08-09 18:06:22 +02:00
// IWYU insists we should forward-declare instead of including <functional>,
// but we cannot forward-declare reliably because some C++ standard libraries
// put the template in an inline namespace.
2018-10-28 12:09:07 +01:00
#ifdef CMAKE_IWYU_FORWARD_STD_HASH
2018-08-09 18:06:22 +02:00
/* clang-format off */
namespace std {
template <class T> struct hash;
}
/* clang-format on */
#endif
2017-04-14 19:02:05 +02:00
class cmExecutionStatus;
class cmSearchPath;
/** \class cmFindPackageCommand
* \brief Load settings from an external project.
*
* cmFindPackageCommand
*/
class cmFindPackageCommand : public cmFindCommon
{
public:
2016-10-30 18:24:19 +01:00
/*! A sorting order strategy to be applied to recovered package folders (see
* FIND_PACKAGE_SORT_ORDER)*/
enum /*class*/ SortOrderType
{
None,
Name_order,
Natural
};
/*! A sorting direction to be applied to recovered package folders (see
* FIND_PACKAGE_SORT_DIRECTION)*/
enum /*class*/ SortDirectionType
{
Asc,
Dec
};
/*! sorts a given list of string based on the input sort parameters */
static void Sort(std::vector<std::string>::iterator begin,
std::vector<std::string>::iterator end, SortOrderType order,
SortDirectionType dir);
2020-02-01 23:06:01 +01:00
cmFindPackageCommand(cmExecutionStatus& status);
2020-02-01 23:06:01 +01:00
bool InitialPass(std::vector<std::string> const& args);
private:
2015-04-27 22:25:09 +02:00
class PathLabel : public cmFindCommon::PathLabel
{
protected:
PathLabel();
2016-07-09 11:21:54 +02:00
2015-04-27 22:25:09 +02:00
public:
2016-07-09 11:21:54 +02:00
PathLabel(const std::string& label)
: cmFindCommon::PathLabel(label)
{
}
2022-08-04 22:12:04 +02:00
static PathLabel PackageRedirect;
2015-04-27 22:25:09 +02:00
static PathLabel UserRegistry;
static PathLabel Builds;
static PathLabel SystemRegistry;
};
2019-11-11 23:01:05 +01:00
bool FindPackageUsingModuleMode();
bool FindPackageUsingConfigMode();
2015-04-27 22:25:09 +02:00
// Add additional search path labels and groups not present in the
// parent class
void AppendSearchPathGroups();
void AppendSuccessInformation();
2012-06-27 20:52:58 +03:00
void AppendToFoundProperty(bool found);
2021-09-14 00:13:48 +02:00
void SetVersionVariables(
const std::function<void(const std::string&, cm::string_view)>&
addDefinition,
const std::string& prefix, const std::string& version, unsigned int count,
unsigned int major, unsigned int minor, unsigned int patch,
unsigned int tweak);
2022-08-04 22:12:04 +02:00
void SetModuleVariables(
const std::string& components,
const std::vector<std::pair<std::string, const char*>>& componentVarDefs);
bool FindModule(bool& found);
2021-09-14 00:13:48 +02:00
void AddFindDefinition(const std::string& var, cm::string_view value);
void RestoreFindDefinitions();
2019-11-11 23:01:05 +01:00
2023-07-02 19:51:09 +02:00
class SetRestoreFindDefinitions;
2019-11-11 23:01:05 +01:00
enum /*class*/ HandlePackageModeType
{
Module,
Config
};
bool HandlePackageMode(HandlePackageModeType type);
2009-10-11 10:55:36 +03:00
bool FindConfig();
bool FindPrefixedConfig();
bool FindFrameworkConfig();
bool FindAppBundleConfig();
2016-07-09 11:21:54 +02:00
enum PolicyScopeRule
{
NoPolicyScope,
DoPolicyScope
};
2019-11-11 23:01:05 +01:00
bool ReadListFile(const std::string& f, PolicyScopeRule psr);
void StoreVersionFound();
2022-08-04 22:12:04 +02:00
void SetConfigDirCacheVariable(const std::string& value);
2023-07-02 19:51:09 +02:00
void PushFindPackageRootPathStack();
void PopFindPackageRootPathStack();
class PushPopRootPathStack;
void ComputePrefixes();
2022-08-04 22:12:04 +02:00
void FillPrefixesPackageRedirect();
2017-08-11 09:33:23 +02:00
void FillPrefixesPackageRoot();
2015-04-27 22:25:09 +02:00
void FillPrefixesCMakeEnvironment();
void FillPrefixesCMakeVariable();
void FillPrefixesSystemEnvironment();
void FillPrefixesUserRegistry();
void FillPrefixesSystemRegistry();
void FillPrefixesCMakeSystemVariable();
void FillPrefixesUserGuess();
void FillPrefixesUserHints();
void LoadPackageRegistryDir(std::string const& dir, cmSearchPath& outPaths);
2011-06-19 15:41:06 +03:00
void LoadPackageRegistryWinUser();
void LoadPackageRegistryWinSystem();
2015-04-27 22:25:09 +02:00
void LoadPackageRegistryWin(bool user, unsigned int view,
cmSearchPath& outPaths);
bool CheckPackageRegistryEntry(const std::string& fname,
cmSearchPath& outPaths);
bool SearchDirectory(std::string const& dir);
bool CheckDirectory(std::string const& dir);
bool FindConfigFile(std::string const& dir, std::string& file);
bool CheckVersion(std::string const& config_file);
2010-11-13 01:00:53 +02:00
bool CheckVersionFile(std::string const& version_file,
std::string& result_version);
bool SearchPrefix(std::string const& prefix);
bool SearchFrameworkPrefix(std::string const& prefix_in);
bool SearchAppBundlePrefix(std::string const& prefix_in);
2016-07-09 11:21:54 +02:00
struct OriginalDef
{
bool exists;
std::string value;
};
2015-04-27 22:25:09 +02:00
std::map<std::string, OriginalDef> OriginalDefs;
2019-11-11 23:01:05 +01:00
std::map<std::string, cmPolicies::PolicyID> DeprecatedFindModules;
2021-09-14 00:13:48 +02:00
static const cm::string_view VERSION_ENDPOINT_INCLUDED;
static const cm::string_view VERSION_ENDPOINT_EXCLUDED;
2015-04-27 22:25:09 +02:00
std::string Name;
std::string Variable;
2021-09-14 00:13:48 +02:00
std::string VersionComplete;
std::string VersionRange;
cm::string_view VersionRangeMin;
cm::string_view VersionRangeMax;
2015-04-27 22:25:09 +02:00
std::string Version;
2021-09-14 00:13:48 +02:00
unsigned int VersionMajor = 0;
unsigned int VersionMinor = 0;
unsigned int VersionPatch = 0;
unsigned int VersionTweak = 0;
unsigned int VersionCount = 0;
std::string VersionMax;
unsigned int VersionMaxMajor = 0;
unsigned int VersionMaxMinor = 0;
unsigned int VersionMaxPatch = 0;
unsigned int VersionMaxTweak = 0;
unsigned int VersionMaxCount = 0;
bool VersionExact = false;
2015-04-27 22:25:09 +02:00
std::string FileFound;
std::string VersionFound;
2021-09-14 00:13:48 +02:00
unsigned int VersionFoundMajor = 0;
unsigned int VersionFoundMinor = 0;
unsigned int VersionFoundPatch = 0;
unsigned int VersionFoundTweak = 0;
unsigned int VersionFoundCount = 0;
KWIML_INT_uint64_t RequiredCMakeVersion = 0;
bool Quiet = false;
bool Required = false;
bool UseConfigFiles = true;
bool UseFindModules = true;
bool NoUserRegistry = false;
bool NoSystemRegistry = false;
bool UseLib32Paths = false;
bool UseLib64Paths = false;
bool UseLibx32Paths = false;
bool UseRealPath = false;
bool PolicyScope = true;
2022-08-04 22:12:04 +02:00
bool GlobalScope = false;
bool RegistryViewDefined = false;
2011-06-19 15:41:06 +03:00
std::string LibraryArchitecture;
std::vector<std::string> Names;
std::vector<std::string> Configs;
2010-11-13 01:00:53 +02:00
std::set<std::string> IgnoredPaths;
2022-03-29 21:10:50 +02:00
std::set<std::string> IgnoredPrefixPaths;
2020-08-30 11:54:41 +02:00
std::string DebugBuffer;
2010-11-13 01:00:53 +02:00
2023-07-02 19:51:09 +02:00
class FlushDebugBufferOnExit;
2016-10-30 18:24:19 +01:00
/*! the selected sortOrder (None by default)*/
2021-09-14 00:13:48 +02:00
SortOrderType SortOrder = None;
2016-10-30 18:24:19 +01:00
/*! the selected sortDirection (Asc by default)*/
2021-09-14 00:13:48 +02:00
SortDirectionType SortDirection = Asc;
2016-10-30 18:24:19 +01:00
2016-07-09 11:21:54 +02:00
struct ConfigFileInfo
{
std::string filename;
std::string version;
2016-10-30 18:24:19 +01:00
bool operator<(ConfigFileInfo const& rhs) const
{
return this->filename < rhs.filename;
}
bool operator==(ConfigFileInfo const& rhs) const
{
return this->filename == rhs.filename;
}
bool operator!=(ConfigFileInfo const& rhs) const
{
return !(*this == rhs);
}
2016-07-09 11:21:54 +02:00
};
2010-11-13 01:00:53 +02:00
std::vector<ConfigFileInfo> ConsideredConfigs;
2018-08-09 18:06:22 +02:00
friend struct std::hash<ConfigFileInfo>;
};
namespace std {
template <>
struct hash<cmFindPackageCommand::ConfigFileInfo>
{
2020-02-01 23:06:01 +01:00
using argument_type = cmFindPackageCommand::ConfigFileInfo;
using result_type = size_t;
2018-08-09 18:06:22 +02:00
result_type operator()(argument_type const& s) const noexcept
{
result_type const h(std::hash<std::string>{}(s.filename));
return h;
}
};
2018-08-09 18:06:22 +02:00
}
2020-02-01 23:06:01 +01:00
bool cmFindPackage(std::vector<std::string> const& args,
cmExecutionStatus& status);