cmAddExecutableCommand.cxx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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::InitialPass(std::vector<std::string> const& args)
  16. {
  17. if(args.size() < 2 )
  18. {
  19. this->SetError("called with incorrect number of arguments");
  20. return false;
  21. }
  22. std::vector<std::string>::const_iterator s = args.begin();
  23. std::string exename = *s;
  24. ++s;
  25. bool use_win32 = false;
  26. bool use_macbundle = 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
  40. {
  41. break;
  42. }
  43. }
  44. std::vector<std::string> srclists(s, args.end());
  45. cmTarget* tgt = m_Makefile->AddExecutable(exename.c_str(), srclists);
  46. if ( use_win32 )
  47. {
  48. tgt->SetProperty("WIN32_EXECUTABLE", "ON");
  49. }
  50. if ( use_macbundle)
  51. {
  52. tgt->SetProperty("MACOSX_BUNDLE", "ON");
  53. #ifdef __APPLE__
  54. std::string f1 = m_Makefile->GetModulesFile("MacOSXBundleInfo.plist.in");
  55. if ( f1.size() == 0 )
  56. {
  57. this->SetError("could not find Mac OSX bundle template file.");
  58. return false;
  59. }
  60. std::string macdir = m_Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
  61. if ( macdir.size() == 0 )
  62. {
  63. macdir = m_Makefile->GetCurrentOutputDirectory();
  64. }
  65. if(macdir.size() && macdir[macdir.size()-1] != '/')
  66. {
  67. macdir += "/";
  68. }
  69. macdir += exename + ".app/Contents/";
  70. std::string f2 = macdir + "Info.plist";
  71. macdir += "MacOS";
  72. cmSystemTools::MakeDirectory(macdir.c_str());
  73. m_Makefile->AddDefinition("MACOSX_BUNDLE_EXECUTABLE_NAME", exename.c_str());
  74. m_Makefile->ConfigureFile(f1.c_str(), f2.c_str(), false, false, false);
  75. #endif
  76. }
  77. return true;
  78. }