diff options
| author | Arthur LAURENT <[email protected]> | 2025-05-21 01:37:17 +0200 |
|---|---|---|
| committer | Arthur LAURENT <[email protected]> | 2025-05-21 04:53:30 +0200 |
| commit | 8b4e9f90ba045edb14cb2800c506ee6bc5118cd7 (patch) | |
| tree | ffa4bc5edf9e19d953689fde3cc811382397e786 /tests/projects/c++/modules/test_cmake.lua | |
| parent | bfc0f75db8c238187aa011f522adf9685e023b31 (diff) | |
(C++ modules support) refactor tests
Diffstat (limited to 'tests/projects/c++/modules/test_cmake.lua')
| -rw-r--r-- | tests/projects/c++/modules/test_cmake.lua | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/projects/c++/modules/test_cmake.lua b/tests/projects/c++/modules/test_cmake.lua new file mode 100644 index 000000000..3f3355eb5 --- /dev/null +++ b/tests/projects/c++/modules/test_cmake.lua @@ -0,0 +1,78 @@ +import("lib.detect.find_tool") +import("core.base.semver") +import("core.tool.toolchain") +import("utils.ci.is_running", {alias = "ci_is_running"}) + +function _gen_cmakelist() + if not os.isfile("CMakeLists.txt") then + os.vrunv("xmake project -k cmake") + end +end + +function _build(name, opt) + opt = opt or {} + local build_args = {} + if ci_is_running() then + table.insert(build_args, "-vD") + end + os.rm(".xmake", "build") + os.mv("xmake.lua", "xmake.lua_") + os.vrunv("xmake", table.join({"f", "--trybuild=cmake", "--toolchain=" .. name}, build_args), {shell = true, envs = opt.envs}) + os.vrunv("xmake", table.join({"b"}, build_args), {shell = true, envs = opt.envs}) + os.mv("xmake.lua_", "xmake.lua") +end + +function _build_with(name, minver) + if name == "msvc" then + local _toolchain = toolchain.load(name, {plat = os.host(), arch = os.arch()}) + if _toolchain and _toolchain:check() then + local vcvars = _toolchain:config("vcvars") + if vcvars and vcvars.VCToolsVersion and semver.compare(vcvars.VCToolsVersion, minver) >= 0 then + _build(name, {envs = vcvars}) + end + end + else + local tool = find_tool(name, {version = true}) + if tool and tool.version and semver.compare(tool.version, minver) >= 0 then + local _toolchain = toolchain.load(name, {plat = os.host(), arch = os.arch()}) + if _toolchain and _toolchain:check() then + _build(name) + end + end + end +end + +function main(t) + os.setenv("CMAKE_GENERATOR", "Ninja") + + local cmake = find_tool("cmake", {version = true}) + local ninja = find_tool("ninja") + if ninja and cmake and cmake.version and semver.compare(cmake.version, "3.28") >= 0 then + _gen_cmakelist() + if is_subhost("windows") then + _build_with("clang", "19") + _build_with("msvc", "14.35") + elseif is_subhost("linux") then + _build_with("gcc", "14") + _build_with("clang", "19") + elseif is_subhost("macosx") then + -- macOS doesn't ship clang-scan-deps currently + -- check if normal clang is avalaible + local regular_clang_available = false + + local outdata = os.iorun("clang --version") + if outdata then + regular_clang_available = true + if outdata:find("Apple") then + regular_clang_available = false + end + end + if not regular_clang_available then + wprint("Appleclang isn't shipped with clang-scan-deps, disabling modules tests") + return + end + _build_with("clang", "19") + end + + end +end |
