File: cmFindCommon.cxx

package info (click to toggle)
cmake 4.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 147,412 kB
  • sloc: ansic: 403,924; cpp: 290,826; sh: 4,091; python: 3,357; yacc: 3,106; lex: 1,189; f90: 532; asm: 471; lisp: 375; cs: 270; java: 266; fortran: 230; perl: 217; objc: 215; xml: 198; makefile: 98; javascript: 83; pascal: 63; tcl: 55; php: 25; ruby: 22
file content (666 lines) | stat: -rw-r--r-- 20,640 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file LICENSE.rst or https://cmake.org/licensing for details.  */
#include "cmFindCommon.h"

#include <algorithm>
#include <array>
#include <utility>

#include <cmext/algorithm>

#include "cmExecutionStatus.h"
#include "cmList.h"
#include "cmMakefile.h"
#include "cmMessageType.h"
#include "cmPolicies.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
#include "cmValue.h"
#include "cmake.h"

#ifndef CMAKE_BOOTSTRAP
#  include <deque>
#  include <iterator>

#  include <cm/optional>
#  include <cm/string_view>
#  include <cmext/string_view>

#  include "cmConfigureLog.h"
#  include "cmRange.h"
#endif

cmFindCommon::PathGroup cmFindCommon::PathGroup::All("ALL");
cmFindCommon::PathLabel cmFindCommon::PathLabel::PackageRoot(
  "PackageName_ROOT");
cmFindCommon::PathLabel cmFindCommon::PathLabel::CMake("CMAKE");
cmFindCommon::PathLabel cmFindCommon::PathLabel::CMakeEnvironment(
  "CMAKE_ENVIRONMENT");
cmFindCommon::PathLabel cmFindCommon::PathLabel::Hints("HINTS");
cmFindCommon::PathLabel cmFindCommon::PathLabel::SystemEnvironment(
  "SYSTEM_ENVIRONMENT");
cmFindCommon::PathLabel cmFindCommon::PathLabel::CMakeSystem("CMAKE_SYSTEM");
cmFindCommon::PathLabel cmFindCommon::PathLabel::Guess("GUESS");

cmFindCommon::cmFindCommon(cmExecutionStatus& status)
  : Makefile(&status.GetMakefile())
  , Status(status)
{
  this->FindRootPathMode = RootPathModeBoth;
  this->FullDebugMode = false;
  this->NoDefaultPath = false;
  this->NoPackageRootPath = false;
  this->NoCMakePath = false;
  this->NoCMakeEnvironmentPath = false;
  this->NoSystemEnvironmentPath = false;
  this->NoCMakeSystemPath = false;
  this->NoCMakeInstallPath = false;

// OS X Bundle and Framework search policy.  The default is to
// search frameworks first on apple.
#if defined(__APPLE__)
  this->SearchFrameworkFirst = true;
  this->SearchAppBundleFirst = true;
#else
  this->SearchFrameworkFirst = false;
  this->SearchAppBundleFirst = false;
#endif
  this->SearchFrameworkOnly = false;
  this->SearchFrameworkLast = false;
  this->SearchAppBundleOnly = false;
  this->SearchAppBundleLast = false;

  this->InitializeSearchPathGroups();

  // Windows Registry views
  // When policy CMP0134 is not NEW, rely on previous behavior:
  if (this->Makefile->GetPolicyStatus(cmPolicies::CMP0134) !=
      cmPolicies::NEW) {
    if (this->Makefile->GetDefinition("CMAKE_SIZEOF_VOID_P") == "8") {
      this->RegistryView = cmWindowsRegistry::View::Reg64;
    } else {
      this->RegistryView = cmWindowsRegistry::View::Reg32;
    }
  }
}

cmFindCommon::~cmFindCommon() = default;

void cmFindCommon::SetError(std::string const& e)
{
  this->Status.SetError(e);
}

bool cmFindCommon::DebugModeEnabled() const
{
  return this->FullDebugMode;
}

void cmFindCommon::DebugMessage(std::string const& msg) const
{
  if (this->Makefile) {
    this->Makefile->IssueMessage(MessageType::LOG, msg);
  }
}

