| [20381] | 1 | local m = {}
|
|---|
| 2 | m._VERSION = "1.0.0-dev"
|
|---|
| 3 |
|
|---|
| [20633] | 4 | m.exepath = nil
|
|---|
| 5 | m.rootfile = nil
|
|---|
| 6 | m.runner = "ErrorPrinter"
|
|---|
| 7 | m.options = ""
|
|---|
| [27764] | 8 | m.rootoptions = ""
|
|---|
| [20381] | 9 |
|
|---|
| [20633] | 10 | -- Premake module for CxxTest support (http://cxxtest.com/).
|
|---|
| 11 | -- The module can be used for generating a root file (that contains the entrypoint
|
|---|
| 12 | -- for the test executable) and source files for each test header.
|
|---|
| [20381] | 13 |
|
|---|
| [20633] | 14 | -- Set the executable path for cxxtestgen
|
|---|
| 15 | function m.setpath(exepath)
|
|---|
| 16 | m.exepath = path.getabsolute(exepath)
|
|---|
| 17 | end
|
|---|
| [20381] | 18 |
|
|---|
| [20633] | 19 | -- Pass all the necessary options to cxxtest (see http://cxxtest.com/guide.html)
|
|---|
| 20 | -- for a reference of available options, that should eventually be implemented in
|
|---|
| 21 | -- this module.
|
|---|
| [27764] | 22 | function m.init(source_root, have_std, runner, includes, root_includes)
|
|---|
| [20633] | 23 |
|
|---|
| 24 | m.rootfile = source_root.."test_root.cpp"
|
|---|
| 25 | m.runner = runner
|
|---|
| 26 |
|
|---|
| 27 | if m.have_std then
|
|---|
| 28 | m.options = m.options.." --have-std"
|
|---|
| [20381] | 29 | end
|
|---|
| [20633] | 30 |
|
|---|
| [27764] | 31 | m.rootoptions = m.options
|
|---|
| 32 | for _,includefile in ipairs(root_includes) do
|
|---|
| 33 | m.rootoptions = m.rootoptions.." --include="..includefile
|
|---|
| 34 | end
|
|---|
| 35 |
|
|---|
| [20633] | 36 | for _,includefile in ipairs(includes) do
|
|---|
| 37 | m.options = m.options.." --include="..includefile
|
|---|
| [20381] | 38 | end
|
|---|
| 39 |
|
|---|
| [20633] | 40 | -- With gmake, create a Utility project that generates the test root file
|
|---|
| 41 | -- This is a workaround for https://github.com/premake/premake-core/issues/286
|
|---|
| 42 | if _ACTION == "gmake" then
|
|---|
| 43 | project "cxxtestroot"
|
|---|
| 44 | kind "Utility"
|
|---|
| [20381] | 45 |
|
|---|
| [20633] | 46 | -- Note: this command is not silent and clutters the output
|
|---|
| 47 | -- Reported upstream: https://github.com/premake/premake-core/issues/954
|
|---|
| 48 | prebuildmessage 'Generating test root file'
|
|---|
| [27764] | 49 | prebuildcommands { m.exepath.." --root "..m.rootoptions.." --runner="..m.runner.." -o "..path.getabsolute(m.rootfile) }
|
|---|
| [20633] | 50 | buildoutputs { m.rootfile }
|
|---|
| 51 | end
|
|---|
| 52 | end
|
|---|
| 53 |
|
|---|
| 54 | -- Populate the test project that was created in premake5.lua.
|
|---|
| 55 | function m.configure_project(hdrfiles)
|
|---|
| 56 |
|
|---|
| 57 | -- Generate the root file, or make sure the utility for generating
|
|---|
| 58 | -- it is a dependancy with gmake.
|
|---|
| 59 | if _ACTION == "gmake" then
|
|---|
| 60 | dependson { "cxxtestroot" }
|
|---|
| 61 | else
|
|---|
| 62 | prebuildmessage 'Generating test root file'
|
|---|
| [27764] | 63 | prebuildcommands { m.exepath.." --root "..m.rootoptions.." --runner="..m.runner.." -o "..path.getabsolute(m.rootfile) }
|
|---|
| [20633] | 64 | end
|
|---|
| 65 |
|
|---|
| [20381] | 66 | -- Add headers
|
|---|
| 67 | for _,hdrfile in ipairs(hdrfiles) do
|
|---|
| 68 | files { hdrfile }
|
|---|
| 69 | end
|
|---|
| 70 |
|
|---|
| 71 | -- Generate the source files from headers
|
|---|
| [20633] | 72 | -- This doesn't work with xcode, see https://github.com/premake/premake-core/issues/940
|
|---|
| [20381] | 73 | filter { "files:**.h", "files:not **precompiled.h" }
|
|---|
| 74 | buildmessage 'Generating %{file.basename}.cpp'
|
|---|
| [20633] | 75 | buildcommands { m.exepath.." --part "..m.options.." -o %{file.directory}/%{file.basename}.cpp %{file.relpath}" }
|
|---|
| [20381] | 76 | buildoutputs { "%{file.directory}/%{file.basename}.cpp" }
|
|---|
| 77 | filter {}
|
|---|
| 78 |
|
|---|
| 79 | -- Add source files
|
|---|
| [20633] | 80 | files { m.rootfile }
|
|---|
| [20381] | 81 | for _,hdrfile in ipairs(hdrfiles) do
|
|---|
| 82 | local srcfile = string.sub(hdrfile, 1, -3) .. ".cpp"
|
|---|
| 83 | files { srcfile }
|
|---|
| 84 | end
|
|---|
| 85 | end
|
|---|
| 86 |
|
|---|
| 87 | return m
|
|---|