cmLocalCommonGenerator.cxx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file LICENSE.rst or https://cmake.org/licensing for details. */
  3. #include "cmLocalCommonGenerator.h"
  4. #include <memory>
  5. #include <utility>
  6. #include <vector>
  7. #include "cmGeneratorTarget.h"
  8. #include "cmGlobalGenerator.h"
  9. #include "cmMakefile.h"
  10. #include "cmOutputConverter.h"
  11. #include "cmStateDirectory.h"
  12. #include "cmStateSnapshot.h"
  13. #include "cmStringAlgorithms.h"
  14. #include "cmValue.h"
  15. cmLocalCommonGenerator::cmLocalCommonGenerator(cmGlobalGenerator* gg,
  16. cmMakefile* mf)
  17. : cmLocalGenerator(gg, mf)
  18. {
  19. // Multi-config generators define one set of configurations at the top.
  20. // Single-config generators nominally define one configuration at the top,
  21. // but the implementation has never been strict about that, so look up the
  22. // per-directory config to preserve behavior.
  23. this->ConfigNames = (gg->IsMultiConfig() && !gg->GetMakefiles().empty()
  24. ? gg->GetMakefiles().front().get()
  25. : this->Makefile)
  26. ->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);
  27. }
  28. cmLocalCommonGenerator::~cmLocalCommonGenerator() = default;
  29. std::string const& cmLocalCommonGenerator::GetWorkingDirectory() const
  30. {
  31. return this->StateSnapshot.GetDirectory().GetCurrentBinary();
  32. }
  33. std::string cmLocalCommonGenerator::GetTargetFortranFlags(
  34. cmGeneratorTarget const* target, std::string const& config)
  35. {
  36. std::string flags;
  37. // Enable module output if necessary.
  38. this->AppendFlags(
  39. flags, this->Makefile->GetSafeDefinition("CMAKE_Fortran_MODOUT_FLAG"));
  40. // Add a module output directory flag if necessary.
  41. std::string mod_dir =
  42. target->GetFortranModuleDirectory(this->GetWorkingDirectory());
  43. if (!mod_dir.empty()) {
  44. mod_dir = this->ConvertToOutputFormat(
  45. this->MaybeRelativeToWorkDir(mod_dir), cmOutputConverter::SHELL);
  46. } else {
  47. mod_dir =
  48. this->Makefile->GetSafeDefinition("CMAKE_Fortran_MODDIR_DEFAULT");
  49. }
  50. if (!mod_dir.empty()) {
  51. std::string modflag = cmStrCat(
  52. this->Makefile->GetRequiredDefinition("CMAKE_Fortran_MODDIR_FLAG"),
  53. mod_dir);
  54. this->AppendFlags(flags, modflag);
  55. // Some compilers do not search their own module output directory
  56. // for using other modules. Add an include directory explicitly
  57. // for consistency with compilers that do search it.
  58. std::string incflag =
  59. this->Makefile->GetSafeDefinition("CMAKE_Fortran_MODDIR_INCLUDE_FLAG");
  60. if (!incflag.empty()) {
  61. incflag = cmStrCat(incflag, mod_dir);
  62. this->AppendFlags(flags, incflag);
  63. }
  64. }
  65. // If there is a separate module path flag then duplicate the
  66. // include path with it. This compiler does not search the include
  67. // path for modules.
  68. if (cmValue modpath_flag =
  69. this->Makefile->GetDefinition("CMAKE_Fortran_MODPATH_FLAG")) {
  70. std::vector<std::string> includes;
  71. this->GetIncludeDirectories(includes, target, "C", config);
  72. for (std::string const& id : includes) {
  73. std::string flg =
  74. cmStrCat(*modpath_flag,
  75. this->ConvertToOutputFormat(id, cmOutputConverter::SHELL));
  76. this->AppendFlags(flags, flg);
  77. }
  78. }
  79. return flags;
  80. }
  81. std::string cmLocalCommonGenerator::GetTargetDirectory(
  82. cmGeneratorTarget const* target) const
  83. {
  84. std::string dir = target->GetName();
  85. #if defined(__VMS)
  86. dir += "_dir";
  87. #else
  88. dir += ".dir";
  89. #endif
  90. return dir;
  91. }
  92. void cmLocalCommonGenerator::ComputeObjectFilenames(
  93. std::map<cmSourceFile const*, std::string>& mapping,
  94. cmGeneratorTarget const* gt)
  95. {
  96. // Determine if these object files should use a custom extension
  97. char const* custom_ext = gt->GetCustomObjectExtension();
  98. for (auto& si : mapping) {
  99. cmSourceFile const* sf = si.first;
  100. bool keptSourceExtension;
  101. si.second = this->GetObjectFileNameWithoutTarget(
  102. *sf, gt->ObjectDirectory, &keptSourceExtension, custom_ext);
  103. }
  104. }