Welcome to mirror list, hosted at ThFree Co, Russian Federation.

codelite_project.lua « codelite « actions « src - github.com/windirstat/premake-4.x-stable.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0d65863ca3139c56a97b6a0980eb22e5ed0f449e (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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
--
-- codelite_project.lua
-- Generate a CodeLite C/C++ project file.
-- Copyright (c) 2009, 2011 Jason Perkins and the Premake project
--

	local codelite = premake.codelite
	local tree = premake.tree


--
-- Write out a list of the source code files in the project.
--

	function codelite.files(prj)
		local tr = premake.project.buildsourcetree(prj)
		tree.traverse(tr, {
			
			-- folders are handled at the internal nodes
			onbranchenter = function(node, depth)
				_p(depth, '<VirtualDirectory Name="%s">', node.name)
			end,

			onbranchexit = function(node, depth)
				_p(depth, '</VirtualDirectory>')
			end,

			-- source files are handled at the leaves
			onleaf = function(node, depth)
				_p(depth, '<File Name="%s"/>', node.cfg.name)
			end,
			
		}, true, 1)
	end
	

--
-- The main function: write out the project file.
--

	function premake.codelite.project(prj)
		io.indent = "  "
		
		_p('<?xml version="1.0" encoding="utf-8"?>')
		_p('<CodeLite_Project Name="%s">', premake.esc(prj.name))

		-- Write out the list of source code files in the project
		codelite.files(prj)

		local types = { 
			ConsoleApp  = "Executable", 
			WindowedApp = "Executable", 
			StaticLib   = "Static Library",
			SharedLib   = "Dynamic Library",
		}
		_p('  <Settings Type="%s">', types[prj.kind])
		
		-- build a list of supported target platforms; I don't support cross-compiling yet
		local platforms = premake.filterplatforms(prj.solution, premake[_OPTIONS.cc].platforms, "Native")
		for i = #platforms, 1, -1 do
			if premake.platforms[platforms[i]].iscrosscompiler then
				table.remove(platforms, i)
			end
		end 

		for _, platform in ipairs(platforms) do
			for cfg in premake.eachconfig(prj, platform) do
				local name = premake.esc(cfg.longname):gsub("|","_")
				local compiler = iif(cfg.language == "C", "gcc", "g++")
				_p('    <Configuration Name="%s" CompilerType="gnu %s" DebuggerType="GNU gdb debugger" Type="%s">', name, compiler, types[cfg.kind])
			
				local fname  = premake.esc(cfg.buildtarget.fullpath)
				local objdir = premake.esc(cfg.objectsdir)
				local runcmd = cfg.buildtarget.name
				local rundir = cfg.debugdir or cfg.buildtarget.directory
				local runargs = table.concat(cfg.debugargs, " ")
				local pause  = iif(cfg.kind == "WindowedApp", "no", "yes")
				_p('      <General OutputFile="%s" IntermediateDirectory="%s" Command="./%s" CommandArguments="%s" WorkingDirectory="%s" PauseExecWhenProcTerminates="%s"/>', fname, objdir, runcmd, runargs, rundir, pause)
				
				-- begin compiler block --
				local flags = premake.esc(table.join(premake.gcc.getcflags(cfg), premake.gcc.getcxxflags(cfg), cfg.buildoptions))
				_p('      <Compiler Required="yes" Options="%s">', table.concat(flags, ";"))
				for _,v in ipairs(cfg.includedirs) do
					_p('        <IncludePath Value="%s"/>', premake.esc(v))
				end
				for _,v in ipairs(cfg.defines) do
					_p('        <Preprocessor Value="%s"/>', premake.esc(v))
				end
				_p('      </Compiler>')
				-- end compiler block --
				
				-- begin linker block --
				flags = premake.esc(table.join(premake.gcc.getldflags(cfg), cfg.linkoptions))
				_p('      <Linker Required="yes" Options="%s">', table.concat(flags, ";"))
				for _,v in ipairs(premake.getlinks(cfg, "all", "directory")) do
					_p('        <LibraryPath Value="%s" />', premake.esc(v))
				end
				for _,v in ipairs(premake.getlinks(cfg, "siblings", "basename")) do
					_p('        <Library Value="%s" />', premake.esc(v))
				end
				for _,v in ipairs(premake.getlinks(cfg, "system", "name")) do
					_p('        <Library Value="%s" />', premake.esc(v))
				end		
				_p('      </Linker>')
				-- end linker block --
				
				-- begin resource compiler block --
				if premake.findfile(cfg, ".rc") then
					local defines = table.implode(table.join(cfg.defines, cfg.resdefines), "-D", ";", "")
					local options = table.concat(cfg.resoptions, ";")
					_p('      <ResourceCompiler Required="yes" Options="%s%s">', defines, options)
					for _,v in ipairs(table.join(cfg.includedirs, cfg.resincludedirs)) do
						_p('        <IncludePath Value="%s"/>', premake.esc(v))
					end
					_p('      </ResourceCompiler>')
				else
					_p('      <ResourceCompiler Required="no" Options=""/>')
				end
				-- end resource compiler block --
				
				-- begin build steps --
				if #cfg.prebuildcommands > 0 then
					_p('      <PreBuild>')
					for _,v in ipairs(cfg.prebuildcommands) do
						_p('        <Command Enabled="yes">%s</Command>', premake.esc(v))
					end
					_p('      </PreBuild>')
				end
				if #cfg.postbuildcommands > 0 then
					_p('      <PostBuild>')
					for _,v in ipairs(cfg.postbuildcommands) do
						_p('        <Command Enabled="yes">%s</Command>', premake.esc(v))
					end
					_p('      </PostBuild>')
				end
				-- end build steps --
				
				_p('      <CustomBuild Enabled="no">')
				_p('        <CleanCommand></CleanCommand>')
				_p('        <BuildCommand></BuildCommand>')
				_p('        <SingleFileCommand></SingleFileCommand>')
				_p('        <MakefileGenerationCommand></MakefileGenerationCommand>')
				_p('        <ThirdPartyToolName>None</ThirdPartyToolName>')
				_p('        <WorkingDirectory></WorkingDirectory>')
				_p('      </CustomBuild>')
				_p('      <AdditionalRules>')
				_p('        <CustomPostBuild></CustomPostBuild>')
				_p('        <CustomPreBuild></CustomPreBuild>')
				_p('      </AdditionalRules>')
				_p('    </Configuration>')
			end
		end
		_p('  </Settings>')

		for _, platform in ipairs(platforms) do
			for cfg in premake.eachconfig(prj, platform) do
				_p('  <Dependencies name="%s">', cfg.longname:gsub("|","_"))
				for _,dep in ipairs(premake.getdependencies(prj)) do
					_p('    <Project Name="%s"/>', dep.name)
				end
				_p('  </Dependencies>')
			end
		end
		
		_p('</CodeLite_Project>')
	end