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