Skip to content

Commit

Permalink
Update cmake.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed Aug 30, 2024
1 parent 3ee57aa commit 412be79
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions xmake/modules/package/tools/cmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,13 @@ function _fix_pdbdir_for_ninja(package)
end
end

-- enter build directory
function _enter_buildir(package, opt)
local buildir = opt.buildir or package:buildir()
os.mkdir(path.join(buildir, "install"))
return os.cd(buildir)
end

-- get build environments
function buildenvs(package, opt)

Expand Down Expand Up @@ -1171,8 +1178,9 @@ function _get_cmake_generator(package, opt)
return cmake_generator
end

function configure(package, configs, opt, sourcedir)
function configure(package, configs, opt)
opt = opt or {}
local oldir = _enter_buildir(package, opt)

-- pass configurations
local argv = {}
Expand All @@ -1186,25 +1194,24 @@ function configure(package, configs, opt, sourcedir)
table.insert(argv, "-D" .. name .. "=" .. value)
end
end
table.insert(argv, sourcedir)
table.insert(argv, oldir)

-- do configure
local cmake = assert(find_tool("cmake"), "cmake not found!")
os.vrunv(cmake.program, argv, {envs = opt.envs or buildenvs(package, opt)})
os.cd(oldir)
end

-- build package
function build(package, configs, opt)
opt = opt or {}
local cmake_generator = _get_cmake_generator(package, opt)

-- enter build directory
local buildir = opt.buildir or package:buildir()
os.mkdir(path.join(buildir, "install"))
local oldir = os.cd(buildir)
configure(package, configs, opt, oldir)
-- do configure
configure(package, configs, opt)

-- do build
local oldir = _enter_buildir(package, opt)
if opt.cmake_build then
_build_for_cmakebuild(package, configs, opt)
elseif cmake_generator then
Expand Down Expand Up @@ -1232,13 +1239,11 @@ function install(package, configs, opt)
opt = opt or {}
local cmake_generator = _get_cmake_generator(package, opt)

-- enter build directory
local buildir = opt.buildir or package:buildir()
os.mkdir(path.join(buildir, "install"))
local oldir = os.cd(buildir)
configure(package, configs, opt, oldir)
-- do configure
configure(package, configs, opt)

-- do build and install
local oldir = _enter_buildir(package, opt)
if opt.cmake_build then
_install_for_cmakebuild(package, configs, opt)
elseif cmake_generator then
Expand Down

0 comments on commit 412be79

Please sign in to comment.