bool cmFindCommon::ComputeIfDebugModeWanted()
{
  return this->Makefile->GetDebugFindPkgMode() ||
    this->Makefile->IsOn("CMAKE_FIND_DEBUG_MODE") ||
    this->Makefile->GetCMakeInstance()->GetDebugFindOutput();
}

bool cmFindCommon::ComputeIfDebugModeWanted(std::string const& var)
{
  return this->ComputeIfDebugModeWanted() ||
    this->Makefile->GetCMakeInstance()->GetDebugFindOutput(var);
}

bool cmFindCommon::ComputeIfImplicitDebugModeSuppressed()
{
  // XXX(find-events): In the future, mirror the `ComputeIfDebugModeWanted`
  // methods if more control is desired.
  return this->Makefile->IsOn(
    "CMAKE_FIND_DEBUG_MODE_NO_IMPLICIT_CONFIGURE_LOG");
}

void cmFindCommon::InitializeSearchPathGroups()
{
  std::vector<PathLabel>* labels;

  // Define the various different groups of path types

  // All search paths
  labels = &this->PathGroupLabelMap[PathGroup::All];
  labels->push_back(PathLabel::PackageRoot);
  labels->push_back(PathLabel::CMake);
  labels->push_back(PathLabel::CMakeEnvironment);
  labels->push_back(PathLabel::Hints);
  labels->push_back(PathLabel::SystemEnvironment);
  labels->push_back(PathLabel::CMakeSystem);
  labels->push_back(PathLabel::Guess);

  // Define the search group order
  this->PathGroupOrder.push_back(PathGroup::All);

  // Create the individual labeled search paths
  this->LabeledPaths.emplace(PathLabel::PackageRoot, cmSearchPath(this));
  this->LabeledPaths.emplace(PathLabel::CMake, cmSearchPath(this));
  this->LabeledPaths.emplace(PathLabel::CMakeEnvironment, cmSearchPath(this));
  this->LabeledPaths.emplace(PathLabel::Hints, cmSearchPath(this));
  this->LabeledPaths.emplace(PathLabel::SystemEnvironment, cmSearchPath(this));
  this->LabeledPaths.emplace(PathLabel::CMakeSystem, cmSearchPath(this));
  this->LabeledPaths.emplace(PathLabel::Guess, cmSearchPath(this));
}

void cmFindCommon::SelectDefaultRootPathMode()
{
  // Check the policy variable for this find command type.
  std::string findRootPathVar =
    cmStrCat("CMAKE_FIND_ROOT_PATH_MODE_", this->CMakePathName);
  std::string rootPathMode =
    this->Makefile->GetSafeDefinition(findRootPathVar);
  if (rootPathMode == "NEVER") {
    this->FindRootPathMode = RootPathModeNever;
  } else if (rootPathMode == "ONLY") {
    this->FindRootPathMode = RootPathModeOnly;
  } else if (rootPathMode == "BOTH") {
    this->FindRootPathMode = RootPathModeBoth;
  }
}

void cmFindCommon::SelectDefaultMacMode()
{
  std::string ff = this->Makefile->GetSafeDefinition("CMAKE_FIND_FRAMEWORK");
  if (ff == "NEVER") {
    this->SearchFrameworkLast = false;
    this->SearchFrameworkFirst = false;
    this->SearchFrameworkOnly = false;
  } else if (ff == "ONLY") {
    this->SearchFrameworkLast = false;
    this->SearchFrameworkFirst = false;
    this->SearchFrameworkOnly = true;
  } else if (ff == "FIRST") {
    this->SearchFrameworkLast = false;
    this->SearchFrameworkFirst = true;
    this->SearchFrameworkOnly = false;
  } else if (ff == "LAST") {
    this->SearchFrameworkLast = true;
    this->SearchFrameworkFirst = false;
    this->SearchFrameworkOnly = false;
  }

  std::string fab = this->Makefile->GetSafeDefinition("CMAKE_FIND_APPBUNDLE");
  if (fab == "NEVER") {
    this->SearchAppBundleLast = false;
    this->SearchAppBundleFirst = false;
    this->SearchAppBundleOnly = false;
  } else if (fab == "ONLY") {
    this->SearchAppBundleLast = false;
    this->SearchAppBundleFirst = false;
    this->SearchAppBundleOnly = true;
  } else if (fab == "FIRST") {
    this->SearchAppBundleLast = false;
    this->SearchAppBundleFirst = true;
    this->SearchAppBundleOnly = false;
  } else if (fab == "LAST") {
    this->SearchAppBundleLast = true;
    this->SearchAppBundleFirst = false;
    this->SearchAppBundleOnly = false;
  }
}

