mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-09-25 04:09:36 +03:00
Autogen: Pass WIN32 to moc when targeting the MSVC ABI
WIN32 was added to the moc definitions only when no moc_predefs.h was
generated, as of commit 5f0f84c7e0 (Autogen: Don't add a WIN32 moc
definition if we have a moc_predefs.h file, 2018-11-27,
v3.14.0-rc1~298^2). For the MSVC ABI that is not enough: WIN32 comes
from our default Windows flags rather than from the compiler, so a
generated moc_predefs.h does not carry it either.
Keep the existing fallback for the other toolchains. GCC predefines
WIN32 on Windows, but only with the GNU dialects, so injecting it
unconditionally would make moc disagree with a strict ISO compile.
Issue: #28093
This commit is contained in:
@@ -713,6 +713,13 @@ bool cmQtAutoGenInitializer::InitCustomTargets()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cmQtAutoGenInitializer::IsMsvcAbi() const
|
||||
{
|
||||
return this->Makefile->GetSafeDefinition("CMAKE_CXX_COMPILER_ID") ==
|
||||
"MSVC" ||
|
||||
this->Makefile->GetSafeDefinition("CMAKE_CXX_SIMULATE_ID") == "MSVC";
|
||||
}
|
||||
|
||||
bool cmQtAutoGenInitializer::InitMoc()
|
||||
{
|
||||
// Mocs compilation file
|
||||
@@ -814,10 +821,12 @@ bool cmQtAutoGenInitializer::InitMoc()
|
||||
auto getDefs = [this](std::string const& cfg) -> std::set<std::string> {
|
||||
std::set<std::string> defines;
|
||||
this->LocalGen->GetTargetDefines(this->GenTarget, cfg, "CXX", defines);
|
||||
if (this->Moc.PredefsCmd.empty() &&
|
||||
this->Makefile->GetSafeDefinition("CMAKE_SYSTEM_NAME") ==
|
||||
"Windows") {
|
||||
// Add WIN32 definition if we don't have a moc_predefs.h
|
||||
if (this->Makefile->GetSafeDefinition("CMAKE_SYSTEM_NAME") ==
|
||||
"Windows" &&
|
||||
(this->Moc.PredefsCmd.empty() || this->IsMsvcAbi())) {
|
||||
// Add WIN32 definition if moc_predefs.h cannot supply it. Targeting
|
||||
// the MSVC ABI it comes from our default flags rather than from the
|
||||
// compiler, so it never appears in moc_predefs.h.
|
||||
defines.insert("WIN32");
|
||||
}
|
||||
return defines;
|
||||
|
||||
@@ -111,6 +111,9 @@ private:
|
||||
return (this->Moc.Enabled || this->Uic.Enabled);
|
||||
}
|
||||
|
||||
/** Whether the CXX compiler targets the MSVC ABI. */
|
||||
bool IsMsvcAbi() const;
|
||||
|
||||
bool InitMoc();
|
||||
bool InitUic();
|
||||
bool InitRcc();
|
||||
|
||||
Reference in New Issue
Block a user