From 49f10f0d24420f7d96c5153ba64a16b3f43c4736 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Fri, 10 Jun 2016 16:58:36 +0200 Subject: cmGeneratorTarget: Adopt Fortran module directory generation Move code to create/get the fortran module directory from the cmCommonTargetGenerator to cmGeneratorTarget. Rename the ComputeFortranModuleDirectory method to CreateFortranModuleDirectory as this method *creates* the directory if it is missing. --- Source/cmCommonTargetGenerator.cxx | 40 +----------------------------------- Source/cmCommonTargetGenerator.h | 6 ------ Source/cmGeneratorTarget.cxx | 35 +++++++++++++++++++++++++++++++ Source/cmGeneratorTarget.h | 6 ++++++ Source/cmMakefileTargetGenerator.cxx | 2 +- 5 files changed, 43 insertions(+), 46 deletions(-) diff --git a/Source/cmCommonTargetGenerator.cxx b/Source/cmCommonTargetGenerator.cxx index 1cc04ea..eb1216e 100644 --- a/Source/cmCommonTargetGenerator.cxx +++ b/Source/cmCommonTargetGenerator.cxx @@ -27,7 +27,6 @@ cmCommonTargetGenerator::cmCommonTargetGenerator(cmGeneratorTarget* gt) gt->LocalGenerator->GetGlobalGenerator())) , ConfigName(LocalGenerator->GetConfigName()) , ModuleDefinitionFile(GeneratorTarget->GetModuleDefinitionFile(ConfigName)) - , FortranModuleDirectoryComputed(false) { } @@ -89,43 +88,6 @@ void cmCommonTargetGenerator::AddModuleDefinitionFlag(std::string& flags) this->LocalGenerator->AppendFlags(flags, flag); } -std::string cmCommonTargetGenerator::ComputeFortranModuleDirectory() const -{ - std::string mod_dir; - const char* target_mod_dir = - this->GeneratorTarget->GetProperty("Fortran_MODULE_DIRECTORY"); - const char* moddir_flag = - this->Makefile->GetDefinition("CMAKE_Fortran_MODDIR_FLAG"); - if (target_mod_dir && moddir_flag) { - // Compute the full path to the module directory. - if (cmSystemTools::FileIsFullPath(target_mod_dir)) { - // Already a full path. - mod_dir = target_mod_dir; - } else { - // Interpret relative to the current output directory. - mod_dir = this->LocalGenerator->GetCurrentBinaryDirectory(); - mod_dir += "/"; - mod_dir += target_mod_dir; - } - - // Make sure the module output directory exists. - cmSystemTools::MakeDirectory(mod_dir); - } - return mod_dir; -} - -std::string cmCommonTargetGenerator::GetFortranModuleDirectory() -{ - // Compute the module directory. - if (!this->FortranModuleDirectoryComputed) { - this->FortranModuleDirectoryComputed = true; - this->FortranModuleDirectory = this->ComputeFortranModuleDirectory(); - } - - // Return the computed directory. - return this->FortranModuleDirectory; -} - void cmCommonTargetGenerator::AddFortranFlags(std::string& flags) { // Enable module output if necessary. @@ -135,7 +97,7 @@ void cmCommonTargetGenerator::AddFortranFlags(std::string& flags) } // Add a module output directory flag if necessary. - std::string mod_dir = this->GetFortranModuleDirectory(); + std::string mod_dir = this->GeneratorTarget->GetFortranModuleDirectory(); if (!mod_dir.empty()) { mod_dir = this->Convert(mod_dir, this->LocalGenerator->GetWorkingDirectory(), diff --git a/Source/cmCommonTargetGenerator.h b/Source/cmCommonTargetGenerator.h index c35d22a..dc4974c 100644 --- a/Source/cmCommonTargetGenerator.h +++ b/Source/cmCommonTargetGenerator.h @@ -53,12 +53,6 @@ protected: // The windows module definition source file (.def), if any. cmSourceFile const* ModuleDefinitionFile; - // Target-wide Fortran module output directory. - bool FortranModuleDirectoryComputed; - std::string FortranModuleDirectory; - std::string GetFortranModuleDirectory(); - virtual std::string ComputeFortranModuleDirectory() const; - // Compute target-specific Fortran language flags. void AddFortranFlags(std::string& flags); diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 5f4b074..15b44a6 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -258,6 +258,7 @@ void CreatePropertyGeneratorExpressions( cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg) : Target(t) + , FortranModuleDirectoryCreated(false) , SourceFileFlagsConstructed(false) , PolicyWarnedCMP0022(false) , DebugIncludesDone(false) @@ -3842,6 +3843,40 @@ void cmGeneratorTarget::GetTargetVersion(bool soversion, int& major, } } +std::string cmGeneratorTarget::GetFortranModuleDirectory() const +{ + if (!this->FortranModuleDirectoryCreated) { + this->FortranModuleDirectory = true; + this->FortranModuleDirectory = this->CreateFortranModuleDirectory(); + } + + return this->FortranModuleDirectory; +} + +std::string cmGeneratorTarget::CreateFortranModuleDirectory() const +{ + static std::string mod_dir; + const char* target_mod_dir = this->GetProperty("Fortran_MODULE_DIRECTORY"); + const char* moddir_flag = + this->Makefile->GetDefinition("CMAKE_Fortran_MODDIR_FLAG"); + if (target_mod_dir && moddir_flag) { + // Compute the full path to the module directory. + if (cmSystemTools::FileIsFullPath(target_mod_dir)) { + // Already a full path. + mod_dir = target_mod_dir; + } else { + // Interpret relative to the current output directory. + mod_dir = this->LocalGenerator->GetCurrentBinaryDirectory(); + mod_dir += "/"; + mod_dir += target_mod_dir; + } + + // Make sure the module output directory exists. + cmSystemTools::MakeDirectory(mod_dir); + } + return mod_dir; +} + std::string cmGeneratorTarget::GetFrameworkVersion() const { assert(this->GetType() != cmState::INTERFACE_LIBRARY); diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 63208bc..2ee9bef 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -526,7 +526,13 @@ public: void GetTargetVersion(bool soversion, int& major, int& minor, int& patch) const; + std::string GetFortranModuleDirectory() const; + private: + std::string CreateFortranModuleDirectory() const; + mutable bool FortranModuleDirectoryCreated; + mutable std::string FortranModuleDirectory; + friend class cmTargetTraceDependencies; struct SourceEntry { diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index daf05d3..8b341a1 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -962,7 +962,7 @@ void cmMakefileTargetGenerator::WriteTargetDependRules() << "\n" << "# Fortran module output directory.\n" << "set(CMAKE_Fortran_TARGET_MODULE_DIR \"" - << this->GetFortranModuleDirectory() << "\")\n"; + << this->GeneratorTarget->GetFortranModuleDirectory() << "\")\n"; /* clang-format on */ // and now write the rule to use it -- cgit v0.12