Skip to content

Commit 0e9dcaa

Browse files
committed
apply PR suggestion
1 parent 40a5806 commit 0e9dcaa

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

xmake/modules/package/tools/cmake.lua

+20-17
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ end
726726
function _get_default_flags(package, configs, buildtype, opt)
727727
local cmake_default_flags = _g.cmake_default_flags and _g.cmake_default_flags[buildtype]
728728
if not cmake_default_flags then
729-
local tmpdir = path.join(os.tmpdir(), package:name(), package:mode())
729+
local tmpdir = path.join(os.tmpdir() .. ".dir", package:name(), package:mode())
730730
local dummy_cmakelist = path.join(tmpdir, "CMakeLists.txt")
731731

732732
io.writefile(dummy_cmakelist, format([[
@@ -747,23 +747,26 @@ function _get_default_flags(package, configs, buildtype, opt)
747747
]], buildtype, buildtype, buildtype, buildtype, buildtype, buildtype, buildtype, buildtype, buildtype, buildtype))
748748

749749
local runenvs = opt.envs or buildenvs(package)
750-
local cmake = find_tool("cmake", {envs = runenvs})
750+
local cmake = find_tool("cmake")
751751
local _configs = table.join(configs, "-S " .. path.directory(dummy_cmakelist), "-B " .. tmpdir)
752752
local _, outdata = os.iorunv(cmake.program, _configs, {envs = runenvs})
753-
cmake_default_flags = {}
754-
cmake_default_flags.cflags = outdata:match("CMAKE_C_FLAGS is (.-)\n"):split(" ")
755-
table.join2(cmake_default_flags.cflags, outdata:match(format("CMAKE_C_FLAGS_%s is (.-)\n", buildtype)):replace("/MDd", ""):replace("/MD", ""):split(" "))
756-
cmake_default_flags.cxxflags = outdata:match("CMAKE_CXX_FLAGS is (.-)\n"):split(" ")
757-
table.join2(cmake_default_flags.cxxflags, outdata:match(format("CMAKE_CXX_FLAGS_%s is (.-)\n", buildtype)):replace("/MDd", ""):replace("/MD", ""):split(" "))
758-
cmake_default_flags.ldflags = outdata:match("CMAKE_EXE_LINKER_FLAGS is (.-)\n"):split(" ")
759-
table.join2(cmake_default_flags.ldflags, outdata:match(format("CMAKE_EXE_LINKER_FLAGS_%s is (.-)\n", buildtype)):split(" "))
760-
cmake_default_flags.shflags = outdata:match("CMAKE_SHARED_LINKER_FLAGS is (.-)\n"):split(" ")
761-
table.join2(cmake_default_flags.shflags, outdata:match(format("CMAKE_SHARED_LINKER_FLAGS_%s is (.-)\n", buildtype)):split(" "))
762-
cmake_default_flags.arflags = outdata:match("CMAKE_STATIC_LINKER_FLAGS is (.-)\n"):split(" ")
763-
table.join2(cmake_default_flags.arflags, outdata:match(format("CMAKE_STATIC_LINKER_FLAGS_%s is (.-)\n", buildtype)):split(" "))
764-
765-
_g.cmake_default_flags = _g.cmake_default_flags or {}
766-
_g.cmake_default_flags[buildtype] = cmake_default_flags
753+
if outdata then
754+
cmake_default_flags = {}
755+
cmake_default_flags.cflags = outdata:match("CMAKE_C_FLAGS is (.-)\n"):split(" ")
756+
table.join2(cmake_default_flags.cflags, outdata:match(format("CMAKE_C_FLAGS_%s is (.-)\n", buildtype)):replace("/MDd", ""):replace("/MD", ""):split(" "))
757+
cmake_default_flags.cxxflags = outdata:match("CMAKE_CXX_FLAGS is (.-)\n"):split(" ")
758+
table.join2(cmake_default_flags.cxxflags, outdata:match(format("CMAKE_CXX_FLAGS_%s is (.-)\n", buildtype)):replace("/MDd", ""):replace("/MD", ""):split(" "))
759+
cmake_default_flags.ldflags = outdata:match("CMAKE_EXE_LINKER_FLAGS is (.-)\n"):split(" ")
760+
table.join2(cmake_default_flags.ldflags, outdata:match(format("CMAKE_EXE_LINKER_FLAGS_%s is (.-)\n", buildtype)):split(" "))
761+
cmake_default_flags.shflags = outdata:match("CMAKE_SHARED_LINKER_FLAGS is (.-)\n"):split(" ")
762+
table.join2(cmake_default_flags.shflags, outdata:match(format("CMAKE_SHARED_LINKER_FLAGS_%s is (.-)\n", buildtype)):split(" "))
763+
cmake_default_flags.arflags = outdata:match("CMAKE_STATIC_LINKER_FLAGS is (.-)\n"):split(" ")
764+
table.join2(cmake_default_flags.arflags, outdata:match(format("CMAKE_STATIC_LINKER_FLAGS_%s is (.-)\n", buildtype)):split(" "))
765+
766+
_g.cmake_default_flags = _g.cmake_default_flags or {}
767+
_g.cmake_default_flags[buildtype] = cmake_default_flags
768+
end
769+
os.rm(tmpdir)
767770
end
768771
return cmake_default_flags
769772
end
@@ -845,7 +848,7 @@ function _get_configs(package, configs, opt)
845848
if runtime_envs then
846849
envs = envs or {}
847850
for name, value in pairs(runtime_envs) do
848-
envs[name] = table.join(envs[name], value)
851+
envs[name] = table.join(envs[name] or {}, value)
849852
end
850853
end
851854
if envs then

0 commit comments

Comments
 (0)