cmAddExecutableCommand.cxx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. // Handle imported target creation.
  77. if(importTarget)
  78. {
  79. // Make sure the target does not already exist.
  80. if(this->Makefile->FindTargetToUse(exename.c_str()))
  81. {
  82. cmOStringStream e;
  83. e << "cannot create imported target \"" << exename
  84. << "\" because another target with the same name already exists.";
  85. this->SetError(e.str().c_str());
  86. return false;
  87. }
  88. // Create the imported target.
  89. this->Makefile->AddImportedTarget(exename.c_str(), cmTarget::EXECUTABLE);
  90. return true;
  91. }
  92. // Enforce name uniqueness.
  93. std::string msg;
  94. if(!this->Makefile->EnforceUniqueName(exename, msg))
  95. {
  96. this->SetError(msg.c_str());
  97. return false;
  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. }