mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-09-21 20:06:40 +00:00
Refactor the cxxtest premake module.
Properly fix the current issues with pre-build commands, improve the documentation of known issues and re-design the module so it is easy to extend it into a fully-fledged CxxTest module supporting all features of the tool. Reviewed By: wraitii Tested By: elexis, bb, Imarok Differential Revision: https://code.wildfiregames.com/D1092 This was SVN commit r20633.
This commit is contained in:
@@ -1,49 +1,77 @@
|
||||
local m = {}
|
||||
m._VERSION = "1.0.0-dev"
|
||||
|
||||
m.path = nil
|
||||
m.exepath = nil
|
||||
m.rootfile = nil
|
||||
m.runner = "ErrorPrinter"
|
||||
m.options = ""
|
||||
|
||||
-- We need to create .cpp files from the .h files before they can be compiled.
|
||||
-- This is done by the cxxtestgen utility.
|
||||
-- Premake module for CxxTest support (http://cxxtest.com/).
|
||||
-- The module can be used for generating a root file (that contains the entrypoint
|
||||
-- for the test executable) and source files for each test header.
|
||||
|
||||
-- We use a custom build rule for headers in order to generate the .cpp files.
|
||||
-- This has several advantages over using pre-build commands:
|
||||
-- - It cannot break when running parallel builds
|
||||
-- - No new generation happens when the header files are untouched
|
||||
-- Set the executable path for cxxtestgen
|
||||
function m.setpath(exepath)
|
||||
m.exepath = path.getabsolute(exepath)
|
||||
end
|
||||
|
||||
function m.configure_project(rootfile, hdrfiles, rootoptions, testoptions)
|
||||
if rootoptions == nil then
|
||||
rootoptions = ''
|
||||
end
|
||||
if testoptions == nil then
|
||||
testoptions = ''
|
||||
-- Pass all the necessary options to cxxtest (see http://cxxtest.com/guide.html)
|
||||
-- for a reference of available options, that should eventually be implemented in
|
||||
-- this module.
|
||||
function m.init(source_root, have_std, runner, includes)
|
||||
|
||||
m.rootfile = source_root.."test_root.cpp"
|
||||
m.runner = runner
|
||||
|
||||
if m.have_std then
|
||||
m.options = m.options.." --have-std"
|
||||
end
|
||||
|
||||
local abspath = path.getabsolute(m.path)
|
||||
local rootpath = path.getabsolute(rootfile)
|
||||
for _,includefile in ipairs(includes) do
|
||||
m.options = m.options.." --include="..includefile
|
||||
end
|
||||
|
||||
-- With gmake, create a Utility project that generates the test root file
|
||||
-- This is a workaround for https://github.com/premake/premake-core/issues/286
|
||||
if _ACTION == "gmake" then
|
||||
project "cxxtestroot"
|
||||
kind "Utility"
|
||||
|
||||
-- Note: this command is not silent and clutters the output
|
||||
-- Reported upstream: https://github.com/premake/premake-core/issues/954
|
||||
prebuildmessage 'Generating test root file'
|
||||
prebuildcommands { m.exepath.." --root "..m.options.." --runner="..m.runner.." -o "..path.getabsolute(m.rootfile) }
|
||||
buildoutputs { m.rootfile }
|
||||
end
|
||||
end
|
||||
|
||||
-- Populate the test project that was created in premake5.lua.
|
||||
function m.configure_project(hdrfiles)
|
||||
|
||||
-- Generate the root file, or make sure the utility for generating
|
||||
-- it is a dependancy with gmake.
|
||||
if _ACTION == "gmake" then
|
||||
dependson { "cxxtestroot" }
|
||||
else
|
||||
prebuildmessage 'Generating test root file'
|
||||
prebuildcommands { m.exepath.." --root "..m.options.." --runner="..m.runner.." -o "..path.getabsolute(m.rootfile) }
|
||||
end
|
||||
|
||||
-- Add headers
|
||||
|
||||
for _,hdrfile in ipairs(hdrfiles) do
|
||||
files { hdrfile }
|
||||
end
|
||||
|
||||
-- Generate the root file
|
||||
prebuildmessage 'Generating test root file'
|
||||
prebuildcommands { abspath.." --root "..rootoptions.." -o "..rootpath }
|
||||
|
||||
-- Generate the source files from headers
|
||||
|
||||
-- This doesn't work with xcode, see https://github.com/premake/premake-core/issues/940
|
||||
filter { "files:**.h", "files:not **precompiled.h" }
|
||||
buildmessage 'Generating %{file.basename}.cpp'
|
||||
buildcommands { abspath.." --part "..testoptions.." -o %{file.directory}/%{file.basename}.cpp %{file.relpath}" }
|
||||
buildcommands { m.exepath.." --part "..m.options.." -o %{file.directory}/%{file.basename}.cpp %{file.relpath}" }
|
||||
buildoutputs { "%{file.directory}/%{file.basename}.cpp" }
|
||||
filter {}
|
||||
|
||||
-- Add source files
|
||||
|
||||
files { rootfile }
|
||||
|
||||
files { m.rootfile }
|
||||
for _,hdrfile in ipairs(hdrfiles) do
|
||||
local srcfile = string.sub(hdrfile, 1, -3) .. ".cpp"
|
||||
files { srcfile }
|
||||
|
||||
+24
-34
@@ -1291,27 +1291,34 @@ end
|
||||
-- tests
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
function configure_cxxtestgen()
|
||||
local lcxxtestrootfile = source_root.."test_root.cpp"
|
||||
function setup_tests()
|
||||
|
||||
-- Define the options used for cxxtestgen
|
||||
local lcxxtestoptions = "--have-std"
|
||||
local lcxxtestrootoptions = "--have-std"
|
||||
local cxxtest = require "cxxtest"
|
||||
|
||||
if _OPTIONS["jenkins-tests"] then
|
||||
lcxxtestrootoptions = lcxxtestrootoptions .. " --runner=XmlPrinter"
|
||||
if os.istarget("windows") then
|
||||
cxxtest.setpath(rootdir.."/build/bin/cxxtestgen.exe")
|
||||
else
|
||||
lcxxtestrootoptions = lcxxtestrootoptions .. " --runner=ErrorPrinter"
|
||||
cxxtest.setpath(rootdir.."/libraries/source/cxxtest-4.4/bin/cxxtestgen")
|
||||
end
|
||||
|
||||
-- Precompiled headers - the header is added to all generated .cpp files
|
||||
-- note that the header isn't actually precompiled here, only #included
|
||||
-- so that the build stage can use it as a precompiled header.
|
||||
local include = " --include=precompiled.h"
|
||||
-- This is required to build against SDL 2.0.4 on Windows
|
||||
include = include .. " --include=lib/external_libraries/libsdl.h"
|
||||
lcxxtestrootoptions = lcxxtestrootoptions .. include
|
||||
lcxxtestoptions = lcxxtestoptions .. include
|
||||
local runner = "ErrorPrinter"
|
||||
if _OPTIONS["jenkins-tests"] then
|
||||
runner = "XmlPrinter"
|
||||
end
|
||||
|
||||
local includefiles = {
|
||||
-- Precompiled headers - the header is added to all generated .cpp files
|
||||
-- note that the header isn't actually precompiled here, only #included
|
||||
-- so that the build stage can use it as a precompiled header.
|
||||
"precompiled.h",
|
||||
-- This is required to build against SDL 2.0.4 on Windows.
|
||||
"lib/external_libraries/libsdl.h",
|
||||
}
|
||||
|
||||
cxxtest.init(source_root, true, runner, includefiles)
|
||||
|
||||
local target_type = get_main_project_target_type()
|
||||
project_create("test", target_type)
|
||||
|
||||
-- Find header files in 'test' subdirectories
|
||||
local all_files = os.matchfiles(source_root .. "**/tests/*.h")
|
||||
@@ -1327,24 +1334,7 @@ function configure_cxxtestgen()
|
||||
end
|
||||
end
|
||||
|
||||
local cxxtest = require "cxxtest"
|
||||
|
||||
if os.istarget("windows") then
|
||||
cxxtest.path = rootdir.."/build/bin/cxxtestgen.exe"
|
||||
else
|
||||
cxxtest.path = rootdir.."/libraries/source/cxxtest-4.4/bin/cxxtestgen"
|
||||
end
|
||||
|
||||
cxxtest.configure_project(lcxxtestrootfile, test_files, lcxxtestrootoptions, lcxxtestoptions)
|
||||
end
|
||||
|
||||
|
||||
function setup_tests()
|
||||
|
||||
local target_type = get_main_project_target_type()
|
||||
project_create("test", target_type)
|
||||
|
||||
configure_cxxtestgen()
|
||||
cxxtest.configure_project(test_files)
|
||||
|
||||
filter "system:not macosx"
|
||||
linkgroups 'On'
|
||||
|
||||
Reference in New Issue
Block a user