[/home/dps/.local/share/xmake/core/main.lua:231]:)
Hello, I just started playing with xmake
and linking simple dependencies like zlib
zlib got compiled but my target can't find neither zlib's include
no it's librarries
here is xmake.lua and c++ file:
https://gist.github.com/zelid/4d1eba93c4b24a9ba2b0379a50da367b
what is the right way to get zlib's includes and libs available for my target?
hi. i've got the following project structure:
.
├── src
│ ├── main.cpp
│ ├── some10.cpp
│ ├── some10.hpp
│ ├── some10_test.cpp
│ ├── some1.cpp
│ ├── some1.hpp
│ ├── some1_test.cpp
│ ├── some2.cpp
│ ├── some2.hpp
│ ├── some2_test.cpp
│ ├── some3.cpp
│ ├── some3.hpp
│ ├── some3_test.cpp
│ ├── some4.cpp
│ ├── some4.hpp
│ ├── some4_test.cpp
│ ├── some5.cpp
│ ├── some5.hpp
│ ├── some5_test.cpp
│ ├── some6.cpp
│ ├── some6.hpp
│ ├── some6_test.cpp
│ ├── some7.cpp
│ ├── some7.hpp
│ ├── some7_test.cpp
│ ├── some8.cpp
│ ├── some8.hpp
│ ├── some8_test.cpp
│ ├── some9.cpp
│ ├── some9.hpp
│ └── some9_test.cpp
└── xmake.lua
files with _test suffix are tests that should be treated as a separate targets, they depend on corresponding .cpp & .hpp files w/o _test suffix (that is some7_test.cpp depends on some7.{hpp,cpp})
and a debug/release target which includes main.cpp and all files that don't have _test suffix.
i'm trying to figure out how to do that in xmake.
my approach is to add mode check and dynamically define targets sort of like this:
local sources = {}
for _, fname in ipairs(os.files("$(projectdir)/src/*.cpp")) do
local bname = path.basename(fname)
if string.match(bname, "_test") then
if is_mode("check") then
target(string.gsub(bname, "_test\\.cpp"))
add_files(fname, strings.gsub(fname, "_test\\.cpp$", ".cpp"))
target_end()
end
else
table.insert(sources, fname)
end
done
But none of that works as xmake has different runtime domains and this should be run only in script domain.
So my question is: can i define dynamic targets for my case or xmake is not suitable for such purpose?
-- add debug/release modes
add_rules("mode.debug", "mode.release")
-- test targets
for _, testfile in ipairs(os.files(path.join(os.projectdir(), "src", "*_test.cpp"))) do
local testname = path.basename(testfile)
target(testname)
set_kind("binary")
set_default(false)
add_files(testfile)
add_files(path.join(path.directory(testfile), testname:gsub("_test", "") .. ".cpp"))
target_end()
end
-- test task
task("test")
set_menu {usage = "xmake test [options]", description = "run all tests.", options = {}}
on_run(function ()
-- build tests
local tests = {}
for _, testfile in ipairs(os.files(path.join(os.projectdir(), "src", "*_test.cpp"))) do
local testname = path.basename(testfile)
table.insert(tests, testname)
os.exec("xmake build %s", testname)
end
-- run tests
for _, testname in ipairs(tests) do
os.exec("xmake run %s", testname)
end
end)
-- demo target
target("demo")
set_kind("binary")
add_files("src/*.cpp|*_test.cpp")
xmake test
to try it.
xmake test
or xmake build xxx_test
or xmake --all
to force to build these test targets.