cmAddLibraryCommand.cxx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. std::vector<std::string>::const_iterator s = args.begin();
  27. this->LibName = *s;
  28. ++s;
  29. // If the second argument is "SHARED" or "STATIC", then it controls
  30. // the type of library. Otherwise, it is treated as a source or
  31. // source list name.
  32. if(s != args.end())
  33. {
  34. std::string libType = *s;
  35. if(libType == "STATIC")
  36. {
  37. ++s;
  38. shared = 0;
  39. }
  40. else if(libType == "SHARED")
  41. {
  42. ++s;
  43. shared = 1;
  44. }
  45. else if(libType == "MODULE")
  46. {
  47. ++s;
  48. shared = 2;
  49. }
  50. }
  51. if (s == args.end())
  52. {
  53. std::string msg = "You have called ADD_LIBRARY for library ";
  54. msg += args[0];
  55. msg += " without any source files. This typically indicates a problem ";
  56. msg += "with your CMakeLists.txt file";
  57. cmSystemTools::Message(msg.c_str() ,"Warning");
  58. }
  59. std::vector<std::string> srclists;
  60. while (s != args.end())
  61. {
  62. srclists.push_back(*s);
  63. ++s;
  64. }
  65. this->Makefile->AddLibrary(this->LibName.c_str(), shared, srclists);
  66. return true;
  67. }