cmLocalCommonGenerator.cxx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmLocalCommonGenerator.h"
  4. #include <vector>
  5. #include "cmGeneratorTarget.h"
  6. #include "cmMakefile.h"
  7. #include "cmOutputConverter.h"
  8. class cmGlobalGenerator;
  9. cmLocalCommonGenerator::cmLocalCommonGenerator(cmGlobalGenerator* gg,
  10. cmMakefile* mf,
  11. std::string const& wd)
  12. : cmLocalGenerator(gg, mf)
  13. , WorkingDirectory(wd)
  14. {
  15. // Store the configuration name that will be generated.
  16. if (const char* config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE")) {
  17. // Use the build type given by the user.
  18. this->ConfigName = config;
  19. } else {
  20. // No configuration type given.
  21. this->ConfigName.clear();
  22. }
  23. }
  24. cmLocalCommonGenerator::~cmLocalCommonGenerator()
  25. {
  26. }
  27. std::string cmLocalCommonGenerator::GetTargetFortranFlags(
  28. cmGeneratorTarget const* target, std::string const& config)
  29. {
  30. std::string flags;
  31. // Enable module output if necessary.
  32. if (const char* modout_flag =
  33. this->Makefile->GetDefinition("CMAKE_Fortran_MODOUT_FLAG")) {
  34. this->AppendFlags(flags, modout_flag);
  35. }
  36. // Add a module output directory flag if necessary.
  37. std::string mod_dir =
  38. target->GetFortranModuleDirectory(this->WorkingDirectory);
  39. if (!mod_dir.empty()) {
  40. mod_dir = this->ConvertToOutputFormat(
  41. this->ConvertToRelativePath(this->WorkingDirectory, mod_dir),
  42. cmOutputConverter::SHELL);
  43. } else {
  44. mod_dir =
  45. this->Makefile->GetSafeDefinition("CMAKE_Fortran_MODDIR_DEFAULT");
  46. }
  47. if (!mod_dir.empty()) {
  48. const char* moddir_flag =
  49. this->Makefile->GetRequiredDefinition("CMAKE_Fortran_MODDIR_FLAG");
  50. std::string modflag = moddir_flag;
  51. modflag += mod_dir;
  52. this->AppendFlags(flags, modflag);
  53. }
  54. // If there is a separate module path flag then duplicate the
  55. // include path with it. This compiler does not search the include
  56. // path for modules.
  57. if (const char* modpath_flag =
  58. this->Makefile->GetDefinition("CMAKE_Fortran_MODPATH_FLAG")) {
  59. std::vector<std::string> includes;
  60. this->GetIncludeDirectories(includes, target, "C", config);
  61. for (std::string const& id : includes) {
  62. std::string flg = modpath_flag;
  63. flg += this->ConvertToOutputFormat(id, cmOutputConverter::SHELL);
  64. this->AppendFlags(flags, flg);
  65. }
  66. }
  67. return flags;
  68. }