Merge topic 'refactor-fortran-module-directory'

e90372a0 cmCommonTargetGenerator: Factor out Fortran module directory computation
70c21301 cmCommonTargetGenerator: Store working directory for relative paths
7371d8f3 cmCommonTargetGenerator: Return string from GetFortranModuleDirectory
613bc08a cmDependsFortran: Use string to store module directory
This commit is contained in:
Brad King 2015-07-30 09:56:16 -04:00 committed by CMake Topic Stage
commit a8c3698526
6 changed files with 70 additions and 63 deletions

View File

@ -20,8 +20,12 @@
#include "cmSystemTools.h" #include "cmSystemTools.h"
#include "cmTarget.h" #include "cmTarget.h"
cmCommonTargetGenerator::cmCommonTargetGenerator(cmGeneratorTarget* gt) cmCommonTargetGenerator::cmCommonTargetGenerator(
: GeneratorTarget(gt) cmOutputConverter::RelativeRoot wd,
cmGeneratorTarget* gt
)
: WorkingDirectory(wd)
, GeneratorTarget(gt)
, Target(gt->Target) , Target(gt->Target)
, Makefile(gt->Makefile) , Makefile(gt->Makefile)
, LocalGenerator(static_cast<cmLocalCommonGenerator*>(gt->LocalGenerator)) , LocalGenerator(static_cast<cmLocalCommonGenerator*>(gt->LocalGenerator))
@ -101,11 +105,9 @@ void cmCommonTargetGenerator::AddModuleDefinitionFlag(std::string& flags)
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
const char* cmCommonTargetGenerator::GetFortranModuleDirectory() std::string cmCommonTargetGenerator::ComputeFortranModuleDirectory() const
{ {
// Compute the module directory. std::string mod_dir;
if(!this->FortranModuleDirectoryComputed)
{
const char* target_mod_dir = const char* target_mod_dir =
this->Target->GetProperty("Fortran_MODULE_DIRECTORY"); this->Target->GetProperty("Fortran_MODULE_DIRECTORY");
const char* moddir_flag = const char* moddir_flag =
@ -116,32 +118,34 @@ const char* cmCommonTargetGenerator::GetFortranModuleDirectory()
if(cmSystemTools::FileIsFullPath(target_mod_dir)) if(cmSystemTools::FileIsFullPath(target_mod_dir))
{ {
// Already a full path. // Already a full path.
this->FortranModuleDirectory = target_mod_dir; mod_dir = target_mod_dir;
} }
else else
{ {
// Interpret relative to the current output directory. // Interpret relative to the current output directory.
this->FortranModuleDirectory = mod_dir = this->Makefile->GetCurrentBinaryDirectory();
this->Makefile->GetCurrentBinaryDirectory(); mod_dir += "/";
this->FortranModuleDirectory += "/"; mod_dir += target_mod_dir;
this->FortranModuleDirectory += target_mod_dir;
} }
// Make sure the module output directory exists. // Make sure the module output directory exists.
cmSystemTools::MakeDirectory(this->FortranModuleDirectory.c_str()); cmSystemTools::MakeDirectory(mod_dir);
} }
return mod_dir;
}
//----------------------------------------------------------------------------
std::string cmCommonTargetGenerator::GetFortranModuleDirectory()
{
// Compute the module directory.
if(!this->FortranModuleDirectoryComputed)
{
this->FortranModuleDirectoryComputed = true; this->FortranModuleDirectoryComputed = true;
this->FortranModuleDirectory = this->ComputeFortranModuleDirectory();
} }
// Return the computed directory. // Return the computed directory.
if(this->FortranModuleDirectory.empty()) return this->FortranModuleDirectory;
{
return 0;
}
else
{
return this->FortranModuleDirectory.c_str();
}
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -155,19 +159,24 @@ void cmCommonTargetGenerator::AddFortranFlags(std::string& flags)
} }
// Add a module output directory flag if necessary. // Add a module output directory flag if necessary.
const char* mod_dir = this->GetFortranModuleDirectory(); std::string mod_dir = this->GetFortranModuleDirectory();
if(!mod_dir) if (!mod_dir.empty())
{ {
mod_dir = this->Makefile->GetDefinition("CMAKE_Fortran_MODDIR_DEFAULT"); mod_dir = this->Convert(mod_dir,
this->WorkingDirectory,
cmLocalGenerator::SHELL);
} }
if(mod_dir) else
{
mod_dir =
this->Makefile->GetSafeDefinition("CMAKE_Fortran_MODDIR_DEFAULT");
}
if (!mod_dir.empty())
{ {
const char* moddir_flag = const char* moddir_flag =
this->Makefile->GetRequiredDefinition("CMAKE_Fortran_MODDIR_FLAG"); this->Makefile->GetRequiredDefinition("CMAKE_Fortran_MODDIR_FLAG");
std::string modflag = moddir_flag; std::string modflag = moddir_flag;
modflag += this->Convert(mod_dir, modflag += mod_dir;
cmLocalGenerator::START_OUTPUT,
cmLocalGenerator::SHELL);
this->LocalGenerator->AppendFlags(flags, modflag); this->LocalGenerator->AppendFlags(flags, modflag);
} }

View File

