Skip to content

Commit

Permalink
apply PR suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthapz committed Apr 28, 2024
1 parent 40a5806 commit eb95459
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions xmake/modules/package/tools/cmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ end
function _get_default_flags(package, configs, buildtype, opt)
local cmake_default_flags = _g.cmake_default_flags and _g.cmake_default_flags[buildtype]
if not cmake_default_flags then
local tmpdir = path.join(os.tmpdir(), package:name(), package:mode())
local tmpdir = path.join(os.tmpdir() .. ".dir", package:name(), package:mode())
local dummy_cmakelist = path.join(tmpdir, "CMakeLists.txt")

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

local runenvs = opt.envs or buildenvs(package)
local cmake = find_tool("cmake", {envs = runenvs})
local cmake = find_tool("cmake")
local _configs = table.join(configs, "-S " .. path.directory(dummy_cmakelist), "-B " .. tmpdir)
local _, outdata = os.iorunv(cmake.program, _configs, {envs = runenvs})
cmake_default_flags = {}
cmake_default_flags.cflags = outdata:match("CMAKE_C_FLAGS is (.-)\n"):split(" ")
table.join2(cmake_default_flags.cflags, outdata:match(format("CMAKE_C_FLAGS_%s is (.-)\n", buildtype)):replace("/MDd", ""):replace("/MD", ""):split(" "))
cmake_default_flags.cxxflags = outdata:match("CMAKE_CXX_FLAGS is (.-)\n"):split(" ")
table.join2(cmake_default_flags.cxxflags, outdata:match(format("CMAKE_CXX_FLAGS_%s is (.-)\n", buildtype)):replace("/MDd", ""):replace("/MD", ""):split(" "))
cmake_default_flags.ldflags = outdata:match("CMAKE_EXE_LINKER_FLAGS is (.-)\n"):split(" ")
table.join2(cmake_default_flags.ldflags, outdata:match(format("CMAKE_EXE_LINKER_FLAGS_%s is (.-)\n", buildtype)):split(" "))
cmake_default_flags.shflags = outdata:match("CMAKE_SHARED_LINKER_FLAGS is (.-)\n"):split(" ")
table.join2(cmake_default_flags.shflags, outdata:match(format("CMAKE_SHARED_LINKER_FLAGS_%s is (.-)\n", buildtype)):split(" "))
cmake_default_flags.arflags = outdata:match("CMAKE_STATIC_LINKER_FLAGS is (.-)\n"):split(" ")
table.join2(cmake_default_flags.arflags, outdata:match(format("CMAKE_STATIC_LINKER_FLAGS_%s is (.-)\n", buildtype)):split(" "))

_g.cmake_default_flags = _g.cmake_default_flags or {}
_g.cmake_default_flags[buildtype] = cmake_default_flags
if outdata then
cmake_default_flags = {}
cmake_default_flags.cflags = outdata:match("CMAKE_C_FLAGS is (.-)\n") or " "
cmake_default_flags.cflags = cmake_default_flags.cflags .. " " .. outdata:match(format("CMAKE_C_FLAGS_%s is (.-)\n", buildtype)):replace("/MDd", ""):replace("/MD", "")
cmake_default_flags.cxxflags = outdata:match("CMAKE_CXX_FLAGS is (.-)\n") or " "
cmake_default_flags.cxxflags = cmake_default_flags.cxxflags .. " " .. outdata:match(format("CMAKE_CXX_FLAGS_%s is (.-)\n", buildtype)):replace("/MDd", ""):replace("/MD", "")
cmake_default_flags.ldflags = outdata:match("CMAKE_EXE_LINKER_FLAGS is (.-)\n") or " "
cmake_default_flags.ldflags = cmake_default_flags.ldflags .. " " .. outdata:match(format("CMAKE_EXE_LINKER_FLAGS_%s is (.-)\n", buildtype))
cmake_default_flags.shflags = outdata:match("CMAKE_SHARED_LINKER_FLAGS is (.-)\n") or " "
cmake_default_flags.shflags = cmake_default_flags.shflags .. " " .. outdata:match(format("CMAKE_SHARED_LINKER_FLAGS_%s is (.-)\n", buildtype))
cmake_default_flags.arflags = outdata:match("CMAKE_STATIC_LINKER_FLAGS is (.-)\n") or " "
cmake_default_flags.arflags = cmake_default_flags.arflags .. " " ..outdata:match(format("CMAKE_STATIC_LINKER_FLAGS_%s is (.-)\n", buildtype))

_g.cmake_default_flags = _g.cmake_default_flags or {}
_g.cmake_default_flags[buildtype] = cmake_default_flags
end
os.rm(tmpdir)
end
return cmake_default_flags
end
Expand Down Expand Up @@ -845,12 +848,8 @@ function _get_configs(package, configs, opt)
if runtime_envs then
envs = envs or {}
for name, value in pairs(runtime_envs) do
envs[name] = table.join(envs[name], value)
end
end
if envs then
for name, value in pairs(envs) do
envs[name] = table.concat(table.unique(value), " ")
print(envs[name], value)
envs[name] = (envs[name] or " ") .. " " .. table.concat(value, " ")
end
end
_insert_configs_from_envs(configs, envs or {}, opt)
Expand Down

0 comments on commit eb95459

Please sign in to comment.