diff options
author | Brad King <brad.king@kitware.com> | 2016-09-19 15:36:00 -0400 |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-09-20 08:48:41 -0400 |
commit | 7b5f85677c8aa067a5fef1cc68f4d8c8600693fa (patch) | |
tree | 1f5d9a419980bb89df73afae0d44aba8c731b314 | |
parent | 1777570fe5eb194d930f6716865bc909269da57e (diff) | |
download | cmake-7b5f85677c8aa067a5fef1cc68f4d8c8600693fa.tar.gz |
Fortran: Use module dir flag if needed for default module directory
Our buildsystem model says that the default Fortran module output
directory is the build tree directory corresponding to the source tree
`CMakeLists.txt` file adding the current target. Extend
`cmGeneratorTarget::GetFortranModuleDirectory` to allow generators to
pass in the compiler working directory. If the working directory does
not match the default Fortran module output directory then we need an
explicit module directory flag (e.g. `-J`) to tell the compiler to
put/use modules in the latter.
This does not affect the Makefile generator but will be useful for
future introduction of Fortran support to the Ninja generator.
-rw-r--r-- | Source/cmGeneratorTarget.cxx | 15 | ||||
-rw-r--r-- | Source/cmGeneratorTarget.h | 5 | ||||
-rw-r--r-- | Source/cmLocalCommonGenerator.cxx | 3 | ||||
-rw-r--r-- | Source/cmMakefileTargetGenerator.cxx | 6 |
4 files changed, 22 insertions, 7 deletions
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index bed0b115a9..f181cf6244 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -3883,22 +3883,31 @@ 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; 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"); diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 715220e5d8..8e17b8f54a 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -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; diff --git a/Source/cmLocalCommonGenerator.cxx b/Source/cmLocalCommonGenerator.cxx index 97323c928e..b75ce62533 100644 --- a/Source/cmLocalCommonGenerator.cxx +++ b/Source/cmLocalCommonGenerator.cxx @@ -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), diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index 014feb9e94..e0d9fda83a 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -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 |