2021-01-14 08:34:20 +00:00
|
|
|
#
|
|
|
|
# Helper module to build macOS version of various source ports
|
2022-01-11 09:43:29 +00:00
|
|
|
# Copyright (C) 2020-2022 Alexey Lysiuk
|
2021-01-14 08:34:20 +00:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
import copy
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import shutil
|
|
|
|
import subprocess
|
|
|
|
import typing
|
2021-08-05 07:12:20 +00:00
|
|
|
from pathlib import Path
|
|
|
|
from platform import machine
|
2021-01-14 08:34:20 +00:00
|
|
|
|
|
|
|
from ..state import BuildState
|
2021-08-05 07:12:20 +00:00
|
|
|
from ..utility import (
|
|
|
|
OS_VERSION_ARM64,
|
|
|
|
OS_VERSION_X86_64,
|
|
|
|
CommandLineOptions,
|
|
|
|
symlink_directory,
|
|
|
|
)
|
2021-01-14 08:34:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Target:
|
|
|
|
DESTINATION_DEPS = 0
|
|
|
|
DESTINATION_OUTPUT = 1
|
|
|
|
|
|
|
|
def __init__(self, name=None):
|
|
|
|
self.name = name
|
|
|
|
self.destination = self.DESTINATION_DEPS
|
|
|
|
|
|
|
|
self.multi_platform = False
|
|
|
|
self.unsupported_architectures = ()
|
|
|
|
|
|
|
|
def prepare_source(self, state: BuildState):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def detect(self, state: BuildState) -> bool:
|
|
|
|
return False
|
|
|
|
|
|
|
|
def configure(self, state: BuildState):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def build(self, state: BuildState):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def post_build(self, state: BuildState):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class BuildTarget(Target):
|
|
|
|
def __init__(self, name=None):
|
|
|
|
super().__init__(name)
|
|
|
|
|
|
|
|
self.src_root = ''
|
|
|
|
self.multi_platform = True
|
|
|
|
|
2021-06-25 07:05:15 +00:00
|
|
|
self.os_version = dict()
|
|
|
|
self.os_version['x86_64'] = OS_VERSION_X86_64
|
|
|
|
self.os_version['arm64'] = OS_VERSION_ARM64
|
|
|
|
|
2021-06-28 07:51:47 +00:00
|
|
|
self.sdk_version = dict()
|
|
|
|
self.sdk_version['x86_64'] = OS_VERSION_X86_64
|
|
|
|
self.sdk_version['arm64'] = OS_VERSION_ARM64
|
|
|
|
|
2021-01-14 08:34:20 +00:00
|
|
|
def configure(self, state: BuildState):
|
2021-06-25 07:05:15 +00:00
|
|
|
os_version = state.os_version()
|
|
|
|
if os_version and os_version < self.os_version[state.architecture()]:
|
|
|
|
raise RuntimeError('Minimum OS version requirement is not met')
|
|
|
|
|
2021-09-12 07:19:16 +00:00
|
|
|
if sdk_version := state.sdk_version():
|
|
|
|
if sdk_version < self.sdk_version[state.architecture()]:
|
2021-06-28 07:51:47 +00:00
|
|
|
raise RuntimeError('Minimum SDK version requirement is not met')
|
|
|
|
|
2021-01-14 08:34:20 +00:00
|
|
|
os.makedirs(state.build_path, exist_ok=True)
|
|
|
|
|
2021-08-05 06:53:07 +00:00
|
|
|
env = state.environment
|
2021-07-22 06:51:13 +00:00
|
|
|
env['PATH'] = os.pathsep.join([
|
|
|
|
str(state.bin_path),
|
|
|
|
env['PATH'],
|
|
|
|
])
|
2021-01-14 08:34:20 +00:00
|
|
|
|
2021-03-30 12:11:18 +00:00
|
|
|
if state.xcode:
|
|
|
|
return
|
2021-01-14 08:34:20 +00:00
|
|
|
|
2021-09-01 08:41:08 +00:00
|
|
|
if c_compiler := state.c_compiler():
|
|
|
|
env['CC'] = str(c_compiler)
|
|
|
|
if cxx_compiler := state.cxx_compiler():
|
|
|
|
env['CXX'] = str(cxx_compiler)
|
2021-01-14 08:34:20 +00:00
|
|
|
|
2021-03-30 12:11:18 +00:00
|
|
|
for prefix in ('CPP', 'C', 'CXX', 'OBJC', 'OBJCXX'):
|
2021-08-05 06:53:07 +00:00
|
|
|
var_name = f'{prefix}FLAGS'
|
2021-03-30 12:11:18 +00:00
|
|
|
|
2021-08-05 06:53:07 +00:00
|
|
|
state.update_environment(var_name, f'-I{state.include_path}')
|
|
|
|
state.set_sdk(var_name)
|
|
|
|
state.set_os_version(var_name)
|
2021-03-30 12:11:18 +00:00
|
|
|
|
|
|
|
ldflags = 'LDFLAGS'
|
|
|
|
|
2021-08-05 06:53:07 +00:00
|
|
|
state.update_environment(ldflags, f'-L{state.lib_path}')
|
|
|
|
state.set_sdk(ldflags)
|
|
|
|
state.set_os_version(ldflags)
|
2021-01-14 08:34:20 +00:00
|
|
|
|
2021-03-16 11:23:48 +00:00
|
|
|
def install(self, state: BuildState, options: CommandLineOptions = None, tool: str = 'gmake'):
|
2021-01-14 08:34:20 +00:00
|
|
|
if state.xcode:
|
|
|
|
return
|
|
|
|
|
2021-07-22 06:51:13 +00:00
|
|
|
if state.install_path.exists():
|
2021-01-14 08:34:20 +00:00
|
|
|
shutil.rmtree(state.install_path)
|
|
|
|
|
|
|
|
args = [tool, 'install']
|
|
|
|
args += options and options.to_list() or []
|
|
|
|
|
2021-08-05 06:53:07 +00:00
|
|
|
subprocess.check_call(args, cwd=state.build_path, env=state.environment)
|
2021-01-14 08:34:20 +00:00
|
|
|
|
|
|
|
self.update_pc_files(state)
|
|
|
|
|
|
|
|
@staticmethod
|
2021-07-22 06:51:13 +00:00
|
|
|
def update_text_file(path: Path, processor: typing.Callable = None):
|
2021-01-14 08:34:20 +00:00
|
|
|
with open(path, 'r') as f:
|
|
|
|
content = f.readlines()
|
|
|
|
|
|
|
|
patched_content = []
|
|
|
|
|
|
|
|
for line in content:
|
|
|
|
patched_line = processor(line) if processor else line
|
|
|
|
|
|
|
|
if patched_line:
|
|
|
|
patched_content.append(patched_line)
|
|
|
|
|
|
|
|
with open(path, 'w') as f:
|
|
|
|
f.writelines(patched_content)
|
|
|
|
|
|
|
|
@staticmethod
|
2021-07-22 06:51:13 +00:00
|
|
|
def _update_variables_file(path: Path, prefix_value: str, processor: typing.Callable = None, quotes: bool = True):
|
2021-01-14 08:34:20 +00:00
|
|
|
prefix = 'prefix='
|
2021-05-31 08:42:12 +00:00
|
|
|
exec_prefix = 'exec_prefix='
|
|
|
|
includedir = 'includedir='
|
|
|
|
libdir = 'libdir='
|
2021-01-14 08:34:20 +00:00
|
|
|
|
2021-06-07 06:56:33 +00:00
|
|
|
def quote(value: str) -> str:
|
|
|
|
return f'"{value}"' if quotes else value
|
|
|
|
|
|
|
|
def patch_proc(line: str) -> str:
|
2021-01-14 08:34:20 +00:00
|
|
|
patched_line = line
|
|
|
|
|
|
|
|
if line.startswith(prefix):
|
2021-06-07 06:56:33 +00:00
|
|
|
patched_line = prefix + quote(prefix_value) + os.linesep
|
2021-05-31 08:42:12 +00:00
|
|
|
elif line.startswith(exec_prefix):
|
2021-06-07 06:56:33 +00:00
|
|
|
patched_line = exec_prefix + quote('${prefix}') + os.linesep
|
2021-05-31 08:42:12 +00:00
|
|
|
elif line.startswith(includedir):
|
2021-06-07 06:56:33 +00:00
|
|
|
patched_line = includedir + quote('${prefix}/include') + os.linesep
|
2021-05-31 08:42:12 +00:00
|
|
|
elif line.startswith(libdir):
|
2021-06-07 06:56:33 +00:00
|
|
|
patched_line = libdir + quote('${exec_prefix}/lib') + os.linesep
|
2021-01-14 08:34:20 +00:00
|
|
|
|
|
|
|
if processor:
|
|
|
|
patched_line = processor(path, patched_line)
|
|
|
|
|
|
|
|
return patched_line
|
|
|
|
|
2021-06-07 06:56:33 +00:00
|
|
|
BuildTarget.update_text_file(path, patch_proc)
|
|
|
|
|
|
|
|
@staticmethod
|
2021-07-22 06:51:13 +00:00
|
|
|
def update_config_script(path: Path, processor: typing.Callable = None):
|
2021-06-07 06:56:33 +00:00
|
|
|
BuildTarget._update_variables_file(path, r'$(cd "${0%/*}/.."; pwd)', processor)
|
|
|
|
|
|
|
|
@staticmethod
|
2021-07-22 06:51:13 +00:00
|
|
|
def update_pc_file(path: Path, processor: typing.Callable = None):
|
2021-06-07 06:56:33 +00:00
|
|
|
BuildTarget._update_variables_file(path, '', processor, quotes=False)
|
2021-01-14 08:34:20 +00:00
|
|
|
|
|
|
|
def update_pc_files(self, state: BuildState):
|
|
|
|
for root, _, files in os.walk(state.install_path, followlinks=True):
|
|
|
|
for filename in files:
|
|
|
|
if filename.endswith('.pc'):
|
2021-08-01 13:14:43 +00:00
|
|
|
file_path = Path(root) / filename
|
2021-01-14 08:34:20 +00:00
|
|
|
BuildTarget.update_pc_file(file_path, self._process_pkg_config)
|
|
|
|
|
|
|
|
@staticmethod
|
2021-07-22 06:51:13 +00:00
|
|
|
def _process_pkg_config(pcfile: Path, line: str) -> str:
|
2021-01-14 08:34:20 +00:00
|
|
|
assert pcfile
|
|
|
|
return line
|
|
|
|
|
|
|
|
def write_pc_file(self, state: BuildState,
|
|
|
|
filename=None, name=None, description=None, version='',
|
|
|
|
requires='', requires_private='', libs='', libs_private='', cflags=''):
|
2021-07-22 06:51:13 +00:00
|
|
|
pkgconfig_path = state.install_path / 'lib/pkgconfig'
|
2021-01-14 08:34:20 +00:00
|
|
|
os.makedirs(pkgconfig_path, exist_ok=True)
|
|
|
|
|
|
|
|
if not filename:
|
|
|
|
filename = self.name + '.pc'
|
|
|
|
if not name:
|
|
|
|
name = self.name
|
|
|
|
if not description:
|
|
|
|
description = self.name
|
|
|
|
if not libs:
|
|
|
|
libs = '-l' + self.name
|
|
|
|
|
|
|
|
pc_content = f'''prefix=
|
|
|
|
exec_prefix=${{prefix}}
|
|
|
|
libdir=${{exec_prefix}}/lib
|
|
|
|
includedir=${{prefix}}/include
|
|
|
|
|
|
|
|
Name: {name}
|
|
|
|
Description: {description}
|
|
|
|
Version: {version}
|
|
|
|
Requires: {requires}
|
|
|
|
Requires.private: {requires_private}
|
|
|
|
Libs: -L${{libdir}} {libs}
|
|
|
|
Libs.private: {libs_private}
|
|
|
|
Cflags: -I${{includedir}} {cflags}
|
|
|
|
'''
|
2021-07-22 06:51:13 +00:00
|
|
|
with open(pkgconfig_path / filename, 'w') as f:
|
2021-01-14 08:34:20 +00:00
|
|
|
f.write(pc_content)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def make_platform_header(state: BuildState, header: str):
|
2021-07-22 06:51:13 +00:00
|
|
|
include_path = state.install_path / 'include'
|
2021-01-14 08:34:20 +00:00
|
|
|
header_parts = header.rsplit(os.sep, 1)
|
2021-02-11 13:51:34 +00:00
|
|
|
|
2021-01-14 08:34:20 +00:00
|
|
|
if len(header_parts) == 1:
|
|
|
|
header_parts.insert(0, '')
|
|
|
|
|
2021-07-22 06:51:13 +00:00
|
|
|
common_header = include_path / header
|
|
|
|
platform_header = include_path / header_parts[0] / f'_aedi_{state.architecture()}_{header_parts[1]}'
|
2021-02-11 13:51:34 +00:00
|
|
|
shutil.move(common_header, platform_header)
|
2021-01-14 08:34:20 +00:00
|
|
|
|
2021-02-11 13:51:34 +00:00
|
|
|
with open(common_header, 'w') as f:
|
2021-01-14 08:34:20 +00:00
|
|
|
f.write(f'''
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#if defined(__x86_64__)
|
2021-02-11 13:51:34 +00:00
|
|
|
# include "_aedi_x86_64_{header_parts[1]}"
|
2021-01-14 08:34:20 +00:00
|
|
|
#elif defined(__aarch64__)
|
2021-02-11 13:51:34 +00:00
|
|
|
# include "_aedi_arm64_{header_parts[1]}"
|
2021-01-14 08:34:20 +00:00
|
|
|
#else
|
|
|
|
# error Unknown architecture
|
|
|
|
#endif
|
|
|
|
''')
|
|
|
|
|
|
|
|
def copy_to_bin(self, state: BuildState, filename: str = None, new_filename: str = None):
|
2021-07-22 06:51:13 +00:00
|
|
|
bin_path = state.install_path / 'bin'
|
2021-01-14 08:34:20 +00:00
|
|
|
os.makedirs(bin_path, exist_ok=True)
|
|
|
|
|
|
|
|
if not filename:
|
|
|
|
filename = self.name
|
|
|
|
if not new_filename:
|
|
|
|
new_filename = filename
|
|
|
|
|
2021-07-22 06:51:13 +00:00
|
|
|
src_path = state.build_path / filename
|
|
|
|
dst_path = bin_path / new_filename
|
2021-01-14 08:34:20 +00:00
|
|
|
shutil.copy(src_path, dst_path)
|
|
|
|
|
|
|
|
|
|
|
|
class MakeTarget(BuildTarget):
|
|
|
|
def __init__(self, name=None):
|
|
|
|
super().__init__(name)
|
2021-03-16 11:23:48 +00:00
|
|
|
self.tool = 'gmake'
|
2021-01-14 08:34:20 +00:00
|
|
|
|
|
|
|
def configure(self, state: BuildState):
|
|
|
|
super().configure(state)
|
|
|
|
|
2021-01-17 10:37:35 +00:00
|
|
|
symlink_directory(state.source, state.build_path)
|
2021-01-14 08:34:20 +00:00
|
|
|
|
|
|
|
def build(self, state: BuildState):
|
|
|
|
assert not state.xcode
|
|
|
|
|
|
|
|
args = [
|
|
|
|
self.tool,
|
|
|
|
'-j', state.jobs,
|
|
|
|
]
|
2021-09-01 08:41:08 +00:00
|
|
|
|
|
|
|
if c_compiler := state.c_compiler():
|
|
|
|
args.append(f'CC={c_compiler}')
|
|
|
|
if cxx_compiler := state.cxx_compiler():
|
|
|
|
args.append(f'CXX={cxx_compiler}')
|
|
|
|
|
2021-08-05 06:59:49 +00:00
|
|
|
args += state.options.to_list()
|
2021-01-14 08:34:20 +00:00
|
|
|
|
2021-07-22 06:51:13 +00:00
|
|
|
work_path = state.build_path / self.src_root
|
2021-08-05 06:53:07 +00:00
|
|
|
subprocess.check_call(args, cwd=work_path, env=state.environment)
|
2021-01-14 08:34:20 +00:00
|
|
|
|
|
|
|
|
2021-08-14 09:31:34 +00:00
|
|
|
class ConfigureMakeTarget(MakeTarget):
|
2021-01-14 08:34:20 +00:00
|
|
|
def __init__(self, name=None):
|
|
|
|
super().__init__(name)
|
|
|
|
|
|
|
|
def configure(self, state: BuildState):
|
|
|
|
super().configure(state)
|
|
|
|
|
2021-07-22 06:51:13 +00:00
|
|
|
work_path = state.build_path / self.src_root
|
|
|
|
configure_path = work_path / 'configure'
|
2021-01-14 08:34:20 +00:00
|
|
|
|
|
|
|
common_args = [
|
|
|
|
configure_path,
|
2021-07-22 06:51:13 +00:00
|
|
|
f'--prefix={state.install_path}',
|
2021-01-14 08:34:20 +00:00
|
|
|
]
|
2021-08-05 06:59:49 +00:00
|
|
|
common_args += state.options.to_list()
|
2021-01-14 08:34:20 +00:00
|
|
|
|
|
|
|
disable_dependency_tracking = '--disable-dependency-tracking'
|
|
|
|
host = '--host=' + state.host()
|
|
|
|
|
|
|
|
args = copy.copy(common_args)
|
|
|
|
args.append(host)
|
|
|
|
args.append(disable_dependency_tracking)
|
|
|
|
|
|
|
|
try:
|
|
|
|
# Try with host and disabled dependency tracking first
|
2021-08-05 06:53:07 +00:00
|
|
|
subprocess.check_call(args, cwd=work_path, env=state.environment)
|
2021-01-14 08:34:20 +00:00
|
|
|
except subprocess.CalledProcessError:
|
|
|
|
# If it fails, try with disabled dependency tracking only
|
|
|
|
args = copy.copy(common_args)
|
|
|
|
args.append(disable_dependency_tracking)
|
|
|
|
|
|
|
|
try:
|
2021-08-05 06:53:07 +00:00
|
|
|
subprocess.check_call(args, cwd=work_path, env=state.environment)
|
2021-01-14 08:34:20 +00:00
|
|
|
except subprocess.CalledProcessError:
|
|
|
|
# Use only common command line arguments
|
2021-08-05 06:53:07 +00:00
|
|
|
subprocess.check_call(common_args, cwd=work_path, env=state.environment)
|
2021-01-14 08:34:20 +00:00
|
|
|
|
|
|
|
def build(self, state: BuildState):
|
2021-08-14 09:31:34 +00:00
|
|
|
# Clear configure script options
|
|
|
|
state.options = CommandLineOptions()
|
|
|
|
|
|
|
|
super().build(state)
|
2021-01-14 08:34:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CMakeTarget(BuildTarget):
|
2021-08-12 10:00:08 +00:00
|
|
|
cached_project_name = None
|
|
|
|
|
2021-01-14 08:34:20 +00:00
|
|
|
def __init__(self, name=None):
|
|
|
|
super().__init__(name)
|
|
|
|
|
|
|
|
def detect(self, state: BuildState) -> bool:
|
2021-08-12 10:00:08 +00:00
|
|
|
if CMakeTarget.cached_project_name:
|
|
|
|
project_name = CMakeTarget.cached_project_name
|
2021-01-14 08:34:20 +00:00
|
|
|
else:
|
2021-08-12 10:00:08 +00:00
|
|
|
cmakelists_path = state.source / self.src_root / 'CMakeLists.txt'
|
|
|
|
|
|
|
|
if not cmakelists_path.exists():
|
|
|
|
return False
|
|
|
|
|
|
|
|
for line in open(cmakelists_path).readlines():
|
|
|
|
project_name = CMakeTarget._extract_project_name(line)
|
|
|
|
if project_name:
|
|
|
|
project_name = project_name.lower()
|
|
|
|
project_name = project_name.replace(' ', '-')
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
2021-08-12 10:00:54 +00:00
|
|
|
if project_name.startswith('lib'):
|
|
|
|
project_name = project_name[3:]
|
|
|
|
|
2021-08-12 10:00:08 +00:00
|
|
|
CMakeTarget.cached_project_name = project_name
|
2021-01-14 08:34:20 +00:00
|
|
|
|
|
|
|
return project_name == self.name
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _extract_project_name(line: str):
|
|
|
|
project_name = None
|
|
|
|
|
|
|
|
# Try to get project name without whitespaces in it
|
2021-08-13 07:19:17 +00:00
|
|
|
match = re.search(r'^\s*project\s*\(\s*(\w[\w-]+)', line, re.IGNORECASE)
|
2021-01-14 08:34:20 +00:00
|
|
|
|
|
|
|
if not match:
|
|
|
|
# Try to get project name that contains whitespaces
|
2021-08-13 07:19:17 +00:00
|
|
|
match = re.search(r'^\s*project\s*\(\s*"?(\w[\s\w-]+)"?', line, re.IGNORECASE)
|
2021-01-14 08:34:20 +00:00
|
|
|
|
|
|
|
if match:
|
|
|
|
project_name = match.group(1)
|
|
|
|
|
|
|
|
return project_name
|
|
|
|
|
|
|
|
def configure(self, state: BuildState):
|
|
|
|
super().configure(state)
|
|
|
|
|
|
|
|
args = [
|
|
|
|
'cmake',
|
|
|
|
'-DCMAKE_BUILD_TYPE=Release',
|
2021-09-10 09:13:56 +00:00
|
|
|
f'-DCMAKE_C_FLAGS="-ffile-prefix-map={state.source}/="',
|
|
|
|
f'-DCMAKE_CXX_FLAGS="-ffile-prefix-map={state.source}/="',
|
2021-07-22 06:51:13 +00:00
|
|
|
f'-DCMAKE_INSTALL_PREFIX={state.install_path}',
|
|
|
|
f'-DCMAKE_PREFIX_PATH={state.prefix_path}',
|
2021-01-14 08:34:20 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
if state.xcode:
|
|
|
|
args.append('-GXcode')
|
|
|
|
else:
|
|
|
|
args.append('-GUnix Makefiles')
|
2021-09-01 08:41:08 +00:00
|
|
|
|
|
|
|
if c_compiler := state.c_compiler():
|
|
|
|
args.append(f'-DCMAKE_C_COMPILER={c_compiler}')
|
|
|
|
if cxx_compiler := state.cxx_compiler():
|
|
|
|
args.append(f'-DCMAKE_CXX_COMPILER={cxx_compiler}')
|
2021-01-14 08:34:20 +00:00
|
|
|
|
|
|
|
architecture = state.architecture()
|
|
|
|
if architecture != machine():
|
|
|
|
args.append('-DCMAKE_SYSTEM_NAME=Darwin')
|
|
|
|
args.append('-DCMAKE_SYSTEM_PROCESSOR=' + 'aarch64' if architecture == 'arm64' else architecture)
|
|
|
|
|
|
|
|
os_version = state.os_version()
|
|
|
|
if os_version:
|
2021-06-25 07:03:53 +00:00
|
|
|
args.append('-DCMAKE_OSX_DEPLOYMENT_TARGET=' + str(os_version))
|
2021-01-14 08:34:20 +00:00
|
|
|
|
|
|
|
sdk_path = state.sdk_path()
|
|
|
|
if sdk_path:
|
2021-07-22 06:51:13 +00:00
|
|
|
args.append(f'-DCMAKE_OSX_SYSROOT={sdk_path}')
|
2021-01-14 08:34:20 +00:00
|
|
|
|
2021-08-05 06:59:49 +00:00
|
|
|
args += state.options.to_list(CommandLineOptions.CMAKE_RULES)
|
2021-07-22 06:51:13 +00:00
|
|
|
args.append(state.source / self.src_root)
|
2021-01-14 08:34:20 +00:00
|
|
|
|
2021-08-05 06:53:07 +00:00
|
|
|
subprocess.check_call(args, cwd=state.build_path, env=state.environment)
|
2021-01-14 08:34:20 +00:00
|
|
|
|
|
|
|
def build(self, state: BuildState):
|
|
|
|
if state.xcode:
|
2021-08-04 06:40:31 +00:00
|
|
|
args = ['cmake', '--open', '.']
|
2021-01-14 08:34:20 +00:00
|
|
|
else:
|
2021-03-16 11:23:48 +00:00
|
|
|
args = ['gmake', '-j', state.jobs]
|
2021-01-14 08:34:20 +00:00
|
|
|
|
|
|
|
if state.verbose:
|
|
|
|
args.append('VERBOSE=1')
|
|
|
|
|
2021-08-05 06:53:07 +00:00
|
|
|
subprocess.check_call(args, cwd=state.build_path, env=state.environment)
|
2021-05-01 08:54:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ConfigureMakeDependencyTarget(ConfigureMakeTarget):
|
|
|
|
def __init__(self, name=None):
|
|
|
|
super().__init__(name)
|
|
|
|
|
|
|
|
def post_build(self, state: BuildState):
|
|
|
|
self.install(state)
|
|
|
|
|
|
|
|
|
|
|
|
class ConfigureMakeStaticDependencyTarget(ConfigureMakeDependencyTarget):
|
|
|
|
def __init__(self, name=None):
|
|
|
|
super().__init__(name)
|
|
|
|
|
2021-08-05 06:59:49 +00:00
|
|
|
def configure(self, state: BuildState):
|
|
|
|
state.options['--enable-shared'] = 'no'
|
|
|
|
super().configure(state)
|
2021-05-01 08:54:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CMakeStaticDependencyTarget(CMakeTarget):
|
|
|
|
def __init__(self, name=None):
|
|
|
|
super().__init__(name)
|
|
|
|
|
2021-08-05 06:59:49 +00:00
|
|
|
def configure(self, state: BuildState):
|
|
|
|
state.options['BUILD_SHARED_LIBS'] = 'NO'
|
|
|
|
super().configure(state)
|
2021-05-01 08:54:52 +00:00
|
|
|
|
|
|
|
def post_build(self, state: BuildState):
|
|
|
|
self.install(state)
|
2021-06-02 09:48:58 +00:00
|
|
|
|
|
|
|
def keep_module_target(self, state: BuildState, target: str):
|
2021-06-20 11:43:17 +00:00
|
|
|
import_patterns = (
|
2021-07-25 09:04:19 +00:00
|
|
|
r'list\s*\(APPEND\s+_IMPORT_CHECK_TARGETS\s+(?P<target>\w+::[\w-]+)[\s)]',
|
|
|
|
r'list\s*\(APPEND\s+_IMPORT_CHECK_FILES_FOR_(?P<target>\w+::[\w-]+)\s',
|
2021-06-20 11:43:17 +00:00
|
|
|
)
|
|
|
|
import_regexes = [re.compile(regex, re.IGNORECASE) for regex in import_patterns]
|
2021-06-02 09:48:58 +00:00
|
|
|
|
2021-06-20 11:43:17 +00:00
|
|
|
def _keep_target(line: str):
|
|
|
|
for regex in import_regexes:
|
|
|
|
match = regex.match(line)
|
|
|
|
|
2021-07-25 09:04:58 +00:00
|
|
|
if match and match.group('target') != target:
|
|
|
|
return None
|
2021-06-20 11:43:17 +00:00
|
|
|
|
|
|
|
return line
|
|
|
|
|
|
|
|
module = 'targets-release.cmake'
|
|
|
|
|
|
|
|
for probe_module in (module, self.name + module):
|
2021-07-22 06:51:13 +00:00
|
|
|
module_path = state.install_path / 'lib' / 'cmake' / self.name / probe_module
|
2021-06-20 11:43:17 +00:00
|
|
|
|
2021-07-22 06:51:13 +00:00
|
|
|
if module_path.exists():
|
2021-06-20 11:43:17 +00:00
|
|
|
self.update_text_file(module_path, _keep_target)
|