cmAddLibraryCommand.cxx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. /* ideally we should check whether for the linker language of the target
  70. CMAKE_${LANG}_CREATE_SHARED_LIBRARY is defined and if not default to
  71. STATIC. But at this point we know only the name of the target, but not
  72. yet its linker language. */
  73. if ((shared != 0) &&
  74. (this->Makefile->IsOn("CMAKE_TARGET_SUPPORTS_ONLY_STATIC_LIBS")))
  75. {
  76. std::string msg = "ADD_LIBRARY for library ";
  77. msg += args[0];
  78. msg += " is used with the SHARED or MODULE option, but the target "
  79. "platform supports only STATIC libraries. Building it STATIC instead. "
  80. "This may lead to problems.";
  81. cmSystemTools::Message(msg.c_str() ,"Warning");
  82. shared = 0;
  83. }
  84. std::vector<std::string> srclists;
  85. while (s != args.end())
  86. {
  87. srclists.push_back(*s);
  88. ++s;
  89. }
  90. this->Makefile->AddLibrary(this->LibName.c_str(), shared, srclists,
  91. excludeFromAll);
  92. return true;
  93. }