Commit 49f10f0d authored by Tobias Hunger's avatar Tobias Hunger Committed by Brad King
Browse files

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.
parent 0392f72b
......@@ -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(),
......
......@@ -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);
......
......@@ -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);
......
......@@ -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
{
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment