File size: 2,397 Bytes
d7c5875 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local assert = _tl_compat and _tl_compat.assert or assert; local io = _tl_compat and _tl_compat.io or io; local os = _tl_compat and _tl_compat.os or os; local pairs = _tl_compat and _tl_compat.pairs or pairs; local string = _tl_compat and _tl_compat.string or string; local type = type
local cmake = { CMakeBuild = {} }
local fs = require("luarocks.fs")
local util = require("luarocks.util")
local cfg = require("luarocks.core.cfg")
function cmake.run(rockspec, no_install)
local build = rockspec.build
local variables = build.variables or {}
util.variable_substitutions(variables, rockspec.variables)
local ok, err_msg = fs.is_tool_available(rockspec.variables.CMAKE, "CMake")
if not ok then
return nil, err_msg
end
local build_cmake = build.cmake
if type(build_cmake) == "string" then
local cmake_handler = assert((io.open(fs.current_dir() .. "/CMakeLists.txt", "w")))
cmake_handler:write(build.cmake)
cmake_handler:close()
end
local args = ""
if cfg.cmake_generator then
args = args .. ' -G"' .. cfg.cmake_generator .. '"'
elseif cfg.is_platform("windows") and cfg.target_cpu:match("x86_64$") then
args = args .. " -DCMAKE_GENERATOR_PLATFORM=x64"
end
for k, v in pairs(variables) do
args = args .. ' -D' .. k .. '="' .. tostring(v) .. '"'
end
if not fs.execute_string(rockspec.variables.CMAKE .. " -H. -Bbuild.luarocks " .. args) then
return nil, "Failed cmake."
end
local do_build, do_install
if rockspec:format_is_at_least("3.0") then
do_build = (build.build_pass == nil) and true or build.build_pass
do_install = (build.install_pass == nil) and true or build.install_pass
else
do_build = true
do_install = true
end
if do_build then
if not fs.execute_string(rockspec.variables.CMAKE .. " --build build.luarocks --config Release") then
return nil, "Failed building."
end
end
if do_install and not no_install then
if not fs.execute_string(rockspec.variables.CMAKE .. " --build build.luarocks --target install --config Release") then
return nil, "Failed installing."
end
end
return true
end
return cmake
|