blob: ed2af3ffa14abde5c928d82c1bbcee45a4b1836b (
plain)
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
|
--- Build back-end for CMake-based modules.
--module("luarocks.build.cmake", package.seeall)
local cmake = {}
local fs = require("luarocks.fs")
local util = require("luarocks.util")
local cfg = require("luarocks.cfg")
--- Driver function for the "cmake" build back-end.
-- @param rockspec table: the loaded rockspec.
-- @return boolean or (nil, string): true if no errors ocurred,
-- nil and an error message otherwise.
function cmake.run(rockspec)
assert(type(rockspec) == "table")
local build = rockspec.build
local variables = build.variables or {}
-- Pass Env variables
variables.CMAKE_MODULE_PATH=os.getenv("CMAKE_MODULE_PATH")
variables.CMAKE_LIBRARY_PATH=os.getenv("CMAKE_LIBRARY_PATH")
variables.CMAKE_INCLUDE_PATH=os.getenv("CMAKE_INCLUDE_PATH")
util.variable_substitutions(variables, rockspec.variables)
if not fs.execute_quiet(rockspec.variables.CMAKE, "--help") then
return nil, "'"..rockspec.variables.CMAKE.."' program not found. Is cmake installed? You may want to edit variables.CMAKE"
end
-- If inline cmake is present create CMakeLists.txt from it.
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
-- Execute cmake with variables.
local args = ""
if cfg.cmake_generator then
args = args .. ' -G"'..cfg.cmake_generator.. '"'
end
for k,v in pairs(variables) do
args = args .. ' -D' ..k.. '="' ..v.. '"'
end
if not fs.execute_string(rockspec.variables.CMAKE.." . " ..args) then
return nil, "Failed cmake."
end
if not fs.execute_string(rockspec.variables.MAKE.." -fMakefile") then
return nil, "Failed building."
end
if not fs.execute_string(rockspec.variables.MAKE.." -fMakefile install") then
return nil, "Failed installing."
end
return true
end
return cmake
|