cmTargetCompileDefinitionsCommand.cxx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 "cmTargetCompileDefinitionsCommand.h"
  4. #include "cmMakefile.h"
  5. #include "cmMessageType.h"
  6. #include "cmStringAlgorithms.h"
  7. #include "cmTarget.h"
  8. class cmExecutionStatus;
  9. bool cmTargetCompileDefinitionsCommand::InitialPass(
  10. std::vector<std::string> const& args, cmExecutionStatus&)
  11. {
  12. return this->HandleArguments(args, "COMPILE_DEFINITIONS");
  13. }
  14. void cmTargetCompileDefinitionsCommand::HandleMissingTarget(
  15. const std::string& name)
  16. {
  17. this->Makefile->IssueMessage(
  18. MessageType::FATAL_ERROR,
  19. cmStrCat("Cannot specify compile definitions for target \"", name,
  20. "\" which is not built by this project."));
  21. }
  22. std::string cmTargetCompileDefinitionsCommand::Join(
  23. const std::vector<std::string>& content)
  24. {
  25. std::string defs;
  26. std::string sep;
  27. for (std::string const& it : content) {
  28. if (cmHasLiteralPrefix(it, "-D")) {
  29. defs += sep + it.substr(2);
  30. } else {
  31. defs += sep + it;
  32. }
  33. sep = ";";
  34. }
  35. return defs;
  36. }
  37. bool cmTargetCompileDefinitionsCommand::HandleDirectContent(
  38. cmTarget* tgt, const std::vector<std::string>& content, bool, bool)
  39. {
  40. tgt->AppendProperty("COMPILE_DEFINITIONS", this->Join(content).c_str());
  41. return true; // Successfully handled.
  42. }