[BOOTDATA] Improve the environment-variables hack to keep them unexpanded when building on Windows

The environment variables used by some shell links for the Live-environment,
are passed as data by CMake on the MKSHELLLINK build tool command-line.
When building on Windows, they are transmitted to the tool via CMD.EXE,
and we have somehow to force CMD.EXE to keep these variables unexpanded.

Depending on the precise context where these variables are being used,
either use an "escaped" format with `^%`, as in: `^%SystemRoot^%` ,
or, surround the variable name with `^` instead: `%^SystemRoot^%` .
This second form appears to work when the variable is specified within
a quoted sub-string given to the CMD.EXE command-line.

Addendum to commit a46e1e96ec.
This commit is contained in:
Hermès Bélusca-Maïto
2026-05-15 17:09:52 +02:00
parent f9effd17bc
commit 8eea7255fd

View File

@@ -78,18 +78,28 @@ function(add_livecd_shortcut name path)
endforeach()
endfunction()
# Win32: Use pseudo-escape hacks to work-around variables expansion by CMD.EXE
if(CMAKE_HOST_WIN32)
macro(cmdenvvar var name used_in_quotes)
if(${used_in_quotes})
set(${var} "%^${name}^%") # The name itself is surrounded by '^'
else()
set(${var} "^%${name}^%") # The '%' are pseudo-escaped to '^%'
endif()
endmacro()
else()
macro(cmdenvvar var name used_in_quotes)
set(${var} "%${name}%")
endmacro()
endif()
cmdenvvar(envvar_systemroot "SystemRoot" FALSE)
cmdenvvar(envvar_homedrive "HOMEDRIVE" FALSE)
cmdenvvar(envvar_homepath "HOMEPATH" FALSE)
## NOTE: What would be nice is to create this list using /media/inf/shortcuts.inf
## and taking their default english translation!
set(env_percent "%")
# Win32: Use pseudo-escapes '^%' to work-around variables expansion by CMD.EXE
if (CMAKE_HOST_WIN32)
set(env_percent "^%")
endif()
set(envvar_systemroot "${env_percent}SystemRoot${env_percent}")
set(envvar_homedrive "${env_percent}HOMEDRIVE${env_percent}")
set(envvar_homepath "${env_percent}HOMEPATH${env_percent}")
set(dir_allusers_desktop "Profiles/All Users/Desktop")
set(dir_startmenu_programs "Profiles/All Users/Start Menu/Programs")
set(dir_startmenu_admintools "${dir_startmenu_programs}/Administrative Tools")