forked from aevum/libgdx-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gdx-wizard.py
143 lines (108 loc) · 4.89 KB
/
gdx-wizard.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import os, sys
import argparse
import shutil
from subprocess import call
import multiprocessing
#
def write_template(origin_file, dest_dir, dest_name, **kwargs):
template = open(origin_file + '.template').read().format(**kwargs)
f = open(dest_dir + '/' + dest_name, 'w')
f.write(template)
f.close()
def cleanup_and_prepare(path, enforce=False):
if os.path.exists(path):
answer = raw_input(path + " already exists. Delete it? <y/N>:")
if answer == 'y' or answer == 'Y':
if enforce:
answer = raw_input(path + " already exists, and is important.Are you REALLY sure?? <yes/Nope>:")
if answer != 'yes':
return False
shutil.rmtree(path)
else:
os.chdir(path)
return False
os.mkdir(path)
os.chdir(path)
return True
def setup():
parser = argparse.ArgumentParser(description='gdx++ project setup tool')
parser.add_argument('--gen-mode', type=str, help="set's up the desired generation mode [android,linux,source,ios]")
parser.add_argument('--root-dir', type=str, help="Defines the directory where the structure will be generated", required=True)
parser.add_argument('--project-name', type=str, help="Defines the name of the project, the executable name and the android apk name", required=True)
parser.add_argument('--android-sdk', type=str, help="The path to the android sdk")
parser.add_argument('--android-ndk', type=str, help="The path to the android ndk")
parser.add_argument('--package-name', type=str, help="The package name when generating Android/iOS deps")
parser.add_argument('--android-target', type=str, help="The android target. ex: 'android-10'")
args = parser.parse_args()
args.gen_mode = args.gen_mode.split(',')
gdx_source_dir = os.getcwd()
root_path = os.path.abspath(os.path.expanduser(args.root_dir)) \
+ '/'+ args.project_name.lower()
if not os.path.exists(root_path):
os.mkdir(root_path)
os.mkdir(root_path + '/src')
if not os.path.exists(root_path + '/src'):
args.gen_mode.append('source')
data_path = root_path + '/data'
source_path = root_path + '/src/' + args.project_name
gdx_source_path = root_path + '/gdx-cpp'
if 'source' in args.gen_mode or not os.path.exists(source_path):
cleanup_and_prepare(source_path, True)
cleanup_and_prepare(data_path)
write_template(gdx_source_dir + '/template/CMakeLists.txt', root_path,
'CMakeLists.txt',
ProjectName = args.project_name )
write_template(gdx_source_dir + '/template/main.cpp', source_path,
'main.cpp',
ProjectName = args.project_name )
call(['cp', gdx_source_dir + '/etc/assets/data/logo.png', data_path])
call(['ln', '-s', gdx_source_dir, gdx_source_path])
if 'linux' in args.gen_mode:
project_path = root_path + '/linux/'
if cleanup_and_prepare(project_path):
call(['cmake', '-DCMAKE_BUILD_TYPE=Release', root_path])
call(['ln', '-s', data_path, 'bin/'])
if 'android' in args.gen_mode:
if not args.android_sdk:
print 'Missing --android-sdk. Aborting'
sys.exit(1)
if not args.package_name:
print 'Missing --package-name. Aborting'
sys.exit(1)
project_path = root_path + '/android'
os.environ['ANDROID_NDK'] = args.android_ndk
if not os.path.exists(root_path + '/src/java'):
args.gen_mode.append('android-src')
if cleanup_and_prepare(project_path):
call(['cmake', '-DCMAKE_TOOLCHAIN_FILE=' + gdx_source_dir + '/cmake/android.toolchain.cmake',
root_path])
del os.environ["ANDROID_NDK"]
if 'android-src' in args.gen_mode:
os.chdir(root_path)
java_src_path = root_path + '/src/java'
activity = args.project_name[0].upper() + args.project_name[1:] + 'Activity'
if cleanup_and_prepare(java_src_path):
call(args.android_sdk + '/tools/android create project --target ' + args.android_target +
' --path ' + java_src_path + ' --activity ' + activity + ' --package ' + args.package_name, shell=True)
os.chdir(java_src_path)
os.mkdir('libs/armeabi-v7a')
os.mkdir('assets')
call(['ln', '-s', root_path + '/android/lib/lib' + args.project_name + '.so', 'libs/armeabi-v7a' ])
call(['ln', '-s', root_path + '/data', java_src_path + '/assets/data' ])
write_template(gdx_source_dir + '/template/MainActivity.java',
root_path + '/src/java/src/' + args.package_name.replace('.','/'),
activity + '.java', PackageName = args.package_name,
ProjectName = args.project_name )
if 'ios' in args.gen_mode:
project_path = root_path + '/ios'
if not os.path.exists(source_path + '/Info.plist'):
write_template(gdx_source_dir + '/template/Info.plist', source_path, 'Info.plist',
PackageName = args.package_name)
if not os.path.exists(source_path + '/bind.mm'):
call(['cp', gdx_source_dir + '/template/bind.mm', source_path])
if cleanup_and_prepare(project_path):
call(['cmake','-GXcode', '-DCMAKE_TOOLCHAIN_FILE=' + gdx_source_dir + '/cmake/iOS.toolchain.cmake', root_path])
if not args.gen_mode:
print 'No target specified (--gen-mode). Exiting.'
if __name__ == "__main__":
setup()