Skip to content

Commit eee321f

Browse files
committed
fix(cmake): support extern "C" when generate header
Signed-off-by: Frederic Pillon <[email protected]>
1 parent cca1658 commit eee321f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Diff for: cmake/scripts/generate_header.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#!/usr/bin/env python3
22

33
import argparse
4+
import re
45
from pathlib import Path
56

67
parser = argparse.ArgumentParser()
78
parser.add_argument("--source", "-i", type=Path, required=True, help="ctags's output")
89
parser.add_argument("--out", "-o", type=Path, required=True, help="header to generate")
910

1011
shargs = parser.parse_args()
11-
12-
12+
externC_regex = re.compile(r'extern\s+"C"')
1313
with open(shargs.source, "r") as infile:
1414
with open(shargs.out, "w") as outfile:
1515
for line in infile:
@@ -20,7 +20,11 @@
2020
fields = line.split("\t")
2121
kind = fields[3].split(":", 1)[1]
2222
if kind == "function":
23+
decl = ""
24+
externC = externC_regex.search(fields[2])
25+
if externC:
26+
decl = 'extern "C" '
2327
symname = fields[0]
2428
signature = fields[5].split(":", 1)[1]
2529
rtype = fields[6].split(":", 1)[1]
26-
print(f"{rtype} {symname}{signature};", file=outfile)
30+
print(f"{decl}{rtype} {symname}{signature};", file=outfile)

0 commit comments

Comments
 (0)