-
Notifications
You must be signed in to change notification settings - Fork 58
/
GenerateCMakeFiles.py
executable file
·60 lines (48 loc) · 1.86 KB
/
GenerateCMakeFiles.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3
###################################################################################
# This script will generate the target files inside CMakeLists.txt #
# Run this script every time files are added to the Squally/Source/ directory. #
###################################################################################
from os import listdir
from os import path
from os.path import isfile, join, splitext, abspath, relpath, realpath, basename, relpath
import os
def main():
generateCmakeFile()
def processFilename(filename):
return " \"${CMAKE_CURRENT_LIST_DIR}/" + filename + "\"";
def generateCmakeFile():
# Get source/header files
currentPath = realpath(__file__)
sourcePath = abspath(join(join(currentPath, ".."), "Source"))
cmakeFile = join(abspath(join(join(currentPath, ".."), "Source")), "manifest.cmake")
cppFiles = []
hFiles = []
for root, dirnames, filenames in os.walk(sourcePath):
for filename in filenames:
pathStr = join(relpath(root, sourcePath), filename).replace("\\", "/").lstrip(".").lstrip("/")
print(pathStr)
if filename.lower().endswith("cpp") or filename.lower().endswith("c"):
cppFiles.append(pathStr)
continue
if filename.lower().endswith("h"):
hFiles.append(pathStr)
continue
cppFiles.sort()
hFiles.sort()
with open(cmakeFile, "w") as manifest:
manifest.write('# Automatically generated by GenerateCMakeFiles.py\n')
manifest.write('cmake_minimum_required(VERSION 3.12 FATAL_ERROR)\n')
manifest.write('\n')
manifest.write('set(GAME_SOURCES\n')
for filename in map(processFilename, cppFiles):
manifest.write(filename)
manifest.write('\n')
manifest.write(')\n\n')
manifest.write('set(GAME_HEADERS\n')
for filename in map(processFilename, hFiles):
manifest.write(filename)
manifest.write('\n')
manifest.write(')\n\n')
if __name__ == '__main__':
main()