From 9e27b7cb822b3ce8ebe819f1b5a208a4b9c6a0b0 Mon Sep 17 00:00:00 2001 From: Ryaan Ahmed Date: Thu, 6 Mar 2025 14:53:01 -0500 Subject: [PATCH] Projucer: Fix malformed VS vcxproj with PCH and multiple platforms A project with a precompiled header and multiple platforms selected for a single configuration would result in multiple ClCompile entries in the Visual Studio project file, which is an invalid file state and would not open in Visual Studio. Projucer now correctly emits a single ClCompile entry for the PCH, including entries for all target platforms. --- .../ProjectSaving/jucer_ProjectExport_MSVC.h | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_MSVC.h b/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_MSVC.h index a85ebe75e480..b26cce88ded1 100644 --- a/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_MSVC.h +++ b/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_MSVC.h @@ -1350,36 +1350,36 @@ class MSVCProjectExporterBase : public ProjectExporter auto& config = *static_cast (&*i); - for (const auto& arch : config.getArchitectures()) - { - auto pchFileContent = config.getPrecompiledHeaderFileContent(); + auto pchFileContent = config.getPrecompiledHeaderFileContent(); - if (pchFileContent.isEmpty()) - continue; + if (pchFileContent.isEmpty()) + continue; - auto pchFile = owner.getTargetFolder().getChildFile (config.getPrecompiledHeaderFilename()).withFileExtension (".h"); + auto pchFile = owner.getTargetFolder().getChildFile (config.getPrecompiledHeaderFilename()).withFileExtension (".h"); - build_tools::writeStreamToFile (pchFile, [&] (MemoryOutputStream& mo) - { - mo << pchFileContent; - }); + build_tools::writeStreamToFile (pchFile, [&] (MemoryOutputStream& mo) + { + mo << pchFileContent; + }); - auto pchSourceFile = pchFile.withFileExtension (".cpp"); + auto pchSourceFile = pchFile.withFileExtension (".cpp"); - build_tools::writeStreamToFile (pchSourceFile, [this] (MemoryOutputStream& mo) - { - mo.setNewLineString (owner.getNewLineString()); + build_tools::writeStreamToFile (pchSourceFile, [this] (MemoryOutputStream& mo) + { + mo.setNewLineString (owner.getNewLineString()); + writeAutoGenWarningComment (mo); - writeAutoGenWarningComment (mo); + mo << " This is an empty source file generated by JUCE required for Visual Studio PCH." << newLine + << newLine + << "*/" << newLine + << newLine; + }); - mo << " This is an empty source file generated by JUCE required for Visual Studio PCH." << newLine - << newLine - << "*/" << newLine - << newLine; - }); + auto* pchSourceElement = cpps.createNewChildElement ("ClCompile"); + pchSourceElement->setAttribute ("Include", prependDot (pchSourceFile.getFileName())); - auto* pchSourceElement = cpps.createNewChildElement ("ClCompile"); - pchSourceElement->setAttribute ("Include", prependDot (pchSourceFile.getFileName())); + for (const auto& arch : config.getArchitectures()) + { setSourceFilePCHSettings (*pchSourceElement, pchFile, "Create", config, arch); } }