pep8 cleanup and fix for keymap test operator from my own recent fix.
[blender.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 (SIMPLE_PROJECTFILE,
35                           SOURCE_DIR,
36                           # CMAKE_DIR,
37                           PROJECT_DIR,
38                           source_list,
39                           is_project_file,
40                           is_c_header,
41                           is_py,
42                           cmake_advanced_info,
43                           cmake_compiler_defines,
44                           )
45
46 import os
47 import sys
48
49
50 def create_qtc_project_main():
51     files = list(source_list(SOURCE_DIR, filename_check=is_project_file))
52     files_rel = [os.path.relpath(f, start=PROJECT_DIR) for f in files]
53     files_rel.sort()
54
55     # --- qtcreator specific, simple format
56     if SIMPLE_PROJECTFILE:
57         # --- qtcreator specific, simple format
58         PROJECT_NAME = "Blender"
59         f = open(os.path.join(PROJECT_DIR, "%s.files" % PROJECT_NAME), 'w')
60         f.write("\n".join(files_rel))
61
62         f = open(os.path.join(PROJECT_DIR, "%s.includes" % PROJECT_NAME), 'w')
63         f.write("\n".join(sorted(list(set(os.path.dirname(f) for f in files_rel if is_c_header(f))))))
64
65         qtc_prj = os.path.join(PROJECT_DIR, "%s.creator" % PROJECT_NAME)
66         f = open(qtc_prj, 'w')
67         f.write("[General]\n")
68
69         qtc_cfg = os.path.join(PROJECT_DIR, "%s.config" % PROJECT_NAME)
70         if not os.path.exists(qtc_cfg):
71             f = open(qtc_cfg, 'w')
72             f.write("// ADD PREDEFINED MACROS HERE!\n")
73     else:
74         includes, defines = cmake_advanced_info()
75
76         # for some reason it doesnt give all internal includes
77         includes = list(set(includes) | set(os.path.dirname(f) for f in files_rel if is_c_header(f)))
78         includes.sort()
79
80         PROJECT_NAME = "Blender"
81         FILE_NAME = PROJECT_NAME.lower()
82         f = open(os.path.join(PROJECT_DIR, "%s.files" % FILE_NAME), 'w')
83         f.write("\n".join(files_rel))
84
85         f = open(os.path.join(PROJECT_DIR, "%s.includes" % FILE_NAME), 'w')
86         f.write("\n".join(sorted(includes)))
87
88         qtc_prj = os.path.join(PROJECT_DIR, "%s.creator" % FILE_NAME)
89         f = open(qtc_prj, 'w')
90         f.write("[General]\n")
91
92         qtc_cfg = os.path.join(PROJECT_DIR, "%s.config" % FILE_NAME)
93         f = open(qtc_cfg, 'w')
94         f.write("// ADD PREDEFINED MACROS HERE!\n")
95         defines_final = [("#define %s %s" % item) for item in defines]
96         if sys.platform != "win32":
97             defines_final += cmake_compiler_defines()  # defines from the compiler
98         f.write("\n".join(defines_final))
99
100     print("Blender project file written to: %s" % qtc_prj)
101     # --- end
102
103
104 def create_qtc_project_python():
105     files = list(source_list(SOURCE_DIR, filename_check=is_py))
106     files_rel = [os.path.relpath(f, start=PROJECT_DIR) for f in files]
107     files_rel.sort()
108
109     # --- qtcreator specific, simple format
110     PROJECT_NAME = "Blender_Python"
111     FILE_NAME = PROJECT_NAME.lower()
112     f = open(os.path.join(PROJECT_DIR, "%s.files" % FILE_NAME), 'w')
113     f.write("\n".join(files_rel))
114
115     qtc_prj = os.path.join(PROJECT_DIR, "%s.creator" % FILE_NAME)
116     f = open(qtc_prj, 'w')
117     f.write("[General]\n")
118
119     qtc_cfg = os.path.join(PROJECT_DIR, "%s.config" % FILE_NAME)
120     if not os.path.exists(qtc_cfg):
121         f = open(qtc_cfg, 'w')
122         f.write("// ADD PREDEFINED MACROS HERE!\n")
123
124     print("Python project file written to:  %s" % qtc_prj)
125
126
127 def main():
128     create_qtc_project_main()
129     create_qtc_project_python()
130
131
132 if __name__ == "__main__":
133     main()