cmTargetCompileDefinitionsCommand.cxx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #include "cmMakefileIncludeDirectoriesEntry.h"
  12. bool cmTargetCompileDefinitionsCommand
  13. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  14. {
  15. return this->HandleArguments(args, "COMPILE_DEFINITIONS");
  16. }
  17. void cmTargetCompileDefinitionsCommand
  18. ::HandleImportedTarget(const std::string &tgt)
  19. {
  20. cmOStringStream e;
  21. e << "Cannot specify compile definitions for imported target \""
  22. << tgt << "\".";
  23. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  24. }
  25. void cmTargetCompileDefinitionsCommand
  26. ::HandleMissingTarget(const std::string &name)
  27. {
  28. cmOStringStream e;
  29. e << "Cannot specify compile definitions for target \"" << name << "\" "
  30. "which is not built by this project.";
  31. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  32. }
  33. //----------------------------------------------------------------------------
  34. std::string cmTargetCompileDefinitionsCommand
  35. ::Join(const std::vector<std::string> &content)
  36. {
  37. std::string defs;
  38. std::string sep;
  39. for(std::vector<std::string>::const_iterator it = content.begin();
  40. it != content.end(); ++it)
  41. {
  42. if (strncmp(it->c_str(), "-D", 2) == 0)
  43. {
  44. defs += sep + it->substr(2);
  45. }
  46. else
  47. {
  48. defs += sep + *it;
  49. }
  50. sep = ";";
  51. }
  52. return defs;
  53. }
  54. //----------------------------------------------------------------------------
  55. void cmTargetCompileDefinitionsCommand
  56. ::HandleDirectContent(cmTarget *tgt, const std::vector<std::string> &content,
  57. bool)
  58. {
  59. tgt->AppendProperty("COMPILE_DEFINITIONS", this->Join(content).c_str());
  60. }