Merge topic 'autogen_header_extension'

f8a310c9d1 cmSystemTools: Remove cmSystemTools::FileFormat method
90b5289c55 cmExtraCodeLiteGenerator: Use cmake::Is*Extension for file type detection
e50fa44a35 cmake: Refactor file extension list setup
8214ad442f Tests: Autogen: Extend SameName test with additional header extensions
4a9154537c Autogen: Use cmake::IsHeader/SourceExtension for file type detection

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !3511
This commit is contained in:
Brad King
2019-07-08 17:00:33 +00:00
committed by Kitware Robot
10 changed files with 123 additions and 156 deletions
+9 -10
View File
@@ -217,22 +217,21 @@ std::string cmExtraCodeLiteGenerator::CollectSourceFiles(
case cmStateEnums::STATIC_LIBRARY:
case cmStateEnums::SHARED_LIBRARY:
case cmStateEnums::MODULE_LIBRARY: {
cmake const* cm = makefile->GetCMakeInstance();
std::vector<cmSourceFile*> sources;
gt->GetSourceFiles(sources,
makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
for (cmSourceFile* s : sources) {
std::string const& fullPath = s->GetFullPath();
std::string const& extLower =
cmSystemTools::LowerCase(s->GetExtension());
// check whether it is a source or a include file
// then put it accordingly into one of the two containers
switch (cmSystemTools::GetFileFormat(s->GetExtension())) {
case cmSystemTools::C_FILE_FORMAT:
case cmSystemTools::CXX_FILE_FORMAT:
case cmSystemTools::CUDA_FILE_FORMAT:
case cmSystemTools::FORTRAN_FILE_FORMAT: {
cFiles[s->GetFullPath()] = s;
} break;
default: {
otherFiles.insert(s->GetFullPath());
}
if (cm->IsSourceExtension(extLower) || cm->IsCudaExtension(extLower) ||
cm->IsFortranExtension(extLower)) {
cFiles[fullPath] = s;
} else {
otherFiles.insert(fullPath);
}
}
}
+14 -17
View File
@@ -620,6 +620,7 @@ bool cmQtAutoGenInitializer::InitRcc()
bool cmQtAutoGenInitializer::InitScanFiles()
{
cmMakefile* makefile = this->Target->Target->GetMakefile();
cmake const* cm = makefile->GetCMakeInstance();
auto const& kw = this->GlobalInitializer->kw();
auto makeMUFile = [this, &kw](cmSourceFile* sf, std::string const& fullPath,
@@ -665,25 +666,21 @@ bool cmQtAutoGenInitializer::InitScanFiles()
if (!pathError.empty() || fullPath.empty()) {
continue;
}
std::string const& ext = sf->GetExtension();
std::string const& extLower =
cmSystemTools::LowerCase(sf->GetExtension());
// Register files that will be scanned by moc or uic
if (this->MocOrUicEnabled()) {
switch (cmSystemTools::GetFileFormat(ext)) {
case cmSystemTools::HEADER_FILE_FORMAT:
addMUFile(makeMUFile(sf, fullPath, true), true);
break;
case cmSystemTools::CXX_FILE_FORMAT:
addMUFile(makeMUFile(sf, fullPath, true), false);
break;
default:
break;
if (cm->IsHeaderExtension(extLower)) {
addMUFile(makeMUFile(sf, fullPath, true), true);
} else if (cm->IsSourceExtension(extLower)) {
addMUFile(makeMUFile(sf, fullPath, true), false);
}
}
// Register rcc enabled files
if (this->Rcc.Enabled) {
if ((ext == kw.qrc) && !sf->GetPropertyAsBool(kw.SKIP_AUTOGEN) &&
if ((extLower == kw.qrc) && !sf->GetPropertyAsBool(kw.SKIP_AUTOGEN) &&
!sf->GetPropertyAsBool(kw.SKIP_AUTORCC)) {
// Register qrc file
Qrc qrc;
@@ -715,7 +712,7 @@ bool cmQtAutoGenInitializer::InitScanFiles()
extraHeaders.reserve(this->AutogenTarget.Sources.size() * 2);
// Header search suffixes and extensions
std::array<std::string, 2> const suffixes{ { "", "_p" } };
auto const& exts = makefile->GetCMakeInstance()->GetHeaderExtensions();
auto const& exts = cm->GetHeaderExtensions();
// Scan through sources
for (auto const& pair : this->AutogenTarget.Sources) {
MUFile const& muf = *pair.second;
@@ -784,10 +781,10 @@ bool cmQtAutoGenInitializer::InitScanFiles()
if (!pathError.empty() || fullPath.empty()) {
continue;
}
std::string const& ext = sf->GetExtension();
std::string const& extLower =
cmSystemTools::LowerCase(sf->GetExtension());
auto const fileFormat = cmSystemTools::GetFileFormat(ext);
if (fileFormat == cmSystemTools::HEADER_FILE_FORMAT) {
if (cm->IsHeaderExtension(extLower)) {
if (this->AutogenTarget.Headers.find(sf) ==
this->AutogenTarget.Headers.end()) {
auto muf = makeMUFile(sf, fullPath, false);
@@ -795,7 +792,7 @@ bool cmQtAutoGenInitializer::InitScanFiles()
this->AutogenTarget.Headers.emplace(sf, std::move(muf));
}
}
} else if (fileFormat == cmSystemTools::CXX_FILE_FORMAT) {
} else if (cm->IsSourceExtension(extLower)) {
if (this->AutogenTarget.Sources.find(sf) ==
this->AutogenTarget.Sources.end()) {
auto muf = makeMUFile(sf, fullPath, false);
@@ -803,7 +800,7 @@ bool cmQtAutoGenInitializer::InitScanFiles()
this->AutogenTarget.Sources.emplace(sf, std::move(muf));
}
}
} else if (this->Uic.Enabled && (ext == kw.ui)) {
} else if (this->Uic.Enabled && (extLower == kw.ui)) {
// .ui file
std::string realPath = cmSystemTools::GetRealPath(fullPath);
bool const skipAutogen = sf->GetPropertyAsBool(kw.SKIP_AUTOGEN);
-59
View File
@@ -1264,65 +1264,6 @@ bool cmSystemTools::SimpleGlob(const std::string& glob,
return res;
}
cmSystemTools::FileFormat cmSystemTools::GetFileFormat(std::string const& ext)
{
if (ext.empty()) {
return cmSystemTools::NO_FILE_FORMAT;
}
if (ext == "c" || ext == ".c" || ext == "m" || ext == ".m") {
return cmSystemTools::C_FILE_FORMAT;
}
if (ext == "C" || ext == ".C" || ext == "M" || ext == ".M" || ext == "c++" ||
ext == ".c++" || ext == "cc" || ext == ".cc" || ext == "cpp" ||
ext == ".cpp" || ext == "cxx" || ext == ".cxx" || ext == "mm" ||
ext == ".mm") {
return cmSystemTools::CXX_FILE_FORMAT;
}
if (ext == "f" || ext == ".f" || ext == "F" || ext == ".F" || ext == "f77" ||
ext == ".f77" || ext == "f90" || ext == ".f90" || ext == "for" ||
ext == ".for" || ext == "f95" || ext == ".f95") {
return cmSystemTools::FORTRAN_FILE_FORMAT;
}
if (ext == "java" || ext == ".java") {
return cmSystemTools::JAVA_FILE_FORMAT;
}
if (ext == "cu" || ext == ".cu") {
return cmSystemTools::CUDA_FILE_FORMAT;
}
if (ext == "H" || ext == ".H" || ext == "h" || ext == ".h" || ext == "h++" ||
ext == ".h++" || ext == "hm" || ext == ".hm" || ext == "hpp" ||
ext == ".hpp" || ext == "hxx" || ext == ".hxx" || ext == "in" ||
ext == ".in" || ext == "txx" || ext == ".txx") {
return cmSystemTools::HEADER_FILE_FORMAT;
}
if (ext == "rc" || ext == ".rc") {
return cmSystemTools::RESOURCE_FILE_FORMAT;
}
if (ext == "def" || ext == ".def") {
return cmSystemTools::DEFINITION_FILE_FORMAT;
}
if (ext == "lib" || ext == ".lib" || ext == "a" || ext == ".a") {
return cmSystemTools::STATIC_LIBRARY_FILE_FORMAT;
}
if (ext == "o" || ext == ".o" || ext == "obj" || ext == ".obj") {
return cmSystemTools::OBJECT_FILE_FORMAT;
}
#ifdef __APPLE__
if (ext == "dylib" || ext == ".dylib") {
return cmSystemTools::SHARED_LIBRARY_FILE_FORMAT;
}
if (ext == "so" || ext == ".so" || ext == "bundle" || ext == ".bundle") {
return cmSystemTools::MODULE_FILE_FORMAT;
}
#else // __APPLE__
if (ext == "so" || ext == ".so" || ext == "sl" || ext == ".sl" ||
ext == "dll" || ext == ".dll") {
return cmSystemTools::SHARED_LIBRARY_FILE_FORMAT;
}
#endif // __APPLE__
return cmSystemTools::UNKNOWN_FILE_FORMAT;
}
std::string cmSystemTools::ConvertToOutputPath(std::string const& path)
{
#if defined(_WIN32) && !defined(__CYGWIN__)
-26
View File
@@ -299,27 +299,6 @@ public:
static void EnableRunCommandOutput() { s_DisableRunCommandOutput = false; }
static bool GetRunCommandOutput() { return s_DisableRunCommandOutput; }
/**
* Some constants for different file formats.
*/
enum FileFormat
{
NO_FILE_FORMAT = 0,
C_FILE_FORMAT,
CXX_FILE_FORMAT,
FORTRAN_FILE_FORMAT,
JAVA_FILE_FORMAT,
CUDA_FILE_FORMAT,
HEADER_FILE_FORMAT,
RESOURCE_FILE_FORMAT,
DEFINITION_FILE_FORMAT,
STATIC_LIBRARY_FILE_FORMAT,
SHARED_LIBRARY_FILE_FORMAT,
MODULE_FILE_FORMAT,
OBJECT_FILE_FORMAT,
UNKNOWN_FILE_FORMAT
};
enum CompareOp
{
OP_EQUAL = 1,
@@ -350,11 +329,6 @@ public:
*/
static int strverscmp(std::string const& lhs, std::string const& rhs);
/**
* Determine the file type based on the extension
*/
static FileFormat GetFileFormat(std::string const& ext);
/** Windows if this is true, the CreateProcess in RunCommand will
* not show new console windows when running programs.
*/
+29 -34
View File
@@ -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()
+39 -10
View File
@@ -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;
+2
View File
@@ -18,9 +18,11 @@ add_executable(sameName
ccc/data.qrc
item.cpp
object.h
object.hh
object.h++
object.hpp
object.hxx
object_upper_ext.H
data.qrc
main.cpp
)
+4
View File
@@ -6,8 +6,10 @@
#include "item.hpp"
#include "object.h"
#include "object.h++"
#include "object.hh"
#include "object.hpp"
#include "object.hxx"
#include "object_upper_ext.H"
int main(int argv, char** args)
{
@@ -20,8 +22,10 @@ int main(int argv, char** args)
::ccc::Item ccc_item;
// Object instances
::Object_h obj_h;
::Object_hh obj_hh;
::Object_hplpl obj_hplpl;
::Object_hpp obj_hpp;
::Object_hxx obj_hxx;
::Object_Upper_Ext_H obj_upper_ext_h;
return 0;
}
+13
View File
@@ -0,0 +1,13 @@
#ifndef OBJECT_HH
#define OBJECT_HH
#include <QObject>
class Object_hh : public QObject
{
Q_OBJECT
Q_SLOT
void go(){};
};
#endif
@@ -0,0 +1,13 @@
#ifndef OBJECT_UPPER_EXT_H
#define OBJECT_UPPER_EXT_H
#include <QObject>
class Object_Upper_Ext_H : public QObject
{
Q_OBJECT
Q_SLOT
void go(){};
};
#endif