MCPcopy Create free account
hub / github.com/Kitware/CMake / IncludeByVariable

Function IncludeByVariable

Source/cmProjectCommand.cxx:330–386  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

328
329namespace {
330bool IncludeByVariable(cmExecutionStatus& status, std::string const& variable)
331{
332 cmMakefile& mf = status.GetMakefile();
333 cmValue include = mf.GetDefinition(variable);
334 if (!include) {
335 return true;
336 }
337 cmList includeFiles{ *include };
338
339 bool failed = false;
340 for (auto filePath : includeFiles) {
341 // Any relative path without a .cmake extension is checked for valid cmake
342 // modules. This logic should be consistent with CMake's include() command.
343 // Otherwise default to checking relative path w.r.t. source directory
344 if (!cmSystemTools::FileIsFullPath(filePath) &&
345 !cmHasLiteralSuffix(filePath, ".cmake")) {
346 std::string mfile = mf.GetModulesFile(cmStrCat(filePath, ".cmake"));
347 if (mfile.empty()) {
348 status.SetError(
349 cmStrCat("could not find requested module:\n ", filePath));
350 failed = true;
351 continue;
352 }
353 filePath = mfile;
354 }
355 std::string includeFile = cmSystemTools::CollapseFullPath(
356 filePath, mf.GetCurrentSourceDirectory());
357 if (!cmSystemTools::FileExists(includeFile)) {
358 status.SetError(
359 cmStrCat("could not find requested file:\n ", filePath));
360 failed = true;
361 continue;
362 }
363 if (cmSystemTools::FileIsDirectory(includeFile)) {
364 status.SetError(
365 cmStrCat("requested file is a directory:\n ", filePath));
366 failed = true;
367 continue;
368 }
369
370 bool const readit = mf.ReadDependentFile(filePath);
371 if (readit) {
372 // If the included file ran successfully, continue to the next file
373 continue;
374 }
375
376 if (cmSystemTools::GetFatalErrorOccurred()) {
377 failed = true;
378 continue;
379 }
380
381 status.SetError(cmStrCat("could not load requested file:\n ", filePath));
382 failed = true;
383 }
384 // At this point all files were processed
385 return !failed;
386}
387

Callers 1

cmProjectCommandFunction · 0.85

Calls 9

cmHasLiteralSuffixFunction · 0.85
ReadDependentFileMethod · 0.80
cmStrCatFunction · 0.70
FileExistsFunction · 0.50
GetMakefileMethod · 0.45
GetDefinitionMethod · 0.45
GetModulesFileMethod · 0.45
emptyMethod · 0.45
SetErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…