cmAddExecutableCommand.cxx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmAddExecutableCommand.h"
  14. // cmExecutableCommand
  15. bool cmAddExecutableCommand
  16. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  17. {
  18. if(args.size() < 2 )
  19. {
  20. this->SetError("called with incorrect number of arguments");
  21. return false;
  22. }
  23. std::vector<std::string>::const_iterator s = args.begin();
  24. std::string exename = *s;
  25. ++s;
  26. bool use_win32 = false;
  27. bool use_macbundle = false;
  28. bool excludeFromAll = false;
  29. bool importTarget = false;
  30. while ( s != args.end() )
  31. {
  32. if (*s == "WIN32")
  33. {
  34. ++s;
  35. use_win32 = true;
  36. }
  37. else if ( *s == "MACOSX_BUNDLE" )
  38. {
  39. ++s;
  40. use_macbundle = true;
  41. }
  42. else if(*s == "EXCLUDE_FROM_ALL")
  43. {
  44. ++s;
  45. excludeFromAll = true;
  46. }
  47. else if(*s == "IMPORTED")
  48. {
  49. ++s;
  50. importTarget = true;
  51. }
  52. else
  53. {
  54. break;
  55. }
  56. }
  57. // Special modifiers are not allowed with IMPORTED signature.
  58. if(importTarget && (use_win32 || use_macbundle || excludeFromAll))
  59. {
  60. if(use_win32)
  61. {
  62. this->SetError("may not be given WIN32 for an IMPORTED target.");
  63. }
  64. else if(use_macbundle)
  65. {
  66. this->SetError(
  67. "may not be given MACOSX_BUNDLE for an IMPORTED target.");
  68. }
  69. else // if(excludeFromAll)
  70. {
  71. this->SetError(
  72. "may not be given EXCLUDE_FROM_ALL for an IMPORTED target.");
  73. }
  74. return false;
  75. }
  76. // Check for an existing target with this name.
  77. cmTarget* existing = this->Makefile->FindTargetToUse(exename.c_str());
  78. if(importTarget)
  79. {
  80. // Make sure the target does not already exist.
  81. if(existing)
  82. {
  83. cmOStringStream e;
  84. e << "cannot create imported target \"" << exename
  85. << "\" because another target with the same name already exists.";
  86. this->SetError(e.str().c_str());
  87. return false;
  88. }
  89. // Create the imported target.
  90. this->Makefile->AddImportedTarget(exename.c_str(), cmTarget::EXECUTABLE);
  91. return true;
  92. }
  93. else
  94. {
  95. // Make sure the target does not conflict with an imported target.
  96. // This should really enforce global name uniqueness for targets
  97. // built within the project too, but that may break compatiblity
  98. // with projects in which it was accidentally working.
  99. if(existing && existing->IsImported())
  100. {
  101. cmOStringStream e;
  102. e << "cannot create target \"" << exename
  103. << "\" because an imported target with the same name already exists.";
  104. this->SetError(e.str().c_str());
  105. return false;
  106. }
  107. }
  108. if (s == args.end())
  109. {
  110. this->SetError
  111. ("called with incorrect number of arguments, no sources provided");
  112. return false;
  113. }
  114. std::vector<std::string> srclists(s, args.end());
  115. cmTarget* tgt = this->Makefile->AddExecutable(exename.c_str(), srclists,
  116. excludeFromAll);
  117. if ( use_win32 )
  118. {
  119. tgt->SetProperty("WIN32_EXECUTABLE", "ON");
  120. }
  121. if ( use_macbundle)
  122. {
  123. tgt->SetProperty("MACOSX_BUNDLE", "ON");
  124. }
  125. return true;
  126. }