Skip to content

Commit f394102

Browse files
add c_standard/cpp_standard xml attributes. (#1301)
* add `c_standard`/`cpp_standard` xml attributes. * add test for `c_standard`/`cpp_standard` attributes * set language standard for PCH compilation too * more generic name for build tool tests
1 parent 21d2df8 commit f394102

27 files changed

Lines changed: 202 additions & 115 deletions

.github/workflows/test.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,16 @@ jobs:
221221
run: haxe compile-cpp.hxml -D ${{ env.HXCPP_ARCH_FLAG }} -D no_http
222222
- name: run
223223
run: bin${{ inputs.sep }}cpp${{ inputs.sep }}TestMain-debug
224+
build_tool:
225+
runs-on: ${{ inputs.os }}
226+
name: build tool tests
227+
steps:
228+
- name: checkout
229+
uses: actions/checkout@v4
230+
- name: setup
231+
uses: ./.github/workflows/setup
232+
with:
233+
haxe: ${{ inputs.haxe }}
234+
- name: test c/cxx_standard attributes
235+
working-directory: test/cxx_standard
236+
run: haxelib run hxcpp Build.xml

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ hxcpp.n
2929

3030
.vscode
3131

32+
test/cxx_standard/main
33+
test/cxx_standard/main.hash
34+
test/cxx_standard/main.exe
35+
test/cxx_standard/main.exe.hash
36+
3237
# Created by https://www.toptal.com/developers/gitignore/api/visualstudio
3338
# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudio
3439

docs/build_xml/Defines.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ Defines affecting how the code is compiled. These can be on the command line wh
3737
| *HXCPP_CHECK_POINTER* | Add null-pointer checks,even in release mode. |
3838
| *HXCPP_PROFILER* | Add profiler support |
3939
| *HXCPP_TELEMETRY* | Add telemetry support |
40-
| *HXCPP_CPP11* | Use c++11 features and link libraries |
41-
| *HXCPP_CPP17* | Use c++17 features and link libraries |
40+
| *HXCPP_C_STANDARD* | Set default C standard |
41+
| *HXCPP_CXX_STANDARD* | Set default C++ standard |
42+
| *HXCPP_OBJC_STANDARD* | Set default Objective-C standard |
43+
| *HXCPP_OBJCXX_STANDARD* | Set default Objective-C++ standard |
4244
| *exe_link* | Generate executable file (rather than dynamic library on android) |
4345
| *static_link* | Generate static library |
4446
| *dll_link* | Generate dynamic library |

docs/build_xml/Files.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@ Files
22
------
33
The files node defines a group of files that all share the same attributes, including relative directory, default compiler flags and dependencies. The node can be used to define a set of header files on which other files can depend, or a set of source files to be compiled and included in a target.
44

5+
```xml
6+
<files id="foo" cxx_standard="14">
7+
<file name="foo.cpp"/>
8+
<file name="bar.c"/>
9+
</files>
10+
```
11+
12+
#### Attributes
13+
14+
+ `c_standard` = Default C standard for the file group
15+
+ `cxx_standard` = Default C++ standard for the file group
16+
+ `objc_standard` = Default Objective-C standard for the file group
17+
+ `objcxx_standard` = Default Objective-C++ standard for the file group
18+
#### Nodes
519
- *depend* - Declare that all files in the group depend on another file or another file group.
620
```xml
721
<depend name="filename" />
@@ -80,13 +94,17 @@ The files node defines a group of files that all share the same attributes, incl
8094

8195
- *file* - Add file to group, with optional attributes
8296
```xml
83-
<file name="filename" tags="tag,tag1" filterout="define" embedName="embed" >
97+
<file name="filename" tags="tag,tag1" filterout="define" embedName="embed" cxx_standard="17">
8498
<depend name="filename1" />
8599
<depend name="filename2" />
86100
</file>
87101
```
88102
+ name = name of file - may be absolute or relative to files.dir
89103
+ tags = optional override of group tags. See [Tags.md](Tags.md).
104+
+ `c_standard` = C standard for the file
105+
+ `cxx_standard` = C++ standard for the file
106+
+ `objc_standard` = Objective-C standard for the file
107+
+ `objcxx_standard` = Objective-C++ standard for the file
90108
+ filterout = allows files to be skipped at compile-time if the named define exists.
91109
This is useful when the define is set sometime after the file list is parsed.
92110
+ depend name = filename of additional dependency

test/RunTests.hx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ class RunTests
114114
command("cpp64"+sep+"Test",[]);
115115
}
116116

117+
public static function cxx_standard() {
118+
setDir("cxx_standard");
119+
command("haxelib", ["run", "hxcpp", "Build.xml"]);
120+
}
121+
117122

118123
public static function setDir(name:String)
119124
{
@@ -199,6 +204,7 @@ class RunTests
199204
run("std64", std64);
200205
run("native", native);
201206
run("debugger", debugger);
207+
run("cxx_standard", cxx_standard);
202208

203209
Sys.println("");
204210

test/cxx_standard/Build.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<xml>
2+
<files id="test" cxx_standard="17">
3+
<compilerflag value="/Zc:__cplusplus" if="isMsvc" />
4+
<file name="main.cpp" />
5+
<file name="cxx14.cpp" cxx_standard="14" />
6+
<file name="c11.c" c_standard="11" />
7+
<file name="c17.c" c_standard="17" />
8+
</files>
9+
10+
<set name="EXESUFFIX" value=".exe" if="windows" />
11+
12+
<target id="default" tool="linker" toolid="exe" output="main${EXESUFFIX}">
13+
<files id="test"/>
14+
</target>
15+
</xml>

test/cxx_standard/c11.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#if __STDC_VERSION__ < 201112L
2+
#error "Not C11"
3+
#endif

test/cxx_standard/c17.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#if __STDC_VERSION__ < 201710L
2+
#error "Not C17"
3+
#endif

test/cxx_standard/cxx14.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#if __cplusplus != 201402L
2+
#error "Not C++14"
3+
#endif

test/cxx_standard/main.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#if __cplusplus < 201703L
2+
#error "Not C++17"
3+
#endif
4+
5+
int main() { return 0; }

0 commit comments

Comments
 (0)