Skip to content

Commit

Permalink
Fix single/double quote in *buildmessage.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarod42 committed Jul 17, 2022
1 parent b6347d5 commit 4ff8657
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions cmake_project.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ local cmake = p.modules.cmake
cmake.project = {}
local m = cmake.project

local function esc_quoted(s)
s = s:gsub("\\", "\\\\")
s = s:gsub("\"", "\\\"")
s = s:gsub("\'", "\\'")

return s
end

function m.getcompiler(cfg)
local default = iif(cfg.system == p.WINDOWS, "msc", "clang")
Expand Down Expand Up @@ -288,7 +295,7 @@ function m.generate(prj)
-- so instead, use add_custom_target to run it before any rule (as obj)
_p('add_custom_target(prebuild-%s', prj.name)
if cfg.prebuildmessage then
local command = os.translateCommandsAndPaths("{ECHO} " .. cfg.prebuildmessage, cfg.project.basedir, cfg.project.location)
local command = os.translateCommandsAndPaths("{ECHO} " .. esc_quoted(cfg.prebuildmessage), cfg.project.basedir, cfg.project.location)
_p(' COMMAND %s', command)
end
local commands = os.translateCommandsAndPaths(cfg.prebuildcommands, cfg.project.basedir, cfg.project.location)
Expand All @@ -302,7 +309,7 @@ function m.generate(prj)
if cfg.postbuildmessage or #cfg.postbuildcommands > 0 then
_p('add_custom_command(TARGET %s POST_BUILD', prj.name)
if cfg.postbuildmessage then
local command = os.translateCommandsAndPaths("{ECHO} " .. cfg.postbuildmessage, cfg.project.basedir, cfg.project.location)
local command = os.translateCommandsAndPaths("{ECHO} " .. esc_quoted(cfg.postbuildmessage), cfg.project.basedir, cfg.project.location)
_p(' COMMAND %s', command)
end
local commands = os.translateCommandsAndPaths(cfg.postbuildcommands, cfg.project.basedir, cfg.project.location)
Expand All @@ -319,7 +326,7 @@ function m.generate(prj)
end
_p('add_custom_command(TARGET OUTPUT %s', table.implode(project.getrelative(cfg.project, fileconfig.buildoutputs),"",""," "))
if fileconfig.buildmessage then
_p(' COMMAND %s', os.translateCommandsAndPaths('{ECHO} ' .. fileconfig.buildmessage, cfg.project.basedir, cfg.project.location))
_p(' COMMAND %s', os.translateCommandsAndPaths('{ECHO} ' .. esc_quoted(fileconfig.buildmessage), cfg.project.basedir, cfg.project.location))
end
for _, command in ipairs(fileconfig.buildcommands) do
_p(' COMMAND %s', os.translateCommandsAndPaths(command, cfg.project.basedir, cfg.project.location))
Expand Down

0 comments on commit 4ff8657

Please sign in to comment.