CMAKE Wix Patch unclosed token error

I have this wixpatch.xml file

<?xml version="1.0" encoding="UTF-8"?>
<CPackWiXPatch>
	<!--  Fragment ID is from: <your build dir>/_CPack_Packages/win64/WIX/files.wxs -->
	<CPackWiXFragment Id="CM_CP_voxedit.voxedit.vengi_voxedit.exe">
		<Environment Id="PATH" Name="PATH" Value="[INSTALL_ROOT]" Permanent="yes" Part="last" Action="set" System="yes" />

		<!-- Open With -->
		<RegistryValue Root="HKCR" Key="Applications\vengi_voxedit.exe" Type="string" Name="FriendlyAppName" Value="Vengi Voxel Editor"/>
		<RegistryValue Root="HKCR" Key="Applications\vengi_voxedit.exe\shell\open\command" Type="string" Value="[#CM_FP_voxedit.voxedit.vengi_voxedit.exe] &quot;%1&quot;"/>

		<!-- App Paths -->
		<RegistryKey Root="HKLM" Key="SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\vengi_voxedit.exe">
			<RegistryValue Type="string" Value="[#CM_FP_voxedit.voxedit.vengi_voxedit.exe]" />
			<RegistryValue Type="string" Name="Path" Value="[#CM_CP_voxedit.voxedit.vengi_voxedit.exe]" />
		</RegistryKey>

		<!-- Default Programs Capabilities -->
		<RegistryKey Root="HKLM" Key="SOFTWARE\vengi-voxedit\Capabilities">
			<RegistryValue Type="string" Name="ApplicationName" Value="vengi-voxedit" />
			<RegistryValue Type="string" Name="ApplicationDescription" Value="Vengi Voxel Editor" />
		</RegistryKey>

		<!-- Registered file extensions -->
		<RegistryValue Root="HKLM" Key="Software\vengi-voxedit\Capabilities\FileAssociations" Name=".vengi" Value="vengi-voxedit.vengi" Type="string" />
		<RegistryValue Root="HKCR" Key="Applications\vengi_voxedit.exe\SupportedTypes" Name=".vengi" Value="" Type="string" />
		<RegistryValue Root="HKCR" Key=".vengi\OpenWithProgids" Name="vengi-voxedit.vengi" Value="" Type="string" />
		<ProgId Id="vengi-voxedit.vengi" Description="Vengi" Icon="CM_FP_voxedit.voxedit.vengi_voxedit.exe">
			<Extension Id="vengi" ContentType="application/x-vengi">
				<Verb Id="open" TargetFile="CM_FP_voxedit.voxedit.vengi_voxedit.exe" Argument="&quot;%1&quot;" />
			</Extension>
		</ProgId>

		<!-- Default Programs entry -->
		<RegistryValue Root="HKLM" Key="SOFTWARE\RegisteredApplications" Name="vengi-voxedit" Value="SOFTWARE\vengi-voxedit\Capabilities" Type="string" />
	</CPackWiXFragment>
</CPackWiXPatch>

Adding this to the package with

set(CPACK_WIX_PATCH_FILE "${ROOT_DIR}/wixpatch.xml")

results in

[cpack] CPack: - Install project: vengi [Debug]
[cpack] CPack: -   Install component: thumbnailer
[cpack] CPack: -   Install component: voxconvert
[cpack] CPack: -   Install component: voxedit
[cpack] CPack: -   Install component: voxelthumb
[cpack] CPack: Create package
[cpack] CPack Error: Error while processing XML patch file at 1:1:  unclosed token
[cpack] CPack Error: Failed parsing XML patch file: 'C:/Users/marti/dev/engine/contrib/installer/windows/wixpatch.xml'
[cpack] CPack Error: Fatal WiX Generator Error
[cpack] CPack Error: Problem compressing the directory

I can’t find any unclosed tokens here. I’ve even tries to reduce the file to just this

<CPackWiXPatch>
	<CPackWiXFragment Id="CM_CP_voxedit.voxedit.vengi_voxedit.exe">
		<Environment Id="PATH" Name="PATH" Value="[INSTALL_ROOT]" Permanent="yes" Part="last" Action="set" System="yes" />
	</CPackWiXFragment>
</CPackWiXPatch>

but still getting the same error.

Can anyone help here? Or is this maybe a bug in cmake somewhere?

cmake version 3.29.2

I’m just guessing without knowing much about this, but perhaps it doesn’t like the self-closed tag, so I would try to use <Environment></Environment> instead of <Environment />.
If it’s not that, then perhaps try to re-save the file in UTF-8 without BOM.

You are right - thanks a lot - there is a BOM in there. Now I just have to find out how it gets there (as the output is generated by printf-style lines with \n captured via > into a file. But again thanks for this hint. I guess I would have never found it.