Previous 199869 Revisions Next

r41655 Sunday 8th November, 2015 at 13:50:45 UTC by Miodrag Milanović
added cmake support to genie (nw)
[3rdparty/genie/src/actions/cmake]_cmake.lua* cmake_project.lua* cmake_workspace.lua*

trunk/3rdparty/genie/src/actions/cmake/_cmake.lua
r0r250167
1--
2-- _cmake.lua
3-- Define the CMake action(s).
4-- Copyright (c) 2015 Miodrag Milanovic
5--
6
7premake.cmake = { }
8
9newaction {
10   trigger         = "cmake",
11   shortname       = "CMake",
12   description     = "Generate CMake project files",
13   valid_kinds     = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib" },
14   valid_languages = { "C", "C++" },
15   valid_tools     = {
16   cc   = { "gcc" },
17   },
18   onsolution = function(sln)
19      premake.generate(sln, "CMakeLists.txt", premake.cmake.workspace)
20   end,
21   onproject = function(prj)
22      premake.generate(prj, "%%/CMakeLists.txt", premake.cmake.project)
23   end,
24   oncleansolution = function(sln)
25      premake.clean.file(sln, "CMakeLists.txt")
26   end,
27   oncleanproject = function(prj)
28      premake.clean.file(prj, "%%/CMakeLists.txt")
29   end
30}
31
trunk/3rdparty/genie/src/actions/cmake/cmake_project.lua
r0r250167
1--
2-- _cmake.lua
3-- Define the CMake action(s).
4-- Copyright (c) 2015 Miodrag Milanovic
5--
6
7local cmake = premake.cmake
8local tree = premake.tree
9
10function cmake.files(prj)
11   local tr = premake.project.buildsourcetree(prj)
12   tree.traverse(tr, {
13      onbranchenter = function(node, depth)
14      end,
15      onbranchexit = function(node, depth)
16      end,
17      onleaf = function(node, depth)
18         _p(1, '../%s', node.cfg.name)
19      end,
20   }, true, 1)
21end
22
23function premake.cmake.project(prj)
24   io.indent = "  "
25   _p('cmake_minimum_required(VERSION 2.8.4)')
26   _p('')
27   _p('project(%s)', premake.esc(prj.name))
28   _p('set(')
29   _p('source_list')
30   cmake.files(prj)
31   _p(')')
32
33   local platforms = premake.filterplatforms(prj.solution, premake[_OPTIONS.cc].platforms, "Native")
34   for i = #platforms, 1, -1 do
35      if premake.platforms[platforms[i]].iscrosscompiler then
36         table.remove(platforms, i)
37      end
38   end
39   
40   for _, platform in ipairs(platforms) do
41      for cfg in premake.eachconfig(prj, platform) do
42         for _,v in ipairs(cfg.includedirs) do
43            _p('include_directories(../%s)', premake.esc(v))
44         end
45      end
46   end
47
48   if (prj.kind=='StaticLib') then
49      _p('add_library(%s STATIC ${source_list})',premake.esc(prj.name))
50   end
51   if (prj.kind=='SharedLib') then
52      _p('add_library(%s SHARED ${source_list})',premake.esc(prj.name))
53   end
54   if (prj.kind=='ConsoleApp') then
55      _p('add_executable(%s ${source_list})',premake.esc(prj.name))
56   end
57   if (prj.kind=='WindowedApp') then
58      _p('add_executable(%s ${source_list})',premake.esc(prj.name))
59   end
60end
trunk/3rdparty/genie/src/actions/cmake/cmake_workspace.lua
r0r250167
1--
2-- _cmake.lua
3-- Define the CMake action(s).
4-- Copyright (c) 2015 Miodrag Milanovic
5--
6
7function premake.cmake.workspace(sln)
8   _p('cmake_minimum_required(VERSION 2.8.4)')
9   _p('')
10   for i,prj in ipairs(sln.projects) do
11      local name = premake.esc(prj.name)
12      _p('add_subdirectory(%s)', name)
13   end
14end


Previous 199869 Revisions Next


© 1997-2024 The MAME Team