cmCheckCustomOutputs.cxx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmCheckCustomOutputs.h"
  4. #include "cmExecutionStatus.h"
  5. #include "cmMakefile.h"
  6. #include "cmStringAlgorithms.h"
  7. #include "cmSystemTools.h"
  8. bool cmCheckCustomOutputs(const std::vector<std::string>& outputs,
  9. cm::string_view keyword, cmExecutionStatus& status)
  10. {
  11. cmMakefile& mf = status.GetMakefile();
  12. for (std::string const& o : outputs) {
  13. // Make sure the file will not be generated into the source
  14. // directory during an out of source build.
  15. if (!mf.CanIWriteThisFile(o)) {
  16. status.SetError(
  17. cmStrCat("attempted to have a file\n ", o,
  18. "\nin a source directory as an output of custom command."));
  19. cmSystemTools::SetFatalErrorOccured();
  20. return false;
  21. }
  22. // Make sure the output file name has no invalid characters.
  23. std::string::size_type pos = o.find_first_of("#<>");
  24. if (pos != std::string::npos) {
  25. status.SetError(cmStrCat("called with ", keyword, " containing a \"",
  26. o[pos], "\". This character is not allowed."));
  27. return false;
  28. }
  29. }
  30. return true;
  31. }