Skip to content

Commit 4ff8657

Browse files
committed
Fix single/double quote in *buildmessage.
1 parent b6347d5 commit 4ff8657

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

cmake_project.lua

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ local cmake = p.modules.cmake
2121
cmake.project = {}
2222
local m = cmake.project
2323

24+
local function esc_quoted(s)
25+
s = s:gsub("\\", "\\\\")
26+
s = s:gsub("\"", "\\\"")
27+
s = s:gsub("\'", "\\'")
28+
29+
return s
30+
end
2431

2532
function m.getcompiler(cfg)
2633
local default = iif(cfg.system == p.WINDOWS, "msc", "clang")
@@ -288,7 +295,7 @@ function m.generate(prj)
288295
-- so instead, use add_custom_target to run it before any rule (as obj)
289296
_p('add_custom_target(prebuild-%s', prj.name)
290297
if cfg.prebuildmessage then
291-
local command = os.translateCommandsAndPaths("{ECHO} " .. cfg.prebuildmessage, cfg.project.basedir, cfg.project.location)
298+
local command = os.translateCommandsAndPaths("{ECHO} " .. esc_quoted(cfg.prebuildmessage), cfg.project.basedir, cfg.project.location)
292299
_p(' COMMAND %s', command)
293300
end
294301
local commands = os.translateCommandsAndPaths(cfg.prebuildcommands, cfg.project.basedir, cfg.project.location)
@@ -302,7 +309,7 @@ function m.generate(prj)
302309
if cfg.postbuildmessage or #cfg.postbuildcommands > 0 then
303310
_p('add_custom_command(TARGET %s POST_BUILD', prj.name)
304311
if cfg.postbuildmessage then
305-
local command = os.translateCommandsAndPaths("{ECHO} " .. cfg.postbuildmessage, cfg.project.basedir, cfg.project.location)
312+
local command = os.translateCommandsAndPaths("{ECHO} " .. esc_quoted(cfg.postbuildmessage), cfg.project.basedir, cfg.project.location)
306313
_p(' COMMAND %s', command)
307314
end
308315
local commands = os.translateCommandsAndPaths(cfg.postbuildcommands, cfg.project.basedir, cfg.project.location)
@@ -319,7 +326,7 @@ function m.generate(prj)
319326
end
320327
_p('add_custom_command(TARGET OUTPUT %s', table.implode(project.getrelative(cfg.project, fileconfig.buildoutputs),"",""," "))
321328
if fileconfig.buildmessage then
322-
_p(' COMMAND %s', os.translateCommandsAndPaths('{ECHO} ' .. fileconfig.buildmessage, cfg.project.basedir, cfg.project.location))
329+
_p(' COMMAND %s', os.translateCommandsAndPaths('{ECHO} ' .. esc_quoted(fileconfig.buildmessage), cfg.project.basedir, cfg.project.location))
323330
end
324331
for _, command in ipairs(fileconfig.buildcommands) do
325332
_p(' COMMAND %s', os.translateCommandsAndPaths(command, cfg.project.basedir, cfg.project.location))

0 commit comments

Comments
 (0)