diff options
author | Jason Perkins <starkos@industriousone.com> | 2011-05-13 00:14:43 +0400 |
---|---|---|
committer | Jason Perkins <starkos@industriousone.com> | 2011-05-13 00:14:43 +0400 |
commit | 21b38a71196abb96de0ee9de2705e3afd0a9b7da (patch) | |
tree | ec126dac824e09a5832c8cc0621b53eddfd917c5 | |
parent | dafe3ba6ec5cbd7dc803317e9c99c2ec645b586f (diff) |
Prepped CodeBlocks for new file configs
-rw-r--r-- | src/actions/codeblocks/_codeblocks.lua | 7 | ||||
-rw-r--r-- | src/actions/codeblocks/codeblocks_cbp.lua | 62 | ||||
-rw-r--r-- | src/actions/codeblocks/codeblocks_workspace.lua | 2 | ||||
-rw-r--r-- | src/actions/codelite/codelite_project.lua | 1 | ||||
-rwxr-xr-x | tests/actions/codeblocks/codeblocks_files.lua | 101 | ||||
-rw-r--r-- | tests/premake4.lua | 3 |
6 files changed, 148 insertions, 28 deletions
diff --git a/src/actions/codeblocks/_codeblocks.lua b/src/actions/codeblocks/_codeblocks.lua index bfe7ad2..1d378be 100644 --- a/src/actions/codeblocks/_codeblocks.lua +++ b/src/actions/codeblocks/_codeblocks.lua @@ -1,9 +1,10 @@ -- -- _codeblocks.lua -- Define the Code::Blocks action(s). --- Copyright (c) 2002-2009 Jason Perkins and the Premake project +-- Copyright (c) 2002-2011 Jason Perkins and the Premake project -- + premake.codeblocks = { } newaction { trigger = "codeblocks", @@ -19,11 +20,11 @@ }, onsolution = function(sln) - premake.generate(sln, "%%.workspace", premake.codeblocks_workspace) + premake.generate(sln, "%%.workspace", premake.codeblocks.workspace) end, onproject = function(prj) - premake.generate(prj, "%%.cbp", premake.codeblocks_cbp) + premake.generate(prj, "%%.cbp", premake.codeblocks.cbp) end, oncleansolution = function(sln) diff --git a/src/actions/codeblocks/codeblocks_cbp.lua b/src/actions/codeblocks/codeblocks_cbp.lua index 00d494d..aeeb22e 100644 --- a/src/actions/codeblocks/codeblocks_cbp.lua +++ b/src/actions/codeblocks/codeblocks_cbp.lua @@ -1,10 +1,45 @@ -- -- codeblocks_cbp.lua -- Generate a Code::Blocks C/C++ project. --- Copyright (c) 2009 Jason Perkins and the Premake project +-- Copyright (c) 2009, 2011 Jason Perkins and the Premake project -- - function premake.codeblocks_cbp(prj) + local codeblocks = premake.codeblocks + + +-- +-- Write out a list of the source code files in the project. +-- + + function codeblocks.files(prj) + local pchheader + if (prj.pchheader) then + pchheader = path.getrelative(prj.location, prj.pchheader) + end + + for _,fname in ipairs(prj.files) do + _p(2,'<Unit filename="%s">', premake.esc(fname)) + if path.isresourcefile(fname) then + _p(3,'<Option compilerVar="WINDRES" />') + elseif path.iscfile(fname) and prj.language == "C++" then + _p(3,'<Option compilerVar="CC" />') + end + if not prj.flags.NoPCH and fname == pchheader then + _p(3,'<Option compilerVar="%s" />', iif(prj.language == "C", "CC", "CPP")) + _p(3,'<Option compile="1" />') + _p(3,'<Option weight="0" />') + _p(3,'<Add option="-x c++-header" />') + end + _p(2,'</Unit>') + end + end + + +-- +-- The main function: write out the project file. +-- + + function premake.codeblocks.cbp(prj) -- alias the C/C++ compiler interface local cc = premake.gettool(prj) @@ -112,28 +147,7 @@ end _p(2,'</Build>') - -- begin files block -- - local pchheader - if (prj.pchheader) then - pchheader = path.getrelative(prj.location, prj.pchheader) - end - - for _,fname in ipairs(prj.files) do - _p(2,'<Unit filename="%s">', premake.esc(fname)) - if path.isresourcefile(fname) then - _p(3,'<Option compilerVar="WINDRES" />') - elseif path.iscfile(fname) and prj.language == "C++" then - _p(3,'<Option compilerVar="CC" />') - end - if not prj.flags.NoPCH and fname == pchheader then - _p(3,'<Option compilerVar="%s" />', iif(prj.language == "C", "CC", "CPP")) - _p(3,'<Option compile="1" />') - _p(3,'<Option weight="0" />') - _p(3,'<Add option="-x c++-header" />') - end - _p(2,'</Unit>') - end - -- end files block -- + codeblocks.files(prj) _p(2,'<Extensions />') _p(1,'</Project>') diff --git a/src/actions/codeblocks/codeblocks_workspace.lua b/src/actions/codeblocks/codeblocks_workspace.lua index 13e4396..4a01a46 100644 --- a/src/actions/codeblocks/codeblocks_workspace.lua +++ b/src/actions/codeblocks/codeblocks_workspace.lua @@ -4,7 +4,7 @@ -- Copyright (c) 2009 Jason Perkins and the Premake project -- - function premake.codeblocks_workspace(sln) + function premake.codeblocks.workspace(sln) _p('<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>') _p('<CodeBlocks_workspace_file>') _p(1,'<Workspace title="%s">', sln.name) diff --git a/src/actions/codelite/codelite_project.lua b/src/actions/codelite/codelite_project.lua index ba36c4d..1a3184b 100644 --- a/src/actions/codelite/codelite_project.lua +++ b/src/actions/codelite/codelite_project.lua @@ -11,6 +11,7 @@ -- -- 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, { diff --git a/tests/actions/codeblocks/codeblocks_files.lua b/tests/actions/codeblocks/codeblocks_files.lua new file mode 100755 index 0000000..b1bda82 --- /dev/null +++ b/tests/actions/codeblocks/codeblocks_files.lua @@ -0,0 +1,101 @@ +-- +-- tests/actions/codeblocks/codeblocks_files.lua +-- Validate generation of files block in CodeLite C/C++ projects. +-- Copyright (c) 2011 Jason Perkins and the Premake project +-- + + T.codeblocks_files = { } + local suite = T.codeblocks_files + local codeblocks = premake.codeblocks + + +-- +-- Setup +-- + + local sln, prj + + function suite.setup() + sln = test.createsolution() + end + + local function prepare() + premake.buildconfigs() + prj = premake.solution.getproject(sln, 1) + codeblocks.files(prj) + end + + +-- +-- Test grouping and nesting +-- + + function suite.SimpleSourceFile() + files { "hello.cpp" } + prepare() + test.capture [[ + <Unit filename="hello.cpp"> + </Unit> + ]] + end + + + function suite.SingleFolderLevel() + files { "src/hello.cpp" } + prepare() + test.capture [[ + <Unit filename="src/hello.cpp"> + </Unit> + ]] + end + + + function suite.MultipleFolderLevels() + files { "src/greetings/hello.cpp" } + prepare() + test.capture [[ + <Unit filename="src/greetings/hello.cpp"> + </Unit> + ]] + end + + +-- +-- Test source file type handling +-- + + function suite.CFileInCppProject() + files { "hello.c" } + prepare() + test.capture [[ + <Unit filename="hello.c"> + <Option compilerVar="CC" /> + </Unit> + ]] + end + + + function suite.WindowsResourceFile() + files { "hello.rc" } + prepare() + test.capture [[ + <Unit filename="hello.rc"> + <Option compilerVar="WINDRES" /> + </Unit> + ]] + end + + + function suite.PchFile() + files { "hello.h" } + pchheader "hello.h" + prepare() + test.capture [[ + <Unit filename="hello.h"> + <Option compilerVar="CPP" /> + <Option compile="1" /> + <Option weight="0" /> + <Add option="-x c++-header" /> + </Unit> + ]] + end diff --git a/tests/premake4.lua b/tests/premake4.lua index 880e89e..a4512be 100644 --- a/tests/premake4.lua +++ b/tests/premake4.lua @@ -113,6 +113,9 @@ -- CodeLite tests dofile("actions/codelite/codelite_files.lua") + + -- CodeBlocks tests + dofile("actions/codeblocks/codeblocks_files.lua") -- -- Register a test action |