add error check for qtcreator&netbeans project file generators to quit early if cmake...
[blender.git] / build_files / cmake / cmake_qtcreator_project.py
1 #!/usr/bin/env python3
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         if (includes, defines) == (None, None):
85             return
86
87         # for some reason it doesnt give all internal includes
88         includes = list(set(includes) | set(os.path.dirname(f)
89                         for f in files_rel if is_c_header(f)))
90         includes.sort()
91
92         if 0:
93             PROJECT_NAME = "Blender"
94         else:
95             # be tricky, get the project name from SVN if we can!
96             PROJECT_NAME = project_name_get(SOURCE_DIR)
97
98         FILE_NAME = PROJECT_NAME.lower()
99         f = open(os.path.join(PROJECT_DIR, "%s.files" % FILE_NAME), 'w')
100         f.write("\n".join(files_rel))
101
102         f = open(os.path.join(PROJECT_DIR, "%s.includes" % FILE_NAME), 'w', encoding='utf-8')
103         f.write("\n".join(sorted(includes)))
104
105         qtc_prj = os.path.join(PROJECT_DIR, "%s.creator" % FILE_NAME)
106         f = open(qtc_prj, 'w')
107         f.write("[General]\n")
108
109         qtc_cfg = os.path.join(PROJECT_DIR, "%s.config" % FILE_NAME)
110         f = open(qtc_cfg, 'w')
111         f.write("// ADD PREDEFINED MACROS TO %s_custom.config!\n" % FILE_NAME)
112         qtc_custom_cfg = os.path.join(PROJECT_DIR, "%s_custom.config" % FILE_NAME)
113         if os.path.exists(qtc_custom_cfg):
114             fc = open(qtc_custom_cfg, 'r')
115             f.write(fc.read())
116             fc.close()
117             f.write("\n")
118         defines_final = [("#define %s %s" % (item[0], quote_define(item[1]))) for item in defines]
119         if sys.platform != "win32":
120             defines_final += cmake_compiler_defines()
121         f.write("\n".join(defines_final))
122
123     print("Blender project file written to: %r" % qtc_prj)
124     # --- end
125
126
127 def create_qtc_project_python():
128     files = list(source_list(SOURCE_DIR, filename_check=is_py))
129     files_rel = [os.path.relpath(f, start=PROJECT_DIR) for f in files]
130     files_rel.sort()
131
132     # --- qtcreator specific, simple format
133     if 0:
134         PROJECT_NAME = "Blender_Python"
135     else:
136         # be tricky, get the project name from SVN if we can!
137         PROJECT_NAME = project_name_get(SOURCE_DIR) + "_Python"
138
139     FILE_NAME = PROJECT_NAME.lower()
140     f = open(os.path.join(PROJECT_DIR, "%s.files" % FILE_NAME), 'w')
141     f.write("\n".join(files_rel))
142
143     qtc_prj = os.path.join(PROJECT_DIR, "%s.creator" % FILE_NAME)
144     f = open(qtc_prj, 'w')
145     f.write("[General]\n")
146
147     qtc_cfg = os.path.join(PROJECT_DIR, "%s.config" % FILE_NAME)
148     if not os.path.exists(qtc_cfg):
149         f = open(qtc_cfg, 'w')
150         f.write("// ADD PREDEFINED MACROS HERE!\n")
151
152     print("Python project file written to:  %r" % qtc_prj)
153
154
155 def main():
156     create_qtc_project_main()
157     create_qtc_project_python()
158
159
160 if __name__ == "__main__":
161     main()