void cmFindCommon::SelectDefaultSearchModes()
{
  std::array<std::pair<bool&, std::string>, 6> const search_paths = {
    { { this->NoPackageRootPath, "CMAKE_FIND_USE_PACKAGE_ROOT_PATH" },
      { this->NoCMakePath, "CMAKE_FIND_USE_CMAKE_PATH" },
      { this->NoCMakeEnvironmentPath,
        "CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH" },
      { this->NoSystemEnvironmentPath,
        "CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH" },
      { this->NoCMakeSystemPath, "CMAKE_FIND_USE_CMAKE_SYSTEM_PATH" },
      { this->NoCMakeInstallPath, "CMAKE_FIND_USE_INSTALL_PREFIX" } }
  };

  for (auto const& path : search_paths) {
    cmValue def = this->Makefile->GetDefinition(path.second);
    if (def) {
      path.first = !def.IsOn();
    }
  }
}

void cmFindCommon::RerootPaths(std::vector<std::string>& paths,
                               std::string* debugBuffer)
{
  // Short-circuit if there is nothing to do.
  if (this->FindRootPathMode == RootPathModeNever) {
    return;
  }

  cmValue sysroot = this->Makefile->GetDefinition("CMAKE_SYSROOT");
  cmValue sysrootCompile =
    this->Makefile->GetDefinition("CMAKE_SYSROOT_COMPILE");
  cmValue sysrootLink = this->Makefile->GetDefinition("CMAKE_SYSROOT_LINK");
  cmValue rootPath = this->Makefile->GetDefinition("CMAKE_FIND_ROOT_PATH");
  bool const noSysroot = !cmNonempty(sysroot);
  bool const noCompileSysroot = !cmNonempty(sysrootCompile);
  bool const noLinkSysroot = !cmNonempty(sysrootLink);
  bool const noRootPath = !cmNonempty(rootPath);
  if (noSysroot && noCompileSysroot && noLinkSysroot && noRootPath) {
    return;
  }

  if (this->DebugModeEnabled() && debugBuffer) {
    *debugBuffer = cmStrCat(
      *debugBuffer, "Prepending the following roots to each prefix:\n");
  }

  auto debugRoot = [this, debugBuffer](std::string const& name,
                                       cmValue value) {
    if (this->DebugModeEnabled() && debugBuffer) {
      *debugBuffer = cmStrCat(*debugBuffer, name, '\n');
      cmList roots{ value };
      if (roots.empty()) {
        *debugBuffer = cmStrCat(*debugBuffer, "  none\n");
      }
      for (auto const& root : roots) {
        *debugBuffer = cmStrCat(*debugBuffer, "  ", root, '\n');
      }
    }
  };

  // Construct the list of path roots with no trailing slashes.
  cmList roots;
  debugRoot("CMAKE_FIND_ROOT_PATH", rootPath);
  if (cmNonempty(rootPath)) {
    roots.assign(*rootPath);
  }
  debugRoot("CMAKE_SYSROOT_COMPILE", sysrootCompile);
  if (cmNonempty(sysrootCompile)) {
    roots.emplace_back(*sysrootCompile);
  }
  debugRoot("CMAKE_SYSROOT_LINK", sysrootLink);
  if (cmNonempty(sysrootLink)) {
    roots.emplace_back(*sysrootLink);
  }
  debugRoot("CMAKE_SYSROOT", sysroot);
  if (cmNonempty(sysroot)) {
    roots.emplace_back(*sysroot);
  }
  for (auto& r : roots) {
    cmSystemTools::ConvertToUnixSlashes(r);
  }

  cmValue stagePrefix = this->Makefile->GetDefinition("CMAKE_STAGING_PREFIX");

  // Copy the original set of unrooted paths.
  auto unrootedPaths = paths;
  paths.clear();

  auto isSameDirectoryOrSubDirectory = [](std::string const& l,
                                          std::string const& r) {
    return (cmSystemTools::GetRealPath(l) == cmSystemTools::GetRealPath(r)) ||
      cmSystemTools::IsSubDirectory(l, r);
  };

  for (auto const& r : roots) {
    for (auto const& up : unrootedPaths) {
      // Place the unrooted path under the current root if it is not
      // already inside.  Skip the unrooted path if it is relative to
      // a user home directory or is empty.
      std::string rootedDir;
      if (isSameDirectoryOrSubDirectory(up, r) ||
          (stagePrefix && isSameDirectoryOrSubDirectory(up, *stagePrefix))) {
        rootedDir = up;
      } else if (!up.empty() && up[0] != '~') {
        auto const* split = cmSystemTools::SplitPathRootComponent(up);
        if (split && *split) {
          // Start with the new root.
          rootedDir = cmStrCat(r, '/', split);
        } else {
          rootedDir = r;
        }
      }

      // Store the new path.
      paths.push_back(rootedDir);
    }
  }

  // If searching both rooted and unrooted paths add the original
  // paths again.
  if (this->FindRootPathMode == RootPathModeBoth) {
    cm::append(paths, unrootedPaths);
  }
}

