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
61 # Config file to be used (relative to blender's sources root)
62 cmake_config_file = "build_files/cmake/config/blender_full.cmake"
63 cmake_player_config_file = None
64 cmake_cuda_config_file = None
68 cmake_extra_options = ['-DCMAKE_BUILD_TYPE:STRING=Release']
69 cuda_cmake_options = []
71 if builder.startswith('mac'):
72 # Set up OSX architecture
73 if builder.endswith('x86_64_10_6_cmake'):
74 cmake_extra_options.append('-DCMAKE_OSX_ARCHITECTURES:STRING=x86_64')
75 cmake_extra_options.append('-DWITH_CODEC_QUICKTIME=OFF')
76 cmake_extra_options.append('-DCMAKE_OSX_DEPLOYMENT_TARGET=10.6')
77 cmake_extra_options.append('-DCUDA_HOST_COMPILER=/usr/local/cuda-hack/clang')
78 cmake_extra_options.append('-DCUDA_NVCC_EXECUTABLE=/usr/local/cuda-hack/nvcc')
82 elif builder.startswith('win'):
83 if builder.endswith('_vc2015'):
84 if builder.startswith('win64'):
85 cmake_options.extend(['-G', 'Visual Studio 14 2015 Win64'])
86 elif builder.startswith('win32'):
88 cmake_options.extend(['-G', 'Visual Studio 14 2015'])
89 cmake_extra_options.append('-DCUDA_NVCC_FLAGS=--cl-version;2013;' +
90 '--compiler-bindir;C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\bin')
92 if builder.startswith('win64'):
93 cmake_options.extend(['-G', 'Visual Studio 12 2013 Win64'])
94 elif builder.startswith('win32'):
96 cmake_options.extend(['-G', 'Visual Studio 12 2013'])
98 elif builder.startswith('linux'):
99 tokens = builder.split("_")
101 if glibc == 'glibc219':
103 elif glibc == 'glibc211':
105 cmake_config_file = "build_files/buildbot/config/blender_linux.cmake"
106 cmake_player_config_file = "build_files/buildbot/config/blender_linux_player.cmake"
107 if builder.endswith('x86_64_cmake'):
108 chroot_name = 'buildbot_' + deb_name + '_x86_64'
109 targets = ['player', 'blender']
110 elif builder.endswith('i686_cmake'):
112 chroot_name = 'buildbot_' + deb_name + '_i686'
113 cuda_chroot_name = 'buildbot_' + deb_name + '_x86_64'
114 targets = ['player', 'blender', 'cuda']
115 cmake_extra_options.extend(["-DCMAKE_C_COMPILER=/usr/bin/gcc-7",
116 "-DCMAKE_CXX_COMPILER=/usr/bin/g++-7"])
118 cmake_options.append("-C" + os.path.join(blender_dir, cmake_config_file))
120 # Prepare CMake options needed to configure cuda binaries compilation.
121 cuda_cmake_options.append("-DWITH_CYCLES_CUDA_BINARIES=%s" % ('ON' if build_cubins else 'OFF'))
122 cuda_cmake_options.append("-DCYCLES_CUDA_BINARIES_ARCH=sm_20;sm_21;sm_30;sm_35;sm_37;sm_50;sm_52;sm_60;sm_61")
123 if build_cubins or 'cuda' in targets:
125 cuda_cmake_options.append("-DCUDA_64_BIT_DEVICE_CODE=OFF")
127 cuda_cmake_options.append("-DCUDA_64_BIT_DEVICE_CODE=ON")
129 # Only modify common cmake options if cuda doesn't require separate target.
130 if 'cuda' not in targets:
131 cmake_options += cuda_cmake_options
133 cmake_options.append("-DCMAKE_INSTALL_PREFIX=%s" % (install_dir))
135 cmake_options += cmake_extra_options
137 # Prepare chroot command prefix if needed
139 chroot_prefix = ['schroot', '-c', chroot_name, '--']
143 cuda_chroot_prefix = ['schroot', '-c', cuda_chroot_name, '--']
145 cuda_chroot_prefix = chroot_prefix[:]
147 # Make sure no garbage remained from the previous run
148 if os.path.isdir(install_dir):
149 shutil.rmtree(install_dir)
151 for target in targets:
152 print("Building target %s" % (target))
153 # Construct build directory name based on the target
154 target_build_dir = build_dir
155 target_chroot_prefix = chroot_prefix[:]
156 if target != 'blender':
157 target_build_dir += '_' + target
158 target_name = 'install'
159 # Make sure build directory exists and enter it
160 if not os.path.isdir(target_build_dir):
161 os.mkdir(target_build_dir)
162 os.chdir(target_build_dir)
163 # Tweaking CMake options to respect the target
164 target_cmake_options = cmake_options[:]
165 if target == 'player':
166 target_cmake_options.append("-C" + os.path.join(blender_dir, cmake_player_config_file))
167 elif target == 'cuda':
168 target_cmake_options += cuda_cmake_options
169 target_chroot_prefix = cuda_chroot_prefix[:]
170 target_name = 'cycles_kernel_cuda'
171 # If cuda binaries are compiled as a separate target, make sure
172 # other targets don't compile cuda binaries.
173 if 'cuda' in targets and target != 'cuda':
174 target_cmake_options.append("-DWITH_CYCLES_CUDA_BINARIES=OFF")
175 # Configure the build
176 print("CMake options:")
177 print(target_cmake_options)
178 if os.path.exists('CMakeCache.txt'):
179 print("Removing CMake cache")
180 os.remove('CMakeCache.txt')
181 retcode = subprocess.call(target_chroot_prefix + ['cmake', blender_dir] + target_cmake_options)
183 print('Configuration FAILED!')
186 if 'win32' in builder or 'win64' in builder:
187 command = ['cmake', '--build', '.', '--target', target_name, '--config', 'Release']
189 command = target_chroot_prefix + ['make', '-s', '-j2', target_name]
191 print("Executing command:")
193 retcode = subprocess.call(command)
198 if builder.startswith('linux') and target == 'cuda':
199 blender_h = os.path.join(blender_dir, "source", "blender", "blenkernel", "BKE_blender_version.h")
200 blender_version = int(parse_header_file(blender_h, 'BLENDER_VERSION'))
201 blender_version = "%d.%d" % (blender_version // 100, blender_version % 100)
202 kernels = os.path.join(target_build_dir, 'intern', 'cycles', 'kernel')
203 install_kernels = os.path.join(install_dir, blender_version, 'scripts', 'addons', 'cycles', 'lib')
204 os.mkdir(install_kernels)
205 print("Copying cuda binaries from %s to %s" % (kernels, install_kernels))
206 os.system('cp %s/*.cubin %s' % (kernels, install_kernels))
209 print("Unknown building system")