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.
This commit is contained in:
parent
0392f72bef
commit
49f10f0d24
|
@ -27,7 +27,6 @@ cmCommonTargetGenerator::cmCommonTargetGenerator(cmGeneratorTarget* gt)
|
||||||
gt->LocalGenerator->GetGlobalGenerator()))
|
gt->LocalGenerator->GetGlobalGenerator()))
|
||||||
, ConfigName(LocalGenerator->GetConfigName())
|
, ConfigName(LocalGenerator->GetConfigName())
|
||||||
, ModuleDefinitionFile(GeneratorTarget->GetModuleDefinitionFile(ConfigName))
|
, ModuleDefinitionFile(GeneratorTarget->GetModuleDefinitionFile(ConfigName))
|
||||||
, FortranModuleDirectoryComputed(false)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,43 +88,6 @@ void cmCommonTargetGenerator::AddModuleDefinitionFlag(std::string& flags)
|
||||||
this->LocalGenerator->AppendFlags(flags, flag);
|
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)
|
void cmCommonTargetGenerator::AddFortranFlags(std::string& flags)
|
||||||
{
|
{
|
||||||
// Enable module output if necessary.
|
// Enable module output if necessary.
|
||||||
|
@ -135,7 +97,7 @@ void cmCommonTargetGenerator::AddFortranFlags(std::string& flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a module output directory flag if necessary.
|
// 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()) {
|
if (!mod_dir.empty()) {
|
||||||
mod_dir =
|
mod_dir =
|
||||||
this->Convert(mod_dir, this->LocalGenerator->GetWorkingDirectory(),
|
this->Convert(mod_dir, this->LocalGenerator->GetWorkingDirectory(),
|
||||||
|
|
|
@ -53,12 +53,6 @@ protected:
|
||||||
// The windows module definition source file (.def), if any.
|
// The windows module definition source file (.def), if any.
|
||||||
cmSourceFile const* ModuleDefinitionFile;
|
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.
|
// Compute target-specific Fortran language flags.
|
||||||
void AddFortranFlags(std::string& flags);
|
void AddFortranFlags(std::string& flags);
|
||||||
|
|
||||||
|
|
|
@ -258,6 +258,7 @@ void CreatePropertyGeneratorExpressions(
|
||||||
|
|
||||||
cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg)
|
cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg)
|
||||||
: Target(t)
|
: Target(t)
|
||||||
|
, FortranModuleDirectoryCreated(false)
|
||||||
, SourceFileFlagsConstructed(false)
|
, SourceFileFlagsConstructed(false)
|
||||||
, PolicyWarnedCMP0022(false)
|
, PolicyWarnedCMP0022(false)
|
||||||
, DebugIncludesDone(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
|
std::string cmGeneratorTarget::GetFrameworkVersion() const
|
||||||
{
|
{
|
||||||
assert(this->GetType() != cmState::INTERFACE_LIBRARY);
|
assert(this->GetType() != cmState::INTERFACE_LIBRARY);
|
||||||
|
|
|
@ -526,7 +526,13 @@ public:
|
||||||
void GetTargetVersion(bool soversion, int& major, int& minor,
|
void GetTargetVersion(bool soversion, int& major, int& minor,
|
||||||
int& patch) const;
|
int& patch) const;
|
||||||
|
|
||||||
|
std::string GetFortranModuleDirectory() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::string CreateFortranModuleDirectory() const;
|
||||||
|
mutable bool FortranModuleDirectoryCreated;
|
||||||
|
mutable std::string FortranModuleDirectory;
|
||||||
|
|
||||||
friend class cmTargetTraceDependencies;
|
friend class cmTargetTraceDependencies;
|
||||||
struct SourceEntry
|
struct SourceEntry
|
||||||
{
|
{
|
||||||
|
|
|
@ -962,7 +962,7 @@ void cmMakefileTargetGenerator::WriteTargetDependRules()
|
||||||
<< "\n"
|
<< "\n"
|
||||||
<< "# Fortran module output directory.\n"
|
<< "# Fortran module output directory.\n"
|
||||||
<< "set(CMAKE_Fortran_TARGET_MODULE_DIR \""
|
<< "set(CMAKE_Fortran_TARGET_MODULE_DIR \""
|
||||||
<< this->GetFortranModuleDirectory() << "\")\n";
|
<< this->GeneratorTarget->GetFortranModuleDirectory() << "\")\n";
|
||||||
/* clang-format on */
|
/* clang-format on */
|
||||||
|
|
||||||
// and now write the rule to use it
|
// and now write the rule to use it
|
||||||
|
|
Loading…
Reference in New Issue