void cmFindCommon::GetIgnoredPaths(std::vector<std::string>& ignore)
{
  std::array<char const*, 2> const paths = { { "CMAKE_SYSTEM_IGNORE_PATH",
                                               "CMAKE_IGNORE_PATH" } };

  // Construct the list of path roots with no trailing slashes.
  for (char const* pathName : paths) {
    // Get the list of paths to ignore from the variable.
    cmList::append(ignore, this->Makefile->GetDefinition(pathName));
  }

  for (std::string& i : ignore) {
    cmSystemTools::ConvertToUnixSlashes(i);
  }
}

void cmFindCommon::GetIgnoredPaths(std::set<std::string>& ignore)
{
  std::vector<std::string> ignoreVec;
  this->GetIgnoredPaths(ignoreVec);
  ignore.insert(ignoreVec.begin(), ignoreVec.end());
}

void cmFindCommon::GetIgnoredPrefixPaths(std::vector<std::string>& ignore)
{
  std::array<char const*, 2> const paths = {
    { "CMAKE_SYSTEM_IGNORE_PREFIX_PATH", "CMAKE_IGNORE_PREFIX_PATH" }
  };
  // Construct the list of path roots with no trailing slashes.
  for (char const* pathName : paths) {
    // Get the list of paths to ignore from the variable.
    cmList::append(ignore, this->Makefile->GetDefinition(pathName));
  }

  for (std::string& i : ignore) {
    cmSystemTools::ConvertToUnixSlashes(i);
  }
}

void cmFindCommon::GetIgnoredPrefixPaths(std::set<std::string>& ignore)
{
  std::vector<std::string> ignoreVec;
  this->GetIgnoredPrefixPaths(ignoreVec);
  ignore.insert(ignoreVec.begin(), ignoreVec.end());
}

bool cmFindCommon::CheckCommonArgument(std::string const& arg)
{
  if (arg == "NO_DEFAULT_PATH") {
    this->NoDefaultPath = true;
    return true;
  }
  if (arg == "NO_PACKAGE_ROOT_PATH") {
    this->NoPackageRootPath = true;
    return true;
  }
  if (arg == "NO_CMAKE_PATH") {
    this->NoCMakePath = true;
    return true;
  }
  if (arg == "NO_CMAKE_ENVIRONMENT_PATH") {
    this->NoCMakeEnvironmentPath = true;
    return true;
  }
  if (arg == "NO_SYSTEM_ENVIRONMENT_PATH") {
    this->NoSystemEnvironmentPath = true;
    return true;
  }
  if (arg == "NO_CMAKE_SYSTEM_PATH") {
    this->NoCMakeSystemPath = true;
    return true;
  }
  if (arg == "NO_CMAKE_INSTALL_PREFIX") {
    this->NoCMakeInstallPath = true;
    return true;
  }
  if (arg == "NO_CMAKE_FIND_ROOT_PATH") {
    this->FindRootPathMode = RootPathModeNever;
    return true;
  }
  if (arg == "ONLY_CMAKE_FIND_ROOT_PATH") {
    this->FindRootPathMode = RootPathModeOnly;
    return true;
  }
  if (arg == "CMAKE_FIND_ROOT_PATH_BOTH") {
    this->FindRootPathMode = RootPathModeBoth;
    return true;
  }
  // The argument is not one of the above.
  return false;
}

