cmAddExecutableCommand.cxx 3.2 KB

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