2020-05-26 21:08:29 +02:00
|
|
|
import subprocess
|
|
|
|
|
|
|
|
from build.project import Project
|
|
|
|
|
2021-07-29 09:32:21 +02:00
|
|
|
def __cmake_compiler_args(language, compiler):
|
|
|
|
s = compiler.split(' ', 1)
|
|
|
|
result = []
|
|
|
|
if len(s) == 2:
|
|
|
|
result.append(f'-DCMAKE_{language}_COMPILER_LAUNCHER={s[0]}')
|
|
|
|
compiler = s[1]
|
|
|
|
result.append(f'-DCMAKE_{language}_COMPILER={compiler}')
|
|
|
|
return result
|
|
|
|
|
2020-05-26 21:08:29 +02:00
|
|
|
def configure(toolchain, src, build, args=()):
|
|
|
|
cross_args = []
|
|
|
|
|
|
|
|
if toolchain.is_windows:
|
|
|
|
cross_args.append('-DCMAKE_SYSTEM_NAME=Windows')
|
|
|
|
cross_args.append('-DCMAKE_RC_COMPILER=' + toolchain.windres)
|
|
|
|
|
|
|
|
configure = [
|
|
|
|
'cmake',
|
|
|
|
src,
|
|
|
|
|
|
|
|
'-DCMAKE_INSTALL_PREFIX=' + toolchain.install_prefix,
|
|
|
|
'-DCMAKE_BUILD_TYPE=release',
|
2021-07-29 09:32:21 +02:00
|
|
|
] + \
|
|
|
|
__cmake_compiler_args('C', toolchain.cc) + \
|
|
|
|
__cmake_compiler_args('CXX', toolchain.cxx) + \
|
|
|
|
[
|
2020-05-26 21:08:29 +02:00
|
|
|
'-DCMAKE_C_FLAGS=' + toolchain.cflags + ' ' + toolchain.cppflags,
|
|
|
|
'-DCMAKE_CXX_FLAGS=' + toolchain.cxxflags + ' ' + toolchain.cppflags,
|
|
|
|
|
|
|
|
'-GNinja',
|
|
|
|
] + cross_args + args
|
|
|
|
|
|
|
|
subprocess.check_call(configure, env=toolchain.env, cwd=build)
|
|
|
|
|
|
|
|
class CmakeProject(Project):
|
|
|
|
def __init__(self, url, md5, installed, configure_args=[],
|
2021-03-12 21:56:32 +01:00
|
|
|
windows_configure_args=[],
|
2020-05-26 21:08:29 +02:00
|
|
|
**kwargs):
|
|
|
|
Project.__init__(self, url, md5, installed, **kwargs)
|
|
|
|
self.configure_args = configure_args
|
2021-03-12 21:56:32 +01:00
|
|
|
self.windows_configure_args = windows_configure_args
|
2020-05-26 21:08:29 +02:00
|
|
|
|
|
|
|
def configure(self, toolchain):
|
|
|
|
src = self.unpack(toolchain)
|
|
|
|
build = self.make_build_path(toolchain)
|
2021-03-12 21:56:32 +01:00
|
|
|
configure_args = self.configure_args
|
|
|
|
if toolchain.is_windows:
|
|
|
|
configure_args = configure_args + self.windows_configure_args
|
|
|
|
configure(toolchain, src, build, configure_args)
|
2020-05-26 21:08:29 +02:00
|
|
|
return build
|
|
|
|
|
2021-08-28 22:41:31 +02:00
|
|
|
def _build(self, toolchain):
|
2020-05-26 21:08:29 +02:00
|
|
|
build = self.configure(toolchain)
|
|
|
|
subprocess.check_call(['ninja', 'install'],
|
|
|
|
cwd=build, env=toolchain.env)
|