3
# ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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.
19
# Contributor(s): Campbell Barton, M.G. Kishalmi
21
# ***** END GPL LICENSE BLOCK *****
27
c:\Python32\python.exe c:\blender_dev\blender\build_files\cmake\cmake_qtcreator_project.py c:\blender_dev\cmake_build
30
python .~/blenderSVN/blender/build_files/cmake/cmake_qtcreator_project.py ~/blenderSVN/cmake
42
"cmake_advanced_info",
43
"cmake_compiler_defines",
49
if not sys.version.startswith("3"):
50
print("\nPython3.x needed, found %s.\nAborting!\n" %
51
sys.version.partition(" ")[0])
56
from os.path import join, dirname, normpath, abspath, splitext, exists
58
SOURCE_DIR = join(dirname(__file__), "..", "..")
59
SOURCE_DIR = normpath(SOURCE_DIR)
60
SOURCE_DIR = abspath(SOURCE_DIR)
62
SIMPLE_PROJECTFILE = False
65
CMAKE_DIR = sys.argv[-1]
67
if not exists(join(CMAKE_DIR, "CMakeCache.txt")):
68
CMAKE_DIR = os.getcwd()
69
if not exists(join(CMAKE_DIR, "CMakeCache.txt")):
70
print("CMakeCache.txt not found in %r or %r\n Pass CMake build dir as an argument, or run from that dir, aborting" % (CMAKE_DIR, os.getcwd()))
75
# PROJECT_DIR = SOURCE_DIR
76
PROJECT_DIR = CMAKE_DIR
79
def source_list(path, filename_check=None):
80
for dirpath, dirnames, filenames in os.walk(path):
83
if dirpath.startswith("."):
86
for filename in filenames:
87
filepath = join(dirpath, filename)
88
if filename_check is None or filename_check(filepath):
93
def is_cmake(filename):
94
ext = splitext(filename)[1]
95
return (ext == ".cmake") or (filename.endswith("CMakeLists.txt"))
98
def is_c_header(filename):
99
ext = splitext(filename)[1]
100
return (ext in (".h", ".hpp", ".hxx"))
104
ext = splitext(filename)[1]
105
return (ext == ".py")
108
def is_glsl(filename):
109
ext = splitext(filename)[1]
110
return (ext == ".glsl")
114
ext = splitext(filename)[1]
115
return (ext in (".c", ".cpp", ".cxx", ".m", ".mm", ".rc", ".cc", ".inl"))
118
def is_c_any(filename):
119
return is_c(filename) or is_c_header(filename)
122
def is_svn_file(filename):
123
dn, fn = os.path.split(filename)
124
filename_svn = join(dn, ".svn", "text-base", "%s.svn-base" % fn)
125
return exists(filename_svn)
128
def is_project_file(filename):
129
return (is_c_any(filename) or is_cmake(filename) or is_glsl(filename)) # and is_svn_file(filename)
132
def cmake_advanced_info():
133
""" Extracr includes and defines from cmake.
136
def create_eclipse_project():
137
print("CMAKE_DIR %r" % CMAKE_DIR)
138
if sys.platform == "win32":
139
cmd = 'cmake "%s" -G"Eclipse CDT4 - MinGW Makefiles"' % CMAKE_DIR
141
cmd = 'cmake "%s" -G"Eclipse CDT4 - Unix Makefiles"' % CMAKE_DIR
148
create_eclipse_project()
150
from xml.dom.minidom import parse
151
tree = parse(join(CMAKE_DIR, ".cproject"))
153
# to check on nicer xml
154
# f = open(".cproject_pretty", 'w')
155
# f.write(tree.toprettyxml(indent=" ", newl=""))
157
ELEMENT_NODE = tree.ELEMENT_NODE
159
cproject, = tree.getElementsByTagName("cproject")
160
for storage in cproject.childNodes:
161
if storage.nodeType != ELEMENT_NODE:
164
if storage.attributes["moduleId"].value == "org.eclipse.cdt.core.settings":
165
cconfig = storage.getElementsByTagName("cconfiguration")[0]
166
for substorage in cconfig.childNodes:
167
if substorage.nodeType != ELEMENT_NODE:
170
moduleId = substorage.attributes["moduleId"].value
172
# org.eclipse.cdt.core.settings
173
# org.eclipse.cdt.core.language.mapping
174
# org.eclipse.cdt.core.externalSettings
175
# org.eclipse.cdt.core.pathentry
176
# org.eclipse.cdt.make.core.buildtargets
178
if moduleId == "org.eclipse.cdt.core.pathentry":
179
for path in substorage.childNodes:
180
if path.nodeType != ELEMENT_NODE:
182
kind = path.attributes["kind"].value
185
# <pathentry kind="mac" name="PREFIX" path="" value=""/opt/blender25""/>
186
defines.append((path.attributes["name"].value, path.attributes["value"].value))
188
# <pathentry include="/data/src/blender/blender/source/blender/editors/include" kind="inc" path="" system="true"/>
189
includes.append(path.attributes["include"].value)
193
return includes, defines
196
def cmake_cache_var(var):
197
cache_file = open(join(CMAKE_DIR, "CMakeCache.txt"), encoding='utf-8')
198
lines = [l_strip for l in cache_file for l_strip in (l.strip(),) if l_strip if not l_strip.startswith("//") if not l_strip.startswith("#")]
202
if l.split(":")[0] == var:
203
return l.split("=", 1)[-1]
207
def cmake_compiler_defines():
208
compiler = cmake_cache_var("CMAKE_C_COMPILER") # could do CXX too
211
print("Couldn't find the compiler, os defines will be omitted...")
215
temp_c = tempfile.mkstemp(suffix=".c")[1]
216
temp_def = tempfile.mkstemp(suffix=".def")[1]
218
os.system("%s -dM -E %s > %s" % (compiler, temp_c, temp_def))
220
temp_def_file = open(temp_def)
221
lines = [l.strip() for l in temp_def_file if l.strip()]
222
temp_def_file.close()
229
def project_name_get(path, fallback="Blender", prefix="Blender_"):
230
if not os.path.isdir(os.path.join(path, ".svn")):
235
info = subprocess.Popen(["svn", "info", path],
236
stdout=subprocess.PIPE).communicate()[0]
238
# possibly 'svn' isnt found/installed
241
# string version, we only want the URL
242
info = info.decode(encoding="utf-8", errors="ignore")
244
for l in info.split("\n"):
246
if l.startswith("URL"):
247
# https://svn.blender.org/svnroot/bf-blender/branches/bmesh/blender
249
if "/branches/" in l:
250
return prefix + l.rsplit("/branches/", 1)[-1].split("/", 1)[0]