Commit f86ba8ee authored by Sebastian Holtermann's avatar Sebastian Holtermann
Browse files

Autogen: Reintroduce per-config sources support

Reintroduce per-config sources support in AUTOGEN but disable it by default.
parent 5d3bca64
# Meta
set(AM_MULTI_CONFIG @_multi_config@)
# Directories and files
set(AM_CMAKE_BINARY_DIR "@CMAKE_BINARY_DIR@/")
set(AM_CMAKE_SOURCE_DIR "@CMAKE_SOURCE_DIR@/")
......@@ -16,7 +18,7 @@ set(AM_QT_RCC_EXECUTABLE @_qt_rcc_executable@)
# MOC settings
set(AM_MOC_SKIP @_moc_skip@)
set(AM_MOC_DEFINITIONS @_moc_compile_defs@)
set(AM_MOC_INCLUDES @_moc_incs@)
set(AM_MOC_INCLUDES @_moc_include_dirs@)
set(AM_MOC_OPTIONS @_moc_options@)
set(AM_MOC_RELAXED_MODE @_moc_relaxed_mode@)
set(AM_MOC_MACRO_NAMES @_moc_macro_names@)
......
......@@ -14,18 +14,22 @@
// - Static variables
const std::string genNameGen = "AutoGen";
const std::string genNameMoc = "AutoMoc";
const std::string genNameUic = "AutoUic";
const std::string genNameRcc = "AutoRcc";
std::string const genNameGen = "AutoGen";
std::string const genNameMoc = "AutoMoc";
std::string const genNameUic = "AutoUic";
std::string const genNameRcc = "AutoRcc";
std::string const mcNameSingle = "SINGLE";
std::string const mcNameWrap = "WRAP";
std::string const mcNameFull = "FULL";
// - Static functions
/// @brief Merges newOpts into baseOpts
/// @arg valueOpts list of options that accept a value
void MergeOptions(std::vector<std::string>& baseOpts,
const std::vector<std::string>& newOpts,
const std::vector<std::string>& valueOpts, bool isQt5)
std::vector<std::string> const& newOpts,
std::vector<std::string> const& valueOpts, bool isQt5)
{
typedef std::vector<std::string>::iterator Iter;
typedef std::vector<std::string>::const_iterator CIter;
......@@ -40,7 +44,7 @@ void MergeOptions(std::vector<std::string>& baseOpts,
std::vector<std::string> extraOpts;
for (CIter fit = newOpts.begin(), fitEnd = newOpts.end(); fit != fitEnd;
++fit) {
const std::string& newOpt = *fit;
std::string const& newOpt = *fit;
Iter existIt = std::find(baseOpts.begin(), baseOpts.end(), newOpt);
if (existIt != baseOpts.end()) {
if (newOpt.size() >= 2) {
......@@ -87,7 +91,7 @@ static std::string utilStripCR(std::string const& line)
/// @brief Reads the resource files list from from a .qrc file - Qt4 version
/// @return True if the .qrc file was successfully parsed
static bool RccListInputsQt4(const std::string& fileName,
static bool RccListInputsQt4(std::string const& fileName,
std::vector<std::string>& files,
std::string* errorMessage)
{
......@@ -140,8 +144,8 @@ static bool RccListInputsQt4(const std::string& fileName,
/// @brief Reads the resource files list from from a .qrc file - Qt5 version
/// @return True if the .qrc file was successfully parsed
static bool RccListInputsQt5(const std::string& rccCommand,
const std::string& fileName,
static bool RccListInputsQt5(std::string const& rccCommand,
std::string const& fileName,
std::vector<std::string>& files,
std::string* errorMessage)
{
......@@ -244,9 +248,9 @@ static bool RccListInputsQt5(const std::string& rccCommand,
// - Class definitions
const std::string cmQtAutoGen::listSep = "@LSEP@";
std::string const cmQtAutoGen::listSep = "@LSEP@";
const std::string& cmQtAutoGen::GeneratorName(Generator type)
std::string const& cmQtAutoGen::GeneratorName(Generator type)
{
switch (type) {
case Generator::GEN:
......@@ -266,7 +270,31 @@ std::string cmQtAutoGen::GeneratorNameUpper(Generator genType)
return cmSystemTools::UpperCase(cmQtAutoGen::GeneratorName(genType));
}
std::string cmQtAutoGen::Quoted(const std::string& text)
std::string const& cmQtAutoGen::MultiConfigName(MultiConfig config)
{
switch (config) {
case MultiConfig::SINGLE:
return mcNameSingle;
case MultiConfig::WRAP:
return mcNameWrap;
case MultiConfig::FULL:
return mcNameFull;
}
return mcNameWrap;
}
cmQtAutoGen::MultiConfig cmQtAutoGen::MultiConfigType(std::string const& name)
{
if (name == mcNameSingle) {
return MultiConfig::SINGLE;
}
if (name == mcNameFull) {
return MultiConfig::FULL;
}
return MultiConfig::WRAP;
}
std::string cmQtAutoGen::Quoted(std::string const& text)
{
static const char* rep[18] = { "\\", "\\\\", "\"", "\\\"", "\a", "\\a",
"\b", "\\b", "\f", "\\f", "\n", "\\n",
......@@ -282,11 +310,28 @@ std::string cmQtAutoGen::Quoted(const std::string& text)
return res;
}
std::string cmQtAutoGen::AppendFilenameSuffix(std::string const& filename,
std::string const& suffix)
{
std::string res;
auto pos = filename.rfind('.');
if (pos != std::string::npos) {
const auto it_dot = filename.begin() + pos;
res.assign(filename.begin(), it_dot);
res.append(suffix);
res.append(it_dot, filename.end());
} else {
res = filename;
res.append(suffix);
}
return res;
}
void cmQtAutoGen::UicMergeOptions(std::vector<std::string>& baseOpts,
const std::vector<std::string>& newOpts,
std::vector<std::string> const& newOpts,
bool isQt5)
{
static const std::vector<std::string> valueOpts = {
static std::vector<std::string> const valueOpts = {
"tr", "translate", "postfix", "generator",
"include", // Since Qt 5.3
"g"
......@@ -295,18 +340,18 @@ void cmQtAutoGen::UicMergeOptions(std::vector<std::string>& baseOpts,
}
void cmQtAutoGen::RccMergeOptions(std::vector<std::string>& baseOpts,
const std::vector<std::string>& newOpts,
std::vector<std::string> const& newOpts,
bool isQt5)
{
static const std::vector<std::string> valueOpts = { "name", "root",
static std::vector<std::string> const valueOpts = { "name", "root",
"compress",
"threshold" };
MergeOptions(baseOpts, newOpts, valueOpts, isQt5);
}
bool cmQtAutoGen::RccListInputs(const std::string& qtMajorVersion,
const std::string& rccCommand,
const std::string& fileName,
bool cmQtAutoGen::RccListInputs(std::string const& qtMajorVersion,
std::string const& rccCommand,
std::string const& fileName,
std::vector<std::string>& files,
std::string* errorMessage)
{
......
......@@ -14,7 +14,7 @@
class cmQtAutoGen
{
public:
static const std::string listSep;
static std::string const listSep;
enum Generator
{
......@@ -24,32 +24,47 @@ public:
RCC
};
enum MultiConfig
{
SINGLE, // Single configuration
WRAP, // Multi configuration using wrapper files
FULL // Full multi configuration using per config sources
};
public:
/// @brief Returns the generator name
static const std::string& GeneratorName(Generator genType);
static std::string const& GeneratorName(Generator genType);
/// @brief Returns the generator name in upper case
static std::string GeneratorNameUpper(Generator genType);
/// @brief Returns the multi configuration name string
static std::string const& MultiConfigName(MultiConfig config);
/// @brief Returns the multi configuration type
static MultiConfig MultiConfigType(std::string const& name);
/// @brief Returns a the string escaped and enclosed in quotes
///
static std::string Quoted(const std::string& text);
static std::string Quoted(std::string const& text);
/// @brief Appends the suffix to the filename before the last dot
static std::string AppendFilenameSuffix(std::string const& filename,
std::string const& suffix);
/// @brief Merges newOpts into baseOpts
static void UicMergeOptions(std::vector<std::string>& baseOpts,
const std::vector<std::string>& newOpts,
std::vector<std::string> const& newOpts,
bool isQt5);
/// @brief Merges newOpts into baseOpts
static void RccMergeOptions(std::vector<std::string>& baseOpts,
const std::vector<std::string>& newOpts,
std::vector<std::string> const& newOpts,
bool isQt5);
/// @brief Reads the resource files list from from a .qrc file
/// @arg fileName Must be the absolute path of the .qrc file
/// @return True if the rcc file was successfully parsed
static bool RccListInputs(const std::string& qtMajorVersion,
const std::string& rccCommand,
const std::string& fileName,
static bool RccListInputs(std::string const& qtMajorVersion,
std::string const& rccCommand,
std::string const& fileName,
std::vector<std::string>& files,
std::string* errorMessage = nullptr);
};
......
This diff is collapsed.
......@@ -15,7 +15,7 @@ class cmQtAutoGeneratorInitializer
public:
static std::string GetQtMajorVersion(cmGeneratorTarget const* target);
static std::string GetQtMinorVersion(cmGeneratorTarget const* target,
const std::string& qtVersionMajor);
std::string const& qtVersionMajor);
static void InitializeAutogenTarget(cmQtAutoGenDigest& digest);
static void SetupAutoGenerateTarget(cmQtAutoGenDigest const& digest);
......
......@@ -131,7 +131,8 @@ static bool ListContains(std::vector<std::string> const& list,
// -- Class methods
cmQtAutoGenerators::cmQtAutoGenerators()
: IncludeProjectDirsBefore(false)
: MultiConfig(cmQtAutoGen::WRAP)
, IncludeProjectDirsBefore(false)
, Verbose(cmSystemTools::HasEnv("VERBOSE"))
, ColorOutput(true)
, MocSettingsChanged(false)
......@@ -196,6 +197,9 @@ bool cmQtAutoGenerators::InitInfoFile(cmMakefile* makefile,
std::string const& targetDirectory,
std::string const& config)
{
// -- Meta
this->HeaderExtensions = makefile->GetCMakeInstance()->GetHeaderExtensions();
// Utility lambdas
auto InfoGet = [makefile](const char* key) {
return makefile->GetSafeDefinition(key);
......@@ -239,10 +243,8 @@ bool cmQtAutoGenerators::InitInfoFile(cmMakefile* makefile,
const char* valueConf = nullptr;
{
std::string keyConf = key;
if (!config.empty()) {
keyConf += '_';
keyConf += config;
}
keyConf += '_';
keyConf += config;
valueConf = makefile->GetDefinition(keyConf);
}
if (valueConf == nullptr) {
......@@ -257,10 +259,10 @@ bool cmQtAutoGenerators::InitInfoFile(cmMakefile* makefile,
return list;
};
// -- Read info file
this->InfoFile = cmSystemTools::CollapseFullPath(targetDirectory);
cmSystemTools::ConvertToUnixSlashes(this->InfoFile);
this->InfoFile += "/AutogenInfo.cmake";
if (!makefile->ReadListFile(this->InfoFile.c_str())) {
this->LogFileError(cmQtAutoGen::GEN, this->InfoFile,
"File processing failed");
......@@ -268,16 +270,11 @@ bool cmQtAutoGenerators::InitInfoFile(cmMakefile* makefile,
}
// -- Meta
this->HeaderExtensions = makefile->GetCMakeInstance()->GetHeaderExtensions();
this->MultiConfig = cmQtAutoGen::MultiConfigType(InfoGet("AM_MULTI_CONFIG"));
this->ConfigSuffix = InfoGetConfig("AM_CONFIG_SUFFIX");
// - Old settings file
{
this->SettingsFile = cmSystemTools::CollapseFullPath(targetDirectory);
cmSystemTools::ConvertToUnixSlashes(this->SettingsFile);
this->SettingsFile += "/AutogenOldSettings";
this->SettingsFile += this->ConfigSuffix;
this->SettingsFile += ".cmake";
if (this->ConfigSuffix.empty()) {
this->ConfigSuffix = "_";
this->ConfigSuffix += config;
}
// - Files and directories
......@@ -499,19 +496,28 @@ bool cmQtAutoGenerators::InitInfoFile(cmMakefile* makefile,
// include directory
this->AutogenIncludeDir = "include";
this->AutogenIncludeDir += this->ConfigSuffix;
if (this->MultiConfig != cmQtAutoGen::SINGLE) {
this->AutogenIncludeDir += this->ConfigSuffix;
}
this->AutogenIncludeDir += "/";
// Moc variables
if (this->MocEnabled()) {
// Mocs compilation file
this->MocCompFileRel = "mocs_compilation.cpp";
this->MocCompFileRel = "mocs_compilation";
if (this->MultiConfig == cmQtAutoGen::FULL) {
this->MocCompFileRel += this->ConfigSuffix;
}
this->MocCompFileRel += ".cpp";
this->MocCompFileAbs = cmSystemTools::CollapseCombinedPath(
this->AutogenBuildDir, this->MocCompFileRel);
// Moc predefs file
if (!this->MocPredefsCmd.empty()) {
this->MocPredefsFileRel = "moc_predefs";
this->MocPredefsFileRel += this->ConfigSuffix;
if (this->MultiConfig != cmQtAutoGen::SINGLE) {
this->MocPredefsFileRel += this->ConfigSuffix;
}
this->MocPredefsFileRel += ".h";
this->MocPredefsFileAbs = cmSystemTools::CollapseCombinedPath(
this->AutogenBuildDir, this->MocPredefsFileRel);
......@@ -585,6 +591,17 @@ bool cmQtAutoGenerators::InitInfoFile(cmMakefile* makefile,
}
}
// - Old settings file
{
this->SettingsFile = cmSystemTools::CollapseFullPath(targetDirectory);
cmSystemTools::ConvertToUnixSlashes(this->SettingsFile);
this->SettingsFile += "/AutogenOldSettings";
if (this->MultiConfig != cmQtAutoGen::SINGLE) {
this->SettingsFile += this->ConfigSuffix;
}
this->SettingsFile += ".cmake";
}
return true;
}
......@@ -1299,18 +1316,18 @@ void cmQtAutoGenerators::MocParseHeaderContent(std::string const& absFilename,
});
if (fit == this->MocJobsIncluded.cend()) {
if (this->MocRequired(contentText)) {
static std::string const prefix = "moc_";
static std::string const suffix = this->ConfigSuffix + ".cpp";
auto job = cm::make_unique<MocJobAuto>();
job->SourceFile = absFilename;
{
std::string& bld = job->BuildFileRel;
bld = this->FilePathChecksum.getPart(absFilename);
bld += "/";
bld += prefix;
bld += '/';
bld += "moc_";
bld += cmSystemTools::GetFilenameWithoutLastExtension(absFilename);
bld += suffix;
if (this->MultiConfig != cmQtAutoGen::SINGLE) {
bld += this->ConfigSuffix;
}
bld += ".cpp";
}
this->MocFindDepends(absFilename, contentText, job->Depends);
this->MocJobsAuto.push_back(std::move(job));
......@@ -1437,9 +1454,12 @@ bool cmQtAutoGenerators::MocGenerateAll()
// Compose mocs compilation file content
{
std::string mocs = "/* This file is autogenerated, do not edit*/\n";
std::string mocs =
"// This file is autogenerated. Changes will be overwritten.\n";
if (this->MocJobsAuto.empty()) {
// Dummy content
// Placeholder content
mocs +=
"// No files found that require moc or the moc files are included\n";
mocs += "enum some_compilers { need_more_than_nothing };\n";
} else {
// Valid content
......@@ -1917,14 +1937,11 @@ bool cmQtAutoGenerators::RccGenerateFile(const RccJob& rccJob)
bool rccGenerated = false;
std::string rccFileAbs;
if (this->ConfigSuffix.empty()) {
if (this->MultiConfig == cmQtAutoGen::SINGLE) {
rccFileAbs = rccJob.RccFile;
} else {
rccFileAbs = SubDirPrefix(rccJob.RccFile);
rccFileAbs +=
cmSystemTools::GetFilenameWithoutLastExtension(rccJob.RccFile);
rccFileAbs += this->ConfigSuffix;
rccFileAbs += cmSystemTools::GetFilenameLastExtension(rccJob.RccFile);
rccFileAbs =
cmQtAutoGen::AppendFilenameSuffix(rccJob.RccFile, this->ConfigSuffix);
}
std::string const rccFileRel = cmSystemTools::RelativePath(
this->AutogenBuildDir.c_str(), rccFileAbs.c_str());
......@@ -2064,15 +2081,16 @@ bool cmQtAutoGenerators::RccGenerateFile(const RccJob& rccJob)
success = false;
}
}
// For a multi configuration generator generate a wrapper file
if (success && !this->ConfigSuffix.empty()) {
// Generate a wrapper source file on demand
if (success && (this->MultiConfig == cmQtAutoGen::WRAP)) {
// Wrapper file name
std::string const& wrapperFileAbs = rccJob.RccFile;
std::string const wrapperFileRel = cmSystemTools::RelativePath(
this->AutogenBuildDir.c_str(), wrapperFileAbs.c_str());
// Wrapper file content
std::string content = "// This is an autogenerated configuration "
"wrapper file. Do not edit.\n"
"wrapper file. Changes will be overwritten.\n"
"#include \"";
content += cmSystemTools::GetFilenameName(rccFileRel);
content += "\"\n";
......
......@@ -183,8 +183,9 @@ private:
std::string& output) const;
// -- Meta
std::string ConfigSuffix;
std::string InfoFile;
std::string ConfigSuffix;
cmQtAutoGen::MultiConfig MultiConfig;
// -- Settings
bool IncludeProjectDirsBefore;
bool Verbose;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment