cmGeneratorTarget.cxx 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2012 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmGeneratorTarget.h"
  11. #include "cmTarget.h"
  12. #include "cmMakefile.h"
  13. #include "cmLocalGenerator.h"
  14. #include "cmGlobalGenerator.h"
  15. #include "cmSourceFile.h"
  16. //----------------------------------------------------------------------------
  17. cmGeneratorTarget::cmGeneratorTarget(cmTarget* t): Target(t)
  18. {
  19. this->Makefile = this->Target->GetMakefile();
  20. this->LocalGenerator = this->Makefile->GetLocalGenerator();
  21. this->GlobalGenerator = this->LocalGenerator->GetGlobalGenerator();
  22. this->ClassifySources();
  23. }
  24. //----------------------------------------------------------------------------
  25. void cmGeneratorTarget::ClassifySources()
  26. {
  27. bool isObjLib = this->Target->GetType() == cmTarget::OBJECT_LIBRARY;
  28. std::vector<cmSourceFile*> badObjLib;
  29. std::vector<cmSourceFile*> const& sources = this->Target->GetSourceFiles();
  30. for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
  31. si != sources.end(); ++si)
  32. {
  33. cmSourceFile* sf = *si;
  34. cmTarget::SourceFileFlags tsFlags =
  35. this->Target->GetTargetSourceFileFlags(sf);
  36. if(sf->GetCustomCommand())
  37. {
  38. this->CustomCommands.push_back(sf);
  39. }
  40. else if(tsFlags.Type != cmTarget::SourceFileTypeNormal)
  41. {
  42. this->OSXContent.push_back(sf);
  43. if(isObjLib) { badObjLib.push_back(sf); }
  44. }
  45. else if(sf->GetPropertyAsBool("HEADER_FILE_ONLY"))
  46. {
  47. this->HeaderSources.push_back(sf);
  48. }
  49. else if(sf->GetPropertyAsBool("EXTERNAL_OBJECT"))
  50. {
  51. this->ExternalObjects.push_back(sf);
  52. if(isObjLib) { badObjLib.push_back(sf); }
  53. }
  54. else if(cmSystemTools::LowerCase(sf->GetExtension()) == "def")
  55. {
  56. this->ModuleDefinitionFile = sf->GetFullPath();
  57. if(isObjLib) { badObjLib.push_back(sf); }
  58. }
  59. else if(this->GlobalGenerator->IgnoreFile(sf->GetExtension().c_str()))
  60. {
  61. // We only get here if a source file is not an external object
  62. // and has an extension that is listed as an ignored file type.
  63. // No message or diagnosis should be given.
  64. }
  65. else if(sf->GetLanguage())
  66. {
  67. this->ObjectSources.push_back(sf);
  68. }
  69. else
  70. {
  71. this->ExtraSources.push_back(sf);
  72. if(isObjLib) { badObjLib.push_back(sf); }
  73. }
  74. }
  75. if(!badObjLib.empty())
  76. {
  77. cmOStringStream e;
  78. e << "OBJECT library \"" << this->Target->GetName() << "\" contains:\n";
  79. for(std::vector<cmSourceFile*>::iterator i = badObjLib.begin();
  80. i != badObjLib.end(); ++i)
  81. {
  82. e << " " << (*i)->GetLocation().GetName() << "\n";
  83. }
  84. e << "but may contain only headers and sources that compile.";
  85. this->GlobalGenerator->GetCMakeInstance()
  86. ->IssueMessage(cmake::FATAL_ERROR, e.str(),
  87. this->Target->GetBacktrace());
  88. }
  89. }