summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-05-22 11:28:58 +0800
committerruki <[email protected]>2022-05-22 11:28:58 +0800
commitc990367664d6389990cb37c5a0ae4e9157d7b24e (patch)
tree571c4bcab2ba96b9e8e4b93435bf8d0844d8fdff
parent34a0c28d63953f48ab4d9e552a46dd70b787d069 (diff)
improve path for cmake/vs
-rw-r--r--xmake/plugins/project/cmake/cmakelists.lua28
-rw-r--r--xmake/plugins/project/vstudio/impl/vs201x.lua15
2 files changed, 31 insertions, 12 deletions
diff --git a/xmake/plugins/project/cmake/cmakelists.lua b/xmake/plugins/project/cmake/cmakelists.lua
index eea74d04f..34c8bc126 100644
--- a/xmake/plugins/project/cmake/cmakelists.lua
+++ b/xmake/plugins/project/cmake/cmakelists.lua
@@ -42,12 +42,25 @@ function _get_cmake_minver()
return cmake_minver
end
+-- tranlate path
+function _translate_path(filepath, outputdir)
+ filepath = path.translate(filepath)
+ if filepath == "" then
+ return ""
+ end
+ if path.is_absolute(filepath) then
+ if filepath:startswith(project.directory()) then
+ return path.relative(filepath, outputdir)
+ end
+ return filepath
+ else
+ return path.relative(path.absolute(filepath), outputdir)
+ end
+end
+
-- get unix path
function _get_unix_path(filepath, outputdir)
- if path.is_absolute(filepath) and filepath:startswith(os.projectdir()) then
- filepath = path.relative(filepath, os.projectdir())
- end
- filepath = path.relative(filepath, outputdir)
+ filepath = _translate_path(filepath, outputdir)
filepath = path.translate(filepath):gsub('\\', '/')
return os.args(filepath)
end
@@ -55,7 +68,8 @@ end
-- get unix path relative to the cmake path
-- @see https://github.com/xmake-io/xmake/issues/2026
function _get_unix_path_relative_to_cmake(filepath, outputdir)
- filepath = _get_unix_path(filepath, outputdir)
+ filepath = _translate_path(filepath, outputdir)
+ filepath = path.translate(filepath):gsub('\\', '/')
if filepath and not path.is_absolute(filepath) then
filepath = "${CMAKE_SOURCE_DIR}/" .. filepath
end
@@ -606,7 +620,9 @@ function _get_command_string(cmd, outputdir)
-- @see https://github.com/xmake-io/xmake/discussions/2156
local argv = {}
for _, v in ipairs(table.join(cmd.program, cmd.argv)) do
- if path.is_absolute(v) then
+ if path.instance_of(v) then
+ v = v:clone():set(_get_unix_path_relative_to_cmake(v:rawstr(), outputdir)):str()
+ elseif path.is_absolute(v) then
v = _get_unix_path_relative_to_cmake(v, outputdir)
end
table.insert(argv, v)
diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua
index 8752d49ed..ce07549c0 100644
--- a/xmake/plugins/project/vstudio/impl/vs201x.lua
+++ b/xmake/plugins/project/vstudio/impl/vs201x.lua
@@ -85,7 +85,9 @@ function _get_command_string(cmd, vcxprojdir)
if cmd.program then
local argv = {}
for _, v in ipairs(table.join(cmd.program, cmd.argv)) do
- if path.is_absolute(v) then
+ if path.instance_of(v) then
+ v = v:clone():set(_translate_path(v:rawstr(), vcxprojdir)):str()
+ elseif path.is_absolute(v) then
v = _translate_path(v, vcxprojdir)
end
table.insert(argv, v)
@@ -96,15 +98,16 @@ function _get_command_string(cmd, vcxprojdir)
end
return command
elseif kind == "cp" then
- return string.format("copy /Y \"%s\" \"%s\"", cmd.srcpath, cmd.dstpath)
+ return string.format("copy /Y \"%s\" \"%s\"", _translate_path(cmd.srcpath, vcxprojdir), _translate_path(cmd.dstpath, vcxprojdir))
elseif kind == "rm" then
- return string.format("del /F /Q \"%s\" || rmdir /S /Q \"%s\"", cmd.filepath, cmd.filepath)
+ return string.format("del /F /Q \"%s\" || rmdir /S /Q \"%s\"", _translate_path(cmd.filepath, vcxprojdir), _translate_path(cmd.filepath, vcxprojdir))
elseif kind == "mv" then
- return string.format("rename \"%s\" \"%s\"", cmd.srcpath, cmd.dstpath)
+ return string.format("rename \"%s\" \"%s\"", _translate_path(cmd.srcpath, vcxprojdir), _translate_path(cmd.dstpath, vcxprojdir))
elseif kind == "cd" then
- return string.format("cd \"%s\"", cmd.dir)
+ return string.format("cd \"%s\"", _translate_path(cmd.dir, vcxprojdir))
elseif kind == "mkdir" then
- return string.format("if not exist \"%s\" mkdir \"%s\"", cmd.dir, cmd.dir)
+ local dir = _translate_path(cmd.dir, vcxprojdir)
+ return string.format("if not exist \"%s\" mkdir \"%s\"", dir, dir)
elseif kind == "show" then
return string.format("echo %s", cmd.showtext)
end