cmTargetCompileFeaturesCommand.cxx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 "cmTargetCompileFeaturesCommand.h"
  4. #include "cmList.h"
  5. #include "cmMakefile.h"
  6. #include "cmMessageType.h"
  7. #include "cmStandardLevelResolver.h"
  8. #include "cmStringAlgorithms.h"
  9. #include "cmTargetPropCommandBase.h"
  10. class cmTarget;
  11. namespace {
  12. class TargetCompileFeaturesImpl : public cmTargetPropCommandBase
  13. {
  14. public:
  15. using cmTargetPropCommandBase::cmTargetPropCommandBase;
  16. private:
  17. void HandleMissingTarget(const std::string& name) override
  18. {
  19. this->Makefile->IssueMessage(
  20. MessageType::FATAL_ERROR,
  21. cmStrCat("Cannot specify compile features for target \"", name,
  22. "\" which is not built by this project."));
  23. }
  24. bool HandleDirectContent(cmTarget* tgt,
  25. const std::vector<std::string>& content,
  26. bool /*prepend*/, bool /*system*/) override
  27. {
  28. cmStandardLevelResolver standardResolver(this->Makefile);
  29. for (std::string const& it : content) {
  30. std::string error;
  31. if (!standardResolver.AddRequiredTargetFeature(tgt, it, &error)) {
  32. this->SetError(error);
  33. return false; // Not (successfully) handled.
  34. }
  35. }
  36. return true; // Successfully handled.
  37. }
  38. std::string Join(const std::vector<std::string>& content) override
  39. {
  40. return cmList::to_string(content);
  41. }
  42. };
  43. } // namespace
  44. bool cmTargetCompileFeaturesCommand(std::vector<std::string> const& args,
  45. cmExecutionStatus& status)
  46. {
  47. return TargetCompileFeaturesImpl(status).HandleArguments(args,
  48. "COMPILE_FEATURES");
  49. }