cmAddExecutableCommand.cxx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  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 "cmAddExecutableCommand.h"
  11. #include "cmQtAutomoc.h"
  12. // cmExecutableCommand
  13. bool cmAddExecutableCommand
  14. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  15. {
  16. if(args.size() < 2 )
  17. {
  18. this->SetError("called with incorrect number of arguments");
  19. return false;
  20. }
  21. std::vector<std::string>::const_iterator s = args.begin();
  22. std::string exename = *s;
  23. ++s;
  24. bool use_win32 = false;
  25. bool use_macbundle = false;
  26. bool excludeFromAll = false;
  27. bool importTarget = false;
  28. bool doAutomoc = false;
  29. while ( s != args.end() )
  30. {
  31. if (*s == "WIN32")
  32. {
  33. ++s;
  34. use_win32 = true;
  35. }
  36. else if ( *s == "MACOSX_BUNDLE" )
  37. {
  38. ++s;
  39. use_macbundle = true;
  40. }
  41. else if ( *s == "AUTOMOC" )
  42. {
  43. ++s;
  44. doAutomoc = true;
  45. }
  46. else if(*s == "EXCLUDE_FROM_ALL")
  47. {
  48. ++s;
  49. excludeFromAll = true;
  50. }
  51. else if(*s == "IMPORTED")
  52. {
  53. ++s;
  54. importTarget = true;
  55. }
  56. else
  57. {
  58. break;
  59. }
  60. }
  61. // Special modifiers are not allowed with IMPORTED signature.
  62. if(importTarget
  63. && (use_win32 || use_macbundle || excludeFromAll || doAutomoc))
  64. {
  65. if(use_win32)
  66. {
  67. this->SetError("may not be given WIN32 for an IMPORTED target.");
  68. }
  69. else if(doAutomoc)
  70. {
  71. this->SetError(
  72. "may not be given AUTOMOC for an IMPORTED target.");
  73. }
  74. else if(use_macbundle)
  75. {
  76. this->SetError(
  77. "may not be given MACOSX_BUNDLE for an IMPORTED target.");
  78. }
  79. else // if(excludeFromAll)
  80. {
  81. this->SetError(
  82. "may not be given EXCLUDE_FROM_ALL for an IMPORTED target.");
  83. }
  84. return false;
  85. }
  86. // Handle imported target creation.
  87. if(importTarget)
  88. {
  89. // Make sure the target does not already exist.
  90. if(this->Makefile->FindTargetToUse(exename.c_str()))
  91. {
  92. cmOStringStream e;
  93. e << "cannot create imported target \"" << exename
  94. << "\" because another target with the same name already exists.";
  95. this->SetError(e.str().c_str());
  96. return false;
  97. }
  98. // Create the imported target.
  99. this->Makefile->AddImportedTarget(exename.c_str(), cmTarget::EXECUTABLE);
  100. return true;
  101. }
  102. // Enforce name uniqueness.
  103. {
  104. std::string msg;
  105. if(!this->Makefile->EnforceUniqueName(exename, msg))
  106. {
  107. this->SetError(msg.c_str());
  108. return false;
  109. }
  110. }
  111. if (s == args.end())
  112. {
  113. this->SetError
  114. ("called with incorrect number of arguments, no sources provided");
  115. return false;
  116. }
  117. std::vector<std::string> srclists(s, args.end());
  118. cmTarget* tgt = this->Makefile->AddExecutable(exename.c_str(), srclists,
  119. excludeFromAll);
  120. if ( use_win32 )
  121. {
  122. tgt->SetProperty("WIN32_EXECUTABLE", "ON");
  123. }
  124. if ( use_macbundle)
  125. {
  126. tgt->SetProperty("MACOSX_BUNDLE", "ON");
  127. }
  128. if ( doAutomoc )
  129. {
  130. cmQtAutomoc automoc;
  131. automoc.SetupAutomocTarget(tgt);
  132. }
  133. return true;
  134. }