cmCommonTargetGenerator: Factor out Fortran module directory computation

Move computation from GetFortranModuleDirectory to a virtual method
so it can be customized for each type of generator.
This commit is contained in:
Brad King 2015-07-29 13:07:02 -04:00
parent 70c21301b2
commit e90372a0db
2 changed files with 32 additions and 24 deletions

View File

@ -104,37 +104,44 @@ 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->Target->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->Makefile->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)
{
const char* target_mod_dir =
this->Target->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.
this->FortranModuleDirectory = target_mod_dir;
}
else
{
// Interpret relative to the current output directory.
this->FortranModuleDirectory =
this->Makefile->GetCurrentBinaryDirectory();
this->FortranModuleDirectory += "/";
this->FortranModuleDirectory += target_mod_dir;
}
// Make sure the module output directory exists.
cmSystemTools::MakeDirectory(this->FortranModuleDirectory.c_str());
}
this->FortranModuleDirectoryComputed = true;
this->FortranModuleDirectory = this->ComputeFortranModuleDirectory();
}
// Return the computed directory.

View File

@ -62,6 +62,7 @@ protected:
bool FortranModuleDirectoryComputed;
std::string FortranModuleDirectory;
std::string GetFortranModuleDirectory();
virtual std::string ComputeFortranModuleDirectory() const;
// Compute target-specific Fortran language flags.
void AddFortranFlags(std::string& flags);