void cmFindCommon::AddPathSuffix(std::string const& arg)
{
  std::string suffix = arg;

  // Strip leading and trailing slashes.
  if (suffix.empty()) {
    return;
  }
  if (suffix.front() == '/') {
    suffix = suffix.substr(1);
  }
  if (suffix.empty()) {
    return;
  }
  if (suffix.back() == '/') {
    suffix = suffix.substr(0, suffix.size() - 1);
  }
  if (suffix.empty()) {
    return;
  }

  // Store the suffix.
  this->SearchPathSuffixes.push_back(std::move(suffix));
}

void cmFindCommon::ComputeFinalPaths(IgnorePaths ignorePaths,
                                     std::string* debugBuffer)
{
  // Filter out ignored paths from the prefix list
  std::set<std::string> ignoredPaths;
  std::set<std::string> ignoredPrefixes;
  if (ignorePaths == IgnorePaths::Yes) {
    this->GetIgnoredPaths(ignoredPaths);
    this->GetIgnoredPrefixPaths(ignoredPrefixes);
  }

  // Combine the separate path types, filtering out ignores
  this->SearchPaths.clear();
  std::vector<PathLabel>& allLabels = this->PathGroupLabelMap[PathGroup::All];
  for (PathLabel const& l : allLabels) {
    this->LabeledPaths[l].ExtractWithout(ignoredPaths, ignoredPrefixes,
                                         this->SearchPaths);
  }

  // Expand list of paths inside all search roots.
  this->RerootPaths(this->SearchPaths, debugBuffer);

  // Add a trailing slash to all paths to aid the search process.
  std::for_each(this->SearchPaths.begin(), this->SearchPaths.end(),
                [](std::string& s) {
                  if (!s.empty() && s.back() != '/') {
                    s += '/';
                  }
                });
}

cmFindCommonDebugState::cmFindCommonDebugState(std::string name,
                                               cmFindCommon const* findCommand)
  : FindCommand(findCommand)
  , CommandName(std::move(name))
  // Strip the `find_` prefix.
  , Mode(this->CommandName.substr(5))
{
}

void cmFindCommonDebugState::FoundAt(std::string const& path,
                                     std::string regexName)
{
  this->IsFound = true;

  if (!this->TrackSearchProgress()) {
    return;
  }

  this->FoundAtImpl(path, regexName);
}

void cmFindCommonDebugState::FailedAt(std::string const& path,
                                      std::string regexName)
{
  if (!this->TrackSearchProgress()) {
    return;
  }

  this->FailedAtImpl(path, regexName);
}

bool cmFindCommonDebugState::ShouldImplicitlyLogEvents() const
{
  return true;
}

void cmFindCommonDebugState::Write()
{
  auto const* const fc = this->FindCommand;

#ifndef CMAKE_BOOTSTRAP
  // Write find event to the configure log if the log exists
  if (cmConfigureLog* log =
        fc->Makefile->GetCMakeInstance()->GetConfigureLog()) {
    // Write event if any of:
    //   - debug mode is enabled
    //   - implicit logging should happen and:
    //     - the variable was not defined (first run)
    //     - the variable found state does not match the new found state (state
    //       transition)
    if (fc->DebugModeEnabled() ||
        (this->ShouldImplicitlyLogEvents() &&
         (!fc->IsDefined() || fc->IsFound() != this->IsFound))) {
      this->WriteEvent(*log, *fc->Makefile);
    }
  }
#endif

  if (fc->DebugModeEnabled()) {
    this->WriteDebug();
  }
}

