mirror of
https://github.com/reactos/CMake.git
synced 2025-01-20 18:34:22 +00:00
cmake: Refactor file extension list setup
Refactor the file extention list setup in cmake.h/cxx and add file extensions lists for Cuda and Fortran.
This commit is contained in:
parent
8214ad442f
commit
e50fa44a35
@ -104,7 +104,6 @@
|
||||
#include <cstring>
|
||||
#include <initializer_list>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <memory> // IWYU pragma: keep
|
||||
#include <sstream>
|
||||
#include <stdio.h>
|
||||
@ -122,9 +121,9 @@ typedef std::unordered_map<std::string, Json::Value> JsonValueMapType;
|
||||
static bool cmakeCheckStampFile(const std::string& stampName);
|
||||
static bool cmakeCheckStampList(const std::string& stampList);
|
||||
|
||||
void cmWarnUnusedCliWarning(const std::string& variable, int /*unused*/,
|
||||
void* ctx, const char* /*unused*/,
|
||||
const cmMakefile* /*unused*/)
|
||||
static void cmWarnUnusedCliWarning(const std::string& variable, int /*unused*/,
|
||||
void* ctx, const char* /*unused*/,
|
||||
const cmMakefile* /*unused*/)
|
||||
{
|
||||
cmake* cm = reinterpret_cast<cmake*>(ctx);
|
||||
cm->MarkCliAsUsed(variable);
|
||||
@ -184,40 +183,36 @@ cmake::cmake(Role role, cmState::Mode mode)
|
||||
// Make sure we can capture the build tool output.
|
||||
cmSystemTools::EnableVSConsoleOutput();
|
||||
|
||||
// Set up a list of source and header extensions
|
||||
// these are used to find files when the extension
|
||||
// is not given
|
||||
// The "c" extension MUST precede the "C" extension.
|
||||
this->SourceFileExtensions.emplace_back("c");
|
||||
this->SourceFileExtensions.emplace_back("C");
|
||||
// Set up a list of source and header extensions.
|
||||
// These are used to find files when the extension is not given.
|
||||
{
|
||||
auto fillExts = [](FileExtensions& exts,
|
||||
std::initializer_list<const char*> extList) {
|
||||
// Fill ordered vector
|
||||
exts.ordered.reserve(extList.size());
|
||||
for (const char* ext : extList) {
|
||||
exts.ordered.emplace_back(ext);
|
||||
};
|
||||
// Fill unordered set
|
||||
exts.unordered.insert(exts.ordered.begin(), exts.ordered.end());
|
||||
};
|
||||
|
||||
this->SourceFileExtensions.emplace_back("c++");
|
||||
this->SourceFileExtensions.emplace_back("cc");
|
||||
this->SourceFileExtensions.emplace_back("cpp");
|
||||
this->SourceFileExtensions.emplace_back("cxx");
|
||||
this->SourceFileExtensions.emplace_back("cu");
|
||||
this->SourceFileExtensions.emplace_back("m");
|
||||
this->SourceFileExtensions.emplace_back("M");
|
||||
this->SourceFileExtensions.emplace_back("mm");
|
||||
// Source extensions
|
||||
// The "c" extension MUST precede the "C" extension.
|
||||
fillExts(this->SourceFileExtensions,
|
||||
{ "c", "C", "c++", "cc", "cpp", "cxx", "cu", "m", "M", "mm" });
|
||||
|
||||
std::copy(this->SourceFileExtensions.begin(),
|
||||
this->SourceFileExtensions.end(),
|
||||
std::inserter(this->SourceFileExtensionsSet,
|
||||
this->SourceFileExtensionsSet.end()));
|
||||
// Header extensions
|
||||
fillExts(this->HeaderFileExtensions,
|
||||
{ "h", "hh", "h++", "hm", "hpp", "hxx", "in", "txx" });
|
||||
|
||||
this->HeaderFileExtensions.emplace_back("h");
|
||||
this->HeaderFileExtensions.emplace_back("hh");
|
||||
this->HeaderFileExtensions.emplace_back("h++");
|
||||
this->HeaderFileExtensions.emplace_back("hm");
|
||||
this->HeaderFileExtensions.emplace_back("hpp");
|
||||
this->HeaderFileExtensions.emplace_back("hxx");
|
||||
this->HeaderFileExtensions.emplace_back("in");
|
||||
this->HeaderFileExtensions.emplace_back("txx");
|
||||
// Cuda extensions
|
||||
fillExts(this->CudaFileExtensions, { "cu" });
|
||||
|
||||
std::copy(this->HeaderFileExtensions.begin(),
|
||||
this->HeaderFileExtensions.end(),
|
||||
std::inserter(this->HeaderFileExtensionsSet,
|
||||
this->HeaderFileExtensionsSet.end()));
|
||||
// Fortran extensions
|
||||
fillExts(this->FortranFileExtensions,
|
||||
{ "f", "F", "for", "f77", "f90", "f95", "f03" });
|
||||
}
|
||||
}
|
||||
|
||||
cmake::~cmake()
|
||||
|
@ -121,6 +121,17 @@ public:
|
||||
bool isAlias;
|
||||
};
|
||||
|
||||
struct FileExtensions
|
||||
{
|
||||
bool Test(std::string const& ext) const
|
||||
{
|
||||
return (this->unordered.find(ext) != this->unordered.end());
|
||||
}
|
||||
|
||||
std::vector<std::string> ordered;
|
||||
std::unordered_set<std::string> unordered;
|
||||
};
|
||||
|
||||
typedef std::map<std::string, cmInstalledFile> InstalledFilesMap;
|
||||
|
||||
static const int NO_BUILD_PARALLEL_LEVEL = -1;
|
||||
@ -233,24 +244,42 @@ public:
|
||||
|
||||
const std::vector<std::string>& GetSourceExtensions() const
|
||||
{
|
||||
return this->SourceFileExtensions;
|
||||
return this->SourceFileExtensions.ordered;
|
||||
}
|
||||
|
||||
bool IsSourceExtension(const std::string& ext) const
|
||||
{
|
||||
return this->SourceFileExtensionsSet.find(ext) !=
|
||||
this->SourceFileExtensionsSet.end();
|
||||
return this->SourceFileExtensions.Test(ext);
|
||||
}
|
||||
|
||||
const std::vector<std::string>& GetHeaderExtensions() const
|
||||
{
|
||||
return this->HeaderFileExtensions;
|
||||
return this->HeaderFileExtensions.ordered;
|
||||
}
|
||||
|
||||
bool IsHeaderExtension(const std::string& ext) const
|
||||
{
|
||||
return this->HeaderFileExtensionsSet.find(ext) !=
|
||||
this->HeaderFileExtensionsSet.end();
|
||||
return this->HeaderFileExtensions.Test(ext);
|
||||
}
|
||||
|
||||
const std::vector<std::string>& GetCudaExtensions() const
|
||||
{
|
||||
return this->CudaFileExtensions.ordered;
|
||||
}
|
||||
|
||||
bool IsCudaExtension(const std::string& ext) const
|
||||
{
|
||||
return this->CudaFileExtensions.Test(ext);
|
||||
}
|
||||
|
||||
const std::vector<std::string>& GetFortranExtensions() const
|
||||
{
|
||||
return this->FortranFileExtensions.ordered;
|
||||
}
|
||||
|
||||
bool IsFortranExtension(const std::string& ext) const
|
||||
{
|
||||
return this->FortranFileExtensions.Test(ext);
|
||||
}
|
||||
|
||||
// Strips the extension (if present and known) from a filename
|
||||
@ -531,10 +560,10 @@ private:
|
||||
std::string CheckStampList;
|
||||
std::string VSSolutionFile;
|
||||
std::string EnvironmentGenerator;
|
||||
std::vector<std::string> SourceFileExtensions;
|
||||
std::unordered_set<std::string> SourceFileExtensionsSet;
|
||||
std::vector<std::string> HeaderFileExtensions;
|
||||
std::unordered_set<std::string> HeaderFileExtensionsSet;
|
||||
FileExtensions SourceFileExtensions;
|
||||
FileExtensions HeaderFileExtensions;
|
||||
FileExtensions CudaFileExtensions;
|
||||
FileExtensions FortranFileExtensions;
|
||||
bool ClearBuildSystem;
|
||||
bool DebugTryCompile;
|
||||
std::unique_ptr<cmFileTimeCache> FileTimeCache;
|
||||
|
Loading…
x
Reference in New Issue
Block a user