2016-09-27 22:01:08 +03:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2015-09-26 20:05:00 +03:00
|
|
|
#include "cmQtAutoGeneratorInitializer.h"
|
|
|
|
|
2016-09-01 21:59:28 +03:00
|
|
|
#include "cmAlgorithms.h"
|
|
|
|
#include "cmCustomCommandLines.h"
|
2016-08-06 15:57:52 +03:00
|
|
|
#include "cmFilePathUuid.h"
|
2016-09-01 21:59:28 +03:00
|
|
|
#include "cmGeneratorTarget.h"
|
|
|
|
#include "cmGlobalGenerator.h"
|
2015-09-26 20:05:00 +03:00
|
|
|
#include "cmLocalGenerator.h"
|
|
|
|
#include "cmMakefile.h"
|
2016-09-01 21:59:28 +03:00
|
|
|
#include "cmOutputConverter.h"
|
2015-09-26 20:05:00 +03:00
|
|
|
#include "cmSourceFile.h"
|
2016-09-01 21:59:28 +03:00
|
|
|
#include "cmSourceFileLocation.h"
|
|
|
|
#include "cmState.h"
|
|
|
|
#include "cmSystemTools.h"
|
|
|
|
#include "cmTarget.h"
|
|
|
|
#include "cmake.h"
|
2015-09-26 20:05:00 +03:00
|
|
|
|
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
2016-05-16 17:34:04 +03:00
|
|
|
#include "cmGlobalVisualStudioGenerator.h"
|
2015-09-26 20:05:00 +03:00
|
|
|
#endif
|
|
|
|
|
2016-09-01 21:59:28 +03:00
|
|
|
#include <algorithm>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <cmConfigure.h>
|
|
|
|
#include <cmsys/FStream.hxx>
|
|
|
|
#include <cmsys/RegularExpression.hxx>
|
|
|
|
#include <iostream>
|
|
|
|
#include <map>
|
|
|
|
#include <set>
|
|
|
|
#include <sstream>
|
|
|
|
#include <string.h>
|
|
|
|
#include <string>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
|
|
|
|
2016-08-06 15:57:52 +03:00
|
|
|
static std::string GetAutogenTargetName(cmGeneratorTarget const* target)
|
|
|
|
{
|
|
|
|
std::string autogenTargetName = target->GetName();
|
|
|
|
autogenTargetName += "_automoc";
|
|
|
|
return autogenTargetName;
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::string GetAutogenTargetDir(cmGeneratorTarget const* target)
|
|
|
|
{
|
|
|
|
cmMakefile* makefile = target->Target->GetMakefile();
|
|
|
|
std::string targetDir = makefile->GetCurrentBinaryDirectory();
|
|
|
|
targetDir += makefile->GetCMakeInstance()->GetCMakeFilesDirectory();
|
|
|
|
targetDir += "/";
|
|
|
|
targetDir += GetAutogenTargetName(target);
|
|
|
|
targetDir += ".dir/";
|
|
|
|
return targetDir;
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::string GetAutogenTargetBuildDir(cmGeneratorTarget const* target)
|
|
|
|
{
|
|
|
|
cmMakefile* makefile = target->Target->GetMakefile();
|
|
|
|
std::string targetDir = makefile->GetCurrentBinaryDirectory();
|
|
|
|
targetDir += "/";
|
|
|
|
targetDir += GetAutogenTargetName(target);
|
|
|
|
targetDir += ".dir/";
|
|
|
|
return targetDir;
|
|
|
|
}
|
|
|
|
|
2015-10-05 20:21:30 +03:00
|
|
|
static void SetupSourceFiles(cmGeneratorTarget const* target,
|
2016-05-16 17:34:04 +03:00
|
|
|
std::vector<std::string>& skipMoc,
|
|
|
|
std::vector<std::string>& mocSources,
|
|
|
|
std::vector<std::string>& mocHeaders,
|
|
|
|
std::vector<std::string>& skipUic)
|
2015-10-05 19:45:21 +03:00
|
|
|
{
|
2015-10-05 20:21:30 +03:00
|
|
|
cmMakefile* makefile = target->Target->GetMakefile();
|
2015-10-05 19:45:21 +03:00
|
|
|
|
|
|
|
std::vector<cmSourceFile*> srcFiles;
|
2015-10-05 20:21:30 +03:00
|
|
|
target->GetConfigCommonSourceFiles(srcFiles);
|
2015-10-05 19:45:21 +03:00
|
|
|
|
|
|
|
std::vector<std::string> newRccFiles;
|
|
|
|
|
2016-08-06 15:57:52 +03:00
|
|
|
cmFilePathUuid fpathUuid(makefile);
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<cmSourceFile*>::const_iterator fileIt = srcFiles.begin();
|
|
|
|
fileIt != srcFiles.end(); ++fileIt) {
|
2015-10-05 19:45:21 +03:00
|
|
|
cmSourceFile* sf = *fileIt;
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string absFile = cmsys::SystemTools::GetRealPath(sf->GetFullPath());
|
2015-10-05 19:45:21 +03:00
|
|
|
bool skipFileForMoc =
|
2016-05-16 17:34:04 +03:00
|
|
|
cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTOMOC"));
|
2015-10-05 19:45:21 +03:00
|
|
|
bool generated = cmSystemTools::IsOn(sf->GetPropertyForUser("GENERATED"));
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTOUIC"))) {
|
2015-10-05 19:45:21 +03:00
|
|
|
skipUic.push_back(absFile);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-10-05 19:45:21 +03:00
|
|
|
|
|
|
|
std::string ext = sf->GetExtension();
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (target->GetPropertyAsBool("AUTORCC")) {
|
|
|
|
if (ext == "qrc" &&
|
|
|
|
!cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTORCC"))) {
|
2015-10-05 19:45:21 +03:00
|
|
|
|
2016-08-06 15:57:52 +03:00
|
|
|
std::string rcc_output_file = GetAutogenTargetBuildDir(target);
|
|
|
|
// Create output directory
|
|
|
|
cmSystemTools::MakeDirectory(rcc_output_file.c_str());
|
|
|
|
rcc_output_file += fpathUuid.get(absFile, "qrc_", ".cpp");
|
|
|
|
|
2015-10-05 19:45:21 +03:00
|
|
|
makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES",
|
2016-05-16 17:34:04 +03:00
|
|
|
rcc_output_file.c_str(), false);
|
2015-10-05 19:45:21 +03:00
|
|
|
makefile->GetOrCreateSource(rcc_output_file, true);
|
|
|
|
newRccFiles.push_back(rcc_output_file);
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-10-05 19:45:21 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!generated) {
|
|
|
|
if (skipFileForMoc) {
|
2015-10-05 19:45:21 +03:00
|
|
|
skipMoc.push_back(absFile);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
|
|
|
cmSystemTools::FileFormat fileType =
|
|
|
|
cmSystemTools::GetFileFormat(ext.c_str());
|
|
|
|
if (fileType == cmSystemTools::CXX_FILE_FORMAT) {
|
2015-10-05 19:45:21 +03:00
|
|
|
mocSources.push_back(absFile);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (fileType == cmSystemTools::HEADER_FILE_FORMAT) {
|
2015-10-05 19:45:21 +03:00
|
|
|
mocHeaders.push_back(absFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-10-05 19:45:21 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator fileIt = newRccFiles.begin();
|
|
|
|
fileIt != newRccFiles.end(); ++fileIt) {
|
2015-08-29 19:10:19 +03:00
|
|
|
const_cast<cmGeneratorTarget*>(target)->AddSource(*fileIt);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-10-05 19:45:21 +03:00
|
|
|
}
|
|
|
|
|
2015-10-05 20:21:30 +03:00
|
|
|
static void GetCompileDefinitionsAndDirectories(
|
2016-05-16 17:34:04 +03:00
|
|
|
cmGeneratorTarget const* target, const std::string& config,
|
|
|
|
std::string& incs, std::string& defs)
|
2015-10-05 19:46:11 +03:00
|
|
|
{
|
|
|
|
std::vector<std::string> includeDirs;
|
2016-05-16 17:34:04 +03:00
|
|
|
cmLocalGenerator* localGen = target->GetLocalGenerator();
|
2015-10-05 19:46:11 +03:00
|
|
|
// Get the include dirs for this target, without stripping the implicit
|
2016-08-12 22:06:35 +03:00
|
|
|
// include dirs off, see https://gitlab.kitware.com/cmake/cmake/issues/13667
|
2015-10-05 20:21:30 +03:00
|
|
|
localGen->GetIncludeDirectories(includeDirs, target, "CXX", config, false);
|
2015-10-05 19:46:11 +03:00
|
|
|
|
|
|
|
incs = cmJoin(includeDirs, ";");
|
|
|
|
|
|
|
|
std::set<std::string> defines;
|
2015-10-09 23:19:57 +03:00
|
|
|
localGen->AddCompileDefinitions(defines, target, config, "CXX");
|
2015-10-05 19:46:11 +03:00
|
|
|
|
|
|
|
defs += cmJoin(defines, ";");
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
static void SetupAutoMocTarget(
|
|
|
|
cmGeneratorTarget const* target, const std::string& autogenTargetName,
|
|
|
|
std::vector<std::string> const& skipMoc,
|
|
|
|
std::vector<std::string> const& mocHeaders,
|
|
|
|
std::map<std::string, std::string>& configIncludes,
|
|
|
|
std::map<std::string, std::string>& configDefines)
|
2015-10-05 19:46:58 +03:00
|
|
|
{
|
2015-10-16 20:19:50 +03:00
|
|
|
cmLocalGenerator* lg = target->GetLocalGenerator();
|
2015-10-05 20:21:30 +03:00
|
|
|
cmMakefile* makefile = target->Target->GetMakefile();
|
2015-10-05 19:46:58 +03:00
|
|
|
|
|
|
|
const char* tmp = target->GetProperty("AUTOMOC_MOC_OPTIONS");
|
2016-06-27 23:44:16 +03:00
|
|
|
std::string _moc_options = (tmp != CM_NULLPTR ? tmp : "");
|
2016-05-16 17:34:04 +03:00
|
|
|
makefile->AddDefinition(
|
|
|
|
"_moc_options", cmOutputConverter::EscapeForCMake(_moc_options).c_str());
|
|
|
|
makefile->AddDefinition(
|
|
|
|
"_skip_moc",
|
|
|
|
cmOutputConverter::EscapeForCMake(cmJoin(skipMoc, ";")).c_str());
|
|
|
|
makefile->AddDefinition(
|
|
|
|
"_moc_headers",
|
|
|
|
cmOutputConverter::EscapeForCMake(cmJoin(mocHeaders, ";")).c_str());
|
2015-10-05 19:46:58 +03:00
|
|
|
bool relaxedMode = makefile->IsOn("CMAKE_AUTOMOC_RELAXED_MODE");
|
|
|
|
makefile->AddDefinition("_moc_relaxed_mode", relaxedMode ? "TRUE" : "FALSE");
|
|
|
|
|
|
|
|
std::string _moc_incs;
|
|
|
|
std::string _moc_compile_defs;
|
|
|
|
std::vector<std::string> configs;
|
|
|
|
const std::string& config = makefile->GetConfigurations(configs);
|
2016-05-16 17:34:04 +03:00
|
|
|
GetCompileDefinitionsAndDirectories(target, config, _moc_incs,
|
|
|
|
_moc_compile_defs);
|
2015-10-05 19:46:58 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
makefile->AddDefinition(
|
|
|
|
"_moc_incs", cmOutputConverter::EscapeForCMake(_moc_incs).c_str());
|
|
|
|
makefile->AddDefinition(
|
|
|
|
"_moc_compile_defs",
|
|
|
|
cmOutputConverter::EscapeForCMake(_moc_compile_defs).c_str());
|
2015-10-05 19:46:58 +03:00
|
|
|
|
|
|
|
for (std::vector<std::string>::const_iterator li = configs.begin();
|
2016-05-16 17:34:04 +03:00
|
|
|
li != configs.end(); ++li) {
|
2015-10-05 19:46:58 +03:00
|
|
|
std::string config_moc_incs;
|
|
|
|
std::string config_moc_compile_defs;
|
2016-05-16 17:34:04 +03:00
|
|
|
GetCompileDefinitionsAndDirectories(target, *li, config_moc_incs,
|
2015-10-05 19:46:58 +03:00
|
|
|
config_moc_compile_defs);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (config_moc_incs != _moc_incs) {
|
|
|
|
configIncludes[*li] = cmOutputConverter::EscapeForCMake(config_moc_incs);
|
|
|
|
if (_moc_incs.empty()) {
|
2015-10-05 19:46:58 +03:00
|
|
|
_moc_incs = config_moc_incs;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (config_moc_compile_defs != _moc_compile_defs) {
|
2015-10-05 19:46:58 +03:00
|
|
|
configDefines[*li] =
|
2016-05-16 17:34:04 +03:00
|
|
|
cmOutputConverter::EscapeForCMake(config_moc_compile_defs);
|
|
|
|
if (_moc_compile_defs.empty()) {
|
2015-10-05 19:46:58 +03:00
|
|
|
_moc_compile_defs = config_moc_compile_defs;
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-10-05 19:46:58 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* qtVersion = makefile->GetDefinition("_target_qt_version");
|
|
|
|
if (strcmp(qtVersion, "5") == 0) {
|
|
|
|
cmGeneratorTarget* qt5Moc = lg->FindGeneratorTargetToUse("Qt5::moc");
|
|
|
|
if (!qt5Moc) {
|
2015-10-05 19:46:58 +03:00
|
|
|
cmSystemTools::Error("Qt5::moc target not found ",
|
2016-05-16 17:34:04 +03:00
|
|
|
autogenTargetName.c_str());
|
2015-10-05 19:46:58 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-10-05 19:46:58 +03:00
|
|
|
makefile->AddDefinition("_qt_moc_executable",
|
|
|
|
qt5Moc->ImportedGetLocation(""));
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (strcmp(qtVersion, "4") == 0) {
|
|
|
|
cmGeneratorTarget* qt4Moc = lg->FindGeneratorTargetToUse("Qt4::moc");
|
|
|
|
if (!qt4Moc) {
|
2015-10-05 19:46:58 +03:00
|
|
|
cmSystemTools::Error("Qt4::moc target not found ",
|
2016-05-16 17:34:04 +03:00
|
|
|
autogenTargetName.c_str());
|
2015-10-05 19:46:58 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-10-05 19:46:58 +03:00
|
|
|
makefile->AddDefinition("_qt_moc_executable",
|
|
|
|
qt4Moc->ImportedGetLocation(""));
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2015-10-05 19:46:58 +03:00
|
|
|
cmSystemTools::Error("The CMAKE_AUTOMOC feature supports only Qt 4 and "
|
2016-05-16 17:34:04 +03:00
|
|
|
"Qt 5 ",
|
|
|
|
autogenTargetName.c_str());
|
|
|
|
}
|
2015-10-05 19:46:58 +03:00
|
|
|
}
|
|
|
|
|
2015-10-05 20:21:30 +03:00
|
|
|
static void GetUicOpts(cmGeneratorTarget const* target,
|
2016-05-16 17:34:04 +03:00
|
|
|
const std::string& config, std::string& optString)
|
2015-10-05 19:47:49 +03:00
|
|
|
{
|
|
|
|
std::vector<std::string> opts;
|
2015-10-05 20:21:30 +03:00
|
|
|
target->GetAutoUicOptions(opts, config);
|
2015-10-05 19:47:49 +03:00
|
|
|
optString = cmJoin(opts, ";");
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
static void SetupAutoUicTarget(
|
|
|
|
cmGeneratorTarget const* target, std::vector<std::string> const& skipUic,
|
|
|
|
std::map<std::string, std::string>& configUicOptions)
|
2015-10-05 19:48:41 +03:00
|
|
|
{
|
2015-10-16 20:19:50 +03:00
|
|
|
cmLocalGenerator* lg = target->GetLocalGenerator();
|
2016-05-16 17:34:04 +03:00
|
|
|
cmMakefile* makefile = target->Target->GetMakefile();
|
2015-10-05 19:48:41 +03:00
|
|
|
|
|
|
|
std::set<std::string> skipped;
|
|
|
|
skipped.insert(skipUic.begin(), skipUic.end());
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
makefile->AddDefinition(
|
|
|
|
"_skip_uic",
|
|
|
|
cmOutputConverter::EscapeForCMake(cmJoin(skipUic, ";")).c_str());
|
2015-10-05 19:48:41 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::vector<cmSourceFile*> uiFilesWithOptions =
|
|
|
|
makefile->GetQtUiFilesWithOptions();
|
2015-10-05 19:48:41 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* qtVersion = makefile->GetDefinition("_target_qt_version");
|
2015-10-05 19:48:41 +03:00
|
|
|
|
|
|
|
std::string _uic_opts;
|
|
|
|
std::vector<std::string> configs;
|
|
|
|
const std::string& config = makefile->GetConfigurations(configs);
|
|
|
|
GetUicOpts(target, config, _uic_opts);
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!_uic_opts.empty()) {
|
2015-10-05 19:48:41 +03:00
|
|
|
_uic_opts = cmOutputConverter::EscapeForCMake(_uic_opts);
|
|
|
|
makefile->AddDefinition("_uic_target_options", _uic_opts.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-10-05 19:48:41 +03:00
|
|
|
for (std::vector<std::string>::const_iterator li = configs.begin();
|
2016-05-16 17:34:04 +03:00
|
|
|
li != configs.end(); ++li) {
|
2015-10-05 19:48:41 +03:00
|
|
|
std::string config_uic_opts;
|
|
|
|
GetUicOpts(target, *li, config_uic_opts);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (config_uic_opts != _uic_opts) {
|
2015-10-05 19:48:41 +03:00
|
|
|
configUicOptions[*li] =
|
2016-05-16 17:34:04 +03:00
|
|
|
cmOutputConverter::EscapeForCMake(config_uic_opts);
|
|
|
|
if (_uic_opts.empty()) {
|
2015-10-05 19:48:41 +03:00
|
|
|
_uic_opts = config_uic_opts;
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-10-05 19:48:41 +03:00
|
|
|
|
|
|
|
std::string uiFileFiles;
|
|
|
|
std::string uiFileOptions;
|
|
|
|
const char* sep = "";
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<cmSourceFile*>::const_iterator fileIt =
|
|
|
|
uiFilesWithOptions.begin();
|
|
|
|
fileIt != uiFilesWithOptions.end(); ++fileIt) {
|
2015-10-05 19:48:41 +03:00
|
|
|
cmSourceFile* sf = *fileIt;
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string absFile = cmsys::SystemTools::GetRealPath(sf->GetFullPath());
|
2015-10-05 19:48:41 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!skipped.insert(absFile).second) {
|
2015-10-05 19:48:41 +03:00
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-10-05 19:48:41 +03:00
|
|
|
uiFileFiles += sep;
|
|
|
|
uiFileFiles += absFile;
|
|
|
|
uiFileOptions += sep;
|
|
|
|
std::string opts = sf->GetProperty("AUTOUIC_OPTIONS");
|
|
|
|
cmSystemTools::ReplaceString(opts, ";", "@list_sep@");
|
|
|
|
uiFileOptions += opts;
|
|
|
|
sep = ";";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-10-05 19:48:41 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
makefile->AddDefinition(
|
|
|
|
"_qt_uic_options_files",
|
|
|
|
cmOutputConverter::EscapeForCMake(uiFileFiles).c_str());
|
|
|
|
makefile->AddDefinition(
|
|
|
|
"_qt_uic_options_options",
|
|
|
|
cmOutputConverter::EscapeForCMake(uiFileOptions).c_str());
|
2015-10-05 19:48:41 +03:00
|
|
|
|
|
|
|
std::string targetName = target->GetName();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (strcmp(qtVersion, "5") == 0) {
|
|
|
|
cmGeneratorTarget* qt5Uic = lg->FindGeneratorTargetToUse("Qt5::uic");
|
|
|
|
if (!qt5Uic) {
|
2015-10-05 19:48:41 +03:00
|
|
|
// Project does not use Qt5Widgets, but has AUTOUIC ON anyway
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2015-10-05 19:48:41 +03:00
|
|
|
makefile->AddDefinition("_qt_uic_executable",
|
|
|
|
qt5Uic->ImportedGetLocation(""));
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (strcmp(qtVersion, "4") == 0) {
|
|
|
|
cmGeneratorTarget* qt4Uic = lg->FindGeneratorTargetToUse("Qt4::uic");
|
|
|
|
if (!qt4Uic) {
|
|
|
|
cmSystemTools::Error("Qt4::uic target not found ", targetName.c_str());
|
2015-10-05 19:48:41 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-10-05 19:48:41 +03:00
|
|
|
makefile->AddDefinition("_qt_uic_executable",
|
|
|
|
qt4Uic->ImportedGetLocation(""));
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2015-10-05 19:48:41 +03:00
|
|
|
cmSystemTools::Error("The CMAKE_AUTOUIC feature supports only Qt 4 and "
|
2016-05-16 17:34:04 +03:00
|
|
|
"Qt 5 ",
|
|
|
|
targetName.c_str());
|
|
|
|
}
|
2015-10-05 19:48:41 +03:00
|
|
|
}
|
|
|
|
|
2015-10-05 20:21:30 +03:00
|
|
|
static std::string GetRccExecutable(cmGeneratorTarget const* target)
|
2015-10-05 19:50:00 +03:00
|
|
|
{
|
2015-10-16 20:19:50 +03:00
|
|
|
cmLocalGenerator* lg = target->GetLocalGenerator();
|
2016-05-16 17:34:04 +03:00
|
|
|
cmMakefile* makefile = target->Target->GetMakefile();
|
|
|
|
const char* qtVersion = makefile->GetDefinition("_target_qt_version");
|
|
|
|
if (!qtVersion) {
|
2015-10-05 19:50:00 +03:00
|
|
|
qtVersion = makefile->GetDefinition("Qt5Core_VERSION_MAJOR");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!qtVersion) {
|
2015-10-05 19:50:00 +03:00
|
|
|
qtVersion = makefile->GetDefinition("QT_VERSION_MAJOR");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (const char* targetQtVersion =
|
|
|
|
target->GetLinkInterfaceDependentStringProperty("QT_MAJOR_VERSION",
|
|
|
|
"")) {
|
2015-10-05 19:50:00 +03:00
|
|
|
qtVersion = targetQtVersion;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-10-05 19:50:00 +03:00
|
|
|
|
|
|
|
std::string targetName = target->GetName();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (strcmp(qtVersion, "5") == 0) {
|
|
|
|
cmGeneratorTarget* qt5Rcc = lg->FindGeneratorTargetToUse("Qt5::rcc");
|
|
|
|
if (!qt5Rcc) {
|
|
|
|
cmSystemTools::Error("Qt5::rcc target not found ", targetName.c_str());
|
2015-10-05 19:50:00 +03:00
|
|
|
return std::string();
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return qt5Rcc->ImportedGetLocation("");
|
2016-08-18 21:36:29 +03:00
|
|
|
}
|
|
|
|
if (strcmp(qtVersion, "4") == 0) {
|
2016-05-16 17:34:04 +03:00
|
|
|
cmGeneratorTarget* qt4Rcc = lg->FindGeneratorTargetToUse("Qt4::rcc");
|
|
|
|
if (!qt4Rcc) {
|
|
|
|
cmSystemTools::Error("Qt4::rcc target not found ", targetName.c_str());
|
2015-10-05 19:50:00 +03:00
|
|
|
return std::string();
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return qt4Rcc->ImportedGetLocation("");
|
|
|
|
}
|
2015-10-05 19:50:00 +03:00
|
|
|
|
|
|
|
cmSystemTools::Error("The CMAKE_AUTORCC feature supports only Qt 4 and "
|
2016-05-16 17:34:04 +03:00
|
|
|
"Qt 5 ",
|
|
|
|
targetName.c_str());
|
2015-10-05 19:50:00 +03:00
|
|
|
return std::string();
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
static void MergeRccOptions(std::vector<std::string>& opts,
|
|
|
|
const std::vector<std::string>& fileOpts,
|
|
|
|
bool isQt5)
|
2015-10-05 19:50:47 +03:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
static const char* valueOptions[] = { "name", "root", "compress",
|
|
|
|
"threshold" };
|
2015-10-05 19:50:47 +03:00
|
|
|
std::vector<std::string> extraOpts;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator it = fileOpts.begin();
|
|
|
|
it != fileOpts.end(); ++it) {
|
|
|
|
std::vector<std::string>::iterator existingIt =
|
|
|
|
std::find(opts.begin(), opts.end(), *it);
|
|
|
|
if (existingIt != opts.end()) {
|
|
|
|
const char* o = it->c_str();
|
|
|
|
if (*o == '-') {
|
2015-10-05 19:50:47 +03:00
|
|
|
++o;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (isQt5 && *o == '-') {
|
2015-10-05 19:50:47 +03:00
|
|
|
++o;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-10-05 19:50:47 +03:00
|
|
|
if (std::find_if(cmArrayBegin(valueOptions), cmArrayEnd(valueOptions),
|
2016-05-16 17:34:04 +03:00
|
|
|
cmStrCmp(*it)) != cmArrayEnd(valueOptions)) {
|
2015-10-05 19:50:47 +03:00
|
|
|
assert(existingIt + 1 != opts.end());
|
|
|
|
*(existingIt + 1) = *(it + 1);
|
|
|
|
++it;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2015-10-05 19:50:47 +03:00
|
|
|
extraOpts.push_back(*it);
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-10-05 19:50:47 +03:00
|
|
|
opts.insert(opts.end(), extraOpts.begin(), extraOpts.end());
|
|
|
|
}
|
|
|
|
|
2015-09-26 20:05:00 +03:00
|
|
|
static void copyTargetProperty(cmTarget* destinationTarget,
|
|
|
|
cmTarget* sourceTarget,
|
|
|
|
const std::string& propertyName)
|
|
|
|
{
|
|
|
|
const char* propertyValue = sourceTarget->GetProperty(propertyName);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (propertyValue) {
|
2015-09-26 20:05:00 +03:00
|
|
|
destinationTarget->SetProperty(propertyName, propertyValue);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-26 20:05:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static std::string cmQtAutoGeneratorsStripCR(std::string const& line)
|
|
|
|
{
|
|
|
|
// Strip CR characters rcc may have printed (possibly more than one!).
|
|
|
|
std::string::size_type cr = line.find('\r');
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cr != line.npos) {
|
2015-09-26 20:05:00 +03:00
|
|
|
return line.substr(0, cr);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-26 20:05:00 +03:00
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::string ReadAll(const std::string& filename)
|
|
|
|
{
|
|
|
|
cmsys::ifstream file(filename.c_str());
|
2016-06-14 23:37:36 +03:00
|
|
|
std::ostringstream stream;
|
2015-09-26 20:05:00 +03:00
|
|
|
stream << file.rdbuf();
|
|
|
|
file.close();
|
|
|
|
return stream.str();
|
|
|
|
}
|
|
|
|
|
2015-10-05 20:21:48 +03:00
|
|
|
static std::string ListQt5RccInputs(cmSourceFile* sf,
|
2016-05-16 17:34:04 +03:00
|
|
|
cmGeneratorTarget const* target,
|
|
|
|
std::vector<std::string>& depends)
|
2015-09-26 20:05:00 +03:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string rccCommand = GetRccExecutable(target);
|
2015-10-28 16:00:51 +03:00
|
|
|
|
|
|
|
bool hasDashDashList = false;
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
std::vector<std::string> command;
|
|
|
|
command.push_back(rccCommand);
|
|
|
|
command.push_back("--help");
|
|
|
|
std::string rccStdOut;
|
|
|
|
std::string rccStdErr;
|
|
|
|
int retVal = 0;
|
2016-06-27 23:44:16 +03:00
|
|
|
bool result =
|
|
|
|
cmSystemTools::RunSingleCommand(command, &rccStdOut, &rccStdErr, &retVal,
|
|
|
|
CM_NULLPTR, cmSystemTools::OUTPUT_NONE);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (result && retVal == 0 &&
|
|
|
|
rccStdOut.find("--list") != std::string::npos) {
|
|
|
|
hasDashDashList = true;
|
2015-10-28 16:00:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-26 20:05:00 +03:00
|
|
|
std::vector<std::string> qrcEntries;
|
|
|
|
|
|
|
|
std::vector<std::string> command;
|
|
|
|
command.push_back(rccCommand);
|
2016-05-16 17:34:04 +03:00
|
|
|
command.push_back(hasDashDashList ? "--list" : "-list");
|
2015-09-26 20:05:00 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string absFile = cmsys::SystemTools::GetRealPath(sf->GetFullPath());
|
2015-09-26 20:05:00 +03:00
|
|
|
|
|
|
|
command.push_back(absFile);
|
|
|
|
|
|
|
|
std::string rccStdOut;
|
|
|
|
std::string rccStdErr;
|
|
|
|
int retVal = 0;
|
2016-06-27 23:44:16 +03:00
|
|
|
bool result =
|
|
|
|
cmSystemTools::RunSingleCommand(command, &rccStdOut, &rccStdErr, &retVal,
|
|
|
|
CM_NULLPTR, cmSystemTools::OUTPUT_NONE);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!result || retVal) {
|
2016-06-14 23:37:36 +03:00
|
|
|
std::ostringstream err;
|
2016-04-24 16:00:26 +03:00
|
|
|
err << "AUTOGEN: error: Rcc list process for " << sf->GetFullPath()
|
2016-05-16 17:34:04 +03:00
|
|
|
<< " failed:\n"
|
|
|
|
<< rccStdOut << "\n"
|
|
|
|
<< rccStdErr << std::endl;
|
2016-04-24 16:00:26 +03:00
|
|
|
std::cerr << err.str();
|
2015-09-26 20:05:00 +03:00
|
|
|
return std::string();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-26 20:05:00 +03:00
|
|
|
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
std::istringstream ostr(rccStdOut);
|
|
|
|
std::string oline;
|
|
|
|
while (std::getline(ostr, oline)) {
|
|
|
|
oline = cmQtAutoGeneratorsStripCR(oline);
|
|
|
|
if (!oline.empty()) {
|
|
|
|
qrcEntries.push_back(oline);
|
2015-09-26 20:05:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
std::istringstream estr(rccStdErr);
|
|
|
|
std::string eline;
|
|
|
|
while (std::getline(estr, eline)) {
|
|
|
|
eline = cmQtAutoGeneratorsStripCR(eline);
|
|
|
|
if (cmHasLiteralPrefix(eline, "RCC: Error in")) {
|
|
|
|
static std::string searchString = "Cannot find file '";
|
|
|
|
|
|
|
|
std::string::size_type pos = eline.find(searchString);
|
|
|
|
if (pos == std::string::npos) {
|
2016-06-14 23:37:36 +03:00
|
|
|
std::ostringstream err;
|
2016-05-16 17:34:04 +03:00
|
|
|
err << "AUTOGEN: error: Rcc lists unparsable output " << eline
|
|
|
|
<< std::endl;
|
|
|
|
std::cerr << err.str();
|
|
|
|
return std::string();
|
2015-09-26 20:05:00 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
pos += searchString.length();
|
|
|
|
std::string::size_type sz = eline.size() - pos - 1;
|
|
|
|
qrcEntries.push_back(eline.substr(pos, sz));
|
2015-09-26 20:05:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
depends.insert(depends.end(), qrcEntries.begin(), qrcEntries.end());
|
|
|
|
return cmJoin(qrcEntries, "@list_sep@");
|
|
|
|
}
|
|
|
|
|
2015-10-05 20:21:48 +03:00
|
|
|
static std::string ListQt4RccInputs(cmSourceFile* sf,
|
2016-05-16 17:34:04 +03:00
|
|
|
std::vector<std::string>& depends)
|
2015-09-26 20:05:00 +03:00
|
|
|
{
|
|
|
|
const std::string qrcContents = ReadAll(sf->GetFullPath());
|
|
|
|
|
|
|
|
cmsys::RegularExpression fileMatchRegex("(<file[^<]+)");
|
|
|
|
|
|
|
|
std::string entriesList;
|
|
|
|
const char* sep = "";
|
|
|
|
|
|
|
|
size_t offset = 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
while (fileMatchRegex.find(qrcContents.c_str() + offset)) {
|
2015-09-26 20:05:00 +03:00
|
|
|
std::string qrcEntry = fileMatchRegex.match(1);
|
|
|
|
|
|
|
|
offset += qrcEntry.size();
|
|
|
|
|
|
|
|
cmsys::RegularExpression fileReplaceRegex("(^<file[^>]*>)");
|
|
|
|
fileReplaceRegex.find(qrcEntry);
|
|
|
|
std::string tag = fileReplaceRegex.match(1);
|
|
|
|
|
|
|
|
qrcEntry = qrcEntry.substr(tag.size());
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmSystemTools::FileIsFullPath(qrcEntry.c_str())) {
|
2015-09-26 20:05:00 +03:00
|
|
|
qrcEntry = sf->GetLocation().GetDirectory() + "/" + qrcEntry;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-26 20:05:00 +03:00
|
|
|
|
|
|
|
entriesList += sep;
|
|
|
|
entriesList += qrcEntry;
|
|
|
|
sep = "@list_sep@";
|
|
|
|
depends.push_back(qrcEntry);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-26 20:05:00 +03:00
|
|
|
return entriesList;
|
|
|
|
}
|
|
|
|
|
2015-10-05 20:21:30 +03:00
|
|
|
static void SetupAutoRccTarget(cmGeneratorTarget const* target)
|
2015-10-05 19:55:09 +03:00
|
|
|
{
|
|
|
|
std::string _rcc_files;
|
|
|
|
const char* sepRccFiles = "";
|
2016-05-16 17:34:04 +03:00
|
|
|
cmMakefile* makefile = target->Target->GetMakefile();
|
2015-10-05 19:55:09 +03:00
|
|
|
|
|
|
|
std::vector<cmSourceFile*> srcFiles;
|
2015-10-05 20:21:30 +03:00
|
|
|
target->GetConfigCommonSourceFiles(srcFiles);
|
2015-10-05 19:55:09 +03:00
|
|
|
|
|
|
|
std::string qrcInputs;
|
|
|
|
const char* qrcInputsSep = "";
|
|
|
|
|
|
|
|
std::string rccFileFiles;
|
|
|
|
std::string rccFileOptions;
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* optionSep = "";
|
2015-10-05 19:55:09 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* qtVersion = makefile->GetDefinition("_target_qt_version");
|
2015-10-05 19:55:09 +03:00
|
|
|
|
|
|
|
std::vector<std::string> rccOptions;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (const char* opts = target->GetProperty("AUTORCC_OPTIONS")) {
|
2015-10-05 19:55:09 +03:00
|
|
|
cmSystemTools::ExpandListArgument(opts, rccOptions);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-10-05 19:55:09 +03:00
|
|
|
std::string qtMajorVersion = makefile->GetSafeDefinition("QT_VERSION_MAJOR");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (qtMajorVersion == "") {
|
2015-10-05 19:55:09 +03:00
|
|
|
qtMajorVersion = makefile->GetSafeDefinition("Qt5Core_VERSION_MAJOR");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-10-05 19:55:09 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<cmSourceFile*>::const_iterator fileIt = srcFiles.begin();
|
|
|
|
fileIt != srcFiles.end(); ++fileIt) {
|
2015-10-05 19:55:09 +03:00
|
|
|
cmSourceFile* sf = *fileIt;
|
|
|
|
std::string ext = sf->GetExtension();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (ext == "qrc") {
|
|
|
|
std::string absFile = cmsys::SystemTools::GetRealPath(sf->GetFullPath());
|
2015-10-05 19:55:09 +03:00
|
|
|
bool skip = cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTORCC"));
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!skip) {
|
2015-10-05 19:55:09 +03:00
|
|
|
_rcc_files += sepRccFiles;
|
|
|
|
_rcc_files += absFile;
|
|
|
|
sepRccFiles = ";";
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (const char* prop = sf->GetProperty("AUTORCC_OPTIONS")) {
|
2015-10-05 19:55:09 +03:00
|
|
|
std::vector<std::string> optsVec;
|
|
|
|
cmSystemTools::ExpandListArgument(prop, optsVec);
|
2016-05-16 17:34:04 +03:00
|
|
|
MergeRccOptions(rccOptions, optsVec, strcmp(qtVersion, "5") == 0);
|
|
|
|
}
|
2015-10-05 19:55:09 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!rccOptions.empty()) {
|
2015-10-05 19:55:09 +03:00
|
|
|
rccFileFiles += optionSep;
|
|
|
|
rccFileFiles += absFile;
|
|
|
|
rccFileOptions += optionSep;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
const char* listSep = "";
|
|
|
|
for (std::vector<std::string>::const_iterator it = rccOptions.begin();
|
|
|
|
it != rccOptions.end(); ++it) {
|
2015-10-05 19:55:09 +03:00
|
|
|
rccFileOptions += listSep;
|
|
|
|
rccFileOptions += *it;
|
|
|
|
listSep = "@list_sep@";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-10-05 19:55:09 +03:00
|
|
|
optionSep = ";";
|
|
|
|
|
|
|
|
std::vector<std::string> depends;
|
|
|
|
|
|
|
|
std::string entriesList;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmSystemTools::IsOn(sf->GetPropertyForUser("GENERATED"))) {
|
|
|
|
if (qtMajorVersion == "5") {
|
2015-10-05 20:21:48 +03:00
|
|
|
entriesList = ListQt5RccInputs(sf, target, depends);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2015-10-05 20:21:48 +03:00
|
|
|
entriesList = ListQt4RccInputs(sf, depends);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (entriesList.empty()) {
|
2015-10-05 19:55:09 +03:00
|
|
|
return;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-10-05 19:55:09 +03:00
|
|
|
qrcInputs += qrcInputsSep;
|
|
|
|
qrcInputs += entriesList;
|
|
|
|
qrcInputsSep = ";";
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
makefile->AddDefinition(
|
|
|
|
"_qt_rcc_inputs_" + target->GetName(),
|
|
|
|
cmOutputConverter::EscapeForCMake(qrcInputs).c_str());
|
2015-10-05 19:55:09 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
makefile->AddDefinition(
|
|
|
|
"_rcc_files", cmOutputConverter::EscapeForCMake(_rcc_files).c_str());
|
2015-10-05 19:55:09 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
makefile->AddDefinition(
|
|
|
|
"_qt_rcc_options_files",
|
|
|
|
cmOutputConverter::EscapeForCMake(rccFileFiles).c_str());
|
|
|
|
makefile->AddDefinition(
|
|
|
|
"_qt_rcc_options_options",
|
|
|
|
cmOutputConverter::EscapeForCMake(rccFileOptions).c_str());
|
2015-10-05 19:55:09 +03:00
|
|
|
|
|
|
|
makefile->AddDefinition("_qt_rcc_executable",
|
2016-05-16 17:34:04 +03:00
|
|
|
GetRccExecutable(target).c_str());
|
2015-10-05 19:55:09 +03:00
|
|
|
}
|
2015-09-26 20:05:00 +03:00
|
|
|
|
2015-10-05 20:21:30 +03:00
|
|
|
void cmQtAutoGeneratorInitializer::InitializeAutogenSources(
|
2016-05-16 17:34:04 +03:00
|
|
|
cmGeneratorTarget* target)
|
2015-09-26 20:05:00 +03:00
|
|
|
{
|
2015-10-05 20:21:30 +03:00
|
|
|
cmMakefile* makefile = target->Target->GetMakefile();
|
2015-09-26 20:05:00 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (target->GetPropertyAsBool("AUTOMOC")) {
|
2015-10-05 20:21:48 +03:00
|
|
|
std::string automocTargetName = GetAutogenTargetName(target);
|
2015-09-26 20:05:00 +03:00
|
|
|
std::string mocCppFile = makefile->GetCurrentBinaryDirectory();
|
|
|
|
mocCppFile += "/";
|
|
|
|
mocCppFile += automocTargetName;
|
|
|
|
mocCppFile += ".cpp";
|
|
|
|
makefile->GetOrCreateSource(mocCppFile, true);
|
2016-05-16 17:34:04 +03:00
|
|
|
makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES", mocCppFile.c_str(),
|
|
|
|
false);
|
2015-09-26 20:05:00 +03:00
|
|
|
|
2015-08-29 19:10:19 +03:00
|
|
|
target->AddSource(mocCppFile);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-26 20:05:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmQtAutoGeneratorInitializer::InitializeAutogenTarget(
|
2016-05-16 17:34:04 +03:00
|
|
|
cmLocalGenerator* lg, cmGeneratorTarget* target)
|
2015-09-26 20:05:00 +03:00
|
|
|
{
|
2015-10-05 20:21:30 +03:00
|
|
|
cmMakefile* makefile = target->Target->GetMakefile();
|
2015-09-26 20:05:00 +03:00
|
|
|
|
|
|
|
std::string qtMajorVersion = makefile->GetSafeDefinition("QT_VERSION_MAJOR");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (qtMajorVersion == "") {
|
2015-09-26 20:05:00 +03:00
|
|
|
qtMajorVersion = makefile->GetSafeDefinition("Qt5Core_VERSION_MAJOR");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-26 20:05:00 +03:00
|
|
|
|
|
|
|
// create a custom target for running generators at buildtime:
|
2015-10-05 20:21:48 +03:00
|
|
|
std::string autogenTargetName = GetAutogenTargetName(target);
|
2015-09-26 20:05:00 +03:00
|
|
|
|
2015-10-05 20:21:48 +03:00
|
|
|
std::string targetDir = GetAutogenTargetDir(target);
|
2015-09-26 20:05:00 +03:00
|
|
|
|
|
|
|
cmCustomCommandLine currentLine;
|
|
|
|
currentLine.push_back(cmSystemTools::GetCMakeCommand());
|
|
|
|
currentLine.push_back("-E");
|
|
|
|
currentLine.push_back("cmake_autogen");
|
|
|
|
currentLine.push_back(targetDir);
|
|
|
|
currentLine.push_back("$<CONFIGURATION>");
|
|
|
|
|
|
|
|
cmCustomCommandLines commandLines;
|
|
|
|
commandLines.push_back(currentLine);
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string workingDirectory =
|
|
|
|
cmSystemTools::CollapseFullPath("", makefile->GetCurrentBinaryDirectory());
|
2015-09-26 20:05:00 +03:00
|
|
|
|
|
|
|
std::vector<std::string> depends;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (const char* autogenDepends =
|
|
|
|
target->GetProperty("AUTOGEN_TARGET_DEPENDS")) {
|
2015-09-26 20:05:00 +03:00
|
|
|
cmSystemTools::ExpandListArgument(autogenDepends, depends);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-26 20:05:00 +03:00
|
|
|
std::vector<std::string> toolNames;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (target->GetPropertyAsBool("AUTOMOC")) {
|
2015-09-26 20:05:00 +03:00
|
|
|
toolNames.push_back("moc");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (target->GetPropertyAsBool("AUTOUIC")) {
|
2015-09-26 20:05:00 +03:00
|
|
|
toolNames.push_back("uic");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (target->GetPropertyAsBool("AUTORCC")) {
|
2015-09-26 20:05:00 +03:00
|
|
|
toolNames.push_back("rcc");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-26 20:05:00 +03:00
|
|
|
|
|
|
|
std::string tools = toolNames[0];
|
|
|
|
toolNames.erase(toolNames.begin());
|
2016-05-16 17:34:04 +03:00
|
|
|
while (toolNames.size() > 1) {
|
2015-09-26 20:05:00 +03:00
|
|
|
tools += ", " + toolNames[0];
|
|
|
|
toolNames.erase(toolNames.begin());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (toolNames.size() == 1) {
|
2015-09-26 20:05:00 +03:00
|
|
|
tools += " and " + toolNames[0];
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-26 20:05:00 +03:00
|
|
|
std::string autogenComment = "Automatic " + tools + " for target ";
|
|
|
|
autogenComment += target->GetName();
|
|
|
|
|
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
|
|
bool usePRE_BUILD = false;
|
|
|
|
cmGlobalGenerator* gg = lg->GetGlobalGenerator();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (gg->GetName().find("Visual Studio") != std::string::npos) {
|
2015-09-26 20:05:00 +03:00
|
|
|
cmGlobalVisualStudioGenerator* vsgg =
|
|
|
|
static_cast<cmGlobalVisualStudioGenerator*>(gg);
|
|
|
|
// Under VS >= 7 use a PRE_BUILD event instead of a separate target to
|
|
|
|
// reduce the number of targets loaded into the IDE.
|
|
|
|
// This also works around a VS 11 bug that may skip updating the target:
|
|
|
|
// https://connect.microsoft.com/VisualStudio/feedback/details/769495
|
|
|
|
usePRE_BUILD = vsgg->GetVersion() >= cmGlobalVisualStudioGenerator::VS7;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (usePRE_BUILD) {
|
2015-09-26 20:05:00 +03:00
|
|
|
for (std::vector<std::string>::iterator it = depends.begin();
|
2016-05-16 17:34:04 +03:00
|
|
|
it != depends.end(); ++it) {
|
|
|
|
if (!makefile->FindTargetToUse(it->c_str())) {
|
2015-09-26 20:05:00 +03:00
|
|
|
usePRE_BUILD = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-26 20:05:00 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
std::vector<std::string> rcc_output;
|
2016-05-16 17:34:04 +03:00
|
|
|
bool const isNinja = lg->GetGlobalGenerator()->GetName() == "Ninja";
|
|
|
|
if (isNinja
|
2015-09-26 20:05:00 +03:00
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
2016-05-16 17:34:04 +03:00
|
|
|
|| usePRE_BUILD
|
2015-09-26 20:05:00 +03:00
|
|
|
#endif
|
2016-05-16 17:34:04 +03:00
|
|
|
) {
|
2015-09-26 20:05:00 +03:00
|
|
|
std::vector<cmSourceFile*> srcFiles;
|
2015-10-05 20:21:30 +03:00
|
|
|
target->GetConfigCommonSourceFiles(srcFiles);
|
2016-08-06 15:57:52 +03:00
|
|
|
cmFilePathUuid fpathUuid(makefile);
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<cmSourceFile*>::const_iterator fileIt = srcFiles.begin();
|
|
|
|
fileIt != srcFiles.end(); ++fileIt) {
|
2015-09-26 20:05:00 +03:00
|
|
|
cmSourceFile* sf = *fileIt;
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string absFile = cmsys::SystemTools::GetRealPath(sf->GetFullPath());
|
2015-09-26 20:05:00 +03:00
|
|
|
|
|
|
|
std::string ext = sf->GetExtension();
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (target->GetPropertyAsBool("AUTORCC")) {
|
|
|
|
if (ext == "qrc" &&
|
|
|
|
!cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTORCC"))) {
|
2016-08-06 15:57:52 +03:00
|
|
|
{
|
|
|
|
std::string rcc_output_file = GetAutogenTargetBuildDir(target);
|
|
|
|
// Create output directory
|
|
|
|
cmSystemTools::MakeDirectory(rcc_output_file.c_str());
|
|
|
|
rcc_output_file += fpathUuid.get(absFile, "qrc_", ".cpp");
|
|
|
|
rcc_output.push_back(rcc_output_file);
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmSystemTools::IsOn(sf->GetPropertyForUser("GENERATED"))) {
|
|
|
|
if (qtMajorVersion == "5") {
|
2015-10-05 20:21:48 +03:00
|
|
|
ListQt5RccInputs(sf, target, depends);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2015-10-05 20:21:48 +03:00
|
|
|
ListQt4RccInputs(sf, depends);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-26 20:05:00 +03:00
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
|
|
// Cannot use PRE_BUILD because the resource files themselves
|
|
|
|
// may not be sources within the target so VS may not know the
|
|
|
|
// target needs to re-build at all.
|
|
|
|
usePRE_BUILD = false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-26 20:05:00 +03:00
|
|
|
|
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
2016-05-16 17:34:04 +03:00
|
|
|
if (usePRE_BUILD) {
|
2015-09-26 20:05:00 +03:00
|
|
|
// Add the pre-build command directly to bypass the OBJECT_LIBRARY
|
|
|
|
// rejection in cmMakefile::AddCustomCommandToTarget because we know
|
|
|
|
// PRE_BUILD will work for an OBJECT_LIBRARY in this specific case.
|
|
|
|
std::vector<std::string> no_output;
|
|
|
|
std::vector<std::string> no_byproducts;
|
|
|
|
cmCustomCommand cc(makefile, no_output, no_byproducts, depends,
|
|
|
|
commandLines, autogenComment.c_str(),
|
|
|
|
workingDirectory.c_str());
|
|
|
|
cc.SetEscapeOldStyle(false);
|
|
|
|
cc.SetEscapeAllowMakeVars(true);
|
2015-10-05 20:21:30 +03:00
|
|
|
target->Target->AddPreBuildCommand(cc);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else
|
2015-09-26 20:05:00 +03:00
|
|
|
#endif
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
2015-09-26 20:05:00 +03:00
|
|
|
cmTarget* autogenTarget = makefile->AddUtilityCommand(
|
2016-05-16 17:34:04 +03:00
|
|
|
autogenTargetName, true, workingDirectory.c_str(),
|
|
|
|
/*byproducts=*/rcc_output, depends, commandLines, false,
|
|
|
|
autogenComment.c_str());
|
2015-09-26 20:05:00 +03:00
|
|
|
|
|
|
|
cmGeneratorTarget* gt = new cmGeneratorTarget(autogenTarget, lg);
|
2015-10-18 17:53:00 +03:00
|
|
|
lg->AddGeneratorTarget(gt);
|
2015-09-26 20:05:00 +03:00
|
|
|
|
|
|
|
// Set target folder
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* autogenFolder =
|
|
|
|
makefile->GetState()->GetGlobalProperty("AUTOMOC_TARGETS_FOLDER");
|
|
|
|
if (!autogenFolder) {
|
|
|
|
autogenFolder =
|
|
|
|
makefile->GetState()->GetGlobalProperty("AUTOGEN_TARGETS_FOLDER");
|
|
|
|
}
|
|
|
|
if (autogenFolder && *autogenFolder) {
|
2015-09-26 20:05:00 +03:00
|
|
|
autogenTarget->SetProperty("FOLDER", autogenFolder);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2015-09-26 20:05:00 +03:00
|
|
|
// inherit FOLDER property from target (#13688)
|
2015-10-05 20:21:30 +03:00
|
|
|
copyTargetProperty(gt->Target, target->Target, "FOLDER");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-26 20:05:00 +03:00
|
|
|
|
2015-10-05 20:21:30 +03:00
|
|
|
target->Target->AddUtility(autogenTargetName);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-26 20:05:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget(
|
2016-05-16 17:34:04 +03:00
|
|
|
cmGeneratorTarget const* target)
|
2015-09-26 20:05:00 +03:00
|
|
|
{
|
2015-10-05 20:21:30 +03:00
|
|
|
cmMakefile* makefile = target->Target->GetMakefile();
|
2015-09-26 20:05:00 +03:00
|
|
|
|
|
|
|
// forget the variables added here afterwards again:
|
|
|
|
cmMakefile::ScopePushPop varScope(makefile);
|
|
|
|
static_cast<void>(varScope);
|
|
|
|
|
|
|
|
// create a custom target for running generators at buildtime:
|
2015-10-05 20:21:48 +03:00
|
|
|
std::string autogenTargetName = GetAutogenTargetName(target);
|
2015-09-26 20:05:00 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
makefile->AddDefinition(
|
|
|
|
"_moc_target_name",
|
|
|
|
cmOutputConverter::EscapeForCMake(autogenTargetName).c_str());
|
|
|
|
makefile->AddDefinition(
|
|
|
|
"_origin_target_name",
|
|
|
|
cmOutputConverter::EscapeForCMake(target->GetName()).c_str());
|
2015-09-26 20:05:00 +03:00
|
|
|
|
2015-10-05 20:21:48 +03:00
|
|
|
std::string targetDir = GetAutogenTargetDir(target);
|
2015-09-26 20:05:00 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* qtVersion = makefile->GetDefinition("Qt5Core_VERSION_MAJOR");
|
|
|
|
if (!qtVersion) {
|
2015-09-26 20:05:00 +03:00
|
|
|
qtVersion = makefile->GetDefinition("QT_VERSION_MAJOR");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (const char* targetQtVersion =
|
|
|
|
target->GetLinkInterfaceDependentStringProperty("QT_MAJOR_VERSION",
|
|
|
|
"")) {
|
2015-09-26 20:05:00 +03:00
|
|
|
qtVersion = targetQtVersion;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (qtVersion) {
|
2015-09-26 20:05:00 +03:00
|
|
|
makefile->AddDefinition("_target_qt_version", qtVersion);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-26 20:05:00 +03:00
|
|
|
|
|
|
|
std::vector<std::string> skipUic;
|
|
|
|
std::vector<std::string> skipMoc;
|
|
|
|
std::vector<std::string> mocSources;
|
|
|
|
std::vector<std::string> mocHeaders;
|
|
|
|
std::map<std::string, std::string> configIncludes;
|
|
|
|
std::map<std::string, std::string> configDefines;
|
|
|
|
std::map<std::string, std::string> configUicOptions;
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (target->GetPropertyAsBool("AUTOMOC") ||
|
|
|
|
target->GetPropertyAsBool("AUTOUIC") ||
|
|
|
|
target->GetPropertyAsBool("AUTORCC")) {
|
2015-10-05 20:21:48 +03:00
|
|
|
SetupSourceFiles(target, skipMoc, mocSources, mocHeaders, skipUic);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
makefile->AddDefinition(
|
|
|
|
"_cpp_files",
|
|
|
|
cmOutputConverter::EscapeForCMake(cmJoin(mocSources, ";")).c_str());
|
|
|
|
if (target->GetPropertyAsBool("AUTOMOC")) {
|
|
|
|
SetupAutoMocTarget(target, autogenTargetName, skipMoc, mocHeaders,
|
|
|
|
configIncludes, configDefines);
|
|
|
|
}
|
|
|
|
if (target->GetPropertyAsBool("AUTOUIC")) {
|
2015-10-05 20:21:48 +03:00
|
|
|
SetupAutoUicTarget(target, skipUic, configUicOptions);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (target->GetPropertyAsBool("AUTORCC")) {
|
2015-10-05 20:21:48 +03:00
|
|
|
SetupAutoRccTarget(target);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-26 20:05:00 +03:00
|
|
|
|
2016-03-14 17:38:19 +03:00
|
|
|
std::string inputFile = cmSystemTools::GetCMakeRoot();
|
2015-09-26 20:05:00 +03:00
|
|
|
inputFile += "/Modules/AutogenInfo.cmake.in";
|
|
|
|
std::string outputFile = targetDir;
|
|
|
|
outputFile += "/AutogenInfo.cmake";
|
2016-05-16 17:34:04 +03:00
|
|
|
makefile->AddDefinition(
|
|
|
|
"_qt_rcc_inputs",
|
|
|
|
makefile->GetDefinition("_qt_rcc_inputs_" + target->GetName()));
|
|
|
|
makefile->ConfigureFile(inputFile.c_str(), outputFile.c_str(), false, true,
|
|
|
|
false);
|
2015-09-26 20:05:00 +03:00
|
|
|
|
|
|
|
// Ensure we have write permission in case .in was read-only.
|
|
|
|
mode_t perm = 0;
|
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
|
|
mode_t mode_write = S_IWRITE;
|
|
|
|
#else
|
|
|
|
mode_t mode_write = S_IWUSR;
|
|
|
|
#endif
|
|
|
|
cmSystemTools::GetPermissions(outputFile, perm);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!(perm & mode_write)) {
|
2015-09-26 20:05:00 +03:00
|
|
|
cmSystemTools::SetPermissions(outputFile, perm | mode_write);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (!configDefines.empty() || !configIncludes.empty() ||
|
|
|
|
!configUicOptions.empty()) {
|
2015-09-26 20:05:00 +03:00
|
|
|
cmsys::ofstream infoFile(outputFile.c_str(), std::ios::app);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!infoFile) {
|
2015-09-26 20:05:00 +03:00
|
|
|
std::string error = "Internal CMake error when trying to open file: ";
|
2016-05-26 23:52:22 +03:00
|
|
|
error += outputFile;
|
2015-09-26 20:05:00 +03:00
|
|
|
error += " for writing.";
|
|
|
|
cmSystemTools::Error(error.c_str());
|
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (!configDefines.empty()) {
|
2015-09-26 20:05:00 +03:00
|
|
|
for (std::map<std::string, std::string>::iterator
|
2016-05-16 17:34:04 +03:00
|
|
|
it = configDefines.begin(),
|
|
|
|
end = configDefines.end();
|
|
|
|
it != end; ++it) {
|
|
|
|
infoFile << "set(AM_MOC_COMPILE_DEFINITIONS_" << it->first << " "
|
|
|
|
<< it->second << ")\n";
|
2015-09-26 20:05:00 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (!configIncludes.empty()) {
|
2015-09-26 20:05:00 +03:00
|
|
|
for (std::map<std::string, std::string>::iterator
|
2016-05-16 17:34:04 +03:00
|
|
|
it = configIncludes.begin(),
|
|
|
|
end = configIncludes.end();
|
|
|
|
it != end; ++it) {
|
|
|
|
infoFile << "set(AM_MOC_INCLUDES_" << it->first << " " << it->second
|
|
|
|
<< ")\n";
|
2015-09-26 20:05:00 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (!configUicOptions.empty()) {
|
2015-09-26 20:05:00 +03:00
|
|
|
for (std::map<std::string, std::string>::iterator
|
2016-05-16 17:34:04 +03:00
|
|
|
it = configUicOptions.begin(),
|
|
|
|
end = configUicOptions.end();
|
|
|
|
it != end; ++it) {
|
|
|
|
infoFile << "set(AM_UIC_TARGET_OPTIONS_" << it->first << " "
|
|
|
|
<< it->second << ")\n";
|
2015-09-26 20:05:00 +03:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-26 20:05:00 +03:00
|
|
|
}
|