#ifndef CMAKE_BOOTSTRAP
void cmFindCommonDebugState::WriteSearchVariables(cmConfigureLog& log,
                                                  cmMakefile const& mf) const
{
  auto WriteString = [&log, &mf](std::string const& name) {
    if (cmValue value = mf.GetDefinition(name)) {
      log.WriteValue(name, *value);
    }
  };
  auto WriteCMakeList = [&log, &mf](std::string const& name) {
    if (cmValue value = mf.GetDefinition(name)) {
      cmList values{ *value };
      if (!values.empty()) {
        log.WriteValue(name, values);
      }
    }
  };
  auto WriteEnvList = [&log](std::string const& name) {
    if (auto value = cmSystemTools::GetEnvVar(name)) {
      auto values = cmSystemTools::SplitEnvPath(*value);
      if (!values.empty()) {
        log.WriteValue(cmStrCat("ENV{", name, '}'), values);
      }
    }
  };

  auto const* fc = this->FindCommand;
  log.BeginObject("search_context"_s);
  auto const& packageRootStack = mf.FindPackageRootPathStack;
  if (!packageRootStack.empty()) {
    bool havePaths =
      std::any_of(packageRootStack.begin(), packageRootStack.end(),
                  [](std::vector<std::string> const& entry) -> bool {
                    return !entry.empty();
                  });
    if (havePaths) {
      log.BeginObject("package_stack");
      log.BeginArray();
      for (auto const& pkgPaths : cmReverseRange(packageRootStack)) {
        if (!pkgPaths.empty()) {
          log.NextArrayElement();
          log.WriteValue("package_paths", pkgPaths);
        }
      }
      log.EndArray();
      log.EndObject();
    }
  }
  auto cmakePathVar = cmStrCat("CMAKE_", fc->CMakePathName, "_PATH");
  WriteCMakeList(cmakePathVar);
  WriteCMakeList("CMAKE_PREFIX_PATH");
  if (fc->CMakePathName == "PROGRAM"_s) {
    WriteCMakeList("CMAKE_APPBUNDLE_PATH");
  } else {
    WriteCMakeList("CMAKE_FRAMEWORK_PATH");
  }
  // Same as above, but ask the environment instead.
  WriteEnvList(cmakePathVar);
  WriteEnvList("CMAKE_PREFIX_PATH");
  if (fc->CMakePathName == "PROGRAM"_s) {
    WriteEnvList("CMAKE_APPBUNDLE_PATH");
  } else {
    WriteEnvList("CMAKE_FRAMEWORK_PATH");
  }
  WriteEnvList("PATH");
  WriteString("CMAKE_INSTALL_PREFIX");
  WriteString("CMAKE_STAGING_PREFIX");
  WriteCMakeList("CMAKE_SYSTEM_PREFIX_PATH");
  auto systemPathVar = cmStrCat("CMAKE_SYSTEM_", fc->CMakePathName, "_PATH");
  WriteCMakeList(systemPathVar);
  // Sysroot paths.
  WriteString("CMAKE_SYSROOT");
  WriteString("CMAKE_SYSROOT_COMPILE");
  WriteString("CMAKE_SYSROOT_LINK");
  WriteString("CMAKE_FIND_ROOT_PATH");
  // Write out paths which are ignored.
  WriteCMakeList("CMAKE_IGNORE_PATH");
  WriteCMakeList("CMAKE_IGNORE_PREFIX_PATH");
  WriteCMakeList("CMAKE_SYSTEM_IGNORE_PATH");
  WriteCMakeList("CMAKE_SYSTEM_IGNORE_PREFIX_PATH");
  if (fc->CMakePathName == "PROGRAM"_s) {
    WriteCMakeList("CMAKE_SYSTEM_APPBUNDLE_PATH");
  } else {
    WriteCMakeList("CMAKE_SYSTEM_FRAMEWORK_PATH");
  }
  for (auto const& extraVar : this->ExtraSearchVariables()) {
    switch (extraVar.first) {
      case VariableSource::String:
        WriteString(extraVar.second);
        break;
      case VariableSource::PathList:
        WriteCMakeList(extraVar.second);
        break;
      case VariableSource::EnvironmentList:
        WriteEnvList(extraVar.second);
        break;
    }
  }
  log.EndObject();
}

std::vector<std::pair<cmFindCommonDebugState::VariableSource, std::string>>
cmFindCommonDebugState::ExtraSearchVariables() const
{
  return {};
}
#endif

bool cmFindCommonDebugState::TrackSearchProgress() const
{
  // Track search progress if debugging or logging the configure.
  return this->FindCommand->DebugModeEnabled()
#ifndef CMAKE_BOOTSTRAP
    || this->FindCommand->Makefile->GetCMakeInstance()->GetConfigureLog()
#endif
    ;
}