cmAddLibraryCommand.cxx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 in_all = true;
  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.
  33. if(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 == "NOT_IN_ALL")
  52. {
  53. ++s;
  54. in_all = false;
  55. }
  56. }
  57. if (s == args.end())
  58. {
  59. std::string msg = "You have called ADD_LIBRARY for library ";
  60. msg += args[0];
  61. msg += " without any source files. This typically indicates a problem ";
  62. msg += "with your CMakeLists.txt file";
  63. cmSystemTools::Message(msg.c_str() ,"Warning");
  64. }
  65. std::vector<std::string> srclists;
  66. while (s != args.end())
  67. {
  68. srclists.push_back(*s);
  69. ++s;
  70. }
  71. this->Makefile->AddLibrary(this->LibName.c_str(), shared, srclists,
  72. in_all);
  73. return true;
  74. }