cmAddLibraryCommand.cxx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. cmTarget::TargetType type = cmTarget::SHARED_LIBRARY;
  25. if (cmSystemTools::IsOff(this->Makefile->GetDefinition("BUILD_SHARED_LIBS")))
  26. {
  27. type = cmTarget::STATIC_LIBRARY;
  28. }
  29. bool excludeFromAll = false;
  30. bool importTarget = false;
  31. std::vector<std::string>::const_iterator s = args.begin();
  32. std::string libName = *s;
  33. ++s;
  34. // If the second argument is "SHARED" or "STATIC", then it controls
  35. // the type of library. Otherwise, it is treated as a source or
  36. // source list name. There may be two keyword arguments, check for them
  37. while ( s != args.end() )
  38. {
  39. std::string libType = *s;
  40. if(libType == "STATIC")
  41. {
  42. ++s;
  43. type = cmTarget::STATIC_LIBRARY;
  44. }
  45. else if(libType == "SHARED")
  46. {
  47. ++s;
  48. type = cmTarget::SHARED_LIBRARY;
  49. }
  50. else if(libType == "MODULE")
  51. {
  52. ++s;
  53. type = cmTarget::MODULE_LIBRARY;
  54. }
  55. else if(*s == "EXCLUDE_FROM_ALL")
  56. {
  57. ++s;
  58. excludeFromAll = true;
  59. }
  60. else if(*s == "IMPORT")
  61. {
  62. ++s;
  63. importTarget = true;
  64. }
  65. else
  66. {
  67. break;
  68. }
  69. }
  70. /* ideally we should check whether for the linker language of the target
  71. CMAKE_${LANG}_CREATE_SHARED_LIBRARY is defined and if not default to
  72. STATIC. But at this point we know only the name of the target, but not
  73. yet its linker language. */
  74. if ((type != cmTarget::STATIC_LIBRARY) &&
  75. (this->Makefile->IsOn("CMAKE_TARGET_SUPPORTS_ONLY_STATIC_LIBS")))
  76. {
  77. std::string msg = "ADD_LIBRARY for library ";
  78. msg += args[0];
  79. msg += " is used with the SHARED or MODULE option, but the target "
  80. "platform supports only STATIC libraries. Building it STATIC instead. "
  81. "This may lead to problems.";
  82. cmSystemTools::Message(msg.c_str() ,"Warning");
  83. type = cmTarget::STATIC_LIBRARY;
  84. }
  85. if (importTarget)
  86. {
  87. this->Makefile->AddNewTarget(type, libName.c_str(), true);
  88. return true;
  89. }
  90. if (s == args.end())
  91. {
  92. std::string msg = "You have called ADD_LIBRARY for library ";
  93. msg += args[0];
  94. msg += " without any source files. This typically indicates a problem ";
  95. msg += "with your CMakeLists.txt file";
  96. cmSystemTools::Message(msg.c_str() ,"Warning");
  97. }
  98. std::vector<std::string> srclists;
  99. while (s != args.end())
  100. {
  101. srclists.push_back(*s);
  102. ++s;
  103. }
  104. this->Makefile->AddLibrary(libName.c_str(), type, srclists,
  105. excludeFromAll);
  106. return true;
  107. }