Coverage Report

Created: 2026-07-14 07:09

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