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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
#!/usr/bin/env python3
# ***** BEGIN GPL LICENSE BLOCK *****
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# Contributor(s): Campbell Barton, M.G. Kishalmi
#
# ***** END GPL LICENSE BLOCK *****
# <pep8 compliant>
r"""
Example Linux usage:
python ~/blender-git/blender/build_files/cmake/cmake_qtcreator_project.py --build-dir ~/blender-git/cmake
Example Win32 usage:
c:\Python32\python.exe c:\blender_dev\blender\build_files\cmake\cmake_qtcreator_project.py --build-dir c:\blender_dev\cmake_build
"""
import os
def quote_define(define):
if " " in define.strip():
return '"%s"' % define
else:
return define
def create_qtc_project_main(name):
from project_info import (
SIMPLE_PROJECTFILE,
SOURCE_DIR,
# CMAKE_DIR,
PROJECT_DIR,
source_list,
is_project_file,
is_c_header,
cmake_advanced_info,
cmake_compiler_defines,
project_name_get,
)
files = list(source_list(SOURCE_DIR, filename_check=is_project_file))
files_rel = [os.path.relpath(f, start=PROJECT_DIR) for f in files]
files_rel.sort()
# --- qtcreator specific, simple format
if SIMPLE_PROJECTFILE:
# --- qtcreator specific, simple format
PROJECT_NAME = name or "Blender"
FILE_NAME = PROJECT_NAME.lower()
with open(os.path.join(PROJECT_DIR, "%s.files" % FILE_NAME), 'w') as f:
f.write("\n".join(files_rel))
with open(os.path.join(PROJECT_DIR, "%s.includes" % FILE_NAME), 'w') as f:
f.write("\n".join(sorted(list(set(os.path.dirname(f)
for f in files_rel if is_c_header(f))))))
qtc_prj = os.path.join(PROJECT_DIR, "%s.creator" % FILE_NAME)
with open(qtc_prj, 'w') as f:
f.write("[General]\n")
qtc_cfg = os.path.join(PROJECT_DIR, "%s.config" % FILE_NAME)
if not os.path.exists(qtc_cfg):
with open(qtc_cfg, 'w') as f:
f.write("// ADD PREDEFINED MACROS HERE!\n")
else:
includes, defines = cmake_advanced_info()
if (includes, defines) == (None, None):
return
# for some reason it doesnt give all internal includes
includes = list(set(includes) | set(os.path.dirname(f)
for f in files_rel if is_c_header(f)))
includes.sort()
# be tricky, get the project name from CMake if we can!
PROJECT_NAME = name or project_name_get()
FILE_NAME = PROJECT_NAME.lower()
with open(os.path.join(PROJECT_DIR, "%s.files" % FILE_NAME), 'w') as f:
f.write("\n".join(files_rel))
with open(os.path.join(PROJECT_DIR, "%s.includes" % FILE_NAME), 'w', encoding='utf-8') as f:
f.write("\n".join(sorted(includes)))
qtc_prj = os.path.join(PROJECT_DIR, "%s.creator" % FILE_NAME)
with open(qtc_prj, 'w') as f:
f.write("[General]\n")
qtc_cfg = os.path.join(PROJECT_DIR, "%s.config" % FILE_NAME)
with open(qtc_cfg, 'w') as f:
f.write("// ADD PREDEFINED MACROS TO %s_custom.config!\n" % FILE_NAME)
qtc_custom_cfg = os.path.join(PROJECT_DIR, "%s_custom.config" % FILE_NAME)
if os.path.exists(qtc_custom_cfg):
with open(qtc_custom_cfg, 'r') as fc:
f.write(fc.read())
f.write("\n")
defines_final = [("#define %s %s" % (item[0], quote_define(item[1]))) for item in defines]
if os.name != "nt":
defines_final += cmake_compiler_defines()
f.write("\n".join(defines_final))
print("Blender project file written to: %r" % qtc_prj)
# --- end
def create_qtc_project_python(name):
from project_info import (
SOURCE_DIR,
# CMAKE_DIR,
PROJECT_DIR,
source_list,
is_py,
project_name_get,
)
files = list(source_list(SOURCE_DIR, filename_check=is_py))
files_rel = [os.path.relpath(f, start=PROJECT_DIR) for f in files]
files_rel.sort()
# --- qtcreator specific, simple format
# be tricky, get the project name from git if we can!
PROJECT_NAME = (name or project_name_get()) + "_Python"
FILE_NAME = PROJECT_NAME.lower()
with open(os.path.join(PROJECT_DIR, "%s.files" % FILE_NAME), 'w') as f:
f.write("\n".join(files_rel))
qtc_prj = os.path.join(PROJECT_DIR, "%s.creator" % FILE_NAME)
with open(qtc_prj, 'w') as f:
f.write("[General]\n")
qtc_cfg = os.path.join(PROJECT_DIR, "%s.config" % FILE_NAME)
if not os.path.exists(qtc_cfg):
with open(qtc_cfg, 'w') as f:
f.write("// ADD PREDEFINED MACROS HERE!\n")
print("Python project file written to: %r" % qtc_prj)
def argparse_create():
import argparse
parser = argparse.ArgumentParser(
description="This script generates Qt Creator project files for Blender",
)
parser.add_argument(
"-n", "--name",
dest="name",
metavar='NAME', type=str,
help="Override default project name (\"Blender\")",
required=False,
)
parser.add_argument(
"-b", "--build-dir",
dest="build_dir",
metavar='BUILD_DIR', type=str,
help="Specify the build path (or fallback to the $PWD)",
required=False,
)
return parser
def main():
parser = argparse_create()
args = parser.parse_args()
name = args.name
import project_info
if not project_info.init(args.build_dir):
return
create_qtc_project_main(name)
create_qtc_project_python(name)
if __name__ == "__main__":
main()
|