Skip to content

Commit 47d82fe

Browse files
authored
Merge pull request #137 from luadebug/xm
xmake Add tests
2 parents 958156e + 217fc10 commit 47d82fe

2 files changed

Lines changed: 49 additions & 6 deletions

File tree

tests/main.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <gtest/gtest.h>
2+
3+
int main(int argc, char** argv) {
4+
testing::InitGoogleTest(&argc, argv);
5+
6+
return RUN_ALL_TESTS();
7+
}

xmake.lua

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ set_warnings("all")
1010
option("avx2")
1111
set_default(true)
1212
set_showmenu(true)
13-
add_defines("OMATH_ENABLE_AVX2")
14-
add_vectorexts("avx2")
1513

1614
after_check(function (option)
1715
import("core.base.cpu")
@@ -22,30 +20,42 @@ option_end()
2220
option("imgui")
2321
set_default(true)
2422
set_showmenu(true)
25-
add_defines("OMATH_IMGUI_INTEGRATION")
2623
option_end()
2724

2825
option("examples")
2926
set_default(true)
3027
set_showmenu(true)
3128
option_end()
3229

30+
option("tests")
31+
set_default(true)
32+
set_showmenu(true)
33+
option_end()
34+
35+
if has_config("avx2") then
36+
add_defines("OMATH_ENABLE_AVX2")
37+
add_vectorexts("avx2")
38+
end
39+
3340
if has_config("imgui") then
41+
add_defines("OMATH_IMGUI_INTEGRATION")
3442
add_requires("imgui")
43+
add_packages("imgui")
3544
end
3645

3746
if has_config("examples") then
3847
add_requires("glew", "glfw")
3948
end
4049

50+
if has_config("tests") then
51+
add_requires("gtest")
52+
end
53+
4154
target("omath")
4255
set_kind("static")
4356
add_files("source/**.cpp")
4457
add_includedirs("include", {public = true})
4558
add_headerfiles("include/(**.hpp)", {prefixdir = "omath"})
46-
if has_config("imgui") then
47-
add_packages("imgui")
48-
end
4959
on_config(function (target)
5060
if has_config("avx2") then
5161
cprint("${green} ✔️ AVX2 supported")
@@ -75,3 +85,29 @@ target("example_glfw3")
7585
add_deps("omath")
7686
add_packages("glew", "glfw")
7787
set_enabled(has_config("examples"))
88+
89+
for _, file in ipairs(os.files("tests/**.cpp")) do
90+
local name = path.basename(file)
91+
target(name)
92+
set_languages("cxx23")
93+
set_kind("binary")
94+
add_files(file, "tests/main.cpp")
95+
add_deps("omath")
96+
add_packages("gtest")
97+
add_defines("OMATH_BUILD_TESTS")
98+
add_tests("default")
99+
set_default(false)
100+
set_enabled(has_config("tests"))
101+
end
102+
103+
task("check")
104+
on_run(function ()
105+
import("core.project.task")
106+
for _, file in ipairs(os.files("tests/**.cpp")) do
107+
local name = path.basename(file)
108+
task.run("run", {target = name})
109+
end
110+
end)
111+
set_menu {
112+
usage = "xmake check", description = "Run tests !", options = {}
113+
}

0 commit comments

Comments
 (0)