cmTargetCompileFeaturesCommand.cxx 1.7 KB

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