1 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
2 # vim: set filetype=python:
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 '''Generic template for target binaries. Meant to be used by other
12 # Add -llog by default, since we use it all over the place.
13 if CONFIG['OS_TARGET'] == 'Android':
19 '''Template for program executables.'''
26 def SimplePrograms(names, ext='.cpp'):
27 '''Template for simple program executables.
29 Those have a single source with the same base name as the executable.
31 SIMPLE_PROGRAMS += names
32 SOURCES += ['%s%s' % (name, ext) for name in names]
38 def CppUnitTests(names, ext='.cpp'):
39 '''Template for C++ unit tests.
41 Those have a single source with the same base name as the executable.
43 COMPILE_FLAGS['EXTRA_INCLUDES'] = ['-I%s/dist/include' % TOPOBJDIR,
44 '-I%s/dist/include/testing' % TOPOBJDIR]
45 CPP_UNIT_TESTS += names
46 SOURCES += ['%s%s' % (name, ext) for name in names]
53 '''Template for libraries.'''
57 def AllowCompilerWarnings():
58 COMPILE_FLAGS['WARNINGS_AS_ERRORS'] = []
61 def DisableCompilerWarnings():
62 COMPILE_FLAGS['WARNINGS_CFLAGS'] = []
65 def RustLibrary(name, features=None, output_category=None):
66 '''Template for Rust libraries.'''
69 IS_RUST_LIBRARY = True
70 # Some Rust build scripts compile C/C++ sources, don't error on warnings for them.
71 AllowCompilerWarnings()
73 # And furthermore, don't even show warnings for them, so they don't regress
74 # the Compiler Warnings build metric
75 # <https://developer.mozilla.org/en-US/docs/Mozilla/Performance/Automated_Performance_Testing_and_Sheriffing/Build_Metrics#compiler_warnings>.
76 DisableCompilerWarnings()
79 RUST_LIBRARY_FEATURES = features
82 RUST_LIBRARY_OUTPUT_CATEGORY = output_category
86 def SharedLibrary(name, output_category=None):
87 '''Template for shared libraries.'''
90 FORCE_SHARED_LIB = True
93 SHARED_LIBRARY_OUTPUT_CATEGORY = output_category
99 def Framework(name, output_category=None):
100 '''Template for OSX Frameworks.'''
101 SharedLibrary(name, output_category)
107 def HostProgram(name):
108 '''Template for build tools executables.'''
113 def HostSimplePrograms(names, ext='.cpp'):
114 '''Template for simple build tools executables.
116 Those have a single source with the same base name as the executable.
118 HOST_SIMPLE_PROGRAMS += names
119 HOST_SOURCES += ['%s%s' % (name.replace('host_', ''), ext)
124 def HostSharedLibrary(name):
125 '''Template for build tools libraries.'''
126 if name != 'clang-plugin':
127 error('Please make sure host shared library support is complete '
128 'before using for something else than the clang plugin')
130 HOST_LIBRARY_NAME = name
132 FORCE_SHARED_LIB = True
135 def HostLibrary(name):
136 '''Template for build tools libraries.'''
137 HOST_LIBRARY_NAME = name
140 def HostRustLibrary(name, features=None):
141 '''Template for host Rust libraries.'''
144 IS_RUST_LIBRARY = True
145 # Some Rust build scripts compile C/C++ sources, don't error on warnings for them.
146 AllowCompilerWarnings()
149 HOST_RUST_LIBRARY_FEATURES = features
152 def DisableStlWrapping():
153 COMPILE_FLAGS['STL'] = []
156 def NoVisibilityFlags():
157 COMPILE_FLAGS['VISIBILITY'] = []
160 def ForceInclude(*headers):
161 """Force includes a set of header files in C++ compilations"""
162 if CONFIG['CC_TYPE'] == 'clang-cl':
165 include_flag = '-include'
166 for header in headers:
167 CXXFLAGS += [include_flag, header]
170 def GeneratedFile(name, *names, **kwargs):
171 """Add one or more GENERATED_FILES with the given attributes.
173 You must pass in at least one generated file (the "name" argument). Other
174 names can be included as positional arguments after "name"."""
175 script = kwargs.get('script')
176 entry_point = kwargs.get('entry_point')
177 inputs = kwargs.get('inputs', [])
178 flags = kwargs.get('flags', [])
179 force = kwargs.get('force', False)
180 if entry_point and not script:
181 error('entry_point cannot be provided if script is not provided')
182 if script and ':' in script:
183 error('script should not include a `:`. If you want to provide an '
184 'alternative entry point for your script, use the entry_point '
187 key = (name,) + names if names else name
188 GENERATED_FILES += [key]
189 generated_file = GENERATED_FILES[key]
190 if script and not entry_point:
191 generated_file.script = script
192 if script and entry_point:
193 generated_file.script = script + ':' + entry_point
194 generated_file.inputs = inputs
195 generated_file.flags = flags
196 generated_file.force = force
198 include('gecko_templates.mozbuild')
199 include('test_templates.mozbuild')