cmake/Source/cmLocalCommonGenerator.cxx

113 lines
3.6 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
2015-11-17 17:22:37 +01:00
#include "cmLocalCommonGenerator.h"
2018-04-23 21:13:27 +02:00
#include <utility>
2017-04-14 19:02:05 +02:00
#include <vector>
2016-10-30 18:24:19 +01:00
#include "cmGeneratorTarget.h"
2015-11-17 17:22:37 +01:00
#include "cmMakefile.h"
2017-04-14 19:02:05 +02:00
#include "cmOutputConverter.h"
2021-09-14 00:13:48 +02:00
#include "cmProperty.h"
#include "cmState.h"
#include "cmStateDirectory.h"
#include "cmStateSnapshot.h"
2020-02-01 23:06:01 +01:00
#include "cmStringAlgorithms.h"
2016-10-30 18:24:19 +01:00
class cmGlobalGenerator;
2015-11-17 17:22:37 +01:00
cmLocalCommonGenerator::cmLocalCommonGenerator(cmGlobalGenerator* gg,
2021-09-14 00:13:48 +02:00
cmMakefile* mf, WorkDir wd)
2016-07-09 11:21:54 +02:00
: cmLocalGenerator(gg, mf)
2021-09-14 00:13:48 +02:00
, WorkingDirectory(wd)
2015-11-17 17:22:37 +01:00
{
2021-09-14 00:13:48 +02:00
this->ConfigNames =
this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);
2015-11-17 17:22:37 +01:00
}
2016-10-30 18:24:19 +01:00
2019-11-11 23:01:05 +01:00
cmLocalCommonGenerator::~cmLocalCommonGenerator() = default;
2017-07-20 19:35:53 +02:00
2021-09-14 00:13:48 +02:00
std::string const& cmLocalCommonGenerator::GetWorkingDirectory() const
{
if (this->WorkingDirectory == WorkDir::TopBin) {
return this->GetState()->GetBinaryDirectory();
}
return this->StateSnapshot.GetDirectory().GetCurrentBinary();
}
std::string cmLocalCommonGenerator::MaybeRelativeToWorkDir(
std::string const& path) const
{
if (this->WorkingDirectory == WorkDir::TopBin) {
return this->MaybeRelativeToTopBinDir(path);
}
return this->MaybeRelativeToCurBinDir(path);
}
2016-10-30 18:24:19 +01:00
std::string cmLocalCommonGenerator::GetTargetFortranFlags(
cmGeneratorTarget const* target, std::string const& config)
{
std::string flags;
// Enable module output if necessary.
2020-02-01 23:06:01 +01:00
this->AppendFlags(
flags, this->Makefile->GetSafeDefinition("CMAKE_Fortran_MODOUT_FLAG"));
2016-10-30 18:24:19 +01:00
// Add a module output directory flag if necessary.
std::string mod_dir =
2021-09-14 00:13:48 +02:00
target->GetFortranModuleDirectory(this->GetWorkingDirectory());
2016-10-30 18:24:19 +01:00
if (!mod_dir.empty()) {
mod_dir = this->ConvertToOutputFormat(
2021-09-14 00:13:48 +02:00
this->MaybeRelativeToWorkDir(mod_dir), cmOutputConverter::SHELL);
2016-10-30 18:24:19 +01:00
} else {
mod_dir =
this->Makefile->GetSafeDefinition("CMAKE_Fortran_MODDIR_DEFAULT");
}
if (!mod_dir.empty()) {
2020-02-01 23:06:01 +01:00
std::string modflag = cmStrCat(
this->Makefile->GetRequiredDefinition("CMAKE_Fortran_MODDIR_FLAG"),
mod_dir);
2016-10-30 18:24:19 +01:00
this->AppendFlags(flags, modflag);
2020-08-30 11:54:41 +02:00
// Some compilers do not search their own module output directory
// for using other modules. Add an include directory explicitly
// for consistency with compilers that do search it.
std::string incflag =
this->Makefile->GetSafeDefinition("CMAKE_Fortran_MODDIR_INCLUDE_FLAG");
if (!incflag.empty()) {
incflag = cmStrCat(incflag, mod_dir);
this->AppendFlags(flags, incflag);
}
2016-10-30 18:24:19 +01:00
}
// 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.
2021-09-14 00:13:48 +02:00
if (cmProp modpath_flag =
2016-10-30 18:24:19 +01:00
this->Makefile->GetDefinition("CMAKE_Fortran_MODPATH_FLAG")) {
std::vector<std::string> includes;
this->GetIncludeDirectories(includes, target, "C", config);
2018-01-26 17:06:56 +01:00
for (std::string const& id : includes) {
2020-02-01 23:06:01 +01:00
std::string flg =
2021-09-14 00:13:48 +02:00
cmStrCat(*modpath_flag,
2020-02-01 23:06:01 +01:00
this->ConvertToOutputFormat(id, cmOutputConverter::SHELL));
2016-10-30 18:24:19 +01:00
this->AppendFlags(flags, flg);
}
}
return flags;
}
2018-04-23 21:13:27 +02:00
void cmLocalCommonGenerator::ComputeObjectFilenames(
std::map<cmSourceFile const*, std::string>& mapping,
cmGeneratorTarget const* gt)
{
// Determine if these object files should use a custom extension
char const* custom_ext = gt->GetCustomObjectExtension();
for (auto& si : mapping) {
cmSourceFile const* sf = si.first;
bool keptSourceExtension;
si.second = this->GetObjectFileNameWithoutTarget(
*sf, gt->ObjectDirectory, &keptSourceExtension, custom_ext);
}
}