diff options
author | Brad King <brad.king@kitware.com> | 2007-12-30 21:11:38 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2007-12-30 21:11:38 (GMT) |
commit | b2e8c07af8bca0122d4dfe62c8341dc58c0da2fa (patch) | |
tree | f6604b080cf5707dfb3998c276b72445b57659fe /Source/cmMakefileTargetGenerator.cxx | |
parent | cd8a2bbab69af0b36076a7acb0af85dedc4f0f1c (diff) | |
download | CMake-b2e8c07af8bca0122d4dfe62c8341dc58c0da2fa.zip CMake-b2e8c07af8bca0122d4dfe62c8341dc58c0da2fa.tar.gz CMake-b2e8c07af8bca0122d4dfe62c8341dc58c0da2fa.tar.bz2 |
ENH: Implemented Fortran module output directory and search path flags.
Diffstat (limited to 'Source/cmMakefileTargetGenerator.cxx')
-rw-r--r-- | Source/cmMakefileTargetGenerator.cxx | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index 13c1b64..0e9ccc5 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -36,6 +36,7 @@ cmMakefileTargetGenerator::cmMakefileTargetGenerator() this->InfoFileStream = 0; this->FlagFileStream = 0; this->CustomCommandDriver = OnBuild; + this->FortranModuleDirectoryComputed = false; } cmMakefileTargetGenerator * @@ -268,6 +269,12 @@ void cmMakefileTargetGenerator::WriteTargetLanguageFlags() ->AddLanguageFlags(flags, lang, this->LocalGenerator->ConfigurationName.c_str()); + // Fortran-specific flags computed for this target. + if(*l == "Fortran") + { + this->AddFortranFlags(flags); + } + // Add shared-library flags if needed. this->LocalGenerator->AddSharedFlags(flags, lang, shared); @@ -823,6 +830,15 @@ void cmMakefileTargetGenerator::WriteTargetDependRules() << " )\n"; } + // Check for a target-specific module output directory. + if(const char* mdir = this->GetFortranModuleDirectory()) + { + *this->InfoFileStream + << "\n" + << "# Fortran module output directory.\n" + << "SET(CMAKE_Fortran_TARGET_MODULE_DIR \"" << mdir << "\")\n"; + } + // and now write the rule to use it std::vector<std::string> depends; std::vector<std::string> commands; @@ -1423,3 +1439,82 @@ cmMakefileTargetGenerator link_command += " --verbose=$(VERBOSE)"; makefile_commands.push_back(link_command); } + +//---------------------------------------------------------------------------- +const char* cmMakefileTargetGenerator::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->GetCurrentOutputDirectory(); + this->FortranModuleDirectory += "/"; + this->FortranModuleDirectory += target_mod_dir; + } + + // Make sure the module output directory exists. + cmSystemTools::MakeDirectory(this->FortranModuleDirectory.c_str()); + } + this->FortranModuleDirectoryComputed = true; + } + + // Return the computed directory. + if(this->FortranModuleDirectory.empty()) + { + return 0; + } + else + { + return this->FortranModuleDirectory.c_str(); + } +} + +//---------------------------------------------------------------------------- +void cmMakefileTargetGenerator::AddFortranFlags(std::string& flags) +{ + // Add a module output directory flag if necessary. + if(const char* mod_dir = this->GetFortranModuleDirectory()) + { + const char* moddir_flag = + this->Makefile->GetRequiredDefinition("CMAKE_Fortran_MODDIR_FLAG"); + std::string modflag = moddir_flag; + modflag += this->Convert(mod_dir, + cmLocalGenerator::START_OUTPUT, + cmLocalGenerator::SHELL); + this->LocalGenerator->AppendFlags(flags, modflag.c_str()); + } + + // If there is a separate module path flag then duplicate the + // include path with it. This compiler does not search the include + // path for modules. + if(const char* modpath_flag = + this->Makefile->GetDefinition("CMAKE_Fortran_MODPATH_FLAG")) + { + std::vector<std::string> includes; + this->LocalGenerator->GetIncludeDirectories(includes); + for(std::vector<std::string>::const_iterator idi = includes.begin(); + idi != includes.end(); ++idi) + { + std::string flg = modpath_flag; + flg += this->Convert(idi->c_str(), + cmLocalGenerator::NONE, + cmLocalGenerator::SHELL); + this->LocalGenerator->AppendFlags(flags, flg.c_str()); + } + } +} |