forked from ianpatt/common
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_cmake.py
42 lines (32 loc) · 955 Bytes
/
generate_cmake.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import os
HEADER_TYPES = (".h", ".hpp", ".hxx", ".inl")
SOURCE_TYPES = (".c", ".cpp", ".cxx")
ALL_TYPES = HEADER_TYPES + SOURCE_TYPES
def main():
cur = os.path.dirname(os.path.realpath(__file__))
os.chdir(cur)
tmp = list()
with os.scandir("common") as it:
for entry in it:
if not entry.name.startswith('.') and entry.is_file():
tmp.append(entry.name)
headers = list()
sources = list()
for file in tmp:
name = "common/" + file
if name.endswith(HEADER_TYPES):
headers.append(name)
elif name.endswith(SOURCE_TYPES):
sources.append(name)
headers.sort()
sources.sort()
def do_make(a_filename, a_varname, a_files):
out = open("cmake/" + a_filename + ".cmake", "w", encoding="utf-8")
out.write("set(" + a_varname + "\n")
for file in a_files:
out.write("\t" + file + "\n")
out.write(")\n")
do_make("headerlist", "headers", headers)
do_make("sourcelist", "sources", sources)
if __name__ == "__main__":
main()