Coverage Report

Created: 2026-06-15 07:03

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmFindPackageCommand.cxx
Line
Count
Source
1
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2
   file LICENSE.rst or https://cmake.org/licensing for details.  */
3
#include "cmFindPackageCommand.h"
4
5
#include <algorithm>
6
#include <cassert>
7
#include <cstdio>
8
#include <deque>
9
#include <functional>
10
#include <iterator>
11
#include <sstream>
12
#include <unordered_set>
13
#include <utility>
14
15
#include <cm/memory>
16
#include <cm/optional>
17
#include <cmext/algorithm>
18
#include <cmext/string_view>
19
20
#include "cmsys/Directory.hxx"
21
#include "cmsys/FStream.hxx"
22
#include "cmsys/Glob.hxx"
23
#include "cmsys/RegularExpression.hxx"
24
#include "cmsys/String.h"
25
26
#include "cmAlgorithms.h"
27
#include "cmConfigureLog.h"
28
#include "cmDependencyProvider.h"
29
#include "cmDiagnostics.h"
30
#include "cmExecutionStatus.h"
31
#include "cmFindPackageStack.h"
32
#include "cmList.h"
33
#include "cmListFileCache.h"
34
#include "cmMakefile.h"
35
#include "cmMessageType.h"
36
#include "cmPackageState.h"
37
#include "cmPolicies.h"
38
#include "cmRange.h"
39
#include "cmSearchPath.h"
40
#include "cmState.h"
41
#include "cmStateSnapshot.h"
42
#include "cmStateTypes.h"
43
#include "cmStringAlgorithms.h"
44
#include "cmSystemTools.h"
45
#include "cmValue.h"
46
#include "cmVersionMacros.h"
47
#include "cmWindowsRegistry.h"
48
49
#if defined(__HAIKU__)
50
#  include <FindDirectory.h>
51
#  include <StorageDefs.h>
52
#endif
53
54
#if defined(_WIN32) && !defined(__CYGWIN__)
55
#  include <windows.h>
56
// http://msdn.microsoft.com/en-us/library/aa384253%28v=vs.85%29.aspx
57
#  if !defined(KEY_WOW64_32KEY)
58
#    define KEY_WOW64_32KEY 0x0200
59
#  endif
60
#  if !defined(KEY_WOW64_64KEY)
61
#    define KEY_WOW64_64KEY 0x0100
62
#  endif
63
#endif
64
65
namespace {
66
67
using pdt = cmFindPackageCommand::PackageDescriptionType;
68
using ParsedVersion = cmPackageInfoReader::Pep440Version;
69
70
template <template <typename> class Op>
71
struct StrverscmpOp
72
{
73
  bool operator()(std::string const& lhs, std::string const& rhs) const
74
0
  {
75
0
    return Op<int>()(cmSystemTools::strverscmp(lhs, rhs), 0);
76
0
  }
Unexecuted instantiation: cmFindPackageCommand.cxx:(anonymous namespace)::StrverscmpOp<std::__1::greater>::operator()(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const
Unexecuted instantiation: cmFindPackageCommand.cxx:(anonymous namespace)::StrverscmpOp<std::__1::less>::operator()(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const
77
};
78
79
std::size_t collectPathsForDebug(std::string& buffer,
80
                                 cmSearchPath const& searchPath,
81
                                 std::size_t const startIndex = 0)
82
0
{
83
0
  auto const& paths = searchPath.GetPaths();
84
0
  if (paths.empty()) {
85
0
    buffer += "  none\n";
86
0
    return 0;
87
0
  }
88
0
  for (auto i = startIndex; i < paths.size(); i++) {
89
0
    buffer += cmStrCat("  ", paths[i].Path, '\n');
90
0
  }
91
0
  return paths.size();
92
0
}
93
94
#if !(defined(_WIN32) && !defined(__CYGWIN__))
95
class cmFindPackageCommandHoldFile
96
{
97
  char const* File;
98
99
public:
100
  cmFindPackageCommandHoldFile(char const* const f)
101
0
    : File(f)
102
0
  {
103
0
  }
104
  ~cmFindPackageCommandHoldFile()
105
0
  {
106
0
    if (this->File) {
107
0
      cmSystemTools::RemoveFile(this->File);
108
0
    }
109
0
  }
110
  cmFindPackageCommandHoldFile(cmFindPackageCommandHoldFile const&) = delete;
111
  cmFindPackageCommandHoldFile& operator=(
112
    cmFindPackageCommandHoldFile const&) = delete;
113
0
  void Release() { this->File = nullptr; }
114
};
115
#endif
116
117
bool isDirentryToIgnore(std::string const& fname)
118
0
{
119
0
  assert(!fname.empty());
120
0
  return fname == "." || fname == "..";
121
0
}
122
123
class cmAppendPathSegmentGenerator
124
{
125
public:
126
  cmAppendPathSegmentGenerator(cm::string_view dirName)
127
0
    : DirName{ dirName }
128
0
  {
129
0
  }
130
131
  std::string GetNextCandidate(std::string const& parent)
132
0
  {
133
0
    if (this->NeedReset) {
134
0
      return {};
135
0
    }
136
0
    this->NeedReset = true;
137
0
    return cmStrCat(parent, this->DirName, '/');
138
0
  }
139
140
0
  void Reset() { this->NeedReset = false; }
141
142
private:
143
  cm::string_view const DirName;
144
  bool NeedReset = false;
145
};
146
147
class cmEnumPathSegmentsGenerator
148
{
149
public:
150
  cmEnumPathSegmentsGenerator(std::vector<cm::string_view> const& init)
151
0
    : Names{ init }
152
0
    , Current{ this->Names.get().cbegin() }
153
0
  {
154
0
  }
155
156
  std::string GetNextCandidate(std::string const& parent)
157
0
  {
158
0
    if (this->Current != this->Names.get().cend()) {
159
0
      return cmStrCat(parent, *this->Current++, '/');
160
0
    }
161
0
    return {};
162
0
  }
163
164
0
  void Reset() { this->Current = this->Names.get().cbegin(); }
165
166
private:
167
  std::reference_wrapper<std::vector<cm::string_view> const> Names;
168
  std::vector<cm::string_view>::const_iterator Current;
169
};
170
171
class cmCaseInsensitiveDirectoryListGenerator
172
{
173
public:
174
  cmCaseInsensitiveDirectoryListGenerator(cm::string_view name)
175
0
    : DirName{ name }
176
0
  {
177
0
  }
178
179
  std::string GetNextCandidate(std::string const& parent)
180
0
  {
181
0
    if (!this->Loaded) {
182
0
      this->CurrentIdx = 0ul;
183
0
      this->Loaded = true;
184
0
      if (!this->DirectoryLister.Load(parent)) {
185
0
        return {};
186
0
      }
187
0
    }
188
189
0
    while (this->CurrentIdx < this->DirectoryLister.GetNumberOfFiles()) {
190
0
      std::string const& fname =
191
0
        this->DirectoryLister.GetFileName(this->CurrentIdx++);
192
0
      if (isDirentryToIgnore(fname)) {
193
0
        continue;
194
0
      }
195
0
      if (cmsysString_strcasecmp(fname.c_str(), this->DirName.data()) == 0) {
196
0
        auto candidate = cmStrCat(parent, fname, '/');
197
0
        if (cmSystemTools::FileIsDirectory(candidate)) {
198
0
          return candidate;
199
0
        }
200
0
      }
201
0
    }
202
0
    return {};
203
0
  }
204
205
0
  void Reset() { this->Loaded = false; }
206
207
private:
208
  cmsys::Directory DirectoryLister;
209
  cm::string_view const DirName;
210
  unsigned long CurrentIdx = 0ul;
211
  bool Loaded = false;
212
};
213
214
class cmDirectoryListGenerator
215
{
216
public:
217
  cmDirectoryListGenerator(std::vector<std::string> const* names,
218
                           bool exactMatch)
219
0
    : Names{ names }
220
0
    , ExactMatch{ exactMatch }
221
0
    , Current{ this->Matches.cbegin() }
222
0
  {
223
0
    assert(names || !exactMatch);
224
0
    assert(!names || !names->empty());
225
0
  }
226
0
  virtual ~cmDirectoryListGenerator() = default;
227
228
  std::string GetNextCandidate(std::string const& parent)
229
0
  {
230
    // Construct a list of matches if not yet
231
0
    if (this->Matches.empty()) {
232
0
      cmsys::Directory directoryLister;
233
      // ALERT `Directory::Load()` keeps only names
234
      // internally and LOST entry type from `dirent`.
235
      // So, `Directory::FileIsDirectory` gonna use
236
      // `SystemTools::FileIsDirectory()` and waste a syscall.
237
      // TODO Need to enhance the `Directory` class.
238
0
      directoryLister.Load(parent);
239
240
      // ATTENTION Is it guaranteed that first two entries are
241
      // `.` and `..`?
242
      // TODO If so, just start with index 2 and drop the
243
      // `isDirentryToIgnore(i)` condition to check.
244
0
      for (auto i = 0ul; i < directoryLister.GetNumberOfFiles(); ++i) {
245
0
        std::string const& fname = directoryLister.GetFileName(i);
246
        // Skip entries to ignore or that aren't directories.
247
0
        if (isDirentryToIgnore(fname)) {
248
0
          continue;
249
0
        }
250
251
0
        if (!this->Names) {
252
0
          if (directoryLister.FileIsDirectory(i)) {
253
0
            this->Matches.emplace_back(fname);
254
0
          }
255
0
        } else {
256
0
          for (auto const& n : *this->Names) {
257
            // NOTE Customization point for
258
            // `cmMacProjectDirectoryListGenerator`
259
0
            auto const name = this->TransformNameBeforeCmp(n);
260
            // Skip entries that don't match.
261
0
            auto const equal =
262
0
              ((this->ExactMatch
263
0
                  ? cmsysString_strcasecmp(fname.c_str(), name.c_str())
264
0
                  : cmsysString_strncasecmp(fname.c_str(), name.c_str(),
265
0
                                            name.length())) == 0);
266
0
            if (equal) {
267
0
              if (directoryLister.FileIsDirectory(i)) {
268
0
                this->Matches.emplace_back(fname);
269
0
              }
270
0
              break;
271
0
            }
272
0
          }
273
0
        }
274
0
      }
275
      // NOTE Customization point for `cmProjectDirectoryListGenerator`
276
0
      this->OnMatchesLoaded();
277
278
0
      this->Current = this->Matches.cbegin();
279
0
    }
280
281
0
    if (this->Current != this->Matches.cend()) {
282
0
      auto candidate = cmStrCat(parent, *this->Current++, '/');
283
0
      return candidate;
284
0
    }
285
286
0
    return {};
287
0
  }
288
289
  void Reset()
290
0
  {
291
0
    this->Matches.clear();
292
0
    this->Current = this->Matches.cbegin();
293
0
  }
294
295
protected:
296
0
  virtual void OnMatchesLoaded() {}
297
0
  virtual std::string TransformNameBeforeCmp(std::string same) { return same; }
298
299
  std::vector<std::string> const* Names;
300
  bool const ExactMatch;
301
  std::vector<std::string> Matches;
302
  std::vector<std::string>::const_iterator Current;
303
};
304
305
class cmProjectDirectoryListGenerator : public cmDirectoryListGenerator
306
{
307
public:
308
  cmProjectDirectoryListGenerator(std::vector<std::string> const* names,
309
                                  cmFindPackageCommand::SortOrderType so,
310
                                  cmFindPackageCommand::SortDirectionType sd,
311
                                  bool exactMatch)
312
0
    : cmDirectoryListGenerator{ names, exactMatch }
313
0
    , SortOrder{ so }
314
0
    , SortDirection{ sd }
315
0
  {
316
0
  }
317
318
protected:
319
  void OnMatchesLoaded() override
320
0
  {
321
    // check if there is a specific sorting order to perform
322
0
    if (this->SortOrder != cmFindPackageCommand::None) {
323
0
      cmFindPackageCommand::Sort(this->Matches.begin(), this->Matches.end(),
324
0
                                 this->SortOrder, this->SortDirection);
325
0
    }
326
0
  }
327
328
private:
329
  // sort parameters
330
  cmFindPackageCommand::SortOrderType const SortOrder;
331
  cmFindPackageCommand::SortDirectionType const SortDirection;
332
};
333
334
class cmMacProjectDirectoryListGenerator : public cmDirectoryListGenerator
335
{
336
public:
337
  cmMacProjectDirectoryListGenerator(std::vector<std::string> const* names,
338
                                     cm::string_view ext)
339
0
    : cmDirectoryListGenerator{ names, true }
340
0
    , Extension{ ext }
341
0
  {
342
0
  }
343
344
protected:
345
  std::string TransformNameBeforeCmp(std::string name) override
346
0
  {
347
0
    return cmStrCat(name, this->Extension);
348
0
  }
349
350
private:
351
  cm::string_view const Extension;
352
};
353
354
class cmAnyDirectoryListGenerator : public cmProjectDirectoryListGenerator
355
{
356
public:
357
  cmAnyDirectoryListGenerator(cmFindPackageCommand::SortOrderType so,
358
                              cmFindPackageCommand::SortDirectionType sd)
359
0
    : cmProjectDirectoryListGenerator(nullptr, so, sd, false)
360
0
  {
361
0
  }
362
};
363
364
#if defined(__LCC__)
365
#  define CM_LCC_DIAG_SUPPRESS_1222
366
#  pragma diag_suppress 1222 // invalid error number (3288, but works anyway)
367
#  define CM_LCC_DIAG_SUPPRESS_3288
368
#  pragma diag_suppress 3288 // parameter was declared but never referenced
369
#  define CM_LCC_DIAG_SUPPRESS_3301
370
#  pragma diag_suppress 3301 // parameter was declared but never referenced
371
#  define CM_LCC_DIAG_SUPPRESS_3308
372
#  pragma diag_suppress 3308 // parameter was declared but never referenced
373
#endif
374
375
void ResetGenerator()
376
0
{
377
0
}
378
379
template <typename Generator>
380
void ResetGenerator(Generator&& generator)
381
0
{
382
0
  std::forward<Generator&&>(generator).Reset();
383
0
}
Unexecuted instantiation: cmFindPackageCommand.cxx:void (anonymous namespace)::ResetGenerator<(anonymous namespace)::cmProjectDirectoryListGenerator&>((anonymous namespace)::cmProjectDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:void (anonymous namespace)::ResetGenerator<(anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&>((anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:void (anonymous namespace)::ResetGenerator<(anonymous namespace)::cmAnyDirectoryListGenerator&>((anonymous namespace)::cmAnyDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:void (anonymous namespace)::ResetGenerator<(anonymous namespace)::cmEnumPathSegmentsGenerator&>((anonymous namespace)::cmEnumPathSegmentsGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:void (anonymous namespace)::ResetGenerator<(anonymous namespace)::cmAppendPathSegmentGenerator&>((anonymous namespace)::cmAppendPathSegmentGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:void (anonymous namespace)::ResetGenerator<(anonymous namespace)::cmMacProjectDirectoryListGenerator&>((anonymous namespace)::cmMacProjectDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:void (anonymous namespace)::ResetGenerator<(anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator>((anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&&)
Unexecuted instantiation: cmFindPackageCommand.cxx:void (anonymous namespace)::ResetGenerator<(anonymous namespace)::cmAppendPathSegmentGenerator>((anonymous namespace)::cmAppendPathSegmentGenerator&&)
384
385
template <typename Generator, typename... Generators>
386
void ResetGenerator(Generator&& generator, Generators&&... generators)
387
0
{
388
0
  ResetGenerator(std::forward<Generator&&>(generator));
389
0
  ResetGenerator(std::forward<Generators&&>(generators)...);
390
0
}
Unexecuted instantiation: cmFindPackageCommand.cxx:void (anonymous namespace)::ResetGenerator<(anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&, (anonymous namespace)::cmAnyDirectoryListGenerator&>((anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&, (anonymous namespace)::cmAnyDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:void (anonymous namespace)::ResetGenerator<(anonymous namespace)::cmProjectDirectoryListGenerator&, (anonymous namespace)::cmAnyDirectoryListGenerator&>((anonymous namespace)::cmProjectDirectoryListGenerator&, (anonymous namespace)::cmAnyDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:void (anonymous namespace)::ResetGenerator<(anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&, (anonymous namespace)::cmProjectDirectoryListGenerator&>((anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&, (anonymous namespace)::cmProjectDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:void (anonymous namespace)::ResetGenerator<(anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmProjectDirectoryListGenerator&>((anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmProjectDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:void (anonymous namespace)::ResetGenerator<(anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmProjectDirectoryListGenerator&, (anonymous namespace)::cmAnyDirectoryListGenerator&>((anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmProjectDirectoryListGenerator&, (anonymous namespace)::cmAnyDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:void (anonymous namespace)::ResetGenerator<(anonymous namespace)::cmProjectDirectoryListGenerator&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&>((anonymous namespace)::cmProjectDirectoryListGenerator&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:void (anonymous namespace)::ResetGenerator<(anonymous namespace)::cmEnumPathSegmentsGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmProjectDirectoryListGenerator&>((anonymous namespace)::cmEnumPathSegmentsGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmProjectDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:void (anonymous namespace)::ResetGenerator<(anonymous namespace)::cmEnumPathSegmentsGenerator&, (anonymous namespace)::cmProjectDirectoryListGenerator&>((anonymous namespace)::cmEnumPathSegmentsGenerator&, (anonymous namespace)::cmProjectDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:void (anonymous namespace)::ResetGenerator<(anonymous namespace)::cmEnumPathSegmentsGenerator&, (anonymous namespace)::cmProjectDirectoryListGenerator&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&>((anonymous namespace)::cmEnumPathSegmentsGenerator&, (anonymous namespace)::cmProjectDirectoryListGenerator&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:void (anonymous namespace)::ResetGenerator<(anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmAnyDirectoryListGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&>((anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmAnyDirectoryListGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:void (anonymous namespace)::ResetGenerator<(anonymous namespace)::cmAnyDirectoryListGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&>((anonymous namespace)::cmAnyDirectoryListGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:void (anonymous namespace)::ResetGenerator<(anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&>((anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:void (anonymous namespace)::ResetGenerator<(anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmAnyDirectoryListGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&>((anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmAnyDirectoryListGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:void (anonymous namespace)::ResetGenerator<(anonymous namespace)::cmAnyDirectoryListGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&>((anonymous namespace)::cmAnyDirectoryListGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:void (anonymous namespace)::ResetGenerator<(anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator>((anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&&)
391
392
template <typename CallbackFn>
393
bool TryGeneratedPaths(CallbackFn&& filesCollector,
394
                       cmFindPackageCommand::PackageDescriptionType type,
395
                       std::string const& fullPath)
396
0
{
397
0
  assert(!fullPath.empty() && fullPath.back() == '/');
398
0
  return std::forward<CallbackFn&&>(filesCollector)(fullPath, type);
399
0
}
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&>(cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchFrameworkPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&>(cmFindPackageCommand::SearchFrameworkPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchAppBundlePrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&>(cmFindPackageCommand::SearchAppBundlePrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchEnvironmentPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&>(cmFindPackageCommand::SearchEnvironmentPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
400
401
template <typename CallbackFn, typename Generator, typename... Rest>
402
bool TryGeneratedPaths(CallbackFn&& filesCollector,
403
                       cmFindPackageCommand::PackageDescriptionType type,
404
                       std::string const& startPath, Generator&& gen,
405
                       Rest&&... tail)
406
0
{
407
0
  ResetGenerator(std::forward<Generator&&>(gen));
408
0
  for (auto path = gen.GetNextCandidate(startPath); !path.empty();
409
0
       path = gen.GetNextCandidate(startPath)) {
410
0
    ResetGenerator(std::forward<Rest&&>(tail)...);
411
0
    if (TryGeneratedPaths(std::forward<CallbackFn&&>(filesCollector), type,
412
0
                          path, std::forward<Rest&&>(tail)...)) {
413
0
      return true;
414
0
    }
415
0
  }
416
0
  return false;
417
0
}
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmProjectDirectoryListGenerator&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&>(cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmProjectDirectoryListGenerator&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmProjectDirectoryListGenerator&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&, (anonymous namespace)::cmAnyDirectoryListGenerator&>(cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmProjectDirectoryListGenerator&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&, (anonymous namespace)::cmAnyDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&, (anonymous namespace)::cmAnyDirectoryListGenerator&>(cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&, (anonymous namespace)::cmAnyDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmAnyDirectoryListGenerator&>(cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmAnyDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&, (anonymous namespace)::cmProjectDirectoryListGenerator&>(cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&, (anonymous namespace)::cmProjectDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&, (anonymous namespace)::cmProjectDirectoryListGenerator&, (anonymous namespace)::cmAnyDirectoryListGenerator&>(cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&, (anonymous namespace)::cmProjectDirectoryListGenerator&, (anonymous namespace)::cmAnyDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmProjectDirectoryListGenerator&, (anonymous namespace)::cmAnyDirectoryListGenerator&>(cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmProjectDirectoryListGenerator&, (anonymous namespace)::cmAnyDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&>(cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmProjectDirectoryListGenerator&>(cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmProjectDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmProjectDirectoryListGenerator&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&, (anonymous namespace)::cmProjectDirectoryListGenerator&>(cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmProjectDirectoryListGenerator&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&, (anonymous namespace)::cmProjectDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmEnumPathSegmentsGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmProjectDirectoryListGenerator&>(cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmEnumPathSegmentsGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmProjectDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmProjectDirectoryListGenerator&>(cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmProjectDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmEnumPathSegmentsGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmProjectDirectoryListGenerator&, (anonymous namespace)::cmAnyDirectoryListGenerator&>(cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmEnumPathSegmentsGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmProjectDirectoryListGenerator&, (anonymous namespace)::cmAnyDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmProjectDirectoryListGenerator&, (anonymous namespace)::cmAnyDirectoryListGenerator&>(cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmProjectDirectoryListGenerator&, (anonymous namespace)::cmAnyDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmEnumPathSegmentsGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&>(cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmEnumPathSegmentsGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmAppendPathSegmentGenerator&>(cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmAppendPathSegmentGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmEnumPathSegmentsGenerator&, (anonymous namespace)::cmProjectDirectoryListGenerator&>(cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmEnumPathSegmentsGenerator&, (anonymous namespace)::cmProjectDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmEnumPathSegmentsGenerator&, (anonymous namespace)::cmProjectDirectoryListGenerator&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&>(cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmEnumPathSegmentsGenerator&, (anonymous namespace)::cmProjectDirectoryListGenerator&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmProjectDirectoryListGenerator&, (anonymous namespace)::cmEnumPathSegmentsGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmProjectDirectoryListGenerator&>(cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmProjectDirectoryListGenerator&, (anonymous namespace)::cmEnumPathSegmentsGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmProjectDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmProjectDirectoryListGenerator&, (anonymous namespace)::cmEnumPathSegmentsGenerator&, (anonymous namespace)::cmProjectDirectoryListGenerator&>(cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmProjectDirectoryListGenerator&, (anonymous namespace)::cmEnumPathSegmentsGenerator&, (anonymous namespace)::cmProjectDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmProjectDirectoryListGenerator&, (anonymous namespace)::cmEnumPathSegmentsGenerator&, (anonymous namespace)::cmProjectDirectoryListGenerator&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&>(cmFindPackageCommand::SearchPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmProjectDirectoryListGenerator&, (anonymous namespace)::cmEnumPathSegmentsGenerator&, (anonymous namespace)::cmProjectDirectoryListGenerator&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchFrameworkPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmMacProjectDirectoryListGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmAnyDirectoryListGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&>(cmFindPackageCommand::SearchFrameworkPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmMacProjectDirectoryListGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmAnyDirectoryListGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchFrameworkPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmAnyDirectoryListGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&>(cmFindPackageCommand::SearchFrameworkPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmAnyDirectoryListGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchFrameworkPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmAnyDirectoryListGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&>(cmFindPackageCommand::SearchFrameworkPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmAnyDirectoryListGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchFrameworkPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&>(cmFindPackageCommand::SearchFrameworkPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchFrameworkPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&>(cmFindPackageCommand::SearchFrameworkPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchFrameworkPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmMacProjectDirectoryListGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&>(cmFindPackageCommand::SearchFrameworkPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmMacProjectDirectoryListGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchFrameworkPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmMacProjectDirectoryListGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&>(cmFindPackageCommand::SearchFrameworkPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmMacProjectDirectoryListGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchFrameworkPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmAppendPathSegmentGenerator&>(cmFindPackageCommand::SearchFrameworkPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmAppendPathSegmentGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchFrameworkPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmMacProjectDirectoryListGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmAnyDirectoryListGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&>(cmFindPackageCommand::SearchFrameworkPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmMacProjectDirectoryListGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmAnyDirectoryListGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchFrameworkPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmAnyDirectoryListGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&>(cmFindPackageCommand::SearchFrameworkPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmAnyDirectoryListGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchFrameworkPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmAnyDirectoryListGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&>(cmFindPackageCommand::SearchFrameworkPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmAnyDirectoryListGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchAppBundlePrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmMacProjectDirectoryListGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator>(cmFindPackageCommand::SearchAppBundlePrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmMacProjectDirectoryListGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchAppBundlePrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator>(cmFindPackageCommand::SearchAppBundlePrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmAppendPathSegmentGenerator&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchAppBundlePrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator>(cmFindPackageCommand::SearchAppBundlePrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmCaseInsensitiveDirectoryListGenerator&&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchAppBundlePrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmMacProjectDirectoryListGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&>(cmFindPackageCommand::SearchAppBundlePrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmMacProjectDirectoryListGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchAppBundlePrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmAppendPathSegmentGenerator&>(cmFindPackageCommand::SearchAppBundlePrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmAppendPathSegmentGenerator&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchEnvironmentPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmProjectDirectoryListGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator>(cmFindPackageCommand::SearchEnvironmentPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmProjectDirectoryListGenerator&, (anonymous namespace)::cmAppendPathSegmentGenerator&&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchEnvironmentPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmAppendPathSegmentGenerator>(cmFindPackageCommand::SearchEnvironmentPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmAppendPathSegmentGenerator&&)
Unexecuted instantiation: cmFindPackageCommand.cxx:bool (anonymous namespace)::TryGeneratedPaths<cmFindPackageCommand::SearchEnvironmentPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, (anonymous namespace)::cmProjectDirectoryListGenerator&>(cmFindPackageCommand::SearchEnvironmentPrefix(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::$_0&, cmFindPackageCommand::PackageDescriptionType, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, (anonymous namespace)::cmProjectDirectoryListGenerator&)
418
419
#ifdef CM_LCC_DIAG_SUPPRESS_3308
420
#  undef CM_LCC_DIAG_SUPPRESS_3308
421
#  pragma diag_default 3308
422
#endif
423
424
#ifdef CM_LCC_DIAG_SUPPRESS_3301
425
#  undef CM_LCC_DIAG_SUPPRESS_3301
426
#  pragma diag_default 3301
427
#endif
428
429
#ifdef CM_LCC_DIAG_SUPPRESS_3288
430
#  undef CM_LCC_DIAG_SUPPRESS_3288
431
#  pragma diag_default 3288
432
#endif
433
434
#ifdef CM_LCC_DIAG_SUPPRESS_1222
435
#  undef CM_LCC_DIAG_SUPPRESS_1222
436
#  pragma diag_default 1222
437
#endif
438
439
// Parse the version number and store the results that were
440
// successfully parsed.
441
unsigned int parseVersion(std::string const& version, unsigned int& major,
442
                          unsigned int& minor, unsigned int& patch,
443
                          unsigned int& tweak)
444
0
{
445
0
  return static_cast<unsigned int>(std::sscanf(
446
0
    version.c_str(), "%u.%u.%u.%u", &major, &minor, &patch, &tweak));
447
0
}
448
449
} // anonymous namespace
450
451
class cmFindPackageCommand::FlushDebugBufferOnExit
452
{
453
  cmFindPackageCommand& Command;
454
455
public:
456
  FlushDebugBufferOnExit(cmFindPackageCommand& command)
457
0
    : Command(command)
458
0
  {
459
0
  }
460
  ~FlushDebugBufferOnExit()
461
0
  {
462
0
    if (!Command.DebugBuffer.empty()) {
463
0
      Command.DebugMessage(Command.DebugBuffer);
464
0
    }
465
0
  }
466
};
467
468
class cmFindPackageCommand::PushPopRootPathStack
469
{
470
  cmFindPackageCommand& Command;
471
472
public:
473
  PushPopRootPathStack(cmFindPackageCommand& command)
474
0
    : Command(command)
475
0
  {
476
0
    Command.PushFindPackageRootPathStack();
477
0
  }
478
0
  ~PushPopRootPathStack() { Command.PopFindPackageRootPathStack(); }
479
};
480
481
class cmFindPackageCommand::SetRestoreFindDefinitions
482
{
483
  cmFindPackageCommand& Command;
484
485
public:
486
  SetRestoreFindDefinitions(cmFindPackageCommand& command)
487
0
    : Command(command)
488
0
  {
489
0
    Command.SetModuleVariables();
490
0
  }
491
0
  ~SetRestoreFindDefinitions() { Command.RestoreFindDefinitions(); }
492
};
493
494
cmFindPackageCommand::PathLabel
495
  cmFindPackageCommand::PathLabel::PackageRedirect("PACKAGE_REDIRECT");
496
cmFindPackageCommand::PathLabel cmFindPackageCommand::PathLabel::UserRegistry(
497
  "PACKAGE_REGISTRY");
498
cmFindPackageCommand::PathLabel cmFindPackageCommand::PathLabel::Builds(
499
  "BUILDS");
500
cmFindPackageCommand::PathLabel
501
  cmFindPackageCommand::PathLabel::SystemRegistry("SYSTEM_PACKAGE_REGISTRY");
502
503
cm::string_view const cmFindPackageCommand::VERSION_ENDPOINT_INCLUDED(
504
  "INCLUDE");
505
cm::string_view const cmFindPackageCommand::VERSION_ENDPOINT_EXCLUDED(
506
  "EXCLUDE");
507
508
void cmFindPackageCommand::Sort(std::vector<std::string>::iterator begin,
509
                                std::vector<std::string>::iterator end,
510
                                SortOrderType const order,
511
                                SortDirectionType const dir)
512
0
{
513
0
  if (order == Name_order) {
514
0
    if (dir == Dec) {
515
0
      std::sort(begin, end, std::greater<std::string>());
516
0
    } else {
517
0
      std::sort(begin, end);
518
0
    }
519
0
  } else if (order == Natural) {
520
    // natural order uses letters and numbers (contiguous numbers digit are
521
    // compared such that e.g. 000  00 < 01 < 010 < 09 < 0 < 1 < 9 < 10
522
0
    if (dir == Dec) {
523
0
      std::sort(begin, end, StrverscmpOp<std::greater>());
524
0
    } else {
525
0
      std::sort(begin, end, StrverscmpOp<std::less>());
526
0
    }
527
0
  }
528
  // else do not sort
529
0
}
530
531
cmFindPackageCommand::cmFindPackageCommand(cmExecutionStatus& status)
532
0
  : cmFindCommon(status)
533
0
  , VersionRangeMin(VERSION_ENDPOINT_INCLUDED)
534
0
  , VersionRangeMax(VERSION_ENDPOINT_INCLUDED)
535
0
{
536
0
  this->CMakePathName = "PACKAGE";
537
0
  this->AppendSearchPathGroups();
538
539
0
  this->DeprecatedFindModules["Boost"] = cmPolicies::CMP0167;
540
0
  this->DeprecatedFindModules["CABLE"] = cmPolicies::CMP0191;
541
0
  this->DeprecatedFindModules["CUDA"] = cmPolicies::CMP0146;
542
0
  this->DeprecatedFindModules["Dart"] = cmPolicies::CMP0145;
543
0
  this->DeprecatedFindModules["GCCXML"] = cmPolicies::CMP0188;
544
0
  this->DeprecatedFindModules["PythonInterp"] = cmPolicies::CMP0148;
545
0
  this->DeprecatedFindModules["PythonLibs"] = cmPolicies::CMP0148;
546
0
  this->DeprecatedFindModules["Qt"] = cmPolicies::CMP0084;
547
0
}
548
549
cmFindPackageCommand::~cmFindPackageCommand()
550
0
{
551
0
  if (this->DebugState) {
552
0
    this->DebugState->Write();
553
0
  }
554
0
}
555
556
void cmFindPackageCommand::AppendSearchPathGroups()
557
0
{
558
  // Update the All group with new paths. Note that package redirection must
559
  // take precedence over everything else, so it has to be first in the array.
560
0
  std::vector<cmFindCommon::PathLabel>* const labels =
561
0
    &this->PathGroupLabelMap[PathGroup::All];
562
0
  labels->insert(labels->begin(), PathLabel::PackageRedirect);
563
0
  labels->insert(
564
0
    std::find(labels->begin(), labels->end(), PathLabel::CMakeSystem),
565
0
    PathLabel::UserRegistry);
566
0
  labels->insert(
567
0
    std::find(labels->begin(), labels->end(), PathLabel::CMakeSystem),
568
0
    PathLabel::Builds);
569
0
  labels->insert(std::find(labels->begin(), labels->end(), PathLabel::Guess),
570
0
                 PathLabel::SystemRegistry);
571
572
  // Create the new path objects
573
0
  this->LabeledPaths.emplace(PathLabel::PackageRedirect, cmSearchPath{ this });
574
0
  this->LabeledPaths.emplace(PathLabel::UserRegistry, cmSearchPath{ this });
575
0
  this->LabeledPaths.emplace(PathLabel::Builds, cmSearchPath{ this });
576
0
  this->LabeledPaths.emplace(PathLabel::SystemRegistry, cmSearchPath{ this });
577
0
}
578
579
void cmFindPackageCommand::InheritOptions(cmFindPackageCommand* other)
580
0
{
581
0
  this->RequiredCMakeVersion = other->RequiredCMakeVersion;
582
0
  this->LibraryArchitecture = other->LibraryArchitecture;
583
0
  this->UseLib32Paths = other->UseLib32Paths;
584
0
  this->UseLib64Paths = other->UseLib64Paths;
585
0
  this->UseLibx32Paths = other->UseLibx32Paths;
586
0
  this->NoUserRegistry = other->NoUserRegistry;
587
0
  this->NoSystemRegistry = other->NoSystemRegistry;
588
0
  this->UseRealPath = other->UseRealPath;
589
0
  this->SortOrder = other->SortOrder;
590
0
  this->SortDirection = other->SortDirection;
591
592
0
  this->GlobalScope = other->GlobalScope;
593
0
  this->RegistryView = other->RegistryView;
594
0
  this->NoDefaultPath = other->NoDefaultPath;
595
0
  this->NoPackageRootPath = other->NoPackageRootPath;
596
0
  this->NoCMakePath = other->NoCMakePath;
597
0
  this->NoCMakeEnvironmentPath = other->NoCMakeEnvironmentPath;
598
0
  this->NoSystemEnvironmentPath = other->NoSystemEnvironmentPath;
599
0
  this->NoCMakeSystemPath = other->NoCMakeSystemPath;
600
0
  this->NoCMakeInstallPath = other->NoCMakeInstallPath;
601
0
  this->FindRootPathMode = other->FindRootPathMode;
602
603
0
  this->SearchFrameworkLast = other->SearchFrameworkLast;
604
0
  this->SearchFrameworkFirst = other->SearchFrameworkFirst;
605
0
  this->SearchFrameworkOnly = other->SearchFrameworkOnly;
606
0
  this->SearchAppBundleLast = other->SearchAppBundleLast;
607
0
  this->SearchAppBundleFirst = other->SearchAppBundleFirst;
608
0
  this->SearchAppBundleOnly = other->SearchAppBundleOnly;
609
0
  this->SearchPathSuffixes = other->SearchPathSuffixes;
610
611
0
  this->Quiet = other->Quiet;
612
0
}
613
614
bool cmFindPackageCommand::IsFound() const
615
0
{
616
0
  return this->InitialState == FindState::Found;
617
0
}
618
619
bool cmFindPackageCommand::IsDefined() const
620
0
{
621
0
  return this->InitialState == FindState::Found ||
622
0
    this->InitialState == FindState::NotFound;
623
0
}
624
625
bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args)
626
0
{
627
0
  if (args.empty()) {
628
0
    this->SetError("called with incorrect number of arguments");
629
0
    return false;
630
0
  }
631
632
0
  if (this->Makefile->GetStateSnapshot().GetUnwindState() ==
633
0
      cmStateEnums::UNWINDING) {
634
0
    this->SetError("called while already in an UNWIND state");
635
0
    return false;
636
0
  }
637
638
  // Lookup required version of CMake.
639
0
  if (cmValue const rv =
640
0
        this->Makefile->GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION")) {
641
0
    unsigned int v[3] = { 0, 0, 0 };
642
0
    std::sscanf(rv->c_str(), "%u.%u.%u", &v[0], &v[1], &v[2]);
643
0
    this->RequiredCMakeVersion = CMake_VERSION_ENCODE(v[0], v[1], v[2]);
644
0
  }
645
646
  // Lookup target architecture, if any.
647
0
  if (cmValue const arch =
648
0
        this->Makefile->GetDefinition("CMAKE_LIBRARY_ARCHITECTURE")) {
649
0
    this->LibraryArchitecture = *arch;
650
0
  }
651
652
  // Lookup whether lib32 paths should be used.
653
0
  if (this->Makefile->PlatformIs32Bit() &&
654
0
      this->Makefile->GetState()->GetGlobalPropertyAsBool(
655
0
        "FIND_LIBRARY_USE_LIB32_PATHS")) {
656
0
    this->UseLib32Paths = true;
657
0
  }
658
659
  // Lookup whether lib64 paths should be used.
660
0
  if (this->Makefile->PlatformIs64Bit() &&
661
0
      this->Makefile->GetState()->GetGlobalPropertyAsBool(
662
0
        "FIND_LIBRARY_USE_LIB64_PATHS")) {
663
0
    this->UseLib64Paths = true;
664
0
  }
665
666
  // Lookup whether libx32 paths should be used.
667
0
  if (this->Makefile->PlatformIsx32() &&
668
0
      this->Makefile->GetState()->GetGlobalPropertyAsBool(
669
0
        "FIND_LIBRARY_USE_LIBX32_PATHS")) {
670
0
    this->UseLibx32Paths = true;
671
0
  }
672
673
  // Check if User Package Registry should be disabled
674
  // The `CMAKE_FIND_USE_PACKAGE_REGISTRY` has
675
  // priority over the deprecated CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY
676
0
  if (cmValue const def =
677
0
        this->Makefile->GetDefinition("CMAKE_FIND_USE_PACKAGE_REGISTRY")) {
678
0
    this->NoUserRegistry = !def.IsOn();
679
0
  } else if (this->Makefile->IsOn("CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY")) {
680
0
    this->NoUserRegistry = true;
681
0
  }
682
683
  // Check if System Package Registry should be disabled
684
  // The `CMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY` has
685
  // priority over the deprecated CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY
686
0
  if (cmValue const def = this->Makefile->GetDefinition(
687
0
        "CMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY")) {
688
0
    this->NoSystemRegistry = !def.IsOn();
689
0
  } else if (this->Makefile->IsOn(
690
0
               "CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY")) {
691
0
    this->NoSystemRegistry = true;
692
0
  }
693
694
  // Check whether we should resolve symlinks when finding packages
695
0
  if (this->Makefile->IsOn("CMAKE_FIND_PACKAGE_RESOLVE_SYMLINKS")) {
696
0
    this->UseRealPath = true;
697
0
  }
698
699
  // Check if Sorting should be enabled
700
0
  if (cmValue const so =
701
0
        this->Makefile->GetDefinition("CMAKE_FIND_PACKAGE_SORT_ORDER")) {
702
703
0
    if (*so == "NAME") {
704
0
      this->SortOrder = Name_order;
705
0
    } else if (*so == "NATURAL") {
706
0
      this->SortOrder = Natural;
707
0
    } else {
708
0
      this->SortOrder = None;
709
0
    }
710
0
  }
711
0
  if (cmValue const sd =
712
0
        this->Makefile->GetDefinition("CMAKE_FIND_PACKAGE_SORT_DIRECTION")) {
713
0
    this->SortDirection = (*sd == "DEC") ? Dec : Asc;
714
0
  }
715
716
  // Find what search path locations have been enabled/disable.
717
0
  this->SelectDefaultSearchModes();
718
719
  // Find the current root path mode.
720
0
  this->SelectDefaultRootPathMode();
721
722
  // Find the current bundle/framework search policy.
723
0
  this->SelectDefaultMacMode();
724
725
  // Record options.
726
0
  this->Name = args[0];
727
0
  cm::string_view componentsSep = ""_s;
728
729
  // Always search directly in a generated path.
730
0
  this->SearchPathSuffixes.emplace_back();
731
732
  // Process debug mode
733
0
  cmMakefile::DebugFindPkgRAII debugFindPkgRAII(this->Makefile, this->Name);
734
0
  this->FullDebugMode = this->ComputeIfDebugModeWanted();
735
0
  if (this->FullDebugMode || !this->ComputeIfImplicitDebugModeSuppressed()) {
736
0
    this->DebugState = cm::make_unique<cmFindPackageDebugState>(this);
737
0
  }
738
739
  // Parse the arguments.
740
0
  enum Doing
741
0
  {
742
0
    DoingNone,
743
0
    DoingComponents,
744
0
    DoingOptionalComponents,
745
0
    DoingNames,
746
0
    DoingPaths,
747
0
    DoingPathSuffixes,
748
0
    DoingConfigs,
749
0
    DoingHints
750
0
  };
751
0
  Doing doing = DoingNone;
752
0
  cmsys::RegularExpression versionRegex(
753
0
    R"V(^([0-9]+(\.[0-9]+)*)(\.\.\.(<?)([0-9]+(\.[0-9]+)*))?$)V");
754
0
  bool haveVersion = false;
755
0
  std::vector<std::size_t> configArgs;
756
0
  std::vector<std::size_t> moduleArgs;
757
0
  for (std::size_t i = 1u; i < args.size(); ++i) {
758
0
    if (args[i] == "QUIET") {
759
0
      this->Quiet = true;
760
0
      doing = DoingNone;
761
0
    } else if (args[i] == "BYPASS_PROVIDER") {
762
0
      this->BypassProvider = true;
763
0
      doing = DoingNone;
764
0
    } else if (args[i] == "EXACT") {
765
0
      this->VersionExact = true;
766
0
      doing = DoingNone;
767
0
    } else if (args[i] == "GLOBAL") {
768
0
      this->GlobalScope = true;
769
0
      doing = DoingNone;
770
0
    } else if (args[i] == "MODULE") {
771
0
      moduleArgs.push_back(i);
772
0
      doing = DoingNone;
773
      // XXX(clang-tidy): https://bugs.llvm.org/show_bug.cgi?id=44165
774
      // NOLINTNEXTLINE(bugprone-branch-clone)
775
0
    } else if (args[i] == "CONFIG") {
776
0
      configArgs.push_back(i);
777
0
      doing = DoingNone;
778
      // XXX(clang-tidy): https://bugs.llvm.org/show_bug.cgi?id=44165
779
      // NOLINTNEXTLINE(bugprone-branch-clone)
780
0
    } else if (args[i] == "NO_MODULE") {
781
0
      configArgs.push_back(i);
782
0
      doing = DoingNone;
783
0
    } else if (args[i] == "REQUIRED") {
784
0
      if (this->Required == RequiredStatus::OptionalExplicit) {
785
0
        this->SetError("cannot be both REQUIRED and OPTIONAL");
786
0
        return false;
787
0
      }
788
0
      this->Required = RequiredStatus::RequiredExplicit;
789
0
      doing = DoingComponents;
790
0
    } else if (args[i] == "OPTIONAL") {
791
0
      if (this->Required == RequiredStatus::RequiredExplicit) {
792
0
        this->SetError("cannot be both REQUIRED and OPTIONAL");
793
0
        return false;
794
0
      }
795
0
      this->Required = RequiredStatus::OptionalExplicit;
796
0
      doing = DoingComponents;
797
0
    } else if (args[i] == "COMPONENTS") {
798
0
      doing = DoingComponents;
799
0
    } else if (args[i] == "OPTIONAL_COMPONENTS") {
800
0
      doing = DoingOptionalComponents;
801
0
    } else if (args[i] == "NAMES") {
802
0
      configArgs.push_back(i);
803
0
      doing = DoingNames;
804
0
    } else if (args[i] == "PATHS") {
805
0
      configArgs.push_back(i);
806
0
      doing = DoingPaths;
807
0
    } else if (args[i] == "HINTS") {
808
0
      configArgs.push_back(i);
809
0
      doing = DoingHints;
810
0
    } else if (args[i] == "PATH_SUFFIXES") {
811
0
      configArgs.push_back(i);
812
0
      doing = DoingPathSuffixes;
813
0
    } else if (args[i] == "CONFIGS") {
814
0
      configArgs.push_back(i);
815
0
      doing = DoingConfigs;
816
0
    } else if (args[i] == "NO_POLICY_SCOPE") {
817
0
      this->PolicyScope = false;
818
0
      doing = DoingNone;
819
0
    } else if (args[i] == "NO_CMAKE_PACKAGE_REGISTRY") {
820
0
      this->NoUserRegistry = true;
821
0
      configArgs.push_back(i);
822
0
      doing = DoingNone;
823
0
    } else if (args[i] == "NO_CMAKE_SYSTEM_PACKAGE_REGISTRY") {
824
0
      this->NoSystemRegistry = true;
825
0
      configArgs.push_back(i);
826
0
      doing = DoingNone;
827
      // XXX(clang-tidy): https://bugs.llvm.org/show_bug.cgi?id=44165
828
      // NOLINTNEXTLINE(bugprone-branch-clone)
829
0
    } else if (args[i] == "NO_CMAKE_BUILDS_PATH") {
830
      // Ignore legacy option.
831
0
      configArgs.push_back(i);
832
0
      doing = DoingNone;
833
0
    } else if (args[i] == "REGISTRY_VIEW") {
834
0
      if (++i == args.size()) {
835
0
        this->SetError("missing required argument for REGISTRY_VIEW");
836
0
        return false;
837
0
      }
838
0
      auto view = cmWindowsRegistry::ToView(args[i]);
839
0
      if (view) {
840
0
        this->RegistryView = *view;
841
0
        this->RegistryViewDefined = true;
842
0
      } else {
843
0
        this->SetError(
844
0
          cmStrCat("given invalid value for REGISTRY_VIEW: ", args[i]));
845
0
        return false;
846
0
      }
847
0
    } else if (args[i] == "UNWIND_INCLUDE") {
848
0
      if (this->Makefile->GetStateSnapshot().GetUnwindType() !=
849
0
          cmStateEnums::CAN_UNWIND) {
850
0
        this->SetError("called with UNWIND_INCLUDE in an invalid context");
851
0
        return false;
852
0
      }
853
0
      this->ScopeUnwind = true;
854
0
      doing = DoingNone;
855
0
    } else if (this->CheckCommonArgument(args[i])) {
856
0
      configArgs.push_back(i);
857
0
      doing = DoingNone;
858
0
    } else if ((doing == DoingComponents) ||
859
0
               (doing == DoingOptionalComponents)) {
860
      // Set a variable telling the find script whether this component
861
      // is required.
862
0
      if (doing == DoingOptionalComponents) {
863
0
        this->OptionalComponents.insert(args[i]);
864
0
      } else {
865
0
        this->RequiredComponents.insert(args[i]);
866
0
      }
867
868
      // Append to the list of required components.
869
0
      this->Components += componentsSep;
870
0
      this->Components += args[i];
871
0
      componentsSep = ";"_s;
872
0
    } else if (doing == DoingNames) {
873
0
      this->Names.push_back(args[i]);
874
0
    } else if (doing == DoingPaths) {
875
0
      this->UserGuessArgs.push_back(args[i]);
876
0
    } else if (doing == DoingHints) {
877
0
      this->UserHintsArgs.push_back(args[i]);
878
0
    } else if (doing == DoingPathSuffixes) {
879
0
      this->AddPathSuffix(args[i]);
880
0
    } else if (doing == DoingConfigs) {
881
0
      if (args[i].find_first_of(":/\\") != std::string::npos ||
882
0
          !cmHasSuffix(args[i], ".cmake"_s)) {
883
0
        this->SetError(cmStrCat(
884
0
          "given CONFIGS option followed by invalid file name \"", args[i],
885
0
          "\".  The names given must be file names without "
886
0
          "a path and with a \".cmake\" extension."));
887
0
        return false;
888
0
      }
889
0
      this->Configs.emplace_back(args[i], pdt::CMake);
890
0
    } else if (!haveVersion && versionRegex.find(args[i])) {
891
0
      haveVersion = true;
892
0
      this->VersionComplete = args[i];
893
0
    } else {
894
0
      this->SetError(
895
0
        cmStrCat("called with invalid argument \"", args[i], '"'));
896
0
      return false;
897
0
    }
898
0
  }
899
900
0
  if (this->Required == RequiredStatus::Optional &&
901
0
      this->Makefile->IsOn("CMAKE_FIND_REQUIRED")) {
902
0
    this->Required = RequiredStatus::RequiredFromFindVar;
903
0
  }
904
905
0
  if (!this->GlobalScope) {
906
0
    cmValue value(
907
0
      this->Makefile->GetDefinition("CMAKE_FIND_PACKAGE_TARGETS_GLOBAL"));
908
0
    this->GlobalScope = value.IsOn();
909
0
  }
910
911
0
  std::vector<std::string> doubledComponents;
912
0
  std::set_intersection(
913
0
    this->RequiredComponents.begin(), this->RequiredComponents.end(),
914
0
    this->OptionalComponents.begin(), this->OptionalComponents.end(),
915
0
    std::back_inserter(doubledComponents));
916
0
  if (!doubledComponents.empty()) {
917
0
    this->SetError(
918
0
      cmStrCat("called with components that are both required and "
919
0
               "optional:\n",
920
0
               cmWrap("  ", doubledComponents, "", "\n"), '\n'));
921
0
    return false;
922
0
  }
923
924
  // Check and eliminate search modes not allowed by the args provided
925
0
  this->UseFindModules = configArgs.empty();
926
0
  this->UseConfigFiles = moduleArgs.empty();
927
0
  if (this->UseConfigFiles) {
928
0
    this->UseCpsFiles = this->Configs.empty();
929
0
  } else {
930
0
    this->UseCpsFiles = false;
931
0
  }
932
0
  if (!this->UseFindModules && !this->UseConfigFiles) {
933
0
    std::ostringstream e;
934
0
    e << "given options exclusive to Module mode:\n";
935
0
    for (auto si : moduleArgs) {
936
0
      e << "  " << args[si] << "\n";
937
0
    }
938
0
    e << "and options exclusive to Config mode:\n";
939
0
    for (auto si : configArgs) {
940
0
      e << "  " << args[si] << "\n";
941
0
    }
942
0
    e << "The options are incompatible.";
943
0
    this->SetError(e.str());
944
0
    return false;
945
0
  }
946
947
0
  bool canBeIrrelevant = true;
948
0
  if (this->UseConfigFiles || this->UseCpsFiles) {
949
0
    canBeIrrelevant = false;
950
0
    if (cmValue v = this->Makefile->GetState()->GetCacheEntryValue(
951
0
          cmStrCat(this->Name, "_DIR"))) {
952
0
      if (!v.IsNOTFOUND()) {
953
0
        this->InitialState = FindState::Found;
954
0
      } else {
955
0
        this->InitialState = FindState::NotFound;
956
0
      }
957
0
    }
958
0
  }
959
960
0
  if (this->UseFindModules &&
961
0
      (this->InitialState == FindState::Undefined ||
962
0
       this->InitialState == FindState::NotFound)) {
963
    // There are no definitive cache variables to know if a given `Find` module
964
    // has been searched for or not. However, if we have a `_FOUND` variable,
965
    // use that as an indication of a previous search.
966
0
    if (cmValue v =
967
0
          this->Makefile->GetDefinition(cmStrCat(this->Name, "_FOUND"))) {
968
0
      if (v.IsOn()) {
969
0
        this->InitialState = FindState::Found;
970
0
      } else {
971
0
        this->InitialState = FindState::NotFound;
972
0
      }
973
0
    }
974
0
  }
975
976
  // If there is no signaling variable and there's no reason to expect a cache
977
  // variable, mark the initial state as "irrelevant".
978
0
  if (this->InitialState == FindState::Undefined && canBeIrrelevant) {
979
0
    this->InitialState = FindState::Irrelevant;
980
0
  }
981
982
  // Ignore EXACT with no version.
983
0
  if (this->VersionComplete.empty() && this->VersionExact) {
984
0
    this->VersionExact = false;
985
0
    this->Makefile->IssueDiagnostic(
986
0
      cmDiagnostics::CMD_AUTHOR,
987
0
      "Ignoring EXACT since no version is requested.");
988
0
  }
989
990
0
  if (this->VersionComplete.empty() || this->Components.empty()) {
991
    // Check whether we are recursing inside "Find<name>.cmake" within
992
    // another find_package(<name>) call.
993
0
    std::string const mod = cmStrCat(this->Name, "_FIND_MODULE");
994
0
    if (this->Makefile->IsOn(mod)) {
995
0
      if (this->VersionComplete.empty()) {
996
        // Get version information from the outer call if necessary.
997
        // Requested version string.
998
0
        std::string const ver = cmStrCat(this->Name, "_FIND_VERSION_COMPLETE");
999
0
        this->VersionComplete = this->Makefile->GetSafeDefinition(ver);
1000
1001
        // Whether an exact version is required.
1002
0
        std::string const exact = cmStrCat(this->Name, "_FIND_VERSION_EXACT");
1003
0
        this->VersionExact = this->Makefile->IsOn(exact);
1004
0
      }
1005
0
      if (this->Components.empty()) {
1006
0
        std::string const componentsVar = this->Name + "_FIND_COMPONENTS";
1007
0
        this->Components = this->Makefile->GetSafeDefinition(componentsVar);
1008
0
        for (auto const& component : cmList{ this->Components }) {
1009
0
          std::string const crVar =
1010
0
            cmStrCat(this->Name, "_FIND_REQUIRED_"_s, component);
1011
0
          if (this->Makefile->GetDefinition(crVar).IsOn()) {
1012
0
            this->RequiredComponents.insert(component);
1013
0
          } else {
1014
0
            this->OptionalComponents.insert(component);
1015
0
          }
1016
0
        }
1017
0
      }
1018
0
    }
1019
0
  }
1020
1021
  // fill various parts of version specification
1022
0
  if (!this->VersionComplete.empty()) {
1023
0
    if (!versionRegex.find(this->VersionComplete)) {
1024
0
      this->SetError("called with invalid version specification.");
1025
0
      return false;
1026
0
    }
1027
1028
0
    this->Version = versionRegex.match(1);
1029
0
    this->VersionMax = versionRegex.match(5);
1030
0
    if (versionRegex.match(4) == "<"_s) {
1031
0
      this->VersionRangeMax = VERSION_ENDPOINT_EXCLUDED;
1032
0
    }
1033
0
    if (!this->VersionMax.empty()) {
1034
0
      this->VersionRange = this->VersionComplete;
1035
0
    }
1036
0
  }
1037
1038
0
  if (!this->VersionRange.empty()) {
1039
    // version range must not be empty
1040
0
    if ((this->VersionRangeMax == VERSION_ENDPOINT_INCLUDED &&
1041
0
         cmSystemTools::VersionCompareGreater(this->Version,
1042
0
                                              this->VersionMax)) ||
1043
0
        (this->VersionRangeMax == VERSION_ENDPOINT_EXCLUDED &&
1044
0
         cmSystemTools::VersionCompareGreaterEq(this->Version,
1045
0
                                                this->VersionMax))) {
1046
0
      this->SetError("specified version range is empty.");
1047
0
      return false;
1048
0
    }
1049
0
  }
1050
1051
0
  if (this->VersionExact && !this->VersionRange.empty()) {
1052
0
    this->SetError("EXACT cannot be specified with a version range.");
1053
0
    return false;
1054
0
  }
1055
1056
0
  if (!this->Version.empty()) {
1057
0
    this->VersionCount =
1058
0
      parseVersion(this->Version, this->VersionMajor, this->VersionMinor,
1059
0
                   this->VersionPatch, this->VersionTweak);
1060
0
  }
1061
0
  if (!this->VersionMax.empty()) {
1062
0
    this->VersionMaxCount = parseVersion(
1063
0
      this->VersionMax, this->VersionMaxMajor, this->VersionMaxMinor,
1064
0
      this->VersionMaxPatch, this->VersionMaxTweak);
1065
0
  }
1066
1067
0
  bool result = this->FindPackage(
1068
0
    this->BypassProvider ? std::vector<std::string>{} : args);
1069
1070
0
  std::string const foundVar = cmStrCat(this->Name, "_FOUND");
1071
0
  bool const isFound = this->Makefile->IsOn(foundVar) ||
1072
0
    this->Makefile->IsOn(cmSystemTools::UpperCase(foundVar));
1073
1074
0
  if (this->ScopeUnwind && (!result || !isFound)) {
1075
0
    this->Makefile->GetStateSnapshot().SetUnwindState(cmStateEnums::UNWINDING);
1076
0
  }
1077
1078
0
  return result;
1079
0
}
1080
1081
bool cmFindPackageCommand::FindPackage(
1082
  std::vector<std::string> const& argsForProvider)
1083
0
{
1084
0
  std::string const makePackageRequiredVar =
1085
0
    cmStrCat("CMAKE_REQUIRE_FIND_PACKAGE_", this->Name);
1086
0
  bool const makePackageRequiredSet =
1087
0
    this->Makefile->IsOn(makePackageRequiredVar);
1088
0
  if (makePackageRequiredSet) {
1089
0
    if (this->IsRequired()) {
1090
0
      this->Makefile->IssueMessage(
1091
0
        MessageType::WARNING,
1092
0
        cmStrCat("for module ", this->Name,
1093
0
                 " already called with REQUIRED, thus ",
1094
0
                 makePackageRequiredVar, " has no effect."));
1095
0
    } else {
1096
0
      this->Required = RequiredStatus::RequiredFromPackageVar;
1097
0
    }
1098
0
  }
1099
1100
0
  std::string const disableFindPackageVar =
1101
0
    cmStrCat("CMAKE_DISABLE_FIND_PACKAGE_", this->Name);
1102
0
  if (this->Makefile->IsOn(disableFindPackageVar)) {
1103
0
    if (this->IsRequired()) {
1104
0
      this->SetError(
1105
0
        cmStrCat("for module ", this->Name,
1106
0
                 (makePackageRequiredSet
1107
0
                    ? " was made REQUIRED with " + makePackageRequiredVar
1108
0
                    : " called with REQUIRED, "),
1109
0
                 " but ", disableFindPackageVar,
1110
0
                 " is enabled. A REQUIRED package cannot be disabled."));
1111
0
      return false;
1112
0
    }
1113
0
    return true;
1114
0
  }
1115
1116
  // Restore PACKAGE_PREFIX_DIR to its pre-call value when we return. If our
1117
  // caller is a file generated by configure_package_config_file(), and if
1118
  // the package we are about to load also has a config file created by that
1119
  // command, it will overwrite PACKAGE_PREFIX_DIR. We need to restore it in
1120
  // case something still refers to it in our caller's scope after we return.
1121
0
  class RestoreVariableOnLeavingScope
1122
0
  {
1123
0
    cmMakefile* makefile_;
1124
0
    cm::optional<std::string> value_;
1125
1126
0
  public:
1127
0
    RestoreVariableOnLeavingScope(cmMakefile* makefile)
1128
0
      : makefile_(makefile)
1129
0
    {
1130
0
      cmValue v = makefile->GetDefinition("PACKAGE_PREFIX_DIR");
1131
0
      if (v) {
1132
0
        value_ = *v;
1133
0
      }
1134
0
    }
1135
0
    ~RestoreVariableOnLeavingScope()
1136
0
    {
1137
0
      if (this->value_) {
1138
0
        makefile_->AddDefinition("PACKAGE_PREFIX_DIR", *value_);
1139
0
      } else {
1140
0
        makefile_->RemoveDefinition("PACKAGE_PREFIX_DIR");
1141
0
      }
1142
0
    }
1143
0
  };
1144
0
  RestoreVariableOnLeavingScope restorePackagePrefixDir(this->Makefile);
1145
1146
  // Now choose what method(s) we will use to satisfy the request. Note that
1147
  // we still want all the above checking of arguments, etc. regardless of the
1148
  // method used. This will ensure ill-formed arguments are caught earlier,
1149
  // before things like dependency providers need to deal with them.
1150
1151
  // A dependency provider (if set) gets first look before other methods.
1152
  // We do this before modifying the package root path stack because a
1153
  // provider might use methods that ignore that.
1154
0
  cmState* const state = this->Makefile->GetState();
1155
0
  cmState::Command const providerCommand = state->GetDependencyProviderCommand(
1156
0
    cmDependencyProvider::Method::FindPackage);
1157
0
  if (argsForProvider.empty()) {
1158
0
    if (this->DebugModeEnabled() && providerCommand) {
1159
0
      this->DebugMessage(
1160
0
        "BYPASS_PROVIDER given, skipping dependency provider");
1161
0
    }
1162
0
  } else if (providerCommand) {
1163
0
    if (this->DebugModeEnabled()) {
1164
0
      this->DebugMessage(cmStrCat("Trying dependency provider command: ",
1165
0
                                  state->GetDependencyProvider()->GetCommand(),
1166
0
                                  "()"));
1167
0
    }
1168
0
    std::vector<cmListFileArgument> listFileArgs(argsForProvider.size() + 1);
1169
0
    listFileArgs[0] =
1170
0
      cmListFileArgument("FIND_PACKAGE"_s, cmListFileArgument::Unquoted, 0);
1171
0
    std::transform(argsForProvider.begin(), argsForProvider.end(),
1172
0
                   listFileArgs.begin() + 1, [](std::string const& arg) {
1173
0
                     return cmListFileArgument(arg,
1174
0
                                               cmListFileArgument::Bracket, 0);
1175
0
                   });
1176
0
    if (!providerCommand(listFileArgs, this->Status)) {
1177
0
      return false;
1178
0
    }
1179
0
    std::string providerName;
1180
0
    if (auto depProvider = state->GetDependencyProvider()) {
1181
0
      providerName = depProvider->GetCommand();
1182
0
    } else {
1183
0
      providerName = "<no provider?>";
1184
0
    }
1185
0
    auto searchPath = cmStrCat("dependency_provider::", providerName);
1186
0
    if (this->Makefile->IsOn(cmStrCat(this->Name, "_FOUND"))) {
1187
0
      if (this->DebugModeEnabled()) {
1188
0
        this->DebugMessage("Package was found by the dependency provider");
1189
0
      }
1190
0
      if (this->DebugState) {
1191
0
        this->DebugState->FoundAt(searchPath);
1192
0
      }
1193
0
      this->FileFound = searchPath;
1194
0
      this->FileFoundMode = FoundPackageMode::Provider;
1195
0
      this->AppendSuccessInformation();
1196
0
      return true;
1197
0
    }
1198
0
    this->ConsideredPaths.emplace_back(searchPath, FoundPackageMode::Provider,
1199
0
                                       SearchResult::NotFound);
1200
0
  }
1201
1202
  // Limit package nesting depth well below the recursion depth limit because
1203
  // find_package nesting uses more stack space than normal recursion.
1204
0
  {
1205
0
    static std::size_t const findPackageDepthMinMax = 100;
1206
0
    std::size_t const findPackageDepthMax = std::max(
1207
0
      this->Makefile->GetRecursionDepthLimit() / 2, findPackageDepthMinMax);
1208
0
    std::size_t const findPackageDepth =
1209
0
      this->Makefile->FindPackageRootPathStack.size() + 1;
1210
0
    if (findPackageDepth > findPackageDepthMax) {
1211
0
      this->SetError(cmStrCat("maximum nesting depth of ", findPackageDepthMax,
1212
0
                              " exceeded."));
1213
0
      return false;
1214
0
    }
1215
0
  }
1216
1217
  // Record package information discovered while it is loaded.
1218
0
  this->PackageInfo = std::make_shared<cmPackageInformation>();
1219
1220
  // RAII objects to ensure we leave this function with consistent state.
1221
0
  FlushDebugBufferOnExit flushDebugBufferOnExit(*this);
1222
0
  PushPopRootPathStack pushPopRootPathStack(*this);
1223
0
  SetRestoreFindDefinitions setRestoreFindDefinitions(*this);
1224
0
  cmMakefile::FindPackageStackRAII findPackageStackRAII(
1225
0
    this->Makefile, this->Name, this->PackageInfo);
1226
1227
  // See if we have been told to delegate to FetchContent or some other
1228
  // redirected config package first. We have to check all names that
1229
  // find_package() may look for, but only need to invoke the override for the
1230
  // first one that matches.
1231
0
  auto overrideNames = this->Names;
1232
0
  if (overrideNames.empty()) {
1233
0
    overrideNames.push_back(this->Name);
1234
0
  }
1235
0
  bool forceConfigMode = false;
1236
0
  auto const redirectsDir =
1237
0
    this->Makefile->GetSafeDefinition("CMAKE_FIND_PACKAGE_REDIRECTS_DIR");
1238
0
  for (auto const& overrideName : overrideNames) {
1239
0
    auto const nameLower = cmSystemTools::LowerCase(overrideName);
1240
0
    auto const delegatePropName =
1241
0
      cmStrCat("_FetchContent_", nameLower, "_override_find_package");
1242
0
    cmValue const delegateToFetchContentProp =
1243
0
      this->Makefile->GetState()->GetGlobalProperty(delegatePropName);
1244
0
    if (delegateToFetchContentProp.IsOn()) {
1245
      // When this property is set, the FetchContent module has already been
1246
      // included at least once, so we know the FetchContent_MakeAvailable()
1247
      // command will be defined. Any future find_package() calls after this
1248
      // one for this package will by-pass this once-only delegation.
1249
      // The following call will typically create a <name>-config.cmake file
1250
      // in the redirectsDir, which we still want to process like any other
1251
      // config file to ensure we follow normal find_package() processing.
1252
0
      cmListFileFunction func(
1253
0
        "FetchContent_MakeAvailable", 0, 0,
1254
0
        { cmListFileArgument(overrideName, cmListFileArgument::Unquoted, 0) });
1255
0
      if (!this->Makefile->ExecuteCommand(func, this->Status)) {
1256
0
        return false;
1257
0
      }
1258
0
    }
1259
1260
0
    if (cmSystemTools::FileExists(
1261
0
          cmStrCat(redirectsDir, '/', nameLower, "-config.cmake")) ||
1262
0
        cmSystemTools::FileExists(
1263
0
          cmStrCat(redirectsDir, '/', overrideName, "Config.cmake"))) {
1264
      // Force the use of this redirected config package file, regardless of
1265
      // the type of find_package() call. Files in the redirectsDir must always
1266
      // take priority over everything else.
1267
0
      forceConfigMode = true;
1268
0
      this->UseConfigFiles = true;
1269
0
      this->UseFindModules = false;
1270
0
      this->Names.clear();
1271
0
      this->Names.emplace_back(overrideName); // Force finding this one
1272
0
      this->Variable = cmStrCat(this->Name, "_DIR");
1273
0
      this->PackageInfo->Directory = redirectsDir;
1274
0
      this->PackageInfo->Version = this->VersionFound;
1275
0
      this->SetConfigDirCacheVariable(redirectsDir);
1276
0
      break;
1277
0
    }
1278
0
  }
1279
1280
  // See if there is a Find<PackageName>.cmake module.
1281
0
  bool loadedPackage = false;
1282
0
  if (forceConfigMode) {
1283
0
    loadedPackage = this->FindPackageUsingConfigMode();
1284
0
  } else if (this->Makefile->IsOn("CMAKE_FIND_PACKAGE_PREFER_CONFIG")) {
1285
0
    if (this->UseConfigFiles && this->FindPackageUsingConfigMode()) {
1286
0
      loadedPackage = true;
1287
0
    } else {
1288
0
      if (this->FindPackageUsingModuleMode()) {
1289
0
        loadedPackage = true;
1290
0
      } else {
1291
        // The package was not loaded. Report errors.
1292
0
        if (this->HandlePackageMode(HandlePackageModeType::Module)) {
1293
0
          loadedPackage = true;
1294
0
        }
1295
0
      }
1296
0
    }
1297
0
  } else {
1298
0
    if (this->UseFindModules && this->FindPackageUsingModuleMode()) {
1299
0
      loadedPackage = true;
1300
0
    } else {
1301
      // Handle CMAKE_FIND_PACKAGE_WARN_NO_MODULE (warn when CONFIG mode is
1302
      // implicitly assumed)
1303
0
      if (this->UseFindModules && this->UseConfigFiles &&
1304
0
          this->Makefile->IsOn("CMAKE_FIND_PACKAGE_WARN_NO_MODULE")) {
1305
0
        std::ostringstream aw;
1306
0
        if (this->RequiredCMakeVersion >= CMake_VERSION_ENCODE(2, 8, 8)) {
1307
0
          aw << "find_package called without either MODULE or CONFIG option "
1308
0
                "and "
1309
0
                "no Find"
1310
0
             << this->Name
1311
0
             << ".cmake module is in CMAKE_MODULE_PATH.  "
1312
0
                "Add MODULE to exclusively request Module mode and fail if "
1313
0
                "Find"
1314
0
             << this->Name
1315
0
             << ".cmake is missing.  "
1316
0
                "Add CONFIG to exclusively request Config mode and search for "
1317
0
                "a "
1318
0
                "package configuration file provided by "
1319
0
             << this->Name << " (" << this->Name << "Config.cmake or "
1320
0
             << cmSystemTools::LowerCase(this->Name) << "-config.cmake).  ";
1321
0
        } else {
1322
0
          aw << "find_package called without NO_MODULE option and no "
1323
0
                "Find"
1324
0
             << this->Name
1325
0
             << ".cmake module is in CMAKE_MODULE_PATH.  "
1326
0
                "Add NO_MODULE to exclusively request Config mode and search "
1327
0
                "for a "
1328
0
                "package configuration file provided by "
1329
0
             << this->Name << " (" << this->Name << "Config.cmake or "
1330
0
             << cmSystemTools::LowerCase(this->Name)
1331
0
             << "-config.cmake).  Otherwise make Find" << this->Name
1332
0
             << ".cmake available in CMAKE_MODULE_PATH.";
1333
0
        }
1334
0
        aw << "\n"
1335
0
              "(Variable CMAKE_FIND_PACKAGE_WARN_NO_MODULE enabled this "
1336
0
              "warning.)";
1337
0
        this->Makefile->IssueDiagnostic(cmDiagnostics::CMD_AUTHOR, aw.str());
1338
0
      }
1339
1340
0
      if (this->FindPackageUsingConfigMode()) {
1341
0
        loadedPackage = true;
1342
0
      }
1343
0
    }
1344
0
  }
1345
1346
0
  this->AppendSuccessInformation();
1347
0
  return loadedPackage;
1348
0
}
1349
1350
bool cmFindPackageCommand::FindPackageUsingModuleMode()
1351
0
{
1352
0
  bool foundModule = false;
1353
0
  if (!this->FindModule(foundModule)) {
1354
0
    return false;
1355
0
  }
1356
0
  return foundModule;
1357
0
}
1358
1359
bool cmFindPackageCommand::FindPackageUsingConfigMode()
1360
0
{
1361
0
  this->Variable = cmStrCat(this->Name, "_DIR");
1362
1363
  // Add the default name.
1364
0
  if (this->Names.empty()) {
1365
0
    this->Names.push_back(this->Name);
1366
0
  }
1367
1368
  // Add the default configs.
1369
0
  if (this->Configs.empty()) {
1370
0
    for (std::string const& n : this->Names) {
1371
0
      std::string config;
1372
0
      if (this->UseCpsFiles) {
1373
0
        config = cmStrCat(n, ".cps");
1374
0
        this->Configs.emplace_back(std::move(config), pdt::Cps);
1375
1376
0
        config = cmStrCat(cmSystemTools::LowerCase(n), ".cps");
1377
0
        if (config != this->Configs.back().Name) {
1378
0
          this->Configs.emplace_back(std::move(config), pdt::Cps);
1379
0
        }
1380
0
      }
1381
1382
0
      config = cmStrCat(n, "Config.cmake");
1383
0
      this->Configs.emplace_back(std::move(config), pdt::CMake);
1384
1385
0
      config = cmStrCat(cmSystemTools::LowerCase(n), "-config.cmake");
1386
0
      this->Configs.emplace_back(std::move(config), pdt::CMake);
1387
0
    }
1388
0
  }
1389
1390
  // get igonored paths from vars and reroot them.
1391
0
  std::vector<std::string> ignored;
1392
0
  this->GetIgnoredPaths(ignored);
1393
0
  this->RerootPaths(ignored);
1394
1395
  // Construct a set of ignored paths
1396
0
  this->IgnoredPaths.clear();
1397
0
  this->IgnoredPaths.insert(ignored.begin(), ignored.end());
1398
1399
  // get igonored prefix paths from vars and reroot them.
1400
0
  std::vector<std::string> ignoredPrefixes;
1401
0
  this->GetIgnoredPrefixPaths(ignoredPrefixes);
1402
0
  this->RerootPaths(ignoredPrefixes);
1403
1404
  // Construct a set of ignored prefix paths
1405
0
  this->IgnoredPrefixPaths.clear();
1406
0
  this->IgnoredPrefixPaths.insert(ignoredPrefixes.begin(),
1407
0
                                  ignoredPrefixes.end());
1408
1409
  // Find and load the package.
1410
0
  return this->HandlePackageMode(HandlePackageModeType::Config);
1411
0
}
1412
1413
void cmFindPackageCommand::SetVersionVariables(
1414
  std::function<void(std::string const&, cm::string_view)> const&
1415
    addDefinition,
1416
  std::string const& prefix, std::string const& version,
1417
  unsigned int const count, unsigned int const major, unsigned int const minor,
1418
  unsigned int const patch, unsigned int const tweak)
1419
0
{
1420
0
  addDefinition(prefix, version);
1421
1422
0
  char buf[64];
1423
0
  snprintf(buf, sizeof(buf), "%u", major);
1424
0
  addDefinition(prefix + "_MAJOR", buf);
1425
0
  snprintf(buf, sizeof(buf), "%u", minor);
1426
0
  addDefinition(prefix + "_MINOR", buf);
1427
0
  snprintf(buf, sizeof(buf), "%u", patch);
1428
0
  addDefinition(prefix + "_PATCH", buf);
1429
0
  snprintf(buf, sizeof(buf), "%u", tweak);
1430
0
  addDefinition(prefix + "_TWEAK", buf);
1431
0
  snprintf(buf, sizeof(buf), "%u", count);
1432
0
  addDefinition(prefix + "_COUNT", buf);
1433
0
}
1434
1435
void cmFindPackageCommand::SetModuleVariables()
1436
0
{
1437
0
  this->AddFindDefinition("CMAKE_FIND_PACKAGE_NAME", this->Name);
1438
1439
  // Nested find calls are not automatically required.
1440
0
  this->AddFindDefinition("CMAKE_FIND_REQUIRED", ""_s);
1441
1442
  // Store the list of components and associated variable definitions.
1443
0
  std::string components_var = this->Name + "_FIND_COMPONENTS";
1444
0
  this->AddFindDefinition(components_var, this->Components);
1445
0
  for (auto const& component : this->OptionalComponents) {
1446
0
    this->AddFindDefinition(
1447
0
      cmStrCat(this->Name, "_FIND_REQUIRED_"_s, component), "0"_s);
1448
0
  }
1449
0
  for (auto const& component : this->RequiredComponents) {
1450
0
    this->AddFindDefinition(
1451
0
      cmStrCat(this->Name, "_FIND_REQUIRED_"_s, component), "1"_s);
1452
0
  }
1453
1454
0
  if (this->Quiet) {
1455
    // Tell the module that is about to be read that it should find
1456
    // quietly.
1457
0
    std::string quietly = cmStrCat(this->Name, "_FIND_QUIETLY");
1458
0
    this->AddFindDefinition(quietly, "1"_s);
1459
0
  }
1460
1461
0
  if (this->IsRequired()) {
1462
    // Tell the module that is about to be read that it should report
1463
    // a fatal error if the package is not found.
1464
0
    std::string req = cmStrCat(this->Name, "_FIND_REQUIRED");
1465
0
    this->AddFindDefinition(req, "1"_s);
1466
0
  }
1467
1468
0
  if (!this->VersionComplete.empty()) {
1469
0
    std::string req = cmStrCat(this->Name, "_FIND_VERSION_COMPLETE");
1470
0
    this->AddFindDefinition(req, this->VersionComplete);
1471
0
  }
1472
1473
  // Tell the module that is about to be read what version of the
1474
  // package has been requested.
1475
0
  auto addDefinition = [this](std::string const& variable,
1476
0
                              cm::string_view value) {
1477
0
    this->AddFindDefinition(variable, value);
1478
0
  };
1479
1480
0
  if (!this->Version.empty()) {
1481
0
    auto prefix = cmStrCat(this->Name, "_FIND_VERSION"_s);
1482
0
    this->SetVersionVariables(addDefinition, prefix, this->Version,
1483
0
                              this->VersionCount, this->VersionMajor,
1484
0
                              this->VersionMinor, this->VersionPatch,
1485
0
                              this->VersionTweak);
1486
1487
    // Tell the module whether an exact version has been requested.
1488
0
    auto exact = cmStrCat(this->Name, "_FIND_VERSION_EXACT");
1489
0
    this->AddFindDefinition(exact, this->VersionExact ? "1"_s : "0"_s);
1490
0
  }
1491
0
  if (!this->VersionRange.empty()) {
1492
0
    auto prefix = cmStrCat(this->Name, "_FIND_VERSION_MIN"_s);
1493
0
    this->SetVersionVariables(addDefinition, prefix, this->Version,
1494
0
                              this->VersionCount, this->VersionMajor,
1495
0
                              this->VersionMinor, this->VersionPatch,
1496
0
                              this->VersionTweak);
1497
1498
0
    prefix = cmStrCat(this->Name, "_FIND_VERSION_MAX"_s);
1499
0
    this->SetVersionVariables(addDefinition, prefix, this->VersionMax,
1500
0
                              this->VersionMaxCount, this->VersionMaxMajor,
1501
0
                              this->VersionMaxMinor, this->VersionMaxPatch,
1502
0
                              this->VersionMaxTweak);
1503
1504
0
    auto id = cmStrCat(this->Name, "_FIND_VERSION_RANGE");
1505
0
    this->AddFindDefinition(id, this->VersionRange);
1506
0
    id = cmStrCat(this->Name, "_FIND_VERSION_RANGE_MIN");
1507
0
    this->AddFindDefinition(id, this->VersionRangeMin);
1508
0
    id = cmStrCat(this->Name, "_FIND_VERSION_RANGE_MAX");
1509
0
    this->AddFindDefinition(id, this->VersionRangeMax);
1510
0
  }
1511
1512
0
  if (this->RegistryViewDefined) {
1513
0
    this->AddFindDefinition(cmStrCat(this->Name, "_FIND_REGISTRY_VIEW"),
1514
0
                            cmWindowsRegistry::FromView(this->RegistryView));
1515
0
  }
1516
0
}
1517
1518
void cmFindPackageCommand::AddFindDefinition(std::string const& var,
1519
                                             cm::string_view const value)
1520
0
{
1521
0
  if (cmValue old = this->Makefile->GetDefinition(var)) {
1522
0
    this->OriginalDefs[var].exists = true;
1523
0
    this->OriginalDefs[var].value = *old;
1524
0
  } else {
1525
0
    this->OriginalDefs[var].exists = false;
1526
0
  }
1527
0
  this->Makefile->AddDefinition(var, value);
1528
0
}
1529
1530
void cmFindPackageCommand::RestoreFindDefinitions()
1531
0
{
1532
0
  for (auto const& i : this->OriginalDefs) {
1533
0
    OriginalDef const& od = i.second;
1534
0
    if (od.exists) {
1535
0
      this->Makefile->AddDefinition(i.first, od.value);
1536
0
    } else {
1537
0
      this->Makefile->RemoveDefinition(i.first);
1538
0
    }
1539
0
  }
1540
0
}
1541
1542
bool cmFindPackageCommand::FindModule(bool& found)
1543
0
{
1544
0
  std::string moduleFileName = cmStrCat("Find", this->Name, ".cmake");
1545
1546
0
  bool system = false;
1547
0
  std::string debugBuffer = cmStrCat(
1548
0
    "find_package considered the following paths for ", moduleFileName, ":\n");
1549
0
  std::string mfile = this->Makefile->GetModulesFile(
1550
0
    moduleFileName, system, this->DebugModeEnabled(), debugBuffer);
1551
0
  if (this->DebugModeEnabled()) {
1552
0
    if (mfile.empty()) {
1553
0
      debugBuffer = cmStrCat(debugBuffer, "The file was not found.\n");
1554
0
    } else {
1555
0
      debugBuffer =
1556
0
        cmStrCat(debugBuffer, "The file was found at\n  ", mfile, '\n');
1557
0
    }
1558
0
    this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer);
1559
0
  }
1560
1561
0
  if (!mfile.empty()) {
1562
0
    if (system) {
1563
0
      auto const it = this->DeprecatedFindModules.find(this->Name);
1564
0
      if (it != this->DeprecatedFindModules.end()) {
1565
0
        cmPolicies::PolicyStatus status =
1566
0
          this->Makefile->GetPolicyStatus(it->second);
1567
0
        switch (status) {
1568
0
          case cmPolicies::WARN: {
1569
0
            this->Makefile->IssuePolicyWarning(it->second);
1570
0
            CM_FALLTHROUGH;
1571
0
          }
1572
0
          case cmPolicies::OLD:
1573
0
            break;
1574
0
          case cmPolicies::NEW:
1575
0
            return true;
1576
0
        }
1577
0
      }
1578
0
    }
1579
1580
    // Load the module we found, and set "<name>_FIND_MODULE" to true
1581
    // while inside it.
1582
0
    found = true;
1583
0
    std::string const var = cmStrCat(this->Name, "_FIND_MODULE");
1584
0
    this->Makefile->AddDefinition(var, "1");
1585
0
    bool result = this->ReadListFile(mfile, cm::PolicyScope::Local);
1586
0
    this->Makefile->RemoveDefinition(var);
1587
1588
0
    std::string const foundVar = cmStrCat(this->Name, "_FOUND");
1589
0
    if (this->Makefile->IsDefinitionSet(foundVar) &&
1590
0
        !this->Makefile->IsOn(foundVar)) {
1591
1592
0
      if (this->DebugModeEnabled()) {
1593
0
        this->DebugBuffer = cmStrCat(
1594
0
          this->DebugBuffer, "The module is considered not found due to ",
1595
0
          foundVar, " being FALSE.");
1596
0
      }
1597
1598
0
      this->ConsideredPaths.emplace_back(mfile, FoundPackageMode::Module,
1599
0
                                         SearchResult::NotFound);
1600
0
      std::string const notFoundMessageVar =
1601
0
        cmStrCat(this->Name, "_NOT_FOUND_MESSAGE");
1602
0
      if (cmValue notFoundMessage =
1603
0
            this->Makefile->GetDefinition(notFoundMessageVar)) {
1604
1605
0
        this->ConsideredPaths.back().Message = *notFoundMessage;
1606
0
      }
1607
0
    } else {
1608
0
      if (this->DebugState) {
1609
0
        this->DebugState->FoundAt(mfile);
1610
0
      }
1611
0
      this->FileFound = mfile;
1612
0
      this->FileFoundMode = FoundPackageMode::Module;
1613
0
      std::string const versionVar = cmStrCat(this->Name, "_VERSION");
1614
0
      if (cmValue version = this->Makefile->GetDefinition(versionVar)) {
1615
0
        this->VersionFound = *version;
1616
0
      }
1617
0
    }
1618
0
    return result;
1619
0
  }
1620
0
  return true;
1621
0
}
1622
1623
bool cmFindPackageCommand::HandlePackageMode(
1624
  HandlePackageModeType const handlePackageModeType)
1625
0
{
1626
0
  this->ConsideredConfigs.clear();
1627
1628
  // Try to find the config file.
1629
0
  cmValue def = this->Makefile->GetDefinition(this->Variable);
1630
1631
  // Try to load the config file if the directory is known
1632
0
  bool fileFound = false;
1633
0
  if (this->UseConfigFiles) {
1634
0
    if (!def.IsOff()) {
1635
      // Get the directory from the variable value.
1636
0
      std::string dir = *def;
1637
0
      cmSystemTools::ConvertToUnixSlashes(dir);
1638
1639
      // Treat relative paths with respect to the current source dir.
1640
0
      if (!cmSystemTools::FileIsFullPath(dir)) {
1641
0
        dir = "/" + dir;
1642
0
        dir = this->Makefile->GetCurrentSourceDirectory() + dir;
1643
0
      }
1644
      // The file location was cached.  Look for the correct file.
1645
0
      std::string file;
1646
0
      FoundPackageMode foundMode = FoundPackageMode::None;
1647
0
      if (this->FindConfigFile(dir, pdt::Any, file, foundMode)) {
1648
0
        if (this->DebugState) {
1649
0
          this->DebugState->FoundAt(file);
1650
0
        }
1651
0
        this->FileFound = std::move(file);
1652
0
        this->FileFoundMode = foundMode;
1653
0
        fileFound = true;
1654
0
      }
1655
0
      def = this->Makefile->GetDefinition(this->Variable);
1656
0
    }
1657
1658
    // Search for the config file if it is not already found.
1659
0
    if (def.IsOff() || !fileFound) {
1660
0
      fileFound = this->FindConfig();
1661
0
    }
1662
1663
    // Sanity check.
1664
0
    if (fileFound && this->FileFound.empty()) {
1665
0
      this->Makefile->IssueMessage(
1666
0
        MessageType::INTERNAL_ERROR,
1667
0
        "fileFound is true but FileFound is empty!");
1668
0
      fileFound = false;
1669
0
    }
1670
0
  }
1671
1672
0
  std::string const foundVar = cmStrCat(this->Name, "_FOUND");
1673
0
  std::string const notFoundMessageVar =
1674
0
    cmStrCat(this->Name, "_NOT_FOUND_MESSAGE");
1675
0
  std::string notFoundMessage;
1676
1677
  // If the directory for the config file was found, try to read the file.
1678
0
  bool result = true;
1679
0
  bool found = false;
1680
0
  bool configFileSetFOUNDFalse = false;
1681
0
  std::vector<std::string> missingTargets;
1682
1683
0
  if (fileFound) {
1684
0
    if (this->Makefile->IsDefinitionSet(foundVar) &&
1685
0
        !this->Makefile->IsOn(foundVar)) {
1686
      // by removing Foo_FOUND here if it is FALSE, we don't really change
1687
      // the situation for the Config file which is about to be included,
1688
      // but we make it possible to detect later on whether the Config file
1689
      // has set Foo_FOUND to FALSE itself:
1690
0
      this->Makefile->RemoveDefinition(foundVar);
1691
0
    }
1692
0
    this->Makefile->RemoveDefinition(notFoundMessageVar);
1693
1694
    // Set the version variables before loading the config file.
1695
    // It may override them.
1696
0
    this->StoreVersionFound();
1697
1698
    // Parse the configuration file.
1699
0
    if (this->CpsReader) {
1700
      // The package has been found.
1701
0
      found = true;
1702
0
      result = this->ReadPackage();
1703
0
    } else if (this->ReadListFile(this->FileFound, cm::PolicyScope::Local)) {
1704
      // The package has been found.
1705
0
      found = true;
1706
1707
      // Check whether the Config file has set Foo_FOUND to FALSE:
1708
0
      if (this->Makefile->IsDefinitionSet(foundVar) &&
1709
0
          !this->Makefile->IsOn(foundVar)) {
1710
        // we get here if the Config file has set Foo_FOUND actively to FALSE
1711
0
        found = false;
1712
0
        configFileSetFOUNDFalse = true;
1713
0
        notFoundMessage =
1714
0
          this->Makefile->GetSafeDefinition(notFoundMessageVar);
1715
0
      }
1716
1717
      // Check whether the required targets are defined.
1718
0
      if (found && !this->RequiredTargets.empty()) {
1719
0
        for (std::string const& t : this->RequiredTargets) {
1720
0
          std::string qualifiedTarget = cmStrCat(this->Name, "::"_s, t);
1721
0
          if (!this->Makefile->FindImportedTarget(qualifiedTarget)) {
1722
0
            missingTargets.emplace_back(std::move(qualifiedTarget));
1723
0
            found = false;
1724
0
          }
1725
0
        }
1726
0
      }
1727
0
    } else {
1728
      // The configuration file is invalid.
1729
0
      result = false;
1730
0
    }
1731
1732
0
    if (this->UseConfigFiles && found) {
1733
0
      this->PackageInfo->Directory =
1734
0
        cmSystemTools::GetFilenamePath(this->FileFound);
1735
0
      this->PackageInfo->Version = this->VersionFound;
1736
0
    }
1737
0
  }
1738
1739
0
  if (this->UseFindModules && !found &&
1740
0
      handlePackageModeType == HandlePackageModeType::Config &&
1741
0
      this->Makefile->IsOn("CMAKE_FIND_PACKAGE_PREFER_CONFIG")) {
1742
    // Config mode failed. Allow Module case.
1743
0
    result = false;
1744
0
  }
1745
1746
  // package not found
1747
0
  if (result && !found) {
1748
    // warn if package required or
1749
    // (neither quiet nor in config mode and not explicitly optional)
1750
0
    if (this->IsRequired() ||
1751
0
        (!(this->Quiet ||
1752
0
           (this->UseConfigFiles && !this->UseFindModules &&
1753
0
            this->ConsideredConfigs.empty())) &&
1754
0
         this->Required != RequiredStatus::OptionalExplicit)) {
1755
      // The variable is not set.
1756
0
      std::ostringstream e;
1757
0
      std::ostringstream aw;
1758
0
      if (configFileSetFOUNDFalse) {
1759
0
        e << "Found package configuration file:\n"
1760
0
             "  "
1761
0
          << this->FileFound
1762
0
          << "\n"
1763
0
             "but it set "
1764
0
          << foundVar << " to FALSE so package \"" << this->Name
1765
0
          << "\" is considered to be NOT FOUND.";
1766
0
        if (!notFoundMessage.empty()) {
1767
0
          e << " Reason given by package: \n" << notFoundMessage << "\n";
1768
0
        }
1769
0
      } else if (!missingTargets.empty()) {
1770
0
        e << "Found package configuration file:\n"
1771
0
             "  "
1772
0
          << this->FileFound
1773
0
          << "\n"
1774
0
             "but the following required targets were not found:\n"
1775
0
             "  "
1776
0
          << cmJoin(cmMakeRange(missingTargets), ", "_s);
1777
0
      } else if (!this->ConsideredConfigs.empty()) {
1778
        // If there are files in ConsideredConfigs, it means that
1779
        // FooConfig.cmake have been found, but they didn't have appropriate
1780
        // versions.
1781
0
        auto duplicate_end = cmRemoveDuplicates(this->ConsideredConfigs);
1782
0
        e << "Could not find a configuration file for package \"" << this->Name
1783
0
          << "\" that "
1784
0
          << (this->VersionExact ? "exactly matches" : "is compatible with")
1785
0
          << " requested version "
1786
0
          << (this->VersionRange.empty() ? "" : "range ") << '"'
1787
0
          << this->VersionComplete
1788
0
          << "\".\n"
1789
0
             "The following configuration files were considered but not "
1790
0
             "accepted:\n";
1791
1792
0
        for (ConfigFileInfo const& info :
1793
0
             cmMakeRange(this->ConsideredConfigs.cbegin(), duplicate_end)) {
1794
0
          e << "  " << info.filename << ", version: " << info.version
1795
0
            << "\n    " << info.message << '\n';
1796
0
        }
1797
0
      } else {
1798
0
        std::string requestedVersionString;
1799
0
        if (!this->VersionComplete.empty()) {
1800
0
          requestedVersionString =
1801
0
            cmStrCat(" (requested version ", this->VersionComplete, ')');
1802
0
        }
1803
1804
0
        if (this->UseConfigFiles) {
1805
0
          if (this->UseFindModules) {
1806
0
            e << "By not providing \"Find" << this->Name
1807
0
              << ".cmake\" in "
1808
0
                 "CMAKE_MODULE_PATH this project has asked CMake to find a "
1809
0
                 "package configuration file provided by \""
1810
0
              << this->Name
1811
0
              << "\", "
1812
0
                 "but CMake did not find one.\n";
1813
0
          }
1814
1815
0
          if (this->Configs.size() == 1) {
1816
0
            e << "Could not find a package configuration file named \""
1817
0
              << this->Configs[0].Name << "\" provided by package \""
1818
0
              << this->Name << "\"" << requestedVersionString << ".\n";
1819
0
          } else {
1820
0
            auto configs = cmMakeRange(this->Configs);
1821
0
            auto configNames =
1822
0
              configs.transform([](ConfigName const& cn) { return cn.Name; });
1823
0
            e << "Could not find a package configuration file provided by \""
1824
0
              << this->Name << "\"" << requestedVersionString
1825
0
              << " with any of the following names:\n"
1826
0
              << cmWrap("  "_s, configNames, ""_s, "\n"_s) << '\n';
1827
0
          }
1828
1829
0
          e << "Add the installation prefix of \"" << this->Name
1830
0
            << "\" to CMAKE_PREFIX_PATH or set \"" << this->Variable
1831
0
            << "\" to a directory containing one of the above files. "
1832
0
               "If \""
1833
0
            << this->Name
1834
0
            << "\" provides a separate development "
1835
0
               "package or SDK, be sure it has been installed.";
1836
0
        } else // if(!this->UseFindModules && !this->UseConfigFiles)
1837
0
        {
1838
0
          e << "No \"Find" << this->Name
1839
0
            << ".cmake\" found in "
1840
0
               "CMAKE_MODULE_PATH.";
1841
1842
0
          aw
1843
0
            << "Find" << this->Name
1844
0
            << ".cmake must either be part of this "
1845
0
               "project itself, in this case adjust CMAKE_MODULE_PATH so that "
1846
0
               "it points to the correct location inside its source tree.\n"
1847
0
               "Or it must be installed by a package which has already been "
1848
0
               "found via find_package().  In this case make sure that "
1849
0
               "package has indeed been found and adjust CMAKE_MODULE_PATH to "
1850
0
               "contain the location where that package has installed "
1851
0
               "Find"
1852
0
            << this->Name
1853
0
            << ".cmake.  This must be a location "
1854
0
               "provided by that package.  This error in general means that "
1855
0
               "the buildsystem of this project is relying on a Find-module "
1856
0
               "without ensuring that it is actually available.\n";
1857
0
        }
1858
0
      }
1859
0
      if (this->Required == RequiredStatus::RequiredFromFindVar) {
1860
0
        e << "\nThis package is considered required because the "
1861
0
             "CMAKE_FIND_REQUIRED variable has been enabled.\n";
1862
0
      } else if (this->Required == RequiredStatus::RequiredFromPackageVar) {
1863
0
        e << "\nThis package is considered required because the "
1864
0
          << cmStrCat("CMAKE_REQUIRE_FIND_PACKAGE_", this->Name)
1865
0
          << " variable has been enabled.\n";
1866
0
      }
1867
1868
0
      this->Makefile->IssueMessage(
1869
0
        this->IsRequired() ? MessageType::FATAL_ERROR : MessageType::WARNING,
1870
0
        e.str());
1871
0
      if (this->IsRequired()) {
1872
0
        cmSystemTools::SetFatalErrorOccurred();
1873
0
      }
1874
1875
0
      if (!aw.str().empty()) {
1876
0
        this->Makefile->IssueDiagnostic(cmDiagnostics::CMD_AUTHOR, aw.str());
1877
0
      }
1878
0
    }
1879
    // output result if in config mode but not in quiet mode
1880
0
    else if (!this->Quiet) {
1881
0
      this->Makefile->DisplayStatus(cmStrCat("Could NOT find ", this->Name,
1882
0
                                             " (missing: ", this->Name,
1883
0
                                             "_DIR)"),
1884
0
                                    -1);
1885
0
    }
1886
0
  }
1887
1888
  // Set a variable marking whether the package was found.
1889
0
  this->Makefile->AddDefinition(foundVar, found ? "1" : "0");
1890
1891
  // Set a variable naming the configuration file that was found.
1892
0
  std::string const fileVar = cmStrCat(this->Name, "_CONFIG");
1893
0
  if (found) {
1894
0
    this->Makefile->AddDefinition(fileVar, this->FileFound);
1895
0
  } else {
1896
0
    this->Makefile->RemoveDefinition(fileVar);
1897
0
  }
1898
1899
0
  std::string const consideredConfigsVar =
1900
0
    cmStrCat(this->Name, "_CONSIDERED_CONFIGS");
1901
0
  std::string const consideredVersionsVar =
1902
0
    cmStrCat(this->Name, "_CONSIDERED_VERSIONS");
1903
1904
0
  std::string consideredConfigFiles;
1905
0
  std::string consideredVersions;
1906
1907
0
  char const* sep = "";
1908
0
  for (ConfigFileInfo const& i : this->ConsideredConfigs) {
1909
0
    consideredConfigFiles += sep;
1910
0
    consideredVersions += sep;
1911
0
    consideredConfigFiles += i.filename;
1912
0
    consideredVersions += i.version;
1913
0
    sep = ";";
1914
0
  }
1915
1916
0
  this->Makefile->AddDefinition(consideredConfigsVar, consideredConfigFiles);
1917
1918
0
  this->Makefile->AddDefinition(consideredVersionsVar, consideredVersions);
1919
1920
0
  return result;
1921
0
}
1922
1923
bool cmFindPackageCommand::FindConfig()
1924
0
{
1925
  // Compute the set of search prefixes.
1926
0
  this->ComputePrefixes();
1927
1928
  // Look for the project's configuration file.
1929
0
  bool found = false;
1930
0
  if (this->DebugModeEnabled()) {
1931
0
    this->DebugBuffer = cmStrCat(this->DebugBuffer,
1932
0
                                 "find_package considered the following "
1933
0
                                 "locations for ",
1934
0
                                 this->Name, "'s Config module:\n");
1935
0
  }
1936
1937
0
  if (!found && this->UseCpsFiles) {
1938
0
    found = this->FindEnvironmentConfig();
1939
0
  }
1940
1941
  // Search for frameworks.
1942
0
  if (!found && (this->SearchFrameworkFirst || this->SearchFrameworkOnly)) {
1943
0
    found = this->FindFrameworkConfig();
1944
0
  }
1945
1946
  // Search for apps.
1947
0
  if (!found && (this->SearchAppBundleFirst || this->SearchAppBundleOnly)) {
1948
0
    found = this->FindAppBundleConfig();
1949
0
  }
1950
1951
  // Search prefixes.
1952
0
  if (!found && !(this->SearchFrameworkOnly || this->SearchAppBundleOnly)) {
1953
0
    found = this->FindPrefixedConfig();
1954
0
  }
1955
1956
  // Search for frameworks.
1957
0
  if (!found && this->SearchFrameworkLast) {
1958
0
    found = this->FindFrameworkConfig();
1959
0
  }
1960
1961
  // Search for apps.
1962
0
  if (!found && this->SearchAppBundleLast) {
1963
0
    found = this->FindAppBundleConfig();
1964
0
  }
1965
1966
0
  if (this->DebugModeEnabled()) {
1967
0
    if (found) {
1968
0
      this->DebugBuffer = cmStrCat(
1969
0
        this->DebugBuffer, "The file was found at\n  ", this->FileFound, '\n');
1970
0
    } else {
1971
0
      this->DebugBuffer =
1972
0
        cmStrCat(this->DebugBuffer, "The file was not found.\n");
1973
0
    }
1974
0
  }
1975
1976
  // Store the entry in the cache so it can be set by the user.
1977
0
  std::string init;
1978
0
  if (found) {
1979
0
    init = cmSystemTools::GetFilenamePath(this->FileFound);
1980
0
  } else {
1981
0
    init = this->Variable + "-NOTFOUND";
1982
0
  }
1983
  // We force the value since we do not get here if it was already set.
1984
0
  this->SetConfigDirCacheVariable(init);
1985
1986
0
  return found;
1987
0
}
1988
1989
void cmFindPackageCommand::SetConfigDirCacheVariable(std::string const& value)
1990
0
{
1991
0
  std::string const help =
1992
0
    cmStrCat("The directory containing a CMake configuration file for ",
1993
0
             this->Name, '.');
1994
0
  this->Makefile->AddCacheDefinition(this->Variable, value, help,
1995
0
                                     cmStateEnums::PATH, true);
1996
0
  if (this->Makefile->GetPolicyStatus(cmPolicies::CMP0126) ==
1997
0
        cmPolicies::NEW &&
1998
0
      this->Makefile->IsNormalDefinitionSet(this->Variable)) {
1999
0
    this->Makefile->AddDefinition(this->Variable, value);
2000
0
  }
2001
0
}
2002
2003
bool cmFindPackageCommand::FindPrefixedConfig()
2004
0
{
2005
0
  std::vector<std::string> const& prefixes = this->SearchPaths;
2006
0
  return std::any_of(
2007
0
    prefixes.begin(), prefixes.end(),
2008
0
    [this](std::string const& p) -> bool { return this->SearchPrefix(p); });
2009
0
}
2010
2011
bool cmFindPackageCommand::FindFrameworkConfig()
2012
0
{
2013
0
  std::vector<std::string> const& prefixes = this->SearchPaths;
2014
0
  return std::any_of(prefixes.begin(), prefixes.end(),
2015
0
                     [this](std::string const& p) -> bool {
2016
0
                       return this->SearchFrameworkPrefix(p);
2017
0
                     });
2018
0
}
2019
2020
bool cmFindPackageCommand::FindAppBundleConfig()
2021
0
{
2022
0
  std::vector<std::string> const& prefixes = this->SearchPaths;
2023
0
  return std::any_of(prefixes.begin(), prefixes.end(),
2024
0
                     [this](std::string const& p) -> bool {
2025
0
                       return this->SearchAppBundlePrefix(p);
2026
0
                     });
2027
0
}
2028
2029
bool cmFindPackageCommand::FindEnvironmentConfig()
2030
0
{
2031
0
  std::vector<std::string> const& prefixes =
2032
0
    cmSystemTools::GetEnvPathNormalized("CPS_PATH");
2033
0
  return std::any_of(prefixes.begin(), prefixes.end(),
2034
0
                     [this](std::string const& p) -> bool {
2035
0
                       return this->SearchEnvironmentPrefix(p);
2036
0
                     });
2037
0
}
2038
2039
cmFindPackageCommand::AppendixMap cmFindPackageCommand::FindAppendices(
2040
  std::string const& base, cmPackageInfoReader const& baseReader) const
2041
0
{
2042
0
  AppendixMap appendices;
2043
2044
  // Find package appendices.
2045
0
  cmsys::Glob glob;
2046
0
  glob.RecurseOff();
2047
0
  if (glob.FindFiles(cmStrCat(cmSystemTools::GetFilenamePath(base), "/"_s,
2048
0
                              cmSystemTools::GetFilenameWithoutExtension(base),
2049
0
                              "[-:]*.[Cc][Pp][Ss]"_s))) {
2050
    // Check glob results for valid appendices.
2051
0
    for (std::string const& extra : glob.GetFiles()) {
2052
      // Exclude configuration-specific files for now; we look at them later
2053
      // when we load their respective configuration-agnostic appendices.
2054
0
      if (extra.find('@') != std::string::npos) {
2055
0
        continue;
2056
0
      }
2057
2058
0
      cmMakefile::CallRAII cs{ this->Makefile, extra, this->Status };
2059
2060
0
      std::unique_ptr<cmPackageInfoReader> reader =
2061
0
        cmPackageInfoReader::Read(this->Makefile, extra, &baseReader);
2062
2063
0
      if (reader && reader->GetName() == this->Name) {
2064
0
        std::vector<std::string> components = reader->GetComponentNames();
2065
0
        Appendix appendix{ std::move(reader), std::move(components) };
2066
0
        appendices.emplace(extra, std::move(appendix));
2067
0
      }
2068
0
    }
2069
0
  }
2070
2071
0
  return appendices;
2072
0
}
2073
2074
bool cmFindPackageCommand::ReadListFile(std::string const& f,
2075
                                        cm::PolicyScope ps)
2076
0
{
2077
0
  if (!this->PolicyScope) {
2078
0
    ps = cm::PolicyScope::None;
2079
0
  }
2080
2081
0
  using ITScope = cmMakefile::ImportedTargetScope;
2082
0
  ITScope scope = this->GlobalScope ? ITScope::Global : ITScope::Local;
2083
0
  cmMakefile::SetGlobalTargetImportScope globScope(this->Makefile, scope);
2084
2085
0
  auto oldUnwind = this->Makefile->GetStateSnapshot().GetUnwindType();
2086
2087
  // This allows child snapshots to inherit the CAN_UNWIND state from us, we'll
2088
  // reset it immediately after the dependent file is done
2089
0
  this->Makefile->GetStateSnapshot().SetUnwindType(cmStateEnums::CAN_UNWIND);
2090
0
  bool const result =
2091
0
    this->Makefile->ReadDependentFile(f, ps, cm::DiagnosticScope::Local);
2092
2093
0
  this->Makefile->GetStateSnapshot().SetUnwindType(oldUnwind);
2094
0
  this->Makefile->GetStateSnapshot().SetUnwindState(
2095
0
    cmStateEnums::NOT_UNWINDING);
2096
2097
0
  if (!result) {
2098
0
    std::string const e =
2099
0
      cmStrCat("Error reading CMake code from \"", f, "\".");
2100
0
    this->SetError(e);
2101
0
  }
2102
2103
0
  return result;
2104
0
}
2105
2106
bool cmFindPackageCommand::ReadPackage()
2107
0
{
2108
  // Resolve any transitive dependencies for the root file.
2109
0
  if (!FindPackageDependencies(this->FileFound, *this->CpsReader,
2110
0
                               this->Required)) {
2111
0
    return false;
2112
0
  }
2113
2114
0
  bool const hasComponentsRequested =
2115
0
    !this->RequiredComponents.empty() || !this->OptionalComponents.empty();
2116
2117
0
  cmMakefile::CallRAII cs{ this->Makefile, this->FileFound, this->Status };
2118
0
  cmMakefile::PolicyPushPop ps{ this->Makefile };
2119
2120
0
  this->Makefile->SetPolicy(cmPolicies::CMP0200, cmPolicies::NEW);
2121
2122
  // Loop over appendices.
2123
0
  auto iter = this->CpsAppendices.begin();
2124
0
  while (iter != this->CpsAppendices.end()) {
2125
0
    RequiredStatus required = RequiredStatus::Optional;
2126
0
    bool important = false;
2127
2128
    // Check if this appendix provides any requested components.
2129
0
    if (hasComponentsRequested) {
2130
0
      auto providesAny = [&iter](
2131
0
                           std::set<std::string> const& desiredComponents) {
2132
0
        return std::any_of(iter->second.Components.begin(),
2133
0
                           iter->second.Components.end(),
2134
0
                           [&desiredComponents](std::string const& component) {
2135
0
                             return cm::contains(desiredComponents, component);
2136
0
                           });
2137
0
      };
2138
2139
0
      if (providesAny(this->RequiredComponents)) {
2140
0
        important = true;
2141
0
        required = this->Required;
2142
0
      } else if (!providesAny(this->OptionalComponents)) {
2143
        // This appendix doesn't provide any requested components; remove it
2144
        // from the set to be imported.
2145
0
        iter = this->CpsAppendices.erase(iter);
2146
0
        continue;
2147
0
      }
2148
0
    }
2149
2150
    // Resolve any transitive dependencies for the appendix.
2151
0
    if (!this->FindPackageDependencies(iter->first, iter->second, required)) {
2152
0
      if (important) {
2153
        // Some dependencies are missing, and we need(ed) this appendix; fail.
2154
0
        return false;
2155
0
      }
2156
2157
      // Some dependencies are missing, but we don't need this appendix; remove
2158
      // it from the set to be imported.
2159
0
      iter = this->CpsAppendices.erase(iter);
2160
0
    } else {
2161
0
      ++iter;
2162
0
    }
2163
0
  }
2164
2165
  // If we made it here, we want to actually import something, but we also
2166
  // need to ensure we don't try to import the same file more than once (which
2167
  // will fail due to the targets already existing). Retrieve the package state
2168
  // so we can record what we're doing.
2169
0
  cmPackageState& state =
2170
0
    this->Makefile->GetStateSnapshot().GetPackageState(this->FileFound);
2171
2172
  // Import targets from root file.
2173
0
  if (!this->ImportPackageTargets(state, this->FileFound, *this->CpsReader)) {
2174
0
    return false;
2175
0
  }
2176
2177
  // Import targets from appendices.
2178
  // NOLINTNEXTLINE(readability-use-anyofallof)
2179
0
  for (auto const& appendix : this->CpsAppendices) {
2180
0
    cmMakefile::CallRAII appendixScope{ this->Makefile, appendix.first,
2181
0
                                        this->Status };
2182
0
    if (!this->ImportPackageTargets(state, appendix.first, appendix.second)) {
2183
0
      return false;
2184
0
    }
2185
0
  }
2186
2187
0
  return true;
2188
0
}
2189
2190
bool cmFindPackageCommand::FindPackageDependencies(
2191
  std::string const& filePath, cmPackageInfoReader const& reader,
2192
  RequiredStatus required)
2193
0
{
2194
  // Get package requirements.
2195
0
  for (cmPackageRequirement const& dep : reader.GetRequirements()) {
2196
0
    cmExecutionStatus status{ *this->Makefile };
2197
0
    cmMakefile::CallRAII scope{ this->Makefile, filePath, status };
2198
2199
    // For each requirement, set up a nested instance to find it.
2200
0
    cmFindPackageCommand fp{ status };
2201
0
    fp.InheritOptions(this);
2202
2203
0
    fp.Name = dep.Name;
2204
0
    fp.Required = required;
2205
0
    fp.UseFindModules = false;
2206
0
    fp.UseCpsFiles = true;
2207
2208
0
    fp.Version = dep.Version;
2209
0
    fp.VersionComplete = dep.Version;
2210
0
    fp.VersionCount =
2211
0
      parseVersion(fp.Version, fp.VersionMajor, fp.VersionMinor,
2212
0
                   fp.VersionPatch, fp.VersionTweak);
2213
2214
0
    fp.Components = cmJoin(cmMakeRange(dep.Components), ";"_s);
2215
0
    fp.OptionalComponents =
2216
0
      std::set<std::string>{ dep.Components.begin(), dep.Components.end() };
2217
0
    fp.RequiredTargets = fp.OptionalComponents;
2218
2219
    // TODO set hints
2220
2221
    // Try to find the requirement; fail if we can't.
2222
0
    if (!fp.FindPackage() || fp.FileFound.empty()) {
2223
0
      this->SetError(cmStrCat("could not find "_s, dep.Name,
2224
0
                              ", required by "_s, this->Name, '.'));
2225
0
      return false;
2226
0
    }
2227
0
  }
2228
2229
  // All requirements (if any) were found.
2230
0
  return true;
2231
0
}
2232
2233
bool cmFindPackageCommand::ImportPackageTargets(cmPackageState& packageState,
2234
                                                std::string const& filePath,
2235
                                                cmPackageInfoReader& reader)
2236
0
{
2237
  // Check if we've already imported this file.
2238
0
  std::string fileName = cmSystemTools::GetFilenameName(filePath);
2239
0
  if (cm::contains(packageState.ImportedFiles, fileName)) {
2240
0
    return true;
2241
0
  }
2242
2243
  // Import base file.
2244
0
  if (!reader.ImportTargets(this->Makefile, this->Status, this->GlobalScope)) {
2245
0
    return false;
2246
0
  }
2247
2248
  // Find supplemental configuration files.
2249
0
  cmsys::Glob glob;
2250
0
  glob.RecurseOff();
2251
0
  if (glob.FindFiles(
2252
0
        cmStrCat(cmSystemTools::GetFilenamePath(filePath), '/',
2253
0
                 cmSystemTools::GetFilenameWithoutExtension(filePath),
2254
0
                 "@*.[Cc][Pp][Ss]"_s))) {
2255
2256
    // Try to read supplemental data from each file found.
2257
0
    for (std::string const& extra : glob.GetFiles()) {
2258
0
      cmMakefile::CallRAII cs{ this->Makefile, extra, this->Status };
2259
2260
0
      std::unique_ptr<cmPackageInfoReader> configReader =
2261
0
        cmPackageInfoReader::Read(this->Makefile, extra, &reader);
2262
0
      if (configReader && configReader->GetName() == this->Name) {
2263
0
        if (!configReader->ImportTargetConfigurations(this->Makefile,
2264
0
                                                      this->Status)) {
2265
0
          return false;
2266
0
        }
2267
0
      }
2268
0
    }
2269
0
  }
2270
2271
0
  packageState.ImportedFiles.emplace(std::move(fileName));
2272
0
  return true;
2273
0
}
2274
2275
void cmFindPackageCommand::AppendToFoundProperty(bool const found)
2276
0
{
2277
0
  cmList foundContents;
2278
0
  cmValue foundProp =
2279
0
    this->Makefile->GetState()->GetGlobalProperty("PACKAGES_FOUND");
2280
0
  if (!foundProp.IsEmpty()) {
2281
0
    foundContents.assign(*foundProp);
2282
0
    foundContents.remove_items({ this->Name });
2283
0
  }
2284
2285
0
  cmList notFoundContents;
2286
0
  cmValue notFoundProp =
2287
0
    this->Makefile->GetState()->GetGlobalProperty("PACKAGES_NOT_FOUND");
2288
0
  if (!notFoundProp.IsEmpty()) {
2289
0
    notFoundContents.assign(*notFoundProp);
2290
0
    notFoundContents.remove_items({ this->Name });
2291
0
  }
2292
2293
0
  if (found) {
2294
0
    foundContents.push_back(this->Name);
2295
0
  } else {
2296
0
    notFoundContents.push_back(this->Name);
2297
0
  }
2298
2299
0
  this->Makefile->GetState()->SetGlobalProperty("PACKAGES_FOUND",
2300
0
                                                foundContents.to_string());
2301
2302
0
  this->Makefile->GetState()->SetGlobalProperty("PACKAGES_NOT_FOUND",
2303
0
                                                notFoundContents.to_string());
2304
0
}
2305
2306
void cmFindPackageCommand::AppendSuccessInformation()
2307
0
{
2308
0
  {
2309
0
    std::string const transitivePropName =
2310
0
      cmStrCat("_CMAKE_", this->Name, "_TRANSITIVE_DEPENDENCY");
2311
0
    this->Makefile->GetState()->SetGlobalProperty(transitivePropName, "False");
2312
0
  }
2313
0
  std::string const found = cmStrCat(this->Name, "_FOUND");
2314
0
  std::string const upperFound = cmSystemTools::UpperCase(found);
2315
2316
0
  bool const upperResult = this->Makefile->IsOn(upperFound);
2317
0
  bool const result = this->Makefile->IsOn(found);
2318
0
  bool const packageFound = (result || upperResult);
2319
2320
0
  this->AppendToFoundProperty(packageFound);
2321
2322
  // Record whether the find was quiet or not, so this can be used
2323
  // e.g. in FeatureSummary.cmake
2324
0
  std::string const quietInfoPropName =
2325
0
    cmStrCat("_CMAKE_", this->Name, "_QUIET");
2326
0
  this->Makefile->GetState()->SetGlobalProperty(
2327
0
    quietInfoPropName, this->Quiet ? "TRUE" : "FALSE");
2328
2329
  // set a global property to record the required version of this package
2330
0
  std::string const versionInfoPropName =
2331
0
    cmStrCat("_CMAKE_", this->Name, "_REQUIRED_VERSION");
2332
0
  std::string versionInfo;
2333
0
  if (!this->VersionRange.empty()) {
2334
0
    versionInfo = this->VersionRange;
2335
0
  } else if (!this->Version.empty()) {
2336
0
    versionInfo =
2337
0
      cmStrCat(this->VersionExact ? "==" : ">=", ' ', this->Version);
2338
0
  }
2339
0
  this->Makefile->GetState()->SetGlobalProperty(versionInfoPropName,
2340
0
                                                versionInfo);
2341
0
  if (this->IsRequired()) {
2342
0
    std::string const requiredInfoPropName =
2343
0
      cmStrCat("_CMAKE_", this->Name, "_TYPE");
2344
0
    this->Makefile->GetState()->SetGlobalProperty(requiredInfoPropName,
2345
0
                                                  "REQUIRED");
2346
0
  }
2347
0
}
2348
2349
void cmFindPackageCommand::PushFindPackageRootPathStack()
2350
0
{
2351
  // Allocate a PACKAGE_ROOT_PATH for the current find_package call.
2352
0
  this->Makefile->FindPackageRootPathStack.emplace_back();
2353
0
  std::vector<std::string>& rootPaths =
2354
0
    this->Makefile->FindPackageRootPathStack.back();
2355
2356
  // Add root paths from <PackageName>_ROOT CMake and environment variables,
2357
  // subject to CMP0074.
2358
0
  std::string const rootVar = this->Name + "_ROOT";
2359
0
  cmValue rootDef = this->Makefile->GetDefinition(rootVar);
2360
0
  if (rootDef && rootDef.IsEmpty()) {
2361
0
    rootDef = nullptr;
2362
0
  }
2363
0
  cm::optional<std::string> rootEnv = cmSystemTools::GetEnvVar(rootVar);
2364
0
  if (rootEnv && rootEnv->empty()) {
2365
0
    rootEnv = cm::nullopt;
2366
0
  }
2367
0
  switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0074)) {
2368
0
    case cmPolicies::WARN:
2369
0
      this->Makefile->MaybeWarnCMP0074(rootVar, rootDef, rootEnv);
2370
0
      CM_FALLTHROUGH;
2371
0
    case cmPolicies::OLD:
2372
      // OLD behavior is to ignore the <PackageName>_ROOT variables.
2373
0
      return;
2374
0
    case cmPolicies::NEW: {
2375
      // NEW behavior is to honor the <PackageName>_ROOT variables.
2376
0
    } break;
2377
0
  }
2378
2379
  // Add root paths from <PACKAGENAME>_ROOT CMake and environment variables,
2380
  // if they are different than <PackageName>_ROOT, and subject to CMP0144.
2381
0
  std::string const rootVAR = cmSystemTools::UpperCase(rootVar);
2382
0
  cmValue rootDEF;
2383
0
  cm::optional<std::string> rootENV;
2384
0
  if (rootVAR != rootVar) {
2385
0
    rootDEF = this->Makefile->GetDefinition(rootVAR);
2386
0
    if (rootDEF && (rootDEF.IsEmpty() || rootDEF == rootDef)) {
2387
0
      rootDEF = nullptr;
2388
0
    }
2389
0
    rootENV = cmSystemTools::GetEnvVar(rootVAR);
2390
0
    if (rootENV && (rootENV->empty() || rootENV == rootEnv)) {
2391
0
      rootENV = cm::nullopt;
2392
0
    }
2393
0
  }
2394
2395
0
  switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0144)) {
2396
0
    case cmPolicies::WARN:
2397
0
      this->Makefile->MaybeWarnCMP0144(rootVAR, rootDEF, rootENV);
2398
0
      CM_FALLTHROUGH;
2399
0
    case cmPolicies::OLD:
2400
      // OLD behavior is to ignore the <PACKAGENAME>_ROOT variables.
2401
0
      rootDEF = nullptr;
2402
0
      rootENV = cm::nullopt;
2403
0
      break;
2404
0
    case cmPolicies::NEW: {
2405
      // NEW behavior is to honor the <PACKAGENAME>_ROOT variables.
2406
0
    } break;
2407
0
  }
2408
2409
0
  if (rootDef) {
2410
0
    cmExpandList(*rootDef, rootPaths);
2411
0
  }
2412
0
  if (rootDEF) {
2413
0
    cmExpandList(*rootDEF, rootPaths);
2414
0
  }
2415
0
  if (rootEnv) {
2416
0
    std::vector<std::string> p =
2417
0
      cmSystemTools::SplitEnvPathNormalized(*rootEnv);
2418
0
    std::move(p.begin(), p.end(), std::back_inserter(rootPaths));
2419
0
  }
2420
0
  if (rootENV) {
2421
0
    std::vector<std::string> p =
2422
0
      cmSystemTools::SplitEnvPathNormalized(*rootENV);
2423
0
    std::move(p.begin(), p.end(), std::back_inserter(rootPaths));
2424
0
  }
2425
0
}
2426
2427
void cmFindPackageCommand::PopFindPackageRootPathStack()
2428
0
{
2429
0
  this->Makefile->FindPackageRootPathStack.pop_back();
2430
0
}
2431
2432
void cmFindPackageCommand::ComputePrefixes()
2433
0
{
2434
0
  this->FillPrefixesPackageRedirect();
2435
2436
0
  if (!this->NoDefaultPath) {
2437
0
    if (!this->NoPackageRootPath) {
2438
0
      this->FillPrefixesPackageRoot();
2439
0
    }
2440
0
    if (!this->NoCMakePath) {
2441
0
      this->FillPrefixesCMakeVariable();
2442
0
    }
2443
0
    if (!this->NoCMakeEnvironmentPath) {
2444
0
      this->FillPrefixesCMakeEnvironment();
2445
0
    }
2446
0
  }
2447
2448
0
  this->FillPrefixesUserHints();
2449
2450
0
  if (!this->NoDefaultPath) {
2451
0
    if (!this->NoSystemEnvironmentPath) {
2452
0
      this->FillPrefixesSystemEnvironment();
2453
0
    }
2454
0
    if (!this->NoUserRegistry) {
2455
0
      this->FillPrefixesUserRegistry();
2456
0
    }
2457
0
    if (!this->NoCMakeSystemPath) {
2458
0
      this->FillPrefixesCMakeSystemVariable();
2459
0
    }
2460
0
    if (!this->NoSystemRegistry) {
2461
0
      this->FillPrefixesSystemRegistry();
2462
0
    }
2463
0
  }
2464
0
  this->FillPrefixesUserGuess();
2465
2466
0
  this->ComputeFinalPaths(IgnorePaths::No, &this->DebugBuffer);
2467
0
}
2468
2469
void cmFindPackageCommand::FillPrefixesPackageRedirect()
2470
0
{
2471
0
  cmSearchPath& paths = this->LabeledPaths[PathLabel::PackageRedirect];
2472
2473
0
  auto const redirectDir =
2474
0
    this->Makefile->GetDefinition("CMAKE_FIND_PACKAGE_REDIRECTS_DIR");
2475
0
  if (redirectDir && !redirectDir->empty()) {
2476
0
    paths.AddPath(*redirectDir);
2477
0
  }
2478
0
  if (this->DebugModeEnabled()) {
2479
0
    std::string debugBuffer =
2480
0
      "The internally managed CMAKE_FIND_PACKAGE_REDIRECTS_DIR.\n";
2481
0
    collectPathsForDebug(debugBuffer, paths);
2482
0
    this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer);
2483
0
  }
2484
0
}
2485
2486
void cmFindPackageCommand::FillPrefixesPackageRoot()
2487
0
{
2488
0
  cmSearchPath& paths = this->LabeledPaths[PathLabel::PackageRoot];
2489
2490
  // Add the PACKAGE_ROOT_PATH from each enclosing find_package call.
2491
0
  for (auto pkgPaths = this->Makefile->FindPackageRootPathStack.rbegin();
2492
0
       pkgPaths != this->Makefile->FindPackageRootPathStack.rend();
2493
0
       ++pkgPaths) {
2494
0
    for (std::string const& path : *pkgPaths) {
2495
0
      paths.AddPath(path);
2496
0
    }
2497
0
  }
2498
0
  if (this->DebugModeEnabled()) {
2499
0
    std::string debugBuffer = "<PackageName>_ROOT CMake variable "
2500
0
                              "[CMAKE_FIND_USE_PACKAGE_ROOT_PATH].\n";
2501
0
    collectPathsForDebug(debugBuffer, paths);
2502
0
    this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer);
2503
0
  }
2504
0
}
2505
2506
void cmFindPackageCommand::FillPrefixesCMakeEnvironment()
2507
0
{
2508
0
  cmSearchPath& paths = this->LabeledPaths[PathLabel::CMakeEnvironment];
2509
0
  std::string debugBuffer;
2510
0
  std::size_t debugOffset = 0;
2511
2512
  // Check the environment variable with the same name as the cache
2513
  // entry.
2514
0
  paths.AddEnvPath(this->Variable);
2515
0
  if (this->DebugModeEnabled()) {
2516
0
    debugBuffer = cmStrCat("Env variable ", this->Variable,
2517
0
                           " [CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH].\n");
2518
0
    debugOffset = collectPathsForDebug(debugBuffer, paths);
2519
0
  }
2520
2521
  // And now the general CMake environment variables
2522
0
  paths.AddEnvPath("CMAKE_PREFIX_PATH");
2523
0
  if (this->DebugModeEnabled()) {
2524
0
    debugBuffer = cmStrCat(debugBuffer,
2525
0
                           "CMAKE_PREFIX_PATH env variable "
2526
0
                           "[CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH].\n");
2527
0
    debugOffset = collectPathsForDebug(debugBuffer, paths, debugOffset);
2528
0
  }
2529
2530
0
  paths.AddEnvPath("CMAKE_FRAMEWORK_PATH");
2531
0
  paths.AddEnvPath("CMAKE_APPBUNDLE_PATH");
2532
0
  if (this->DebugModeEnabled()) {
2533
0
    debugBuffer =
2534
0
      cmStrCat(debugBuffer,
2535
0
               "CMAKE_FRAMEWORK_PATH and CMAKE_APPBUNDLE_PATH env "
2536
0
               "variables [CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH].\n");
2537
0
    collectPathsForDebug(debugBuffer, paths, debugOffset);
2538
0
    this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer);
2539
0
  }
2540
0
}
2541
2542
void cmFindPackageCommand::FillPrefixesCMakeVariable()
2543
0
{
2544
0
  cmSearchPath& paths = this->LabeledPaths[PathLabel::CMake];
2545
0
  std::string debugBuffer;
2546
0
  std::size_t debugOffset = 0;
2547
2548
0
  paths.AddCMakePath("CMAKE_PREFIX_PATH");
2549
0
  if (this->DebugModeEnabled()) {
2550
0
    debugBuffer = "CMAKE_PREFIX_PATH variable [CMAKE_FIND_USE_CMAKE_PATH].\n";
2551
0
    debugOffset = collectPathsForDebug(debugBuffer, paths);
2552
0
  }
2553
2554
0
  paths.AddCMakePath("CMAKE_FRAMEWORK_PATH");
2555
0
  paths.AddCMakePath("CMAKE_APPBUNDLE_PATH");
2556
0
  if (this->DebugModeEnabled()) {
2557
0
    debugBuffer =
2558
0
      cmStrCat(debugBuffer,
2559
0
               "CMAKE_FRAMEWORK_PATH and CMAKE_APPBUNDLE_PATH variables "
2560
0
               "[CMAKE_FIND_USE_CMAKE_PATH].\n");
2561
0
    collectPathsForDebug(debugBuffer, paths, debugOffset);
2562
0
    this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer);
2563
0
  }
2564
0
}
2565
2566
void cmFindPackageCommand::FillPrefixesSystemEnvironment()
2567
0
{
2568
0
  cmSearchPath& paths = this->LabeledPaths[PathLabel::SystemEnvironment];
2569
2570
  // Use the system search path to generate prefixes.
2571
  // Relative paths are interpreted with respect to the current
2572
  // working directory.
2573
0
  std::vector<std::string> envPATH =
2574
0
    cmSystemTools::GetEnvPathNormalized("PATH");
2575
0
  for (std::string const& i : envPATH) {
2576
    // If the path is a PREFIX/bin case then add its parent instead.
2577
0
    if ((cmHasLiteralSuffix(i, "/bin")) || (cmHasLiteralSuffix(i, "/sbin"))) {
2578
0
      paths.AddPath(cmSystemTools::GetFilenamePath(i));
2579
0
    } else {
2580
0
      paths.AddPath(i);
2581
0
    }
2582
0
  }
2583
0
  if (this->DebugModeEnabled()) {
2584
0
    std::string debugBuffer = "Standard system environment variables "
2585
0
                              "[CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH].\n";
2586
0
    collectPathsForDebug(debugBuffer, paths);
2587
0
    this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer);
2588
0
  }
2589
0
}
2590
2591
void cmFindPackageCommand::FillPrefixesUserRegistry()
2592
0
{
2593
#if defined(_WIN32) && !defined(__CYGWIN__)
2594
  this->LoadPackageRegistryWinUser();
2595
#elif defined(__HAIKU__)
2596
  char dir[B_PATH_NAME_LENGTH];
2597
  if (find_directory(B_USER_SETTINGS_DIRECTORY, -1, false, dir, sizeof(dir)) ==
2598
      B_OK) {
2599
    std::string fname = cmStrCat(dir, "/cmake/packages/", Name);
2600
    this->LoadPackageRegistryDir(fname,
2601
                                 this->LabeledPaths[PathLabel::UserRegistry]);
2602
  }
2603
#else
2604
0
  std::string dir;
2605
0
  if (cmSystemTools::GetEnv("HOME", dir)) {
2606
0
    dir += "/.cmake/packages/";
2607
0
    dir += this->Name;
2608
0
    this->LoadPackageRegistryDir(dir,
2609
0
                                 this->LabeledPaths[PathLabel::UserRegistry]);
2610
0
  }
2611
0
#endif
2612
0
  if (this->DebugModeEnabled()) {
2613
0
    std::string debugBuffer =
2614
0
      "CMake User Package Registry [CMAKE_FIND_USE_PACKAGE_REGISTRY].\n";
2615
0
    collectPathsForDebug(debugBuffer,
2616
0
                         this->LabeledPaths[PathLabel::UserRegistry]);
2617
0
    this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer);
2618
0
  }
2619
0
}
2620
2621
void cmFindPackageCommand::FillPrefixesSystemRegistry()
2622
0
{
2623
0
  if (this->NoSystemRegistry || this->NoDefaultPath) {
2624
0
    return;
2625
0
  }
2626
2627
#if defined(_WIN32) && !defined(__CYGWIN__)
2628
  this->LoadPackageRegistryWinSystem();
2629
#endif
2630
2631
0
  if (this->DebugModeEnabled()) {
2632
0
    std::string debugBuffer =
2633
0
      "CMake System Package Registry "
2634
0
      "[CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY].\n";
2635
0
    collectPathsForDebug(debugBuffer,
2636
0
                         this->LabeledPaths[PathLabel::SystemRegistry]);
2637
0
    this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer);
2638
0
  }
2639
0
}
2640
2641
#if defined(_WIN32) && !defined(__CYGWIN__)
2642
void cmFindPackageCommand::LoadPackageRegistryWinUser()
2643
{
2644
  // HKEY_CURRENT_USER\\Software shares 32-bit and 64-bit views.
2645
  this->LoadPackageRegistryWin(true, 0,
2646
                               this->LabeledPaths[PathLabel::UserRegistry]);
2647
}
2648
2649
void cmFindPackageCommand::LoadPackageRegistryWinSystem()
2650
{
2651
  cmSearchPath& paths = this->LabeledPaths[PathLabel::SystemRegistry];
2652
2653
  // HKEY_LOCAL_MACHINE\\SOFTWARE has separate 32-bit and 64-bit views.
2654
  // Prefer the target platform view first.
2655
  if (this->Makefile->PlatformIs64Bit()) {
2656
    this->LoadPackageRegistryWin(false, KEY_WOW64_64KEY, paths);
2657
    this->LoadPackageRegistryWin(false, KEY_WOW64_32KEY, paths);
2658
  } else {
2659
    this->LoadPackageRegistryWin(false, KEY_WOW64_32KEY, paths);
2660
    this->LoadPackageRegistryWin(false, KEY_WOW64_64KEY, paths);
2661
  }
2662
}
2663
2664
void cmFindPackageCommand::LoadPackageRegistryWin(bool const user,
2665
                                                  unsigned int const view,
2666
                                                  cmSearchPath& outPaths)
2667
{
2668
  std::wstring key = L"Software\\Kitware\\CMake\\Packages\\";
2669
  key += cmsys::Encoding::ToWide(this->Name);
2670
  std::set<std::wstring> bad;
2671
  HKEY hKey;
2672
  if (RegOpenKeyExW(user ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE, key.c_str(),
2673
                    0, KEY_QUERY_VALUE | view, &hKey) == ERROR_SUCCESS) {
2674
    DWORD valueType = REG_NONE;
2675
    wchar_t name[16383]; // RegEnumValue docs limit name to 32767 _bytes_
2676
    std::vector<wchar_t> data(512);
2677
    bool done = false;
2678
    DWORD index = 0;
2679
    while (!done) {
2680
      DWORD nameSize = static_cast<DWORD>(sizeof(name));
2681
      DWORD dataSize = static_cast<DWORD>(data.size() * sizeof(data[0]));
2682
      switch (RegEnumValueW(hKey, index, name, &nameSize, 0, &valueType,
2683
                            (BYTE*)&data[0], &dataSize)) {
2684
        case ERROR_SUCCESS:
2685
          ++index;
2686
          if (valueType == REG_SZ) {
2687
            data[dataSize] = 0;
2688
            if (!this->CheckPackageRegistryEntry(
2689
                  cmsys::Encoding::ToNarrow(&data[0]), outPaths)) {
2690
              // The entry is invalid.
2691
              bad.insert(name);
2692
            }
2693
          }
2694
          break;
2695
        case ERROR_MORE_DATA:
2696
          data.resize((dataSize + sizeof(data[0]) - 1) / sizeof(data[0]));
2697
          break;
2698
        case ERROR_NO_MORE_ITEMS:
2699
        default:
2700
          done = true;
2701
          break;
2702
      }
2703
    }
2704
    RegCloseKey(hKey);
2705
  }
2706
2707
  // Remove bad values if possible.
2708
  if (user && !bad.empty() &&
2709
      RegOpenKeyExW(HKEY_CURRENT_USER, key.c_str(), 0, KEY_SET_VALUE | view,
2710
                    &hKey) == ERROR_SUCCESS) {
2711
    for (std::wstring const& v : bad) {
2712
      RegDeleteValueW(hKey, v.c_str());
2713
    }
2714
    RegCloseKey(hKey);
2715
  }
2716
}
2717
2718
#else
2719
void cmFindPackageCommand::LoadPackageRegistryDir(std::string const& dir,
2720
                                                  cmSearchPath& outPaths)
2721
0
{
2722
0
  cmsys::Directory files;
2723
0
  if (!files.Load(dir)) {
2724
0
    return;
2725
0
  }
2726
2727
0
  std::string fname;
2728
0
  for (unsigned long i = 0; i < files.GetNumberOfFiles(); ++i) {
2729
0
    fname = cmStrCat(dir, '/', files.GetFileName(i));
2730
2731
0
    if (!cmSystemTools::FileIsDirectory(fname)) {
2732
      // Hold this file hostage until it behaves.
2733
0
      cmFindPackageCommandHoldFile holdFile(fname.c_str());
2734
2735
      // Load the file.
2736
0
      cmsys::ifstream fin(fname.c_str(), std::ios::in | std::ios::binary);
2737
0
      std::string fentry;
2738
0
      if (fin && cmSystemTools::GetLineFromStream(fin, fentry) &&
2739
0
          this->CheckPackageRegistryEntry(fentry, outPaths)) {
2740
        // The file references an existing package, so release it.
2741
0
        holdFile.Release();
2742
0
      }
2743
0
    }
2744
0
  }
2745
2746
  // TODO: Wipe out the directory if it is empty.
2747
0
}
2748
#endif
2749
2750
bool cmFindPackageCommand::CheckPackageRegistryEntry(std::string const& fname,
2751
                                                     cmSearchPath& outPaths)
2752
0
{
2753
  // Parse the content of one package registry entry.
2754
0
  if (cmSystemTools::FileIsFullPath(fname)) {
2755
    // The first line in the stream is the full path to a file or
2756
    // directory containing the package.
2757
0
    if (cmSystemTools::FileExists(fname)) {
2758
      // The path exists.  Look for the package here.
2759
0
      if (!cmSystemTools::FileIsDirectory(fname)) {
2760
0
        outPaths.AddPath(cmSystemTools::GetFilenamePath(fname));
2761
0
      } else {
2762
0
        outPaths.AddPath(fname);
2763
0
      }
2764
0
      return true;
2765
0
    }
2766
    // The path does not exist.  Assume the stream content is
2767
    // associated with an old package that no longer exists, and
2768
    // delete it to keep the package registry clean.
2769
0
    return false;
2770
0
  }
2771
  // The first line in the stream is not the full path to a file or
2772
  // directory.  Assume the stream content was created by a future
2773
  // version of CMake that uses a different format, and leave it.
2774
0
  return true;
2775
0
}
2776
2777
void cmFindPackageCommand::FillPrefixesCMakeSystemVariable()
2778
0
{
2779
0
  cmSearchPath& paths = this->LabeledPaths[PathLabel::CMakeSystem];
2780
2781
0
  bool const install_prefix_in_list =
2782
0
    !this->Makefile->IsOn("CMAKE_FIND_NO_INSTALL_PREFIX");
2783
0
  bool const remove_install_prefix = this->NoCMakeInstallPath;
2784
0
  bool const add_install_prefix = !this->NoCMakeInstallPath &&
2785
0
    this->Makefile->IsDefinitionSet("CMAKE_FIND_USE_INSTALL_PREFIX");
2786
2787
  // We have 3 possible states for `CMAKE_SYSTEM_PREFIX_PATH` and
2788
  // `CMAKE_INSTALL_PREFIX`.
2789
  // Either we need to remove `CMAKE_INSTALL_PREFIX`, add
2790
  // `CMAKE_INSTALL_PREFIX`, or do nothing.
2791
  //
2792
  // When we need to remove `CMAKE_INSTALL_PREFIX` we remove the Nth occurrence
2793
  // of `CMAKE_INSTALL_PREFIX` from `CMAKE_SYSTEM_PREFIX_PATH`, where `N` is
2794
  // computed by `CMakeSystemSpecificInformation.cmake` while constructing
2795
  // `CMAKE_SYSTEM_PREFIX_PATH`. This ensures that if projects / toolchains
2796
  // have removed `CMAKE_INSTALL_PREFIX` from the list, we don't remove
2797
  // some other entry by mistake
2798
0
  long install_prefix_count = -1;
2799
0
  std::string install_path_to_remove;
2800
0
  if (cmValue to_skip = this->Makefile->GetDefinition(
2801
0
        "_CMAKE_SYSTEM_PREFIX_PATH_INSTALL_PREFIX_COUNT")) {
2802
0
    cmStrToLong(*to_skip, &install_prefix_count);
2803
0
  }
2804
0
  if (cmValue install_value = this->Makefile->GetDefinition(
2805
0
        "_CMAKE_SYSTEM_PREFIX_PATH_INSTALL_PREFIX_VALUE")) {
2806
0
    install_path_to_remove = *install_value;
2807
0
  }
2808
2809
0
  if (remove_install_prefix && install_prefix_in_list &&
2810
0
      install_prefix_count > 0 && !install_path_to_remove.empty()) {
2811
2812
0
    cmValue prefix_paths =
2813
0
      this->Makefile->GetDefinition("CMAKE_SYSTEM_PREFIX_PATH");
2814
    // remove entry from CMAKE_SYSTEM_PREFIX_PATH
2815
0
    cmList expanded{ *prefix_paths };
2816
0
    long count = 0;
2817
0
    for (auto const& path : expanded) {
2818
0
      bool const to_add =
2819
0
        !(path == install_path_to_remove && ++count == install_prefix_count);
2820
0
      if (to_add) {
2821
0
        paths.AddPath(path);
2822
0
      }
2823
0
    }
2824
0
  } else if (add_install_prefix && !install_prefix_in_list) {
2825
0
    paths.AddCMakePath("CMAKE_INSTALL_PREFIX");
2826
0
    paths.AddCMakePath("CMAKE_SYSTEM_PREFIX_PATH");
2827
0
  } else {
2828
    // Otherwise the current setup of `CMAKE_SYSTEM_PREFIX_PATH` is correct
2829
0
    paths.AddCMakePath("CMAKE_SYSTEM_PREFIX_PATH");
2830
0
  }
2831
2832
0
  paths.AddCMakePath("CMAKE_SYSTEM_FRAMEWORK_PATH");
2833
0
  paths.AddCMakePath("CMAKE_SYSTEM_APPBUNDLE_PATH");
2834
2835
0
  if (this->DebugModeEnabled()) {
2836
0
    std::string debugBuffer = "CMake variables defined in the Platform file "
2837
0
                              "[CMAKE_FIND_USE_CMAKE_SYSTEM_PATH].\n";
2838
0
    collectPathsForDebug(debugBuffer, paths);
2839
0
    this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer);
2840
0
  }
2841
0
}
2842
2843
void cmFindPackageCommand::FillPrefixesUserGuess()
2844
0
{
2845
0
  cmSearchPath& paths = this->LabeledPaths[PathLabel::Guess];
2846
2847
0
  for (std::string const& p : this->UserGuessArgs) {
2848
0
    paths.AddUserPath(p);
2849
0
  }
2850
0
  if (this->DebugModeEnabled()) {
2851
0
    std::string debugBuffer =
2852
0
      "Paths specified by the find_package PATHS option.\n";
2853
0
    collectPathsForDebug(debugBuffer, paths);
2854
0
    this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer);
2855
0
  }
2856
0
}
2857
2858
void cmFindPackageCommand::FillPrefixesUserHints()
2859
0
{
2860
0
  cmSearchPath& paths = this->LabeledPaths[PathLabel::Hints];
2861
2862
0
  for (std::string const& p : this->UserHintsArgs) {
2863
0
    paths.AddUserPath(p);
2864
0
  }
2865
0
  if (this->DebugModeEnabled()) {
2866
0
    std::string debugBuffer =
2867
0
      "Paths specified by the find_package HINTS option.\n";
2868
0
    collectPathsForDebug(debugBuffer, paths);
2869
0
    this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer);
2870
0
  }
2871
0
}
2872
2873
bool cmFindPackageCommand::SearchDirectory(std::string const& dir,
2874
                                           PackageDescriptionType type)
2875
0
{
2876
0
  assert(!dir.empty() && dir.back() == '/');
2877
2878
  // Check each path suffix on this directory.
2879
0
  for (std::string const& s : this->SearchPathSuffixes) {
2880
0
    std::string d = dir;
2881
0
    if (!s.empty()) {
2882
0
      d += s;
2883
0
      d += '/';
2884
0
    }
2885
0
    if (this->CheckDirectory(d, type)) {
2886
0
      return true;
2887
0
    }
2888
0
  }
2889
0
  return false;
2890
0
}
2891
2892
bool cmFindPackageCommand::CheckDirectory(std::string const& dir,
2893
                                          PackageDescriptionType type)
2894
0
{
2895
0
  assert(!dir.empty() && dir.back() == '/');
2896
2897
0
  std::string const d = dir.substr(0, dir.size() - 1);
2898
0
  if (cm::contains(this->IgnoredPaths, d)) {
2899
0
    this->ConsideredPaths.emplace_back(
2900
0
      dir, cmFindPackageCommand::FoundMode(type), SearchResult::Ignored);
2901
0
    return false;
2902
0
  }
2903
2904
  // Look for the file in this directory.
2905
0
  std::string file;
2906
0
  FoundPackageMode foundMode = FoundPackageMode::None;
2907
0
  if (this->FindConfigFile(d, type, file, foundMode)) {
2908
0
    this->FileFound = std::move(file);
2909
0
    this->FileFoundMode = foundMode;
2910
0
    return true;
2911
0
  }
2912
0
  return false;
2913
0
}
2914
2915
bool cmFindPackageCommand::FindConfigFile(std::string const& dir,
2916
                                          PackageDescriptionType type,
2917
                                          std::string& file,
2918
                                          FoundPackageMode& foundMode)
2919
0
{
2920
0
  for (auto const& config : this->Configs) {
2921
0
    if (type != pdt::Any && config.Type != type) {
2922
0
      continue;
2923
0
    }
2924
0
    file = cmStrCat(dir, '/', config.Name);
2925
0
    if (this->DebugModeEnabled()) {
2926
0
      this->DebugBuffer = cmStrCat(this->DebugBuffer, "  ", file, '\n');
2927
0
    }
2928
0
    if (cmSystemTools::FileExists(file, true)) {
2929
      // Allow resolving symlinks when the config file is found through a link
2930
0
      if (this->UseRealPath) {
2931
0
        file = cmSystemTools::GetRealPath(file);
2932
0
      } else {
2933
0
        file = cmSystemTools::ToNormalizedPathOnDisk(file);
2934
0
      }
2935
0
      if (this->CheckVersion(file)) {
2936
0
        foundMode = cmFindPackageCommand::FoundMode(config.Type);
2937
0
        return true;
2938
0
      }
2939
0
      this->ConsideredPaths.emplace_back(
2940
0
        file, cmFindPackageCommand::FoundMode(type),
2941
0
        this->ConsideredConfigs.back().result,
2942
0
        this->ConsideredConfigs.back().message);
2943
0
    } else {
2944
0
      this->ConsideredPaths.emplace_back(
2945
0
        file, cmFindPackageCommand::FoundMode(type), SearchResult::NoExist);
2946
0
    }
2947
0
  }
2948
0
  return false;
2949
0
}
2950
2951
bool cmFindPackageCommand::CheckVersion(std::string const& config_file)
2952
0
{
2953
0
  bool result = false; // by default, assume the version is not ok.
2954
0
  bool haveResult = false;
2955
0
  std::string version = "unknown";
2956
0
  std::string message;
2957
0
  SearchResult reason = SearchResult::InsufficientVersion;
2958
2959
  // Get the file extension.
2960
0
  std::string::size_type pos = config_file.rfind('.');
2961
0
  std::string ext = cmSystemTools::LowerCase(config_file.substr(pos));
2962
2963
0
  if (ext == ".cps"_s) {
2964
0
    cmMakefile::CallRAII cs{ this->Makefile, config_file, this->Status };
2965
2966
0
    std::unique_ptr<cmPackageInfoReader> reader =
2967
0
      cmPackageInfoReader::Read(this->Makefile, config_file);
2968
2969
0
    if (reader && reader->GetName() == this->Name) {
2970
      // Read version information.
2971
0
      cm::optional<std::string> cpsVersion = reader->GetVersion();
2972
0
      cm::optional<ParsedVersion> const& parsedVersion =
2973
0
        reader->ParseVersion(cpsVersion);
2974
0
      bool const hasVersion = cpsVersion.has_value();
2975
2976
      // Test for version compatibility.
2977
0
      result = this->Version.empty();
2978
0
      if (hasVersion) {
2979
0
        version = std::move(*cpsVersion);
2980
2981
0
        if (!this->Version.empty()) {
2982
0
          if (!parsedVersion) {
2983
            // If we don't understand the version, compare the exact versions
2984
            // using full string comparison. This is the correct behavior for
2985
            // the "custom" schema, and the best we can do otherwise.
2986
0
            result = (this->Version == version);
2987
0
          } else if (this->VersionExact) {
2988
            // If EXACT is specified, the version must be exactly the requested
2989
            // version.
2990
0
            result =
2991
0
              cmSystemTools::VersionCompareEqual(this->Version, version);
2992
0
          } else {
2993
            // Do we have a compat_version?
2994
0
            cm::optional<std::string> const& compatVersion =
2995
0
              reader->GetCompatVersion();
2996
0
            if (reader->ParseVersion(compatVersion)) {
2997
              // If yes, the initial result is whether the requested version is
2998
              // between the actual version and the compat version, inclusive.
2999
0
              result = cmSystemTools::VersionCompareGreaterEq(version,
3000
0
                                                              this->Version) &&
3001
0
                cmSystemTools::VersionCompareGreaterEq(this->Version,
3002
0
                                                       *compatVersion);
3003
3004
0
              if (result && !this->VersionMax.empty()) {
3005
                // We must also check that the version is less than the version
3006
                // limit.
3007
0
                if (this->VersionRangeMax == VERSION_ENDPOINT_EXCLUDED) {
3008
0
                  result = cmSystemTools::VersionCompareGreater(
3009
0
                    this->VersionMax, version);
3010
0
                } else {
3011
0
                  result = cmSystemTools::VersionCompareGreaterEq(
3012
0
                    this->VersionMax, version);
3013
0
                }
3014
0
              }
3015
3016
0
              if (!result) {
3017
0
                message =
3018
0
                  cmStrCat("Version \""_s, version,
3019
0
                           "\" (compatibility version \""_s, *compatVersion,
3020
0
                           "\") is not compatible "
3021
0
                           "with the version requested."_s);
3022
0
              }
3023
0
            } else {
3024
              // If no, compat_version is assumed to be exactly the actual
3025
              // version, so the result is whether the requested version is
3026
              // exactly the actual version, and we can ignore the version
3027
              // limit.
3028
0
              result =
3029
0
                cmSystemTools::VersionCompareEqual(this->Version, version);
3030
0
            }
3031
0
          }
3032
0
        }
3033
3034
0
        if (!result && message.empty()) {
3035
0
          message =
3036
0
            cmStrCat("Version \""_s, version,
3037
0
                     "\" is not compatible with the version requested."_s);
3038
0
        }
3039
0
      }
3040
3041
0
      if (result) {
3042
        // Locate appendices.
3043
0
        cmFindPackageCommand::AppendixMap appendices =
3044
0
          this->FindAppendices(config_file, *reader);
3045
3046
        // Collect available components.
3047
0
        std::set<std::string> allComponents;
3048
3049
0
        std::vector<std::string> const& rootComponents =
3050
0
          reader->GetComponentNames();
3051
0
        allComponents.insert(rootComponents.begin(), rootComponents.end());
3052
3053
0
        for (auto const& appendix : appendices) {
3054
0
          allComponents.insert(appendix.second.Components.begin(),
3055
0
                               appendix.second.Components.end());
3056
0
        }
3057
3058
        // Verify that all required components are available.
3059
0
        std::set<std::string> requiredComponents = this->RequiredComponents;
3060
0
        requiredComponents.insert(this->RequiredTargets.begin(),
3061
0
                                  this->RequiredTargets.end());
3062
3063
0
        std::vector<std::string> missingComponents;
3064
0
        std::set_difference(requiredComponents.begin(),
3065
0
                            requiredComponents.end(), allComponents.begin(),
3066
0
                            allComponents.end(),
3067
0
                            std::back_inserter(missingComponents));
3068
0
        if (!missingComponents.empty()) {
3069
0
          bool const single = (missingComponents.size() == 1);
3070
0
          result = false;
3071
0
          message =
3072
0
            cmStrCat((single ? "Required component was not found: "_s
3073
0
                             : "Required components were not found: "_s),
3074
0
                     cmJoin(missingComponents, ", "_s), '.');
3075
0
          reason = SearchResult::InsufficientComponents;
3076
0
        }
3077
3078
0
        if (result && hasVersion) {
3079
0
          this->VersionFound = version;
3080
3081
0
          if (parsedVersion) {
3082
0
            std::vector<unsigned> const& versionParts =
3083
0
              parsedVersion->ReleaseComponents;
3084
3085
0
            this->VersionFoundCount =
3086
0
              static_cast<unsigned>(versionParts.size());
3087
0
            switch (std::min(this->VersionFoundCount, 4u)) {
3088
0
              case 4:
3089
0
                this->VersionFoundTweak = versionParts[3];
3090
0
                CM_FALLTHROUGH;
3091
0
              case 3:
3092
0
                this->VersionFoundPatch = versionParts[2];
3093
0
                CM_FALLTHROUGH;
3094
0
              case 2:
3095
0
                this->VersionFoundMinor = versionParts[1];
3096
0
                CM_FALLTHROUGH;
3097
0
              case 1:
3098
0
                this->VersionFoundMajor = versionParts[0];
3099
0
                CM_FALLTHROUGH;
3100
0
              default:
3101
0
                break;
3102
0
            }
3103
0
          } else {
3104
0
            this->VersionFoundCount = 0;
3105
0
          }
3106
0
        }
3107
0
        this->CpsReader = std::move(reader);
3108
0
        this->CpsAppendices = std::move(appendices);
3109
0
        this->RequiredComponents = std::move(requiredComponents);
3110
0
      }
3111
0
    } else if (reader) {
3112
0
      message =
3113
0
        cmStrCat("The file describes the package \""_s, reader->GetName(),
3114
0
                 "\", which is not the requested package."_s);
3115
0
      reason = SearchResult::Ignored;
3116
0
    } else {
3117
0
      message = "The package description file could not be read.";
3118
0
      reason = SearchResult::Error;
3119
0
    }
3120
0
  } else {
3121
    // Get the filename without the .cmake extension.
3122
0
    std::string version_file_base = config_file.substr(0, pos);
3123
3124
    // Look for foo-config-version.cmake
3125
0
    std::string version_file = cmStrCat(version_file_base, "-version.cmake");
3126
0
    if (!haveResult && cmSystemTools::FileExists(version_file, true)) {
3127
0
      result = this->CheckVersionFile(version_file, version);
3128
0
      haveResult = true;
3129
0
    }
3130
3131
    // Look for fooConfigVersion.cmake
3132
0
    version_file = cmStrCat(version_file_base, "Version.cmake");
3133
0
    if (!haveResult && cmSystemTools::FileExists(version_file, true)) {
3134
0
      result = this->CheckVersionFile(version_file, version);
3135
0
      haveResult = true;
3136
0
    }
3137
3138
0
    if (haveResult && !result) {
3139
0
      message =
3140
0
        "The version found is not compatible with the version requested.";
3141
0
    }
3142
3143
    // If no version was requested a versionless package is acceptable.
3144
0
    if (!haveResult && this->Version.empty()) {
3145
0
      result = true;
3146
0
    }
3147
0
  }
3148
3149
0
  if (result) {
3150
0
    reason = SearchResult::Acceptable;
3151
0
  }
3152
3153
0
  ConfigFileInfo configFileInfo;
3154
0
  configFileInfo.filename = config_file;
3155
0
  configFileInfo.version = version;
3156
0
  configFileInfo.message = message;
3157
0
  configFileInfo.result = reason;
3158
0
  this->ConsideredConfigs.push_back(std::move(configFileInfo));
3159
3160
0
  return result;
3161
0
}
3162
3163
bool cmFindPackageCommand::CheckVersionFile(std::string const& version_file,
3164
                                            std::string& result_version)
3165
0
{
3166
  // The version file will be loaded in an isolated scope.
3167
0
  cmMakefile::ScopePushPop const varScope(this->Makefile);
3168
0
  cmMakefile::PolicyPushPop const polScope(this->Makefile);
3169
0
  static_cast<void>(varScope);
3170
0
  static_cast<void>(polScope);
3171
3172
  // Clear the output variables.
3173
0
  this->Makefile->RemoveDefinition("PACKAGE_VERSION");
3174
0
  this->Makefile->RemoveDefinition("PACKAGE_VERSION_UNSUITABLE");
3175
0
  this->Makefile->RemoveDefinition("PACKAGE_VERSION_COMPATIBLE");
3176
0
  this->Makefile->RemoveDefinition("PACKAGE_VERSION_EXACT");
3177
3178
  // Set the input variables.
3179
0
  this->Makefile->AddDefinition("PACKAGE_FIND_NAME", this->Name);
3180
0
  this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_COMPLETE",
3181
0
                                this->VersionComplete);
3182
3183
0
  auto addDefinition = [this](std::string const& variable,
3184
0
                              cm::string_view value) {
3185
0
    this->Makefile->AddDefinition(variable, value);
3186
0
  };
3187
0
  this->SetVersionVariables(addDefinition, "PACKAGE_FIND_VERSION",
3188
0
                            this->Version, this->VersionCount,
3189
0
                            this->VersionMajor, this->VersionMinor,
3190
0
                            this->VersionPatch, this->VersionTweak);
3191
0
  if (!this->VersionRange.empty()) {
3192
0
    this->SetVersionVariables(addDefinition, "PACKAGE_FIND_VERSION_MIN",
3193
0
                              this->Version, this->VersionCount,
3194
0
                              this->VersionMajor, this->VersionMinor,
3195
0
                              this->VersionPatch, this->VersionTweak);
3196
0
    this->SetVersionVariables(addDefinition, "PACKAGE_FIND_VERSION_MAX",
3197
0
                              this->VersionMax, this->VersionMaxCount,
3198
0
                              this->VersionMaxMajor, this->VersionMaxMinor,
3199
0
                              this->VersionMaxPatch, this->VersionMaxTweak);
3200
3201
0
    this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_RANGE",
3202
0
                                  this->VersionComplete);
3203
0
    this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_RANGE_MIN",
3204
0
                                  this->VersionRangeMin);
3205
0
    this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_RANGE_MAX",
3206
0
                                  this->VersionRangeMax);
3207
0
  }
3208
3209
  // Load the version check file.
3210
  // Pass NoPolicyScope because we do our own policy push/pop.
3211
0
  bool suitable = false;
3212
0
  if (this->ReadListFile(version_file, cm::PolicyScope::None)) {
3213
    // Check the output variables.
3214
0
    bool okay = this->Makefile->IsOn("PACKAGE_VERSION_EXACT");
3215
0
    bool const unsuitable = this->Makefile->IsOn("PACKAGE_VERSION_UNSUITABLE");
3216
0
    if (!okay && !this->VersionExact) {
3217
0
      okay = this->Makefile->IsOn("PACKAGE_VERSION_COMPATIBLE");
3218
0
    }
3219
3220
    // The package is suitable if the version is okay and not
3221
    // explicitly unsuitable.
3222
0
    suitable = !unsuitable && (okay || this->Version.empty());
3223
0
    if (suitable) {
3224
      // Get the version found.
3225
0
      this->VersionFound =
3226
0
        this->Makefile->GetSafeDefinition("PACKAGE_VERSION");
3227
3228
      // Try to parse the version number and store the results that were
3229
      // successfully parsed.
3230
0
      unsigned int parsed_major;
3231
0
      unsigned int parsed_minor;
3232
0
      unsigned int parsed_patch;
3233
0
      unsigned int parsed_tweak;
3234
0
      this->VersionFoundCount =
3235
0
        parseVersion(this->VersionFound, parsed_major, parsed_minor,
3236
0
                     parsed_patch, parsed_tweak);
3237
0
      switch (this->VersionFoundCount) {
3238
0
        case 4:
3239
0
          this->VersionFoundTweak = parsed_tweak;
3240
0
          CM_FALLTHROUGH;
3241
0
        case 3:
3242
0
          this->VersionFoundPatch = parsed_patch;
3243
0
          CM_FALLTHROUGH;
3244
0
        case 2:
3245
0
          this->VersionFoundMinor = parsed_minor;
3246
0
          CM_FALLTHROUGH;
3247
0
        case 1:
3248
0
          this->VersionFoundMajor = parsed_major;
3249
0
          CM_FALLTHROUGH;
3250
0
        default:
3251
0
          break;
3252
0
      }
3253
0
    }
3254
0
  }
3255
3256
0
  result_version = this->Makefile->GetSafeDefinition("PACKAGE_VERSION");
3257
0
  if (result_version.empty()) {
3258
0
    result_version = "unknown";
3259
0
  }
3260
3261
  // Succeed if the version is suitable.
3262
0
  return suitable;
3263
0
}
3264
3265
void cmFindPackageCommand::StoreVersionFound()
3266
0
{
3267
  // Store the whole version string.
3268
0
  std::string const ver = cmStrCat(this->Name, "_VERSION");
3269
0
  auto addDefinition = [this](std::string const& variable,
3270
0
                              cm::string_view value) {
3271
0
    this->Makefile->AddDefinition(variable, value);
3272
0
  };
3273
3274
0
  this->SetVersionVariables(addDefinition, ver, this->VersionFound,
3275
0
                            this->VersionFoundCount, this->VersionFoundMajor,
3276
0
                            this->VersionFoundMinor, this->VersionFoundPatch,
3277
0
                            this->VersionFoundTweak);
3278
3279
0
  if (this->VersionFound.empty()) {
3280
0
    this->Makefile->RemoveDefinition(ver);
3281
0
  }
3282
0
}
3283
3284
bool cmFindPackageCommand::SearchPrefix(std::string const& prefix)
3285
0
{
3286
0
  assert(!prefix.empty() && prefix.back() == '/');
3287
3288
  // Skip this if the prefix does not exist.
3289
0
  if (!cmSystemTools::FileIsDirectory(prefix)) {
3290
0
    return false;
3291
0
  }
3292
3293
  // Skip this if it's in ignored paths.
3294
0
  std::string prefixWithoutSlash = prefix;
3295
0
  if (prefixWithoutSlash != "/" && prefixWithoutSlash.back() == '/') {
3296
0
    prefixWithoutSlash.erase(prefixWithoutSlash.length() - 1);
3297
0
  }
3298
0
  if (this->IgnoredPaths.count(prefixWithoutSlash) ||
3299
0
      this->IgnoredPrefixPaths.count(prefixWithoutSlash)) {
3300
0
    return false;
3301
0
  }
3302
3303
0
  auto searchFn = [this](std::string const& fullPath,
3304
0
                         PackageDescriptionType type) -> bool {
3305
0
    return this->SearchDirectory(fullPath, type);
3306
0
  };
3307
3308
0
  auto iCpsGen = cmCaseInsensitiveDirectoryListGenerator{ "cps"_s };
3309
0
  auto iCMakeGen = cmCaseInsensitiveDirectoryListGenerator{ "cmake"_s };
3310
0
  auto anyDirGen =
3311
0
    cmAnyDirectoryListGenerator{ this->SortOrder, this->SortDirection };
3312
0
  auto cpsPkgDirGen =
3313
0
    cmProjectDirectoryListGenerator{ &this->Names, this->SortOrder,
3314
0
                                     this->SortDirection, true };
3315
0
  auto cmakePkgDirGen =
3316
0
    cmProjectDirectoryListGenerator{ &this->Names, this->SortOrder,
3317
0
                                     this->SortDirection, false };
3318
3319
  // PREFIX/(Foo|foo|FOO)/(cps|CPS)/
3320
0
  if (TryGeneratedPaths(searchFn, pdt::Cps, prefix, cpsPkgDirGen, iCpsGen)) {
3321
0
    return true;
3322
0
  }
3323
3324
  // PREFIX/(Foo|foo|FOO)/*/(cps|CPS)/
3325
0
  if (TryGeneratedPaths(searchFn, pdt::Cps, prefix, cpsPkgDirGen, iCpsGen,
3326
0
                        anyDirGen)) {
3327
0
    return true;
3328
0
  }
3329
3330
  // PREFIX/(cps|CPS)/(Foo|foo|FOO)/
3331
0
  if (TryGeneratedPaths(searchFn, pdt::Cps, prefix, iCpsGen, cpsPkgDirGen)) {
3332
0
    return true;
3333
0
  }
3334
3335
  // PREFIX/(cps|CPS)/(Foo|foo|FOO)/*/
3336
0
  if (TryGeneratedPaths(searchFn, pdt::Cps, prefix, iCpsGen, cpsPkgDirGen,
3337
0
                        anyDirGen)) {
3338
0
    return true;
3339
0
  }
3340
3341
  // PREFIX/(cps|CPS)/ (useful on windows or in build trees)
3342
0
  if (TryGeneratedPaths(searchFn, pdt::Cps, prefix, iCpsGen)) {
3343
0
    return true;
3344
0
  }
3345
3346
  // PREFIX/ (useful on windows or in build trees)
3347
0
  if (this->SearchDirectory(prefix, pdt::CMake)) {
3348
0
    return true;
3349
0
  }
3350
3351
  // PREFIX/(cmake|CMake)/ (useful on windows or in build trees)
3352
0
  if (TryGeneratedPaths(searchFn, pdt::CMake, prefix, iCMakeGen)) {
3353
0
    return true;
3354
0
  }
3355
3356
  // PREFIX/(Foo|foo|FOO).*/
3357
0
  if (TryGeneratedPaths(searchFn, pdt::CMake, prefix, cmakePkgDirGen)) {
3358
0
    return true;
3359
0
  }
3360
3361
  // PREFIX/(Foo|foo|FOO).*/(cmake|CMake)/
3362
0
  if (TryGeneratedPaths(searchFn, pdt::CMake, prefix, cmakePkgDirGen,
3363
0
                        iCMakeGen)) {
3364
0
    return true;
3365
0
  }
3366
3367
0
  auto secondPkgDirGen =
3368
0
    cmProjectDirectoryListGenerator{ &this->Names, this->SortOrder,
3369
0
                                     this->SortDirection, false };
3370
3371
  // PREFIX/(Foo|foo|FOO).*/(cmake|CMake)/(Foo|foo|FOO).*/
3372
0
  if (TryGeneratedPaths(searchFn, pdt::CMake, prefix, cmakePkgDirGen,
3373
0
                        iCMakeGen, secondPkgDirGen)) {
3374
0
    return true;
3375
0
  }
3376
3377
  // Construct list of common install locations (lib and share).
3378
0
  std::vector<cm::string_view> common;
3379
0
  std::string libArch;
3380
0
  if (!this->LibraryArchitecture.empty()) {
3381
0
    libArch = "lib/" + this->LibraryArchitecture;
3382
0
    common.emplace_back(libArch);
3383
0
  }
3384
0
  if (this->UseLib32Paths) {
3385
0
    common.emplace_back("lib32"_s);
3386
0
  }
3387
0
  if (this->UseLib64Paths) {
3388
0
    common.emplace_back("lib64"_s);
3389
0
  }
3390
0
  if (this->UseLibx32Paths) {
3391
0
    common.emplace_back("libx32"_s);
3392
0
  }
3393
0
  common.emplace_back("lib"_s);
3394
0
  common.emplace_back("share"_s);
3395
3396
0
  auto commonGen = cmEnumPathSegmentsGenerator{ common };
3397
0
  auto cmakeGen = cmAppendPathSegmentGenerator{ "cmake"_s };
3398
0
  auto cpsGen = cmAppendPathSegmentGenerator{ "cps"_s };
3399
3400
  // PREFIX/(lib/ARCH|lib*|share)/cps/(Foo|foo|FOO)/
3401
0
  if (TryGeneratedPaths(searchFn, pdt::Cps, prefix, commonGen, cpsGen,
3402
0
                        cpsPkgDirGen)) {
3403
0
    return true;
3404
0
  }
3405
3406
  // PREFIX/(lib/ARCH|lib*|share)/cps/(Foo|foo|FOO)/*/
3407
0
  if (TryGeneratedPaths(searchFn, pdt::Cps, prefix, commonGen, cpsGen,
3408
0
                        cpsPkgDirGen, anyDirGen)) {
3409
0
    return true;
3410
0
  }
3411
3412
  // PREFIX/(lib/ARCH|lib*|share)/cps/
3413
0
  if (TryGeneratedPaths(searchFn, pdt::Cps, prefix, commonGen, cpsGen)) {
3414
0
    return true;
3415
0
  }
3416
3417
  // PREFIX/(lib/ARCH|lib*|share)/cmake/(Foo|foo|FOO).*/
3418
0
  if (TryGeneratedPaths(searchFn, pdt::CMake, prefix, commonGen, cmakeGen,
3419
0
                        cmakePkgDirGen)) {
3420
0
    return true;
3421
0
  }
3422
3423
  // PREFIX/(lib/ARCH|lib*|share)/(Foo|foo|FOO).*/
3424
0
  if (TryGeneratedPaths(searchFn, pdt::CMake, prefix, commonGen,
3425
0
                        cmakePkgDirGen)) {
3426
0
    return true;
3427
0
  }
3428
3429
  // PREFIX/(lib/ARCH|lib*|share)/(Foo|foo|FOO).*/(cmake|CMake)/
3430
0
  if (TryGeneratedPaths(searchFn, pdt::CMake, prefix, commonGen,
3431
0
                        cmakePkgDirGen, iCMakeGen)) {
3432
0
    return true;
3433
0
  }
3434
3435
  // PREFIX/(Foo|foo|FOO).*/(lib/ARCH|lib*|share)/cmake/(Foo|foo|FOO).*/
3436
0
  if (TryGeneratedPaths(searchFn, pdt::CMake, prefix, cmakePkgDirGen,
3437
0
                        commonGen, cmakeGen, secondPkgDirGen)) {
3438
0
    return true;
3439
0
  }
3440
3441
  // PREFIX/(Foo|foo|FOO).*/(lib/ARCH|lib*|share)/(Foo|foo|FOO).*/
3442
0
  if (TryGeneratedPaths(searchFn, pdt::CMake, prefix, cmakePkgDirGen,
3443
0
                        commonGen, secondPkgDirGen)) {
3444
0
    return true;
3445
0
  }
3446
3447
  // PREFIX/(Foo|foo|FOO).*/(lib/ARCH|lib*|share)/(Foo|foo|FOO).*/(cmake|CMake)/
3448
0
  return TryGeneratedPaths(searchFn, pdt::CMake, prefix, cmakePkgDirGen,
3449
0
                           commonGen, secondPkgDirGen, iCMakeGen);
3450
0
}
3451
3452
bool cmFindPackageCommand::SearchFrameworkPrefix(std::string const& prefix)
3453
0
{
3454
0
  assert(!prefix.empty() && prefix.back() == '/');
3455
3456
0
  auto searchFn = [this](std::string const& fullPath,
3457
0
                         PackageDescriptionType type) -> bool {
3458
0
    return this->SearchDirectory(fullPath, type);
3459
0
  };
3460
3461
0
  auto iCMakeGen = cmCaseInsensitiveDirectoryListGenerator{ "cmake"_s };
3462
0
  auto iCpsGen = cmCaseInsensitiveDirectoryListGenerator{ "cps"_s };
3463
0
  auto fwGen =
3464
0
    cmMacProjectDirectoryListGenerator{ &this->Names, ".framework"_s };
3465
0
  auto rGen = cmAppendPathSegmentGenerator{ "Resources"_s };
3466
0
  auto vGen = cmAppendPathSegmentGenerator{ "Versions"_s };
3467
0
  auto anyGen =
3468
0
    cmAnyDirectoryListGenerator{ this->SortOrder, this->SortDirection };
3469
3470
  // <prefix>/Foo.framework/Versions/*/Resources/CPS/
3471
0
  if (TryGeneratedPaths(searchFn, pdt::Cps, prefix, fwGen, vGen, anyGen, rGen,
3472
0
                        iCpsGen)) {
3473
0
    return true;
3474
0
  }
3475
3476
  // <prefix>/Foo.framework/Resources/CPS/
3477
0
  if (TryGeneratedPaths(searchFn, pdt::Cps, prefix, fwGen, rGen, iCpsGen)) {
3478
0
    return true;
3479
0
  }
3480
3481
  // <prefix>/Foo.framework/Resources/
3482
0
  if (TryGeneratedPaths(searchFn, pdt::CMake, prefix, fwGen, rGen)) {
3483
0
    return true;
3484
0
  }
3485
3486
  // <prefix>/Foo.framework/Resources/CMake/
3487
0
  if (TryGeneratedPaths(searchFn, pdt::CMake, prefix, fwGen, rGen,
3488
0
                        iCMakeGen)) {
3489
0
    return true;
3490
0
  }
3491
3492
  // <prefix>/Foo.framework/Versions/*/Resources/
3493
0
  if (TryGeneratedPaths(searchFn, pdt::CMake, prefix, fwGen, vGen, anyGen,
3494
0
                        rGen)) {
3495
0
    return true;
3496
0
  }
3497
3498
  // <prefix>/Foo.framework/Versions/*/Resources/CMake/
3499
0
  return TryGeneratedPaths(searchFn, pdt::CMake, prefix, fwGen, vGen, anyGen,
3500
0
                           rGen, iCMakeGen);
3501
0
}
3502
3503
bool cmFindPackageCommand::SearchAppBundlePrefix(std::string const& prefix)
3504
0
{
3505
0
  assert(!prefix.empty() && prefix.back() == '/');
3506
3507
0
  auto searchFn = [this](std::string const& fullPath,
3508
0
                         PackageDescriptionType type) -> bool {
3509
0
    return this->SearchDirectory(fullPath, type);
3510
0
  };
3511
3512
0
  auto appGen = cmMacProjectDirectoryListGenerator{ &this->Names, ".app"_s };
3513
0
  auto crGen = cmAppendPathSegmentGenerator{ "Contents/Resources"_s };
3514
3515
  // <prefix>/Foo.app/Contents/Resources/CPS/
3516
0
  if (TryGeneratedPaths(searchFn, pdt::Cps, prefix, appGen, crGen,
3517
0
                        cmCaseInsensitiveDirectoryListGenerator{ "cps"_s })) {
3518
0
    return true;
3519
0
  }
3520
3521
  // <prefix>/Foo.app/Contents/Resources/
3522
0
  if (TryGeneratedPaths(searchFn, pdt::CMake, prefix, appGen, crGen)) {
3523
0
    return true;
3524
0
  }
3525
3526
  // <prefix>/Foo.app/Contents/Resources/CMake/
3527
0
  return TryGeneratedPaths(
3528
0
    searchFn, pdt::CMake, prefix, appGen, crGen,
3529
0
    cmCaseInsensitiveDirectoryListGenerator{ "cmake"_s });
3530
0
}
3531
3532
bool cmFindPackageCommand::SearchEnvironmentPrefix(std::string const& prefix)
3533
0
{
3534
0
  assert(!prefix.empty() && prefix.back() == '/');
3535
3536
  // Skip this if the prefix does not exist.
3537
0
  if (!cmSystemTools::FileIsDirectory(prefix)) {
3538
0
    return false;
3539
0
  }
3540
3541
0
  auto searchFn = [this](std::string const& fullPath,
3542
0
                         PackageDescriptionType type) -> bool {
3543
0
    return this->SearchDirectory(fullPath, type);
3544
0
  };
3545
3546
0
  auto pkgDirGen =
3547
0
    cmProjectDirectoryListGenerator{ &this->Names, this->SortOrder,
3548
0
                                     this->SortDirection, true };
3549
3550
  // <environment-path>/(Foo|foo|FOO)/cps/
3551
0
  if (TryGeneratedPaths(searchFn, pdt::Cps, prefix, pkgDirGen,
3552
0
                        cmAppendPathSegmentGenerator{ "cps"_s })) {
3553
0
    return true;
3554
0
  }
3555
3556
  // <environment-path>/(Foo|foo|FOO)/
3557
0
  return TryGeneratedPaths(searchFn, pdt::Cps, prefix, pkgDirGen);
3558
0
}
3559
3560
bool cmFindPackageCommand::IsRequired() const
3561
0
{
3562
0
  return this->Required == RequiredStatus::RequiredExplicit ||
3563
0
    this->Required == RequiredStatus::RequiredFromPackageVar ||
3564
0
    this->Required == RequiredStatus::RequiredFromFindVar;
3565
0
}
3566
3567
cmFindPackageCommand::FoundPackageMode cmFindPackageCommand::FoundMode(
3568
  PackageDescriptionType type)
3569
0
{
3570
0
  switch (type) {
3571
0
    case PackageDescriptionType::Any:
3572
0
      return FoundPackageMode::None;
3573
0
    case PackageDescriptionType::CMake:
3574
0
      return FoundPackageMode::Config;
3575
0
    case PackageDescriptionType::Cps:
3576
0
      return FoundPackageMode::Cps;
3577
0
  }
3578
0
  return FoundPackageMode::None;
3579
0
}
3580
3581
// TODO: Debug cmsys::Glob double slash problem.
3582
3583
bool cmFindPackage(std::vector<std::string> const& args,
3584
                   cmExecutionStatus& status)
3585
0
{
3586
0
  return cmFindPackageCommand(status).InitialPass(args);
3587
0
}
3588
3589
cmFindPackageDebugState::cmFindPackageDebugState(
3590
  cmFindPackageCommand const* findPackage)
3591
0
  : cmFindCommonDebugState("find_package", findPackage)
3592
0
  , FindPackageCommand(findPackage)
3593
0
{
3594
0
}
3595
3596
0
cmFindPackageDebugState::~cmFindPackageDebugState() = default;
3597
3598
void cmFindPackageDebugState::FoundAtImpl(std::string const& path,
3599
                                          std::string regexName)
3600
0
{
3601
0
  (void)path;
3602
0
  (void)regexName;
3603
0
}
3604
3605
void cmFindPackageDebugState::FailedAtImpl(std::string const& path,
3606
                                           std::string regexName)
3607
0
{
3608
0
  (void)path;
3609
0
  (void)regexName;
3610
0
}
3611
3612
bool cmFindPackageDebugState::ShouldImplicitlyLogEvents() const
3613
0
{
3614
0
  auto const* fpc = this->FindPackageCommand;
3615
0
  bool const canUsePackage = fpc->UseConfigFiles || fpc->UseCpsFiles;
3616
0
  return canUsePackage &&
3617
0
    fpc->FileFoundMode != cmFindPackageCommand::FoundPackageMode::Module &&
3618
0
    std::any_of(fpc->ConsideredPaths.begin(), fpc->ConsideredPaths.end(),
3619
0
                [](cmFindPackageCommand::ConsideredPath const& cp) {
3620
0
                  return cp.Mode >
3621
0
                    cmFindPackageCommand::FoundPackageMode::Module;
3622
0
                });
3623
0
}
3624
3625
void cmFindPackageDebugState::WriteDebug() const
3626
0
{
3627
0
}
3628
3629
#ifndef CMAKE_BOOTSTRAP
3630
void cmFindPackageDebugState::WriteEvent(cmConfigureLog& log,
3631
                                         cmMakefile const& mf) const
3632
0
{
3633
0
  (void)log;
3634
0
  (void)mf;
3635
3636
0
  log.BeginEvent("find_package-v1", mf);
3637
3638
0
  auto const* fpc = this->FindPackageCommand;
3639
3640
0
  log.WriteValue("name"_s, fpc->Name);
3641
0
  if (!fpc->Components.empty()) {
3642
0
    log.BeginObject("components"_s);
3643
0
    log.BeginArray();
3644
0
    for (auto const& component : cmList{ fpc->Components }) {
3645
0
      log.NextArrayElement();
3646
0
      log.WriteValue("name"_s, component);
3647
0
      log.WriteValue("required"_s,
3648
0
                     fpc->RequiredComponents.find(component) !=
3649
0
                       fpc->RequiredComponents.end());
3650
0
      log.WriteValue("found"_s,
3651
0
                     mf.IsOn(cmStrCat(fpc->Name, '_', component, "_FOUND")));
3652
0
    }
3653
0
    log.EndArray();
3654
0
    log.EndObject();
3655
0
  }
3656
0
  if (!fpc->Configs.empty()) {
3657
0
    auto pdt_name =
3658
0
      [](cmFindPackageCommand::PackageDescriptionType type) -> std::string {
3659
0
      switch (type) {
3660
0
        case pdt::Any:
3661
0
          return "any";
3662
0
        case pdt::CMake:
3663
0
          return "cmake";
3664
0
        case pdt::Cps:
3665
0
          return "cps";
3666
0
      }
3667
0
      assert(false);
3668
0
      return "<UNKNOWN>";
3669
0
    };
3670
3671
0
    log.BeginObject("configs"_s);
3672
0
    log.BeginArray();
3673
0
    for (auto const& config : fpc->Configs) {
3674
0
      log.NextArrayElement();
3675
0
      log.WriteValue("filename"_s, config.Name);
3676
0
      log.WriteValue("kind"_s, pdt_name(config.Type));
3677
0
    }
3678
0
    log.EndArray();
3679
0
    log.EndObject();
3680
0
  }
3681
0
  {
3682
0
    log.BeginObject("version_request"_s);
3683
0
    if (!fpc->Version.empty()) {
3684
0
      log.WriteValue("version"_s, fpc->Version);
3685
0
    }
3686
0
    if (!fpc->VersionComplete.empty()) {
3687
0
      log.WriteValue("version_complete"_s, fpc->VersionComplete);
3688
0
    }
3689
0
    if (!fpc->VersionRange.empty()) {
3690
0
      log.WriteValue("min"_s, std::string(fpc->VersionRangeMin));
3691
0
      log.WriteValue("max"_s, std::string(fpc->VersionRangeMax));
3692
0
    }
3693
0
    log.WriteValue("exact"_s, fpc->VersionExact);
3694
0
    log.EndObject();
3695
0
  }
3696
0
  {
3697
0
    auto required_str =
3698
0
      [](cmFindPackageCommand::RequiredStatus status) -> std::string {
3699
0
      switch (status) {
3700
0
        case cmFindPackageCommand::RequiredStatus::Optional:
3701
0
          return "optional";
3702
0
        case cmFindPackageCommand::RequiredStatus::OptionalExplicit:
3703
0
          return "optional_explicit";
3704
0
        case cmFindPackageCommand::RequiredStatus::RequiredExplicit:
3705
0
          return "required_explicit";
3706
0
        case cmFindPackageCommand::RequiredStatus::RequiredFromPackageVar:
3707
0
          return "required_from_package_variable";
3708
0
        case cmFindPackageCommand::RequiredStatus::RequiredFromFindVar:
3709
0
          return "required_from_find_variable";
3710
0
      }
3711
0
      assert(false);
3712
0
      return "<UNKNOWN>";
3713
0
    };
3714
0
    log.BeginObject("settings"_s);
3715
0
    log.WriteValue("required"_s, required_str(fpc->Required));
3716
0
    log.WriteValue("quiet"_s, fpc->Quiet);
3717
0
    log.WriteValue("global"_s, fpc->GlobalScope);
3718
0
    log.WriteValue("policy_scope"_s, fpc->PolicyScope);
3719
0
    log.WriteValue("bypass_provider"_s, fpc->BypassProvider);
3720
0
    if (!fpc->UserHintsArgs.empty()) {
3721
0
      log.WriteValue("hints"_s, fpc->UserHintsArgs);
3722
0
    }
3723
0
    if (!fpc->Names.empty()) {
3724
0
      log.WriteValue("names"_s, fpc->Names);
3725
0
    }
3726
0
    if (!fpc->UserGuessArgs.empty()) {
3727
0
      log.WriteValue("search_paths"_s, fpc->UserGuessArgs);
3728
0
    }
3729
0
    if (!fpc->SearchPathSuffixes.empty()) {
3730
0
      log.WriteValue("path_suffixes"_s, fpc->SearchPathSuffixes);
3731
0
    }
3732
0
    if (fpc->RegistryViewDefined) {
3733
0
      log.WriteValue(
3734
0
        "registry_view"_s,
3735
0
        std::string(cmWindowsRegistry::FromView(fpc->RegistryView)));
3736
0
    }
3737
0
    {
3738
0
      auto find_root_path_mode =
3739
0
        [](cmFindCommon::RootPathMode mode) -> std::string {
3740
0
        switch (mode) {
3741
0
          case cmFindCommon::RootPathModeNever:
3742
0
            return "NEVER";
3743
0
          case cmFindCommon::RootPathModeOnly:
3744
0
            return "ONLY";
3745
0
          case cmFindCommon::RootPathModeBoth:
3746
0
            return "BOTH";
3747
0
        }
3748
0
        assert(false);
3749
0
        return "<UNKNOWN>";
3750
0
      };
3751
0
      log.BeginObject("paths"_s);
3752
0
      log.WriteValue("CMAKE_FIND_USE_CMAKE_PATH"_s, !fpc->NoDefaultPath);
3753
0
      log.WriteValue("CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH"_s,
3754
0
                     !fpc->NoCMakeEnvironmentPath);
3755
0
      log.WriteValue("CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH"_s,
3756
0
                     !fpc->NoSystemEnvironmentPath);
3757
0
      log.WriteValue("CMAKE_FIND_USE_CMAKE_SYSTEM_PATH"_s,
3758
0
                     !fpc->NoCMakeSystemPath);
3759
0
      log.WriteValue("CMAKE_FIND_USE_INSTALL_PREFIX"_s,
3760
0
                     !fpc->NoCMakeInstallPath);
3761
0
      log.WriteValue("CMAKE_FIND_USE_PACKAGE_ROOT_PATH"_s,
3762
0
                     !fpc->NoPackageRootPath);
3763
0
      log.WriteValue("CMAKE_FIND_USE_CMAKE_PACKAGE_REGISTRY"_s,
3764
0
                     !fpc->NoUserRegistry);
3765
0
      log.WriteValue("CMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY"_s,
3766
0
                     !fpc->NoSystemRegistry);
3767
0
      log.WriteValue("CMAKE_FIND_ROOT_PATH_MODE"_s,
3768
0
                     find_root_path_mode(fpc->FindRootPathMode));
3769
0
      log.EndObject();
3770
0
    }
3771
0
    log.EndObject();
3772
0
  }
3773
3774
0
  auto found_mode =
3775
0
    [](cmFindPackageCommand::FoundPackageMode status) -> std::string {
3776
0
    switch (status) {
3777
0
      case cmFindPackageCommand::FoundPackageMode::None:
3778
0
        return "none?";
3779
0
      case cmFindPackageCommand::FoundPackageMode::Module:
3780
0
        return "module";
3781
0
      case cmFindPackageCommand::FoundPackageMode::Config:
3782
0
        return "config";
3783
0
      case cmFindPackageCommand::FoundPackageMode::Cps:
3784
0
        return "cps";
3785
0
      case cmFindPackageCommand::FoundPackageMode::Provider:
3786
0
        return "provider";
3787
0
    }
3788
0
    assert(false);
3789
0
    return "<UNKNOWN>";
3790
0
  };
3791
0
  if (!fpc->ConsideredPaths.empty()) {
3792
0
    auto search_result =
3793
0
      [](cmFindPackageCommand::SearchResult type) -> std::string {
3794
0
      switch (type) {
3795
0
        case cmFindPackageCommand::SearchResult::Acceptable:
3796
0
          return "acceptable";
3797
0
        case cmFindPackageCommand::SearchResult::InsufficientVersion:
3798
0
          return "insufficient_version";
3799
0
        case cmFindPackageCommand::SearchResult::InsufficientComponents:
3800
0
          return "insufficient_components";
3801
0
        case cmFindPackageCommand::SearchResult::Error:
3802
0
          return "error";
3803
0
        case cmFindPackageCommand::SearchResult::NoExist:
3804
0
          return "no_exist";
3805
0
        case cmFindPackageCommand::SearchResult::Ignored:
3806
0
          return "ignored";
3807
0
        case cmFindPackageCommand::SearchResult::NoConfigFile:
3808
0
          return "no_config_file";
3809
0
        case cmFindPackageCommand::SearchResult::NotFound:
3810
0
          return "not_found";
3811
0
      }
3812
0
      assert(false);
3813
0
      return "<UNKNOWN>";
3814
0
    };
3815
3816
0
    log.BeginObject("candidates"_s);
3817
0
    log.BeginArray();
3818
0
    for (auto const& considered : fpc->ConsideredPaths) {
3819
0
      log.NextArrayElement();
3820
0
      log.WriteValue("path"_s, considered.Path);
3821
0
      log.WriteValue("mode"_s, found_mode(considered.Mode));
3822
0
      log.WriteValue("reason"_s, search_result(considered.Reason));
3823
0
      if (!considered.Message.empty()) {
3824
0
        log.WriteValue("message"_s, considered.Message);
3825
0
      }
3826
0
    }
3827
0
    log.EndArray();
3828
0
    log.EndObject();
3829
0
  }
3830
  // TODO: Add provider information (see #26925)
3831
0
  if (!fpc->FileFound.empty()) {
3832
0
    log.BeginObject("found"_s);
3833
0
    log.WriteValue("path"_s, fpc->FileFound);
3834
0
    log.WriteValue("mode"_s, found_mode(fpc->FileFoundMode));
3835
0
    log.WriteValue("version"_s, fpc->VersionFound);
3836
0
    log.EndObject();
3837
0
  } else {
3838
0
    log.WriteValue("found"_s, nullptr);
3839
0
  }
3840
3841
0
  this->WriteSearchVariables(log, mf);
3842
3843
0
  log.EndEvent();
3844
0
}
3845
3846
std::vector<std::pair<cmFindCommonDebugState::VariableSource, std::string>>
3847
cmFindPackageDebugState::ExtraSearchVariables() const
3848
0
{
3849
0
  std::vector<std::pair<cmFindCommonDebugState::VariableSource, std::string>>
3850
0
    extraSearches;
3851
0
  if (this->FindPackageCommand->UseFindModules) {
3852
0
    extraSearches.emplace_back(VariableSource::PathList, "CMAKE_MODULE_PATH");
3853
0
  }
3854
0
  return extraSearches;
3855
0
}
3856
#endif