Bug 1744358 move MediaEngineDefault-specific MediaEngineSource classes out of header...
[gecko.git] / build / templates.mozbuild
blob6ac4c12380ecfa06e3d7a5df2cf4faebec7574ed
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/.
7 @template
8 def Binary():
9     '''Generic template for target binaries. Meant to be used by other
10     templates.'''
12     # Add -llog by default, since we use it all over the place.
13     if CONFIG['OS_TARGET'] == 'Android':
14         OS_LIBS += ['log']
17 @template
18 def Program(name):
19     '''Template for program executables.'''
20     PROGRAM = name
22     Binary()
25 @template
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.
30     '''
31     SIMPLE_PROGRAMS += names
32     SOURCES += ['%s%s' % (name, ext) for name in names]
34     Binary()
37 @template
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.
42     '''
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]
48     Binary()
51 @template
52 def Library(name):
53     '''Template for libraries.'''
54     LIBRARY_NAME = name
56 @template
57 def AllowCompilerWarnings():
58     COMPILE_FLAGS['WARNINGS_AS_ERRORS'] = []
59     WASM_FLAGS['WARNINGS_AS_ERRORS'] = []
61 @template
62 def DisableCompilerWarnings():
63     COMPILE_FLAGS['WARNINGS_CFLAGS'] = []
65 @template
66 def RustLibrary(name, features=None, output_category=None, is_gkrust=False):
67     '''Template for Rust libraries.'''
68     Library(name)
70     IS_RUST_LIBRARY = True
71     # Some Rust build scripts compile C/C++ sources, don't error on warnings for them.
72     AllowCompilerWarnings()
74     # And furthermore, don't even show warnings for them, so they don't regress
75     # the Compiler Warnings build metric
76     # <https://developer.mozilla.org/en-US/docs/Mozilla/Performance/Automated_Performance_Testing_and_Sheriffing/Build_Metrics#compiler_warnings>.
77     DisableCompilerWarnings()
79     if features:
80         RUST_LIBRARY_FEATURES = features
82     if output_category:
83         RUST_LIBRARY_OUTPUT_CATEGORY = output_category
85     if is_gkrust:
86         IS_GKRUST = True
89 @template
90 def SharedLibrary(name, output_category=None):
91     '''Template for shared libraries.'''
92     Library(name)
94     FORCE_SHARED_LIB = True
96     if output_category:
97         SHARED_LIBRARY_OUTPUT_CATEGORY = output_category
99     Binary()
102 @template
103 def Framework(name, output_category=None):
104     '''Template for OSX Frameworks.'''
105     SharedLibrary(name, output_category)
107     IS_FRAMEWORK = True
110 @template
111 def HostProgram(name):
112     '''Template for build tools executables.'''
113     HOST_PROGRAM = name
116 @template
117 def HostSimplePrograms(names, ext='.cpp'):
118     '''Template for simple build tools executables.
120     Those have a single source with the same base name as the executable.
121     '''
122     HOST_SIMPLE_PROGRAMS += names
123     HOST_SOURCES += ['%s%s' % (name.replace('host_', ''), ext)
124         for name in names]
127 @template
128 def HostSharedLibrary(name):
129     '''Template for build tools libraries.'''
130     if name != 'clang-plugin':
131         error('Please make sure host shared library support is complete '
132               'before using for something else than the clang plugin')
134     HOST_LIBRARY_NAME = name
136     FORCE_SHARED_LIB = True
138 @template
139 def HostLibrary(name):
140     '''Template for build tools libraries.'''
141     HOST_LIBRARY_NAME = name
143 @template
144 def HostRustLibrary(name, features=None):
145     '''Template for host Rust libraries.'''
146     HostLibrary(name)
148     IS_RUST_LIBRARY = True
149     # Some Rust build scripts compile C/C++ sources, don't error on warnings for them.
150     AllowCompilerWarnings()
152     if features:
153         HOST_RUST_LIBRARY_FEATURES = features
155 @template
156 def DisableStlWrapping():
157     COMPILE_FLAGS['STL'] = []
159 @template
160 def NoVisibilityFlags():
161     COMPILE_FLAGS['VISIBILITY'] = []
163 @template
164 def ForceInclude(*headers):
165     """Force includes a set of header files in C++ compilations"""
166     if CONFIG['CC_TYPE'] == 'clang-cl':
167         include_flag = '-FI'
168     else:
169         include_flag = '-include'
170     for header in headers:
171         CXXFLAGS += [include_flag, header]
173 @template
174 def GeneratedFile(name, *names, **kwargs):
175     """Add one or more GENERATED_FILES with the given attributes.
177     You must pass in at least one generated file (the "name" argument). Other
178     names can be included as positional arguments after "name"."""
179     script = kwargs.pop('script', None)
180     entry_point = kwargs.pop('entry_point', None)
181     inputs = kwargs.pop('inputs', [])
182     flags = kwargs.pop('flags', [])
183     force = kwargs.pop('force', False)
184     if kwargs:
185         error('Unrecognized argument(s) to GeneratedFile: %s' %
186               ', '.join(kwargs))
187     if entry_point and not script:
188        error('entry_point cannot be provided if script is not provided')
189     if script and ':' in script:
190        error('script should not include a `:`. If you want to provide an '
191              'alternative entry point for your script, use the entry_point '
192              'parameter.')
194     key = (name,) + names if names else name
195     GENERATED_FILES += [key]
196     generated_file = GENERATED_FILES[key]
197     if script and not entry_point:
198         generated_file.script = script
199     if script and entry_point:
200         generated_file.script = script + ':' + entry_point
201     generated_file.inputs = inputs
202     generated_file.flags = flags
203     generated_file.force = force
205 @template
206 def CbindgenHeader(name, inputs):
207     """Add one GENERATED_FILES by running RunCbindgen.py"""
209     inputs = ['!/config/cbindgen-metadata.json'] + inputs
210     GeneratedFile(name, script='/build/RunCbindgen.py',
211                   entry_point='generate', inputs=inputs)
214 include('gecko_templates.mozbuild')