cmTargetCompileDefinitionsCommand.cxx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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::HandleImportedTarget(
  16. const std::string& tgt)
  17. {
  18. std::ostringstream e;
  19. e << "Cannot specify compile definitions for imported target \"" << tgt
  20. << "\".";
  21. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  22. }
  23. void cmTargetCompileDefinitionsCommand::HandleMissingTarget(
  24. const std::string& name)
  25. {
  26. std::ostringstream e;
  27. e << "Cannot specify compile definitions for target \"" << name
  28. << "\" "
  29. "which is not built by this project.";
  30. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  31. }
  32. std::string cmTargetCompileDefinitionsCommand::Join(
  33. const std::vector<std::string>& content)
  34. {
  35. std::string defs;
  36. std::string sep;
  37. for (std::vector<std::string>::const_iterator it = content.begin();
  38. it != content.end(); ++it) {
  39. if (cmHasLiteralPrefix(it->c_str(), "-D")) {
  40. defs += sep + it->substr(2);
  41. } else {
  42. defs += sep + *it;
  43. }
  44. sep = ";";
  45. }
  46. return defs;
  47. }
  48. bool cmTargetCompileDefinitionsCommand::HandleDirectContent(
  49. cmTarget* tgt, const std::vector<std::string>& content, bool, bool)
  50. {
  51. tgt->AppendProperty("COMPILE_DEFINITIONS", this->Join(content).c_str());
  52. return true;
  53. }