Source code

Revision control

Other Tools

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/.
6
7
@template
8
def Binary():
9
'''Generic template for target binaries. Meant to be used by other
10
templates.'''
11
12
# Add -llog by default, since we use it all over the place.
13
if CONFIG['OS_TARGET'] == 'Android':
14
OS_LIBS += ['log']
15
16
17
@template
18
def Program(name):
19
'''Template for program executables.'''
20
PROGRAM = name
21
22
Binary()
23
24
25
@template
26
def SimplePrograms(names, ext='.cpp'):
27
'''Template for simple program executables.
28
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]
33
34
Binary()
35
36
37
@template
38
def CppUnitTests(names, ext='.cpp'):
39
'''Template for C++ unit tests.
40
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]
47
48
Binary()
49
50
51
@template
52
def Library(name):
53
'''Template for libraries.'''
54
LIBRARY_NAME = name
55
56
@template
57
def AllowCompilerWarnings():
58
COMPILE_FLAGS['WARNINGS_AS_ERRORS'] = []
59
60
@template
61
def DisableCompilerWarnings():
62
COMPILE_FLAGS['WARNINGS_CFLAGS'] = []
63
64
@template
65
def RustLibrary(name, features=None, output_category=None):
66
'''Template for Rust libraries.'''
67
Library(name)
68
69
IS_RUST_LIBRARY = True
70
# Some Rust build scripts compile C/C++ sources, don't error on warnings for them.
71
AllowCompilerWarnings()
72
73
# And furthermore, don't even show warnings for them, so they don't regress
74
# the Compiler Warnings build metric
76
DisableCompilerWarnings()
77
78
if features:
79
RUST_LIBRARY_FEATURES = features
80
81
if output_category:
82
RUST_LIBRARY_OUTPUT_CATEGORY = output_category
83
84
85
@template
86
def SharedLibrary(name, output_category=None):
87
'''Template for shared libraries.'''
88
Library(name)
89
90
FORCE_SHARED_LIB = True
91
92
if output_category:
93
SHARED_LIBRARY_OUTPUT_CATEGORY = output_category
94
95
Binary()
96
97
98
@template
99
def Framework(name, output_category=None):
100
'''Template for OSX Frameworks.'''
101
SharedLibrary(name, output_category)
102
103
IS_FRAMEWORK = True
104
105
106
@template
107
def HostProgram(name):
108
'''Template for build tools executables.'''
109
HOST_PROGRAM = name
110
111
112
@template
113
def HostSimplePrograms(names, ext='.cpp'):
114
'''Template for simple build tools executables.
115
116
Those have a single source with the same base name as the executable.
117
'''
118
HOST_SIMPLE_PROGRAMS += names
119
HOST_SOURCES += ['%s%s' % (name.replace('host_', ''), ext)
120
for name in names]
121
122
123
@template
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')
129
130
HOST_LIBRARY_NAME = name
131
132
FORCE_SHARED_LIB = True
133
134
@template
135
def HostLibrary(name):
136
'''Template for build tools libraries.'''
137
HOST_LIBRARY_NAME = name
138
139
@template
140
def HostRustLibrary(name, features=None):
141
'''Template for host Rust libraries.'''
142
HostLibrary(name)
143
144
IS_RUST_LIBRARY = True
145
# Some Rust build scripts compile C/C++ sources, don't error on warnings for them.
146
AllowCompilerWarnings()
147
148
if features:
149
HOST_RUST_LIBRARY_FEATURES = features
150
151
@template
152
def DisableStlWrapping():
153
COMPILE_FLAGS['STL'] = []
154
155
@template
156
def NoVisibilityFlags():
157
COMPILE_FLAGS['VISIBILITY'] = []
158
159
@template
160
def ForceInclude(*headers):
161
"""Force includes a set of header files in C++ compilations"""
162
if CONFIG['CC_TYPE'] == 'clang-cl':
163
include_flag = '-FI'
164
else:
165
include_flag = '-include'
166
for header in headers:
167
CXXFLAGS += [include_flag, header]
168
169
include('gecko_templates.mozbuild')
170
include('test_templates.mozbuild')