diff options
| author | ruki <[email protected]> | 2025-12-03 00:52:16 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-12-03 00:52:16 +0800 |
| commit | d66186fac83f009715e4d3307b47e361954fa708 (patch) | |
| tree | dc5191d6d7b8d93ca70394430e78b2859d7c4cea /xmake/rules | |
| parent | 3aca93627b3cada55db8d0215d6ff87ca418ceab (diff) | |
add xmake check syntax
Diffstat (limited to 'xmake/rules')
| -rw-r--r-- | xmake/rules/c++/config/main.lua | 6 | ||||
| -rw-r--r-- | xmake/rules/c++/config/syntax_only.lua | 55 |
2 files changed, 60 insertions, 1 deletions
diff --git a/xmake/rules/c++/config/main.lua b/xmake/rules/c++/config/main.lua index dce7cff6b..bde849965 100644 --- a/xmake/rules/c++/config/main.lua +++ b/xmake/rules/c++/config/main.lua @@ -20,9 +20,10 @@ -- imports import("rules.c++.config.basic", {rootdir = os.programdir(), alias = "config_basic"}) +import("rules.c++.config.dynamic_debugging", {rootdir = os.programdir(), alias = "config_dynamic_debugging"}) +import("rules.c++.config.syntax_only", {rootdir = os.programdir(), alias = "config_syntax_only"}) import("rules.c++.config.optimization", {rootdir = os.programdir(), alias = "config_optimization"}) import("rules.c++.config.sanitizer", {rootdir = os.programdir(), alias = "config_sanitizer"}) -import("rules.c++.config.dynamic_debugging", {rootdir = os.programdir(), alias = "config_dynamic_debugging"}) -- main entry function main(target, sourcekind) @@ -33,6 +34,9 @@ function main(target, sourcekind) -- config dynamic debugging configs (must be before optimization to disable incompatible flags) config_dynamic_debugging(target, sourcekind) + -- config syntax only configs (must be before optimization to disable incompatible flags) + config_syntax_only(target, sourcekind) + -- config optimization configs config_optimization(target, sourcekind) diff --git a/xmake/rules/c++/config/syntax_only.lua b/xmake/rules/c++/config/syntax_only.lua new file mode 100644 index 000000000..4f0045192 --- /dev/null +++ b/xmake/rules/c++/config/syntax_only.lua @@ -0,0 +1,55 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, Xmake Open Source Community. +-- +-- @author ruki +-- @file syntax_only.lua +-- + +-- imports +import("core.project.project") + +-- add syntax-only check support +-- @see https://github.com/mesonbuild/meson/issues/12228 +function main(target, sourcekind) + -- check if syntax-only is enabled + local enabled = target:policy("build.c++.syntax_only") + if enabled == nil then + enabled = project.policy("build.c++.syntax_only") + end + if not enabled then + return + end + + -- get flag name for sourcekind + local flagnames = { + cc = "cflags", + cxx = "cxxflags", + mm = "mflags", + mxx = "mxxflags" + } + local cflag = flagnames[sourcekind] or (sourcekind == "cxx" and "cxxflags" or "cflags") + + -- check compiler and add appropriate flag + local toolname = sourcekind == "cxx" and "cxx" or "cc" + if target:has_tool(toolname, "gcc", "gxx", "clang", "clangxx") then + -- gcc/clang: -fsyntax-only + target:add(cflag, "-fsyntax-only", {force = true}) + elseif target:has_tool(toolname, "cl") then + -- MSVC: /Zs (syntax check only) + target:add(cflag, "/Zs", {force = true}) + end +end + |
