cmAddExecutableCommand.cxx 3.4 KB

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