cmAddLibraryCommand.cxx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 "cmAddLibraryCommand.h"
  14. // cmLibraryCommand
  15. bool cmAddLibraryCommand::InitialPass(std::vector<std::string> const& args)
  16. {
  17. if(args.size() < 1 )
  18. {
  19. this->SetError("called with incorrect number of arguments");
  20. return false;
  21. }
  22. // Library type defaults to value of BUILD_SHARED_LIBS, if it exists,
  23. // otherwise it defaults to static library.
  24. int shared =
  25. !cmSystemTools::IsOff(this->Makefile->GetDefinition("BUILD_SHARED_LIBS"));
  26. bool excludeFromAll = false;
  27. std::vector<std::string>::const_iterator s = args.begin();
  28. this->LibName = *s;
  29. ++s;
  30. // If the second argument is "SHARED" or "STATIC", then it controls
  31. // the type of library. Otherwise, it is treated as a source or
  32. // source list name. There man be two keyword arguments, check for them
  33. while ( s != args.end() )
  34. {
  35. std::string libType = *s;
  36. if(libType == "STATIC")
  37. {
  38. ++s;
  39. shared = 0;
  40. }
  41. else if(libType == "SHARED")
  42. {
  43. ++s;
  44. shared = 1;
  45. }
  46. else if(libType == "MODULE")
  47. {
  48. ++s;
  49. shared = 2;
  50. }
  51. else if(*s == "EXCLUDE_FROM_ALL")
  52. {
  53. ++s;
  54. excludeFromAll = true;
  55. }
  56. else
  57. {
  58. break;
  59. }
  60. }
  61. if (s == args.end())
  62. {
  63. std::string msg = "You have called ADD_LIBRARY for library ";
  64. msg += args[0];
  65. msg += " without any source files. This typically indicates a problem ";
  66. msg += "with your CMakeLists.txt file";
  67. cmSystemTools::Message(msg.c_str() ,"Warning");
  68. }
  69. std::vector<std::string> srclists;
  70. while (s != args.end())
  71. {
  72. srclists.push_back(*s);
  73. ++s;
  74. }
  75. this->Makefile->AddLibrary(this->LibName.c_str(), shared, srclists,
  76. excludeFromAll);
  77. return true;
  78. }