UI: fix access of freed memory in buttons handling code.
[blender-staging.git] / build_files / cmake / cmake_qtcreator_project.py
1 #!/usr/bin/env python
2
3 # $Id$
4 # ***** BEGIN GPL LICENSE BLOCK *****
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software Foundation,
18 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #
20 # Contributor(s): Campbell Barton, M.G. Kishalmi
21 #
22 # ***** END GPL LICENSE BLOCK *****
23
24 # <pep8 compliant>
25
26 """
27 Example Win32 usage:
28  c:\Python32\python.exe c:\blender_dev\blender\build_files\cmake\cmake_qtcreator_project.py c:\blender_dev\cmake_build
29
30 example linux usage
31  python .~/blenderSVN/blender/build_files/cmake/cmake_qtcreator_project.py ~/blenderSVN/cmake
32 """
33
34 from project_info import *
35
36 import os
37 from os.path import join, dirname, normpath, abspath, splitext, relpath, exists
38
39 import sys
40
41
42 def create_qtc_project_main():
43     files = list(source_list(SOURCE_DIR, filename_check=is_project_file))
44     files_rel = [relpath(f, start=PROJECT_DIR) for f in files]
45     files_rel.sort()
46
47     # --- qtcreator specific, simple format
48     if SIMPLE_PROJECTFILE:
49         # --- qtcreator specific, simple format
50         PROJECT_NAME = "Blender"
51         f = open(join(PROJECT_DIR, "%s.files" % PROJECT_NAME), 'w')
52         f.write("\n".join(files_rel))
53
54         f = open(join(PROJECT_DIR, "%s.includes" % PROJECT_NAME), 'w')
55         f.write("\n".join(sorted(list(set(dirname(f) for f in files_rel if is_c_header(f))))))
56
57         qtc_prj = join(PROJECT_DIR, "%s.creator" % PROJECT_NAME)
58         f = open(qtc_prj, 'w')
59         f.write("[General]\n")
60
61         qtc_cfg = join(PROJECT_DIR, "%s.config" % PROJECT_NAME)
62         if not exists(qtc_cfg):
63             f = open(qtc_cfg, 'w')
64             f.write("// ADD PREDEFINED MACROS HERE!\n")
65     else:
66         includes, defines = cmake_advanced_info()
67
68         # for some reason it doesnt give all internal includes
69         includes = list(set(includes) | set(dirname(f) for f in files_rel if is_c_header(f)))
70         includes.sort()
71
72         PROJECT_NAME = "Blender"
73         FILE_NAME = PROJECT_NAME.lower()
74         f = open(join(PROJECT_DIR, "%s.files" % FILE_NAME), 'w')
75         f.write("\n".join(files_rel))
76
77         f = open(join(PROJECT_DIR, "%s.includes" % FILE_NAME), 'w')
78         f.write("\n".join(sorted(includes)))
79
80         qtc_prj = join(PROJECT_DIR, "%s.creator" % FILE_NAME)
81         f = open(qtc_prj, 'w')
82         f.write("[General]\n")
83
84         qtc_cfg = join(PROJECT_DIR, "%s.config" % FILE_NAME)
85         f = open(qtc_cfg, 'w')
86         f.write("// ADD PREDEFINED MACROS HERE!\n")
87         defines_final = [("#define %s %s" % item) for item in defines]
88         if sys.platform != "win32":
89             defines_final += cmake_compiler_defines()  # defines from the compiler
90         f.write("\n".join(defines_final))
91
92     print("Blender project file written to: %s" % qtc_prj)
93     # --- end
94
95
96 def create_qtc_project_python():
97     files = list(source_list(SOURCE_DIR, filename_check=is_py))
98     files_rel = [relpath(f, start=PROJECT_DIR) for f in files]
99     files_rel.sort()
100
101     # --- qtcreator specific, simple format
102     PROJECT_NAME = "Blender_Python"
103     FILE_NAME = PROJECT_NAME.lower()
104     f = open(join(PROJECT_DIR, "%s.files" % FILE_NAME), 'w')
105     f.write("\n".join(files_rel))
106
107     qtc_prj = join(PROJECT_DIR, "%s.creator" % FILE_NAME)
108     f = open(qtc_prj, 'w')
109     f.write("[General]\n")
110
111     qtc_cfg = join(PROJECT_DIR, "%s.config" % FILE_NAME)
112     if not exists(qtc_cfg):
113         f = open(qtc_cfg, 'w')
114         f.write("// ADD PREDEFINED MACROS HERE!\n")
115
116     print("Python project file written to:  %s" % qtc_prj)
117
118
119 def main():
120     create_qtc_project_main()
121     create_qtc_project_python()
122
123
124 if __name__ == "__main__":
125     main()