cmTargetCompileDefinitionsCommand.cxx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2013 Stephen Kelly <[email protected]>
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmTargetCompileDefinitionsCommand.h"
  11. bool cmTargetCompileDefinitionsCommand
  12. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  13. {
  14. return this->HandleArguments(args, "COMPILE_DEFINITIONS");
  15. }
  16. void cmTargetCompileDefinitionsCommand
  17. ::HandleImportedTarget(const std::string &tgt)
  18. {
  19. cmOStringStream e;
  20. e << "Cannot specify compile definitions for imported target \""
  21. << tgt << "\".";
  22. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  23. }
  24. void cmTargetCompileDefinitionsCommand
  25. ::HandleMissingTarget(const std::string &name)
  26. {
  27. cmOStringStream e;
  28. e << "Cannot specify compile definitions for target \"" << name << "\" "
  29. "which is not built by this project.";
  30. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  31. }
  32. //----------------------------------------------------------------------------
  33. std::string cmTargetCompileDefinitionsCommand
  34. ::Join(const std::vector<std::string> &content)
  35. {
  36. std::string defs;
  37. std::string sep;
  38. for(std::vector<std::string>::const_iterator it = content.begin();
  39. it != content.end(); ++it)
  40. {
  41. if (strncmp(it->c_str(), "-D", 2) == 0)
  42. {
  43. defs += sep + it->substr(2);
  44. }
  45. else
  46. {
  47. defs += sep + *it;
  48. }
  49. sep = ";";
  50. }
  51. return defs;
  52. }
  53. //----------------------------------------------------------------------------
  54. void cmTargetCompileDefinitionsCommand
  55. ::HandleDirectContent(cmTarget *tgt, const std::vector<std::string> &content,
  56. bool, bool)
  57. {
  58. tgt->AppendProperty("COMPILE_DEFINITIONS", this->Join(content).c_str());
  59. }