cmTargetCompileDefinitionsCommand.cxx 1.4 KB

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