Generate sources in workspace

Modify our cxxtest module so that it generates sources in the
configured build directory instead of the source tree. This simplifies
cleaning build output and .gitignore.

Make test_root.cpp a build target so it doesn't have to be generated on
each run. This means no more building and linking into test target
unless needed either. Unfortunately there is no source for test_root.cpp
and an update to cxxtest might require a manual make clean.

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
This commit is contained in:
Ralph Sennhauser
2024-11-03 17:21:41 +01:00
parent 4e98704b71
commit 8d993b9250
4 changed files with 24 additions and 19 deletions
-5
View File
@@ -57,11 +57,6 @@ __pycache__/
*.lo *.lo
*.la *.la
# Test .cpp files (generated during the build)
test_*.cpp
stub_*.cpp
!test_setup.cpp
# Translation files # Translation files
binaries/data/mods/public/gui/credits/texts/translators.json binaries/data/mods/public/gui/credits/texts/translators.json
*.po *.po
+21 -11
View File
@@ -1,8 +1,7 @@
local m = {} local m = {}
m._VERSION = "1.0.1-dev" m._VERSION = "1.1.0-dev"
m.exepath = nil m.exepath = nil
m.rootfile = nil
m.runner = "ErrorPrinter" m.runner = "ErrorPrinter"
m.options = "" m.options = ""
m.rootoptions = "" m.rootoptions = ""
@@ -19,9 +18,8 @@ end
-- Pass all the necessary options to cxxtest (see http://cxxtest.com/guide.html) -- 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 -- for a reference of available options, that should eventually be implemented in
-- this module. -- this module.
function m.init(source_root, have_std, have_eh, runner, includes, root_includes) function m.init(have_std, have_eh, runner, includes, root_includes)
m.rootfile = source_root.."test_root.cpp"
m.runner = runner m.runner = runner
if have_std then if have_std then
@@ -47,11 +45,17 @@ function m.init(source_root, have_std, have_eh, runner, includes, root_includes)
project "cxxtestroot" project "cxxtestroot"
kind "Makefile" kind "Makefile"
targetdir "%{wks.location}/generated"
targetname "test_root.cpp"
-- Note: this command is not silent and clutters the output -- Note: this command is not silent and clutters the output
-- Reported upstream: https://github.com/premake/premake-core/issues/954 -- Reported upstream: https://github.com/premake/premake-core/issues/954
buildmessage 'Generating test root file' buildmessage 'Generating test root file'
buildcommands { m.exepath.." --root "..m.rootoptions.." --runner="..m.runner.." -o "..path.getabsolute(m.rootfile) } buildcommands {
cleancommands { "rm " .. path.getabsolute(m.rootfile) } "{MKDIR} %{wks.location}/generated",
m.exepath.." --root "..m.rootoptions.." --runner="..m.runner.." -o %{wks.location}/generated/test_root.cpp"
}
cleancommands { "{DELETE} %{wks.location}/generated/test_root.cpp" }
end end
end end
@@ -64,7 +68,10 @@ function m.configure_project(hdrfiles)
dependson { "cxxtestroot" } dependson { "cxxtestroot" }
else else
prebuildmessage 'Generating test root file' prebuildmessage 'Generating test root file'
prebuildcommands { m.exepath.." --root "..m.rootoptions.." --runner="..m.runner.." -o "..path.getabsolute(m.rootfile) } prebuildcommands {
"{MKDIR} %{wks.location}/generated",
m.exepath.." --root "..m.rootoptions.." --runner="..m.runner.." -o %{wks.location}/generated/test_root.cpp"
}
end end
-- Add headers -- Add headers
@@ -76,15 +83,18 @@ function m.configure_project(hdrfiles)
-- This doesn't work with xcode, see https://github.com/premake/premake-core/issues/940 -- This doesn't work with xcode, see https://github.com/premake/premake-core/issues/940
filter { "files:**.h", "files:not **precompiled.h" } filter { "files:**.h", "files:not **precompiled.h" }
buildmessage 'Generating %{file.basename}.cpp' buildmessage 'Generating %{file.basename}.cpp'
buildcommands { m.exepath.." --part "..m.options.." -o %{file.directory}/%{file.basename}.cpp %{file.relpath}" } buildcommands {
buildoutputs { "%{file.directory}/%{file.basename}.cpp" } "{MKDIR} %{wks.location}/generated",
m.exepath.." --part "..m.options.." -o %{wks.location}/generated/%{file.basename}.cpp %{file.relpath}"
}
buildoutputs { "%{wks.location}/generated/%{file.basename}.cpp" }
filter {} filter {}
-- Add source files -- Add source files
files { m.rootfile } files { "%{wks.location}/generated/test_root.cpp" }
if not (_ACTION == "gmake2") then if not (_ACTION == "gmake2") then
for _,hdrfile in ipairs(hdrfiles) do for _,hdrfile in ipairs(hdrfiles) do
local srcfile = string.sub(hdrfile, 1, -3) .. ".cpp" local srcfile = "%{wks.location}/generated/".. path.getbasename(hdrfile) .. ".cpp"
files { srcfile } files { srcfile }
end end
end end
+1 -1
View File
@@ -1434,7 +1434,7 @@ function setup_tests()
table.insert(test_root_include_files, "lib/external_libraries/libsdl.h") table.insert(test_root_include_files, "lib/external_libraries/libsdl.h")
end end
cxxtest.init(source_root, true, true, runner, include_files, test_root_include_files) cxxtest.init(true, true, runner, include_files, test_root_include_files)
local target_type = get_main_project_target_type() local target_type = get_main_project_target_type()
project_create("test", target_type) project_create("test", target_type)
+2 -2
View File
@@ -3,8 +3,8 @@
# This script remains for backwards compatibility, but consists of a single # This script remains for backwards compatibility, but consists of a single
# git command. # git command.
cd "$(dirname "$0")/../../" || exit 1 cd "$(dirname "$0")" || exit 1
git clean -fx build source git clean -fx .
echo "WARNING: This script has been split with libraries/clean-source-libs.sh" echo "WARNING: This script has been split with libraries/clean-source-libs.sh"
echo "If you want to fix a problem with bundled libs, it's the other script" echo "If you want to fix a problem with bundled libs, it's the other script"