@ -29,7 +29,8 @@ class cmTarget;
class cmCommonTargetGenerator class cmCommonTargetGenerator
{ {
public: public:
cmCommonTargetGenerator(cmGeneratorTarget* gt); cmCommonTargetGenerator(cmOutputConverter::RelativeRoot wd,
cmGeneratorTarget* gt);
virtual ~cmCommonTargetGenerator(); virtual ~cmCommonTargetGenerator();
std::string const& GetConfigName() const; std::string const& GetConfigName() const;
@ -46,6 +47,7 @@ protected:
// Helper to add flag for windows .def file. // Helper to add flag for windows .def file.
void AddModuleDefinitionFlag(std::string& flags); void AddModuleDefinitionFlag(std::string& flags);
cmOutputConverter::RelativeRoot WorkingDirectory;
cmGeneratorTarget* GeneratorTarget; cmGeneratorTarget* GeneratorTarget;
cmTarget* Target; cmTarget* Target;
cmMakefile* Makefile; cmMakefile* Makefile;
@ -59,7 +61,8 @@ protected:
// Target-wide Fortran module output directory. // Target-wide Fortran module output directory.
bool FortranModuleDirectoryComputed; bool FortranModuleDirectoryComputed;
std::string FortranModuleDirectory; std::string FortranModuleDirectory;
const char* GetFortranModuleDirectory(); std::string GetFortranModuleDirectory();
virtual std::string ComputeFortranModuleDirectory() const;
// Compute target-specific Fortran language flags. // Compute target-specific Fortran language flags.
void AddFortranFlags(std::string& flags); void AddFortranFlags(std::string& flags);

View File

@ -154,14 +154,10 @@ bool cmDependsFortran::Finalize(std::ostream& makeDepends,
const char* stamp_dir = this->TargetDirectory.c_str(); const char* stamp_dir = this->TargetDirectory.c_str();
// Get the directory in which module files will be created. // Get the directory in which module files will be created.
const char* mod_dir;
cmMakefile* mf = this->LocalGenerator->GetMakefile(); cmMakefile* mf = this->LocalGenerator->GetMakefile();
if(const char* target_mod_dir = std::string mod_dir =
mf->GetDefinition("CMAKE_Fortran_TARGET_MODULE_DIR")) mf->GetSafeDefinition("CMAKE_Fortran_TARGET_MODULE_DIR");
{ if (mod_dir.empty())
mod_dir = target_mod_dir;
}
else
{ {
mod_dir = mod_dir =
this->LocalGenerator->GetMakefile()->GetCurrentBinaryDirectory(); this->LocalGenerator->GetMakefile()->GetCurrentBinaryDirectory();
@ -356,7 +352,8 @@ bool
cmDependsFortran cmDependsFortran
::WriteDependenciesReal(const char *obj, ::WriteDependenciesReal(const char *obj,
cmFortranSourceInfo const& info, cmFortranSourceInfo const& info,
const char* mod_dir, const char* stamp_dir, std::string const& mod_dir,
const char* stamp_dir,
std::ostream& makeDepends, std::ostream& makeDepends,
std::ostream& internalDepends) std::ostream& internalDepends)
{ {

View File

@ -66,7 +66,8 @@ protected:
// Actually write the depenencies to the streams. // Actually write the depenencies to the streams.
bool WriteDependenciesReal(const char *obj, bool WriteDependenciesReal(const char *obj,
cmFortranSourceInfo const& info, cmFortranSourceInfo const& info,
const char* mod_dir, const char* stamp_dir, std::string const& mod_dir,
const char* stamp_dir,
std::ostream& makeDepends, std::ostream& makeDepends,
std::ostream& internalDepends); std::ostream& internalDepends);

View File

@ -33,7 +33,7 @@
#include <ctype.h> #include <ctype.h>
cmMakefileTargetGenerator::cmMakefileTargetGenerator(cmGeneratorTarget* target) cmMakefileTargetGenerator::cmMakefileTargetGenerator(cmGeneratorTarget* target)
: cmCommonTargetGenerator(target) : cmCommonTargetGenerator(cmOutputConverter::START_OUTPUT, target)
, OSXBundleGenerator(0) , OSXBundleGenerator(0)
, MacOSXContentGenerator(0) , MacOSXContentGenerator(0)
{ {
@ -1068,14 +1068,11 @@ void cmMakefileTargetGenerator::WriteTargetDependRules()
<< " )\n"; << " )\n";
} }
// Check for a target-specific module output directory.
if(const char* mdir = this->GetFortranModuleDirectory())
{
*this->InfoFileStream *this->InfoFileStream
<< "\n" << "\n"
<< "# Fortran module output directory.\n" << "# Fortran module output directory.\n"
<< "set(CMAKE_Fortran_TARGET_MODULE_DIR \"" << mdir << "\")\n"; << "set(CMAKE_Fortran_TARGET_MODULE_DIR \""
} << this->GetFortranModuleDirectory() << "\")\n";
// and now write the rule to use it // and now write the rule to use it
std::vector<std::string> depends; std::vector<std::string> depends;

View File

@ -58,7 +58,7 @@ cmNinjaTargetGenerator::New(cmGeneratorTarget* target)
} }
cmNinjaTargetGenerator::cmNinjaTargetGenerator(cmGeneratorTarget* target) cmNinjaTargetGenerator::cmNinjaTargetGenerator(cmGeneratorTarget* target)
: cmCommonTargetGenerator(target), : cmCommonTargetGenerator(cmOutputConverter::HOME_OUTPUT, target),
MacOSXContentGenerator(0), MacOSXContentGenerator(0),
OSXBundleGenerator(0), OSXBundleGenerator(0),
MacContentFolders(), MacContentFolders(),