1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 import cmakeparser
as cp
12 AOM_DIR
= '../../third_party/aom'
14 def write_aom_config(system
, arch
, variables
, cache_variables
):
15 # read template cmake file
16 variables
['year'] = datetime
.datetime
.now().year
17 cp
.parse(variables
, [], os
.path
.join(AOM_DIR
, 'build', 'cmake',
18 'generate_aom_config_templates.cmake'))
21 cache_variables
= [x
for x
in sorted(cache_variables
)
22 if x
and not x
.startswith((' ', 'CMAKE', 'AOM_C', 'AOM_RTCD'))]
24 # inherit this from the mozilla build config
25 cache_variables
.remove('HAVE_PTHREAD_H')
27 outdir
= os
.path
.join('config', system
, arch
, 'config')
33 with
open(os
.path
.join(outdir
, 'aom_config.h'), 'w') as f
:
34 header
= variables
['h_file_header_block']
37 for var
in cache_variables
:
38 f
.write('#define %s %s\n' % (var
, variables
[var
]))
39 f
.write('#endif /* AOM_CONFIG_H_ */\n')
41 with
open(os
.path
.join(outdir
, 'aom_config.asm'), 'w') as f
:
42 header
= variables
['asm_file_header_block']
45 for var
in cache_variables
:
46 if var
in ['INCLUDE_INSTALL_DIR', 'INLINE',
47 'LIB_INSTALL_DIR', 'RESTRICT']:
50 f
.write('.equ %s, %s\n' % (var
, variables
[var
]))
52 f
.write('%s equ %s\n' % (var
, variables
[var
]))
55 f
.write('.section .note.GNU-stack,"",%progbits')
58 if __name__
== '__main__':
62 'CMAKE_CURRENT_SOURCE_DIR': AOM_DIR
,
63 'CONFIG_AV1_DECODER': 1,
64 'CONFIG_AV1_ENCODER': 1,
65 'CONFIG_COLLECT_INTER_MODE_RD_STATS': 0,
66 'CONFIG_INSPECTION': 0,
67 'CONFIG_INTERNAL_STATS': 0,
69 'CONFIG_LOWBITDEPTH': 1,
70 'CONFIG_MULTITHREAD': 1,
73 'CMAKE_CURRENT_BINARY_DIR': 'OBJDIR',
74 'CMAKE_INSTALL_PREFIX': 'INSTALLDIR',
75 'CMAKE_SYSTEM_NAME': 'Linux',
76 'CMAKE_SYSTEM_PROCESSOR': 'x86_64',
82 'AOM_TEST_TEST_CMAKE_': 1, #prevent building tests
85 f
= open('sources.mozbuild', 'w')
86 f
.write('# This file is generated. Do not edit.\n\n')
87 f
.write('files = {\n')
90 ('armv7', 'linux', 'arm', True),
91 ('generic', '', 'generic', True),
92 ('x86', 'linux', 'ia32', True),
93 ('x86', 'win', 'ia32', False),
94 ('x86_64', 'linux', 'x64', True),
95 ('x86_64', 'mac', 'x64', False),
96 ('x86_64', 'win', 'x64', False),
98 for cpu
, system
, arch
, generate_sources
in platforms
:
99 print('Running CMake for %s (%s)' % (cpu
, system
))
100 variables
= shared_variables
.copy()
101 variables
['AOM_TARGET_CPU'] = cpu
103 # We skip compiling test programs that detect these
104 variables
['HAVE_FEXCEPT'] = 1
105 variables
['INLINE'] = 'inline'
106 if cpu
== 'x86' and system
== 'linux':
107 variables
['CONFIG_PIC'] = 1
109 variables
['CONFIG_PIC'] = 1
111 variables
['MSVC'] = 1
114 sources
= cp
.parse(variables
, cache_variables
,
115 os
.path
.join(AOM_DIR
, 'CMakeLists.txt'))
117 # Disable HAVE_UNISTD_H.
118 cache_variables
.remove('HAVE_UNISTD_H')
119 write_aom_config(system
, arch
, variables
, cache_variables
)
121 # Windows x86_64 needs this -- all other source files are shared
123 if cpu
is 'x86_64' and system
is 'win':
124 f
.write(' \'X64_WIN_SOURCES\': [\n')
125 f
.write(' \'%s\',\n' % variables
['AOM_PORTS_ASM_X86'])
128 # Currently, the sources are the same for each supported cpu
129 # regardless of operating system / compiler. If that changes, we'll
130 # have to generate sources for each combination.
132 # Remove spurious sources and perl files
133 sources
= list(filter(lambda x
: x
.startswith(AOM_DIR
), sources
))
134 sources
= list(filter(lambda x
: not x
.endswith('.pl'), sources
))
137 exports
= list(filter(lambda x
: re
.match(os
.path
.join(AOM_DIR
, '(aom|aom_mem|aom_ports|aom_scale)/.*h$'), x
), sources
))
138 exports
= list(filter(lambda x
: not re
.search('(internal|src)', x
), exports
))
139 exports
= list(filter(lambda x
: not re
.search('(emmintrin_compat.h|mem_.*|msvc.h|aom_once.h)$', x
), exports
))
141 sources
= list(sources
)
143 for export
in exports
:
144 if export
in sources
:
145 sources
.remove(export
)
147 # Remove header and .inc files
148 sources
= sorted(filter(lambda x
: not x
.endswith('.h'), sources
))
149 sources
= sorted(filter(lambda x
: not x
.endswith('.inc'), sources
))
151 # The build system is unhappy if two files have the same prefix
152 # In libaom, sometimes .asm and .c files share the same prefix
153 for i
in range(len(sources
) - 1):
154 if sources
[i
].endswith('.asm'):
155 if os
.path
.splitext(sources
[i
])[0] == os
.path
.splitext(sources
[i
+ 1])[0]:
157 sources
[i
] = sources
[i
].replace('.asm', '_asm.asm')
158 if not os
.path
.exists(sources
[i
]):
159 os
.rename(old
, sources
[i
])
161 f
.write(' \'%s_EXPORTS\': [\n' % arch
.upper())
162 for export
in sorted(exports
):
163 f
.write(' \'%s\',\n' % export
)
166 f
.write(' \'%s_SOURCES\': [\n' % arch
.upper())
167 for source
in sorted(sources
):
168 f
.write(' \'%s\',\n' % source
)