1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
28 sys.stderr.write("Not enough arguments, expecting builder name\n")
33 # we run from build/ directory
34 blender_dir = os.path.join('..', 'blender.git')
37 def parse_header_file(filename, define):
39 regex = re.compile("^#\s*define\s+%s\s+(.*)" % define)
40 with open(filename, "r") as file:
42 match = regex.match(l)
47 if 'cmake' in builder:
50 # Some fine-tuning configuration
51 blender_dir = os.path.join('..', blender_dir)
52 build_dir = os.path.abspath(os.path.join('..', 'build', builder))
53 install_dir = os.path.abspath(os.path.join('..', 'install', builder))
56 chroot_name = None # If not None command will be delegated to that chroot
57 cuda_chroot_name = None # If not None cuda compilationcommand will be delegated to that chroot
58 build_cubins = True # Whether to build Cycles CUDA kernels
59 remove_install_dir = False # Remove installation folder before building
62 # Config file to be used (relative to blender's sources root)
63 cmake_config_file = "build_files/cmake/config/blender_full.cmake"
64 cmake_player_config_file = None
65 cmake_cuda_config_file = None
69 cmake_extra_options = ['-DCMAKE_BUILD_TYPE:STRING=Release']
70 cuda_cmake_options = []
72 if builder.startswith('mac'):
74 # Set up OSX architecture
75 if builder.endswith('x86_64_10_6_cmake'):
76 cmake_extra_options.append('-DCMAKE_OSX_ARCHITECTURES:STRING=x86_64')
78 elif builder.startswith('win'):
80 if builder.startswith('win64'):
81 cmake_options.append(['-G', '"Visual Studio 12 2013 Win64"'])
82 elif builder.startswith('win32'):
84 cmake_options.append(['-G', '"Visual Studio 12 2013"'])
86 elif builder.startswith('linux'):
87 tokens = builder.split("_")
89 if glibc == 'glibc219':
91 elif glibc == 'glibc211':
93 remove_install_dir = True
94 cmake_config_file = "build_files/buildbot/config/blender_linux.cmake"
95 cmake_player_config_file = "build_files/buildbot/config/blender_linux_player.cmake"
96 if builder.endswith('x86_64_cmake'):
97 chroot_name = 'buildbot_' + deb_name + '_x86_64'
98 targets = ['player', 'blender']
99 elif builder.endswith('i386_cmake'):
101 chroot_name = 'buildbot_' + deb_name + '_i686'
102 cuda_chroot_name = 'buildbot_' + deb_name + '_x86_64'
103 targets = ['player', 'blender', 'cuda']
105 cmake_options.append("-C" + os.path.join(blender_dir, cmake_config_file))
107 # Prepare CMake options needed to configure cuda binaries compilation.
108 cuda_cmake_options.append("-DWITH_CYCLES_CUDA_BINARIES=%s" % ('ON' if build_cubins else 'OFF'))
109 if build_cubins or 'cuda' in targets:
111 cuda_cmake_options.append("-DCUDA_64_BIT_DEVICE_CODE=OFF")
113 cuda_cmake_options.append("-DCUDA_64_BIT_DEVICE_CODE=ON")
115 # Only modify common cmake options if cuda doesn't require separate target.
116 if 'cuda' not in targets:
117 cmake_options += cuda_cmake_options
120 cmake_options.append("-DCMAKE_INSTALL_PREFIX=%s" % (install_dir))
122 cmake_options += cmake_extra_options
124 # Prepare chroot command prefix if needed
126 chroot_prefix = ['schroot', '-c', chroot_name, '--']
130 cuda_chroot_prefix = ['schroot', '-c', cuda_chroot_name, '--']
132 cuda_chroot_prefix = chroot_prefix[:]
134 # Make sure no garbage remained from the previous run
135 # (only do it if builder requested this)
136 if remove_install_dir:
137 if os.path.isdir(install_dir):
138 shutil.rmtree(install_dir)
140 for target in targets:
141 print("Building target %s" % (target))
142 # Construct build directory name based on the target
143 target_build_dir = build_dir
144 target_chroot_prefix = chroot_prefix[:]
145 if target != 'blender':
146 target_build_dir += '_' + target
147 target_name = 'install'
148 # Make sure build directory exists and enter it
149 if not os.path.isdir(target_build_dir):
150 os.mkdir(target_build_dir)
151 os.chdir(target_build_dir)
152 # Tweaking CMake options to respect the target
153 target_cmake_options = cmake_options[:]
154 if target == 'player':
155 target_cmake_options.append("-C" + os.path.join(blender_dir, cmake_player_config_file))
156 elif target == 'cuda':
157 target_cmake_options += cuda_cmake_options
158 target_chroot_prefix = cuda_chroot_prefix[:]
159 target_name = 'cycles_kernel_cuda'
160 # If cuda binaries are compiled as a separate target, make sure
161 # other targets don't compile cuda binaries.
162 if 'cuda' in targets and target != 'cuda':
163 target_cmake_options.append("-DWITH_CYCLES_CUDA_BINARIES=OFF")
164 # Configure the build
165 print("CMake options:")
166 print(target_cmake_options)
167 if os.path.exists('CMakeCache.txt'):
168 print("Removing CMake cache")
169 os.remove('CMakeCache.txt')
170 retcode = subprocess.call(target_chroot_prefix + ['cmake', blender_dir] + target_cmake_options)
172 print('Condifuration FAILED!')
175 if 'win32' in builder:
176 command = ['msbuild', 'INSTALL.vcxproj', '/Property:PlatformToolset=v120_xp', '/p:Configuration=Release']
177 elif 'win64' in builder:
178 command = ['msbuild', 'INSTALL.vcxproj', '/p:Configuration=Release']
180 command = target_chroot_prefix + ['make', '-s', '-j2', target_name]
182 print("Executing command:")
184 retcode = subprocess.call(command)
189 if builder.startswith('linux') and target == 'cuda':
190 blender_h = os.path.join(blender_dir, "source", "blender", "blenkernel", "BKE_blender.h")
191 blender_version = int(parse_header_file(blender_h, 'BLENDER_VERSION'))
192 blender_version = "%d.%d" % (blender_version // 100, blender_version % 100)
193 kernels = os.path.join(target_build_dir, 'intern', 'cycles', 'kernel')
194 install_kernels = os.path.join(install_dir, blender_version, 'scripts', 'addons', 'cycles', 'lib')
195 os.mkdir(install_kernels)
196 print("Copying cuda binaries from %s to %s" % (kernels, install_kernels))
197 os.system('cp %s/*.cubin %s' % (kernels, install_kernels))
200 print("Unknown building system")