cmCommonTargetGenerator.cxx 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2015 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 "cmCommonTargetGenerator.h"
  11. #include "cmGeneratorTarget.h"
  12. #include "cmGlobalCommonGenerator.h"
  13. #include "cmLocalCommonGenerator.h"
  14. #include "cmMakefile.h"
  15. #include "cmTarget.h"
  16. cmCommonTargetGenerator::cmCommonTargetGenerator(cmGeneratorTarget* gt)
  17. : GeneratorTarget(gt)
  18. , Target(gt->Target)
  19. , Makefile(gt->Makefile)
  20. , LocalGenerator(static_cast<cmLocalCommonGenerator*>(gt->LocalGenerator))
  21. , GlobalGenerator(static_cast<cmGlobalCommonGenerator*>(
  22. gt->LocalGenerator->GetGlobalGenerator()))
  23. , ConfigName(LocalGenerator->GetConfigName())
  24. , ModuleDefinitionFile(GeneratorTarget->GetModuleDefinitionFile(ConfigName))
  25. {
  26. }
  27. cmCommonTargetGenerator::~cmCommonTargetGenerator()
  28. {
  29. }
  30. std::string const& cmCommonTargetGenerator::GetConfigName() const
  31. {
  32. return this->ConfigName;
  33. }
  34. //----------------------------------------------------------------------------
  35. const char* cmCommonTargetGenerator::GetFeature(const std::string& feature)
  36. {
  37. return this->GeneratorTarget->GetFeature(feature, this->ConfigName);
  38. }
  39. //----------------------------------------------------------------------------
  40. bool cmCommonTargetGenerator::GetFeatureAsBool(const std::string& feature)
  41. {
  42. return this->GeneratorTarget->GetFeatureAsBool(feature, this->ConfigName);
  43. }
  44. //----------------------------------------------------------------------------
  45. void cmCommonTargetGenerator::AddFeatureFlags(
  46. std::string& flags, const std::string& lang
  47. )
  48. {
  49. // Add language-specific flags.
  50. this->LocalGenerator->AddLanguageFlags(flags, lang, this->ConfigName);
  51. if(this->GetFeatureAsBool("INTERPROCEDURAL_OPTIMIZATION"))
  52. {
  53. this->LocalGenerator->AppendFeatureOptions(flags, lang, "IPO");
  54. }
  55. }
  56. //----------------------------------------------------------------------------
  57. void cmCommonTargetGenerator::AddModuleDefinitionFlag(std::string& flags)
  58. {
  59. if(this->ModuleDefinitionFile.empty())
  60. {
  61. return;
  62. }
  63. // TODO: Create a per-language flag variable.
  64. const char* defFileFlag =
  65. this->Makefile->GetDefinition("CMAKE_LINK_DEF_FILE_FLAG");
  66. if(!defFileFlag)
  67. {
  68. return;
  69. }
  70. // Append the flag and value. Use ConvertToLinkReference to help
  71. // vs6's "cl -link" pass it to the linker.
  72. std::string flag = defFileFlag;
  73. flag += (this->LocalGenerator->ConvertToLinkReference(
  74. this->ModuleDefinitionFile));
  75. this->LocalGenerator->AppendFlags(flags, flag);
  76. }