-
Notifications
You must be signed in to change notification settings - Fork 4
/
cmake_solution.lua
134 lines (101 loc) · 3.08 KB
/
cmake_solution.lua
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
--
-- cmake_solution.lua
-- Generate a solution-level cmakelist.txt file.
-- Copyright (c) 2014 Manu Evans and the Premake project
--
local cmake = premake.extensions.cmake
local solution = premake.solution
local project = premake.project
--
-- Generate a GNU make "solution" makefile, with support for the new platforms API.
--
function make.generate_solution(sln)
premake.eol("\n")
make.header(sln)
make.configmap(sln)
make.projects(sln)
_p('.PHONY: all clean help $(PROJECTS)')
_p('')
_p('all: $(PROJECTS)')
_p('')
make.projectrules(sln)
make.cleanrules(sln)
make.helprule(sln)
end
--
-- Write out the solution's configuration map, which maps solution
-- level configurations to the project level equivalents.
--
function make.configmap(sln)
for cfg in solution.eachconfig(sln) do
_p('ifeq ($(config),%s)', cfg.shortname)
for prj in solution.eachproject(sln) do
local prjcfg = project.getconfig(prj, cfg.buildcfg, cfg.platform)
if prjcfg then
_p(' %s_config = %s', make.tovar(prj.name), prjcfg.shortname)
end
end
_p('endif')
end
_p('')
end
--
-- Write out the rules for the `make clean` action.
--
function make.cleanrules(sln)
_p('clean:')
for prj in solution.eachproject(sln) do
local prjpath = project.getfilename(prj, make.getmakefilename(prj, true))
local prjdir = path.getdirectory(path.getrelative(sln.location, prjpath))
local prjname = path.getname(prjpath)
_x(1,'@${MAKE} --no-print-directory -C %s -f %s clean', prjdir, prjname)
end
_p('')
end
--
-- Write out the make file help rule and configurations list.
--
function make.helprule(sln)
_p('help:')
_p(1,'@echo "Usage: make [config=name] [target]"')
_p(1,'@echo ""')
_p(1,'@echo "CONFIGURATIONS:"')
for cfg in solution.eachconfig(sln) do
_x(1, '@echo " %s"', cfg.shortname)
end
_p(1,'@echo ""')
_p(1,'@echo "TARGETS:"')
_p(1,'@echo " all (default)"')
_p(1,'@echo " clean"')
for prj in solution.eachproject(sln) do
_p(1,'@echo " %s"', prj.name)
end
_p(1,'@echo ""')
_p(1,'@echo "For more information, see http://industriousone.com/premake/quick-start"')
end
--
-- Write out the list of projects that comprise the solution.
--
function make.projects(sln)
_p('PROJECTS := %s', table.concat(premake.esc(table.extract(sln.projects, "name")), " "))
_p('')
end
--
-- Write out the rules to build each of the solution's projects.
--
function make.projectrules(sln)
for prj in solution.eachproject(sln) do
local deps = project.getdependencies(prj)
deps = table.extract(deps, "name")
_p('%s:%s', premake.esc(prj.name), make.list(deps))
local cfgvar = make.tovar(prj.name)
_p('ifneq (,$(%s_config))', cfgvar)
_p(1,'@echo "==== Building %s ($(%s_config)) ===="', prj.name, cfgvar)
local prjpath = project.getfilename(prj, make.getmakefilename(prj, true))
local prjdir = path.getdirectory(path.getrelative(sln.location, prjpath))
local prjname = path.getname(prjpath)
_x(1,'@${MAKE} --no-print-directory -C %s -f %s config=$(%s_config)', prjdir, prjname, cfgvar)
_p('endif')
_p('')
end
end