86201da23decc66739d1c3ff18328327e486106a
[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         # 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 TO %s_custom.config!\n" % FILE_NAME)
109         qtc_custom_cfg = os.path.join(PROJECT_DIR, "%s_custom.config" % FILE_NAME)
110         if os.path.exists(qtc_custom_cfg):
111             fc = open(qtc_custom_cfg, 'r')
112             f.write(fc.read())
113             fc.close()
114             f.write("\n")
115         defines_final = [("#define %s %s" % (item[0], quote_define(item[1]))) for item in defines]
116         if sys.platform != "win32":
117             defines_final += cmake_compiler_defines()
118         f.write("\n".join(defines_final))
119
120     print("Blender project file written to: %r" % qtc_prj)
121     # --- end
122
123
124 def create_qtc_project_python():
125     files = list(source_list(SOURCE_DIR, filename_check=is_py))
126     files_rel = [os.path.relpath(f, start=PROJECT_DIR) for f in files]
127     files_rel.sort()
128
129     # --- qtcreator specific, simple format
130     if 0:
131         PROJECT_NAME = "Blender_Python"
132     else:
133         # be tricky, get the project name from SVN if we can!
134         PROJECT_NAME = project_name_get(SOURCE_DIR) + "_Python"
135
136     FILE_NAME = PROJECT_NAME.lower()
137     f = open(os.path.join(PROJECT_DIR, "%s.files" % FILE_NAME), 'w')
138     f.write("\n".join(files_rel))
139
140     qtc_prj = os.path.join(PROJECT_DIR, "%s.creator" % FILE_NAME)
141     f = open(qtc_prj, 'w')
142     f.write("[General]\n")
143
144     qtc_cfg = os.path.join(PROJECT_DIR, "%s.config" % FILE_NAME)
145     if not os.path.exists(qtc_cfg):
146         f = open(qtc_cfg, 'w')
147         f.write("// ADD PREDEFINED MACROS HERE!\n")
148
149     print("Python project file written to:  %r" % qtc_prj)
150
151
152 def main():
153     create_qtc_project_main()
154     create_qtc_project_python()
155
156
157 if __name__ == "__main__":
158     main()