cmAddExecutableCommand.cxx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 && (use_win32 || use_macbundle || excludeFromAll))
  56. {
  57. if(use_win32)
  58. {
  59. this->SetError("may not be given WIN32 for an IMPORTED target.");
  60. }
  61. else if(use_macbundle)
  62. {
  63. this->SetError(
  64. "may not be given MACOSX_BUNDLE for an IMPORTED target.");
  65. }
  66. else // if(excludeFromAll)
  67. {
  68. this->SetError(
  69. "may not be given EXCLUDE_FROM_ALL for an IMPORTED target.");
  70. }
  71. return false;
  72. }
  73. // Handle imported target creation.
  74. if(importTarget)
  75. {
  76. // Make sure the target does not already exist.
  77. if(this->Makefile->FindTargetToUse(exename.c_str()))
  78. {
  79. cmOStringStream e;
  80. e << "cannot create imported target \"" << exename
  81. << "\" because another target with the same name already exists.";
  82. this->SetError(e.str().c_str());
  83. return false;
  84. }
  85. // Create the imported target.
  86. this->Makefile->AddImportedTarget(exename.c_str(), cmTarget::EXECUTABLE);
  87. return true;
  88. }
  89. // Enforce name uniqueness.
  90. {
  91. std::string msg;
  92. if(!this->Makefile->EnforceUniqueName(exename, msg))
  93. {
  94. this->SetError(msg.c_str());
  95. return false;
  96. }
  97. }
  98. if (s == args.end())
  99. {
  100. this->SetError
  101. ("called with incorrect number of arguments, no sources provided");
  102. return false;
  103. }
  104. std::vector<std::string> srclists(s, args.end());
  105. cmTarget* tgt = this->Makefile->AddExecutable(exename.c_str(), srclists,
  106. excludeFromAll);
  107. if ( use_win32 )
  108. {
  109. tgt->SetProperty("WIN32_EXECUTABLE", "ON");
  110. }
  111. if ( use_macbundle)
  112. {
  113. tgt->SetProperty("MACOSX_BUNDLE", "ON");
  114. }
  115. return true;
  116. }