Merge topic 'refactor-fortran-module-dir-lookup'
7b5f8567
Fortran: Use module dir flag if needed for default module directory1777570f
cmGeneratorTarget: Refactor Fortran module directory lookup
This commit is contained in:
commit
0ebd7554bc
|
@ -3883,23 +3883,35 @@ void cmGeneratorTarget::GetTargetVersion(bool soversion, int& major,
|
|||
}
|
||||
}
|
||||
|
||||
std::string cmGeneratorTarget::GetFortranModuleDirectory() const
|
||||
std::string cmGeneratorTarget::GetFortranModuleDirectory(
|
||||
std::string const& working_dir) const
|
||||
{
|
||||
if (!this->FortranModuleDirectoryCreated) {
|
||||
this->FortranModuleDirectory = true;
|
||||
this->FortranModuleDirectory = this->CreateFortranModuleDirectory();
|
||||
this->FortranModuleDirectory =
|
||||
this->CreateFortranModuleDirectory(working_dir);
|
||||
}
|
||||
|
||||
return this->FortranModuleDirectory;
|
||||
}
|
||||
|
||||
std::string cmGeneratorTarget::CreateFortranModuleDirectory() const
|
||||
std::string cmGeneratorTarget::CreateFortranModuleDirectory(
|
||||
std::string const& working_dir) const
|
||||
{
|
||||
std::string mod_dir;
|
||||
const char* target_mod_dir = this->GetProperty("Fortran_MODULE_DIRECTORY");
|
||||
std::string target_mod_dir;
|
||||
if (const char* prop = this->GetProperty("Fortran_MODULE_DIRECTORY")) {
|
||||
target_mod_dir = prop;
|
||||
} else {
|
||||
std::string const& default_mod_dir =
|
||||
this->LocalGenerator->GetCurrentBinaryDirectory();
|
||||
if (default_mod_dir != working_dir) {
|
||||
target_mod_dir = default_mod_dir;
|
||||
}
|
||||
}
|
||||
const char* moddir_flag =
|
||||
this->Makefile->GetDefinition("CMAKE_Fortran_MODDIR_FLAG");
|
||||
if (target_mod_dir && moddir_flag) {
|
||||
if (!target_mod_dir.empty() && moddir_flag) {
|
||||
// Compute the full path to the module directory.
|
||||
if (cmSystemTools::FileIsFullPath(target_mod_dir)) {
|
||||
// Already a full path.
|
||||
|
|
|
@ -537,12 +537,13 @@ public:
|
|||
void GetTargetVersion(bool soversion, int& major, int& minor,
|
||||
int& patch) const;
|
||||
|
||||
std::string GetFortranModuleDirectory() const;
|
||||
std::string GetFortranModuleDirectory(std::string const& working_dir) const;
|
||||
|
||||
private:
|
||||
void AddSourceCommon(const std::string& src);
|
||||
|
||||
std::string CreateFortranModuleDirectory() const;
|
||||
std::string CreateFortranModuleDirectory(
|
||||
std::string const& working_dir) const;
|
||||
mutable bool FortranModuleDirectoryCreated;
|
||||
mutable std::string FortranModuleDirectory;
|
||||
|
||||
|
|
|
@ -54,7 +54,8 @@ std::string cmLocalCommonGenerator::GetTargetFortranFlags(
|
|||
}
|
||||
|
||||
// Add a module output directory flag if necessary.
|
||||
std::string mod_dir = target->GetFortranModuleDirectory();
|
||||
std::string mod_dir =
|
||||
target->GetFortranModuleDirectory(this->WorkingDirectory);
|
||||
if (!mod_dir.empty()) {
|
||||
mod_dir = this->ConvertToOutputFormat(
|
||||
this->ConvertToRelativePath(this->WorkingDirectory, mod_dir),
|
||||
|
|
|
@ -993,12 +993,16 @@ void cmMakefileTargetGenerator::WriteTargetDependRules()
|
|||
*this->InfoFileStream << " )\n";
|
||||
}
|
||||
|
||||
std::string const& working_dir =
|
||||
this->LocalGenerator->GetCurrentBinaryDirectory();
|
||||
|
||||
/* clang-format off */
|
||||
*this->InfoFileStream
|
||||
<< "\n"
|
||||
<< "# Fortran module output directory.\n"
|
||||
<< "set(CMAKE_Fortran_TARGET_MODULE_DIR \""
|
||||
<< this->GeneratorTarget->GetFortranModuleDirectory() << "\")\n";
|
||||
<< this->GeneratorTarget->GetFortranModuleDirectory(working_dir)
|
||||
<< "\")\n";
|
||||
/* clang-format on */
|
||||
|
||||
// and now write the rule to use it
|
||||
|
|
Loading…
Reference in New Issue