mirror of
https://github.com/QuasarApp/LIEF.git
synced 2025-04-27 04:44:31 +00:00
Enhance CI & platforms
This commit is contained in:
parent
64481662f5
commit
f4fc5784af
@ -4,6 +4,9 @@ clone_folder: c:\projects\lief
|
|||||||
|
|
||||||
configuration: Release
|
configuration: Release
|
||||||
|
|
||||||
|
services:
|
||||||
|
- docker
|
||||||
|
|
||||||
platform:
|
platform:
|
||||||
- x86
|
- x86
|
||||||
- x64
|
- x64
|
||||||
@ -13,7 +16,7 @@ environment:
|
|||||||
secure: TT7SXISIifq2/tf02n2ATgPj+Ky4Cjl3Fg44BAfyI4yRa4i87UAQIx5EFeV63+Xv2rhcU7JcMgl+An7QBrV6ofuQ9jxbuw+Gd1GqcCrAIyY=
|
secure: TT7SXISIifq2/tf02n2ATgPj+Ky4Cjl3Fg44BAfyI4yRa4i87UAQIx5EFeV63+Xv2rhcU7JcMgl+An7QBrV6ofuQ9jxbuw+Gd1GqcCrAIyY=
|
||||||
LIEF_AUTOMATIC_BUILDS_IV:
|
LIEF_AUTOMATIC_BUILDS_IV:
|
||||||
secure: /S6Vbt3vEisoC81siFbkqOXQeVnwxLZZPMYp1r79G7h+HFjLlWUZSidxxpsAgHNE
|
secure: /S6Vbt3vEisoC81siFbkqOXQeVnwxLZZPMYp1r79G7h+HFjLlWUZSidxxpsAgHNE
|
||||||
SCCACHE_CACHE_SIZE: "250M"
|
SCCACHE_CACHE_SIZE: "750M"
|
||||||
SCCACHE_DIR: C:\Users\appveyor\AppData\Local\Mozilla\sccache
|
SCCACHE_DIR: C:\Users\appveyor\AppData\Local\Mozilla\sccache
|
||||||
SCCACHE_ERROR_LOG: C:\projects\sccache.log
|
SCCACHE_ERROR_LOG: C:\projects\sccache.log
|
||||||
matrix:
|
matrix:
|
||||||
@ -89,12 +92,27 @@ install:
|
|||||||
build_script:
|
build_script:
|
||||||
- cd %APPVEYOR_BUILD_FOLDER%
|
- cd %APPVEYOR_BUILD_FOLDER%
|
||||||
- set MSBuildLogger="C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
|
- set MSBuildLogger="C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
|
||||||
- python.exe .\setup.py --ninja --sdk --lief-test bdist_wheel && exit 0 # Ignore warnings...
|
- python.exe .\setup.py --ninja --lief-test build bdist_wheel --skip-build && exit 0 # Ignore warnings...
|
||||||
|
- ps: if ($env:PYTHON_VERSION -eq "3.9") { python.exe .\scripts\windows\package_sdk.py }
|
||||||
|
|
||||||
after_build:
|
after_build:
|
||||||
- ps: Get-Service -Name 'ssh-agent' | Set-Service -StartupType Manual
|
- ps: Get-Service -Name 'ssh-agent' | Set-Service -StartupType Manual
|
||||||
- ps: Start-Service -Name 'ssh-agent'
|
- ps: Start-Service -Name 'ssh-agent'
|
||||||
- bash ./.github/deploy.sh
|
- cd %APPVEYOR_BUILD_FOLDER%
|
||||||
|
- ps: docker pull liefproject/deploy:latest
|
||||||
|
- ps: |
|
||||||
|
docker run `
|
||||||
|
-v ${PWD}:/src `
|
||||||
|
-e APPVEYOR="true" `
|
||||||
|
-e APPVEYOR_PULL_REQUEST_NUMBER="$env:APPVEYOR_PULL_REQUEST_NUMBER" `
|
||||||
|
-e APPVEYOR_REPO_NAME="$env:APPVEYOR_REPO_NAME" `
|
||||||
|
-e APPVEYOR_REPO_BRANCH="$env:APPVEYOR_REPO_BRANCH" `
|
||||||
|
-e APPVEYOR_BUILD_FOLDER="$env:APPVEYOR_BUILD_FOLDER" `
|
||||||
|
-e LIEF_AUTOMATIC_BUILDS_KEY="$env:LIEF_AUTOMATIC_BUILDS_KEY" `
|
||||||
|
-e LIEF_AUTOMATIC_BUILDS_IV="$env:LIEF_AUTOMATIC_BUILDS_IV" `
|
||||||
|
--rm `
|
||||||
|
liefproject/deploy python3 /src/.github/deploy.py
|
||||||
|
$host.SetShouldExit(0)
|
||||||
|
|
||||||
on_finish:
|
on_finish:
|
||||||
- cmd: sccache.exe --stop-server
|
- cmd: sccache.exe --stop-server
|
||||||
|
62
.circleci/config.yml
Normal file
62
.circleci/config.yml
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
version: 2.1
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
macos:
|
||||||
|
xcode: 12.3.0
|
||||||
|
steps:
|
||||||
|
- checkout:
|
||||||
|
path: ~/LIEF
|
||||||
|
- restore_cache:
|
||||||
|
keys:
|
||||||
|
- ccache-{{ arch }}-{{ .Branch }}
|
||||||
|
- ccache-{{ arch }}-master
|
||||||
|
- ccache-{{ arch }}
|
||||||
|
- pyenv
|
||||||
|
- run:
|
||||||
|
name: Install pyenv
|
||||||
|
command: |
|
||||||
|
brew install pyenv
|
||||||
|
pyenv root
|
||||||
|
pyenv install --list
|
||||||
|
- run:
|
||||||
|
name: Install ccache
|
||||||
|
command: brew install ccache
|
||||||
|
- run:
|
||||||
|
name: Install ninja
|
||||||
|
command: brew install ninja
|
||||||
|
- run:
|
||||||
|
name: CCache initialization
|
||||||
|
command: |
|
||||||
|
ccache --show-stats
|
||||||
|
ccache --zero-stats
|
||||||
|
ccache --max-size=10.0G
|
||||||
|
ccache --set-config=compiler_check=content
|
||||||
|
- run:
|
||||||
|
name: LIEF build setup
|
||||||
|
command: |
|
||||||
|
export PYTHON_CONFIGURE_OPTS="--enable-shared --enable-unicode=ucs2"
|
||||||
|
pyenv install --skip-existing 3.9.0
|
||||||
|
export PYTHON_BINARY=$(pyenv root)/versions/3.9.0/bin/python3.9
|
||||||
|
$PYTHON_BINARY -m pip install --upgrade pip setuptools wheel
|
||||||
|
$PYTHON_BINARY ./setup.py --ninja --lief-test build bdist_wheel
|
||||||
|
bash scripts/osx/package_sdk.sh
|
||||||
|
- run:
|
||||||
|
name: LIEF deploy
|
||||||
|
command: |
|
||||||
|
export PYTHON_BINARY=$(pyenv root)/versions/3.9.0/bin/python3.9
|
||||||
|
$PYTHON_BINARY -m pip install --upgrade requests mako
|
||||||
|
$PYTHON_BINARY .github/deploy.py
|
||||||
|
- run:
|
||||||
|
name: ccache stats
|
||||||
|
when: always
|
||||||
|
command: |
|
||||||
|
ccache --show-stats
|
||||||
|
- save_cache:
|
||||||
|
key: 'ccache-{{ arch }}-{{ .Branch }}'
|
||||||
|
paths: [ "/home/circleci/.ccache" ]
|
||||||
|
- save_cache:
|
||||||
|
key: 'pyenv'
|
||||||
|
paths: [ "/home/circleci/.pyenv" ]
|
||||||
|
|
||||||
|
|
||||||
|
|
343
.github/deploy.py
vendored
Normal file
343
.github/deploy.py
vendored
Normal file
@ -0,0 +1,343 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import logging
|
||||||
|
import pathlib
|
||||||
|
import subprocess
|
||||||
|
import shutil
|
||||||
|
from mako.template import Template
|
||||||
|
from enum import Enum, auto
|
||||||
|
|
||||||
|
class CI(Enum):
|
||||||
|
UNKNOWN = auto()
|
||||||
|
TRAVIS = auto()
|
||||||
|
APPVEYOR = auto()
|
||||||
|
GITLAB_CI = auto()
|
||||||
|
CIRCLE_CI = auto()
|
||||||
|
GITHUB_ACTIONS = auto()
|
||||||
|
AZURE = auto()
|
||||||
|
LOCAL = auto()
|
||||||
|
|
||||||
|
def pretty_ci_name(ci):
|
||||||
|
return str(ci).split(".")[-1].replace("_", "-").lower()
|
||||||
|
|
||||||
|
def is_pr(ci):
|
||||||
|
if ci == CI.TRAVIS:
|
||||||
|
cond1 = os.getenv("TRAVIS_EVENT_TYPE", "pull_request") == "pull_request"
|
||||||
|
cond2 = not os.getenv("TRAVIS_REPO_SLUG", "").startswith("lief-project/")
|
||||||
|
return cond1 or cond2
|
||||||
|
elif ci == CI.APPVEYOR:
|
||||||
|
logger.info("%s - %s", os.getenv("APPVEYOR_PULL_REQUEST_NUMBER", -1), os.getenv("APPVEYOR_REPO_NAME", ""))
|
||||||
|
pr_number = os.getenv("APPVEYOR_PULL_REQUEST_NUMBER", "")
|
||||||
|
cond1 = len(pr_number) != 0 and int(pr_number) >= 0
|
||||||
|
cond2 = not os.getenv("APPVEYOR_REPO_NAME", "").startswith("lief-project/")
|
||||||
|
return cond1 or cond2
|
||||||
|
elif ci == CI.CIRCLE_CI:
|
||||||
|
cond1 = int(os.getenv("CIRCLE_PR_NUMBER", -1)) >= 0
|
||||||
|
cond2 = os.getenv("CIRCLE_PROJECT_USERNAME", "") != "lief-project"
|
||||||
|
return cond1 or cond2
|
||||||
|
elif ci == CI.GITHUB_ACTIONS:
|
||||||
|
cond1 = os.getenv("GITHUB_HEAD_REF", "") != ""
|
||||||
|
cond2 = not os.getenv("GITHUB_REPOSITORY", "").startswith("lief-project/")
|
||||||
|
return cond1 or cond2
|
||||||
|
elif ci == CI.LOCAL:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
def get_branch(ci):
|
||||||
|
if ci == CI.TRAVIS:
|
||||||
|
return os.getenv("TRAVIS_BRANCH")
|
||||||
|
elif ci == CI.APPVEYOR:
|
||||||
|
return os.getenv("APPVEYOR_REPO_BRANCH")
|
||||||
|
elif ci == CI.CIRCLE_CI:
|
||||||
|
return os.getenv("CIRCLE_BRANCH")
|
||||||
|
elif ci == CI.GITHUB_ACTIONS:
|
||||||
|
return os.getenv("GITHUB_REF").replace("refs/heads/", "")
|
||||||
|
elif ci == CI.LOCAL:
|
||||||
|
return os.getenv("CI_BRANCH")
|
||||||
|
return None
|
||||||
|
|
||||||
|
def get_ci_workdir(ci):
|
||||||
|
if ci == CI.CIRCLE_CI:
|
||||||
|
return os.getenv("CIRCLE_WORKING_DIRECTORY")
|
||||||
|
elif ci == CI.TRAVIS:
|
||||||
|
return os.getenv("TRAVIS_BUILD_DIR")
|
||||||
|
elif ci == CI.APPVEYOR:
|
||||||
|
return os.getenv("APPVEYOR_BUILD_FOLDER")
|
||||||
|
elif ci == CI.GITHUB_ACTIONS:
|
||||||
|
return os.getenv("GITHUB_WORKSPACE")
|
||||||
|
elif ci == CI.LOCAL:
|
||||||
|
return os.getenv("CI_WORKING_DIR")
|
||||||
|
else:
|
||||||
|
logger.critical("Unsupported CI to resolve working directory")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
LOG_LEVEL = logging.DEBUG
|
||||||
|
|
||||||
|
logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))
|
||||||
|
logging.getLogger().setLevel(LOG_LEVEL)
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
CURRENT_CI = CI.UNKNOWN
|
||||||
|
|
||||||
|
# Detect CI
|
||||||
|
# ===========================================
|
||||||
|
if os.getenv("TRAVIS", None) is not None:
|
||||||
|
CURRENT_CI = CI.TRAVIS
|
||||||
|
elif os.getenv("APPVEYOR", None) is not None:
|
||||||
|
CURRENT_CI = CI.APPVEYOR
|
||||||
|
elif os.getenv("GITHUB_ACTIONS", None) is not None:
|
||||||
|
CURRENT_CI = CI.GITHUB_ACTIONS
|
||||||
|
elif os.getenv("GITLAB_CI", None) is not None:
|
||||||
|
CURRENT_CI = CI.GITLAB_CI
|
||||||
|
elif os.getenv("CI_LOCAL", "") == "true":
|
||||||
|
CURRENT_CI = CI.LOCAL
|
||||||
|
else:
|
||||||
|
print("Can't detect CI!", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
# TODO(romain): Azure
|
||||||
|
|
||||||
|
logger.info("CI: %s", pretty_ci_name(CURRENT_CI))
|
||||||
|
|
||||||
|
ALLOWED_BRANCHES = {"master", "deploy", "devel", "enhancement/cpack"}
|
||||||
|
BRANCH_NAME = get_branch(CURRENT_CI)
|
||||||
|
logger.info("Branch: %s", BRANCH_NAME)
|
||||||
|
if BRANCH_NAME not in ALLOWED_BRANCHES:
|
||||||
|
logger.info("Skip deployment for branch '%s'", BRANCH_NAME)
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
if is_pr(CURRENT_CI):
|
||||||
|
logger.info("Skip pull request")
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
CURRENTDIR = pathlib.Path(__file__).resolve().parent
|
||||||
|
REPODIR = CURRENTDIR.parent
|
||||||
|
|
||||||
|
DEPLOY_KEY = os.getenv("LIEF_AUTOMATIC_BUILDS_KEY", None)
|
||||||
|
DEPLOY_IV = os.getenv("LIEF_AUTOMATIC_BUILDS_IV", None)
|
||||||
|
|
||||||
|
if DEPLOY_KEY is None or len(DEPLOY_KEY) == 0:
|
||||||
|
print("Deploy key is not set!", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if DEPLOY_IV is None or len(DEPLOY_IV) == 0:
|
||||||
|
print("Deploy IV is not set!", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
GIT_USER = "lief-{}-ci".format(pretty_ci_name(CURRENT_CI))
|
||||||
|
GIT_EMAIL = "lief@quarkslab.com"
|
||||||
|
|
||||||
|
CI_CWD = pathlib.Path(get_ci_workdir(CURRENT_CI))
|
||||||
|
|
||||||
|
if CI_CWD is None:
|
||||||
|
logger.debug("Can't resolve CI working dir")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
LIEF_PACKAGE_REPO = "https://github.com/lief-project/packages.git"
|
||||||
|
LIEF_PACKAGE_DIR = REPODIR / "deploy-packages"
|
||||||
|
LIEF_PACKAGE_SSH_REPO = "git@github.com:lief-project/packages.git"
|
||||||
|
SDK_PACKAGE_DIR = LIEF_PACKAGE_DIR / "sdk"
|
||||||
|
PYPI_PACKAGE_DIR = LIEF_PACKAGE_DIR / "lief"
|
||||||
|
DIST_DIR = REPODIR / "dist"
|
||||||
|
BUILD_DIR = REPODIR / "build"
|
||||||
|
|
||||||
|
|
||||||
|
logger.debug("Working directory: %s", CI_CWD)
|
||||||
|
|
||||||
|
SSH_DIR = pathlib.Path("~/.ssh").expanduser().resolve()
|
||||||
|
PYTHON = shutil.which("python")
|
||||||
|
GIT = shutil.which("git")
|
||||||
|
TAR = shutil.which("tar")
|
||||||
|
OPENSSL = shutil.which("openssl")
|
||||||
|
MV = shutil.which("mv")
|
||||||
|
RM = shutil.which("rm")
|
||||||
|
SSH_AGENT = shutil.which("ssh-agent")
|
||||||
|
SSH_ADD = shutil.which("ssh-add")
|
||||||
|
SSH_KEYSCAN = shutil.which("ssh-keyscan")
|
||||||
|
|
||||||
|
if DEPLOY_KEY is None:
|
||||||
|
print("Deploy key is not set!", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if DEPLOY_IV is None:
|
||||||
|
print("Deploy IV is not set!", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
#####################
|
||||||
|
# Clone package repo
|
||||||
|
#####################
|
||||||
|
target_branch = "gh-pages"
|
||||||
|
if not LIEF_PACKAGE_DIR.is_dir():
|
||||||
|
cmd = "{} clone --branch={} -j8 --single-branch {} {}".format(GIT, target_branch, LIEF_PACKAGE_REPO, LIEF_PACKAGE_DIR)
|
||||||
|
p = subprocess.Popen(cmd, shell=True, cwd=REPODIR, stderr=subprocess.STDOUT)
|
||||||
|
p.wait()
|
||||||
|
|
||||||
|
if p.returncode:
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
SDK_PACKAGE_DIR.mkdir(exist_ok=True)
|
||||||
|
PYPI_PACKAGE_DIR.mkdir(exist_ok=True)
|
||||||
|
|
||||||
|
logger.info("CI: %s - %s", GIT_USER, GIT_EMAIL)
|
||||||
|
cmds = [
|
||||||
|
#"chmod 700 .git",
|
||||||
|
"{} config user.name '{}'".format(GIT, GIT_USER),
|
||||||
|
"{} config user.email '{}'".format(GIT, GIT_EMAIL),
|
||||||
|
"{} reset --soft root".format(GIT),
|
||||||
|
"{} ls-files -v".format(GIT),
|
||||||
|
]
|
||||||
|
|
||||||
|
for cmd in cmds:
|
||||||
|
p = subprocess.Popen(cmd, shell=True, cwd=LIEF_PACKAGE_DIR, stderr=subprocess.STDOUT)
|
||||||
|
p.wait()
|
||||||
|
|
||||||
|
if p.returncode:
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
for file in DIST_DIR.glob("*.whl"):
|
||||||
|
logger.debug("Copying '%s' to '%s'", file.as_posix(), PYPI_PACKAGE_DIR.as_posix())
|
||||||
|
shutil.copy(file.as_posix(), PYPI_PACKAGE_DIR.as_posix())
|
||||||
|
|
||||||
|
for file in BUILD_DIR.glob("*.zip"):
|
||||||
|
logger.debug("Copying '%s' to '%s'", file.as_posix(), SDK_PACKAGE_DIR.as_posix())
|
||||||
|
shutil.copy(file.as_posix(), SDK_PACKAGE_DIR.as_posix())
|
||||||
|
|
||||||
|
for file in BUILD_DIR.glob("*.tar.gz"):
|
||||||
|
logger.debug("Copying '%s' to '%s'", file.as_posix(), SDK_PACKAGE_DIR.as_posix())
|
||||||
|
shutil.copy(file.as_posix(), SDK_PACKAGE_DIR.as_posix())
|
||||||
|
|
||||||
|
|
||||||
|
INDEX_TEMPLATE = r"""
|
||||||
|
<html>
|
||||||
|
<title>Links for lief</title>
|
||||||
|
<body>
|
||||||
|
<h1>Links for lief</h1>
|
||||||
|
% for name in names:
|
||||||
|
<a href="${base_url}/${base}/${name}">${name}</a><br />
|
||||||
|
% endfor
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
"""
|
||||||
|
|
||||||
|
EXCLUDED = ['index.html', '.gitkeep']
|
||||||
|
BASE_URL = "https://lief-project.github.io"
|
||||||
|
|
||||||
|
fnames = [fname for fname in sorted(f.name for f in PYPI_PACKAGE_DIR.iterdir() if f.is_file() and f.name not in EXCLUDED)]
|
||||||
|
html = Template(INDEX_TEMPLATE).render(names=fnames, base_url=BASE_URL, base="packages/lief")
|
||||||
|
with open((PYPI_PACKAGE_DIR / "index.html").as_posix(), "w") as f:
|
||||||
|
f.write(html)
|
||||||
|
|
||||||
|
|
||||||
|
fnames = [fname for fname in sorted(f.name for f in SDK_PACKAGE_DIR.iterdir() if f.is_file() and f.name not in EXCLUDED)]
|
||||||
|
html = Template(INDEX_TEMPLATE).render(names=fnames, base_url=BASE_URL, base="packages/sdk")
|
||||||
|
with open((SDK_PACKAGE_DIR / "index.html").as_posix(), "w") as f:
|
||||||
|
f.write(html)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if not SSH_DIR.is_dir():
|
||||||
|
SSH_DIR.mkdir(mode=0o700)
|
||||||
|
|
||||||
|
#fix_ssh_perms()
|
||||||
|
deploy_key_path = (REPODIR / ".github" / "deploy-key.enc").as_posix()
|
||||||
|
output_key_path = (REPODIR / ".git" / "deploy-key")
|
||||||
|
cmd = "{} aes-256-cbc -K {} -iv {} -in {} -out {} -d".format(
|
||||||
|
OPENSSL, DEPLOY_KEY, DEPLOY_IV, deploy_key_path, output_key_path.as_posix())
|
||||||
|
|
||||||
|
kwargs = {
|
||||||
|
'shell': True,
|
||||||
|
'cwd': REPODIR,
|
||||||
|
'stdout': subprocess.DEVNULL,
|
||||||
|
'stderr': subprocess.DEVNULL,
|
||||||
|
}
|
||||||
|
|
||||||
|
p = subprocess.Popen(cmd, **kwargs)
|
||||||
|
p.wait()
|
||||||
|
|
||||||
|
if p.returncode:
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
output_key_path.chmod(0o600)
|
||||||
|
print(output_key_path)
|
||||||
|
|
||||||
|
process = subprocess.run(SSH_AGENT, stdout=subprocess.PIPE, universal_newlines=True, stderr=subprocess.STDOUT)
|
||||||
|
OUTPUT_PATTERN = re.compile(r'SSH_AUTH_SOCK=(?P<socket>[^;]+).*SSH_AGENT_PID=(?P<pid>\d+)', re.MULTILINE | re.DOTALL)
|
||||||
|
match = OUTPUT_PATTERN.search(process.stdout)
|
||||||
|
if match is None:
|
||||||
|
logger.error("Can't start ssh-agent")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
agent_data = match.groupdict()
|
||||||
|
logger.info(f'ssh agent data: {agent_data!s}')
|
||||||
|
logger.info('Exporting ssh agent environment variables' )
|
||||||
|
|
||||||
|
os.environ['SSH_AUTH_SOCK'] = agent_data['socket']
|
||||||
|
os.environ['SSH_AGENT_PID'] = agent_data['pid']
|
||||||
|
|
||||||
|
process = subprocess.run([SSH_ADD, output_key_path], stderr=subprocess.STDOUT)
|
||||||
|
if process.returncode != 0:
|
||||||
|
raise Exception(f'Failed to add the key: {output_key_path}')
|
||||||
|
known_hosts = (SSH_DIR / "known_hosts").as_posix()
|
||||||
|
cmd = "{} -H github.com >> {}".format(SSH_KEYSCAN, known_hosts)
|
||||||
|
|
||||||
|
kwargs = {
|
||||||
|
'shell': True,
|
||||||
|
'cwd': REPODIR,
|
||||||
|
'stderr': subprocess.STDOUT,
|
||||||
|
}
|
||||||
|
|
||||||
|
p = subprocess.Popen(cmd, **kwargs)
|
||||||
|
p.wait()
|
||||||
|
|
||||||
|
if p.returncode:
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
cmds = [
|
||||||
|
#f"{GIT} diff --cached --exit-code --quiet",
|
||||||
|
#"chown -R 1000:1000 *",
|
||||||
|
"{} add .".format(GIT),
|
||||||
|
"{} commit -m 'Automatic build'".format(GIT),
|
||||||
|
"{} ls-files -v".format(GIT),
|
||||||
|
#f"{GIT} log --pretty=fuller",
|
||||||
|
]
|
||||||
|
|
||||||
|
for cmd in cmds:
|
||||||
|
logger.info("Running %s", cmd)
|
||||||
|
p = subprocess.Popen(cmd, shell=True, cwd=LIEF_PACKAGE_DIR, stderr=subprocess.STDOUT)
|
||||||
|
p.wait()
|
||||||
|
|
||||||
|
if p.returncode:
|
||||||
|
logger.error("Error while running %s", cmd)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
for i in range(10):
|
||||||
|
p = subprocess.Popen("{} push --force {} {}".format(GIT, LIEF_PACKAGE_SSH_REPO, target_branch),
|
||||||
|
shell=True, cwd=LIEF_PACKAGE_DIR, stderr=subprocess.STDOUT)
|
||||||
|
p.wait()
|
||||||
|
|
||||||
|
if p.returncode == 0:
|
||||||
|
break
|
||||||
|
|
||||||
|
cmds = [
|
||||||
|
"{} branch -a -v".format(GIT),
|
||||||
|
"{} fetch -v origin {}".format(GIT, target_branch),
|
||||||
|
"{} branch -a -v".format(GIT),
|
||||||
|
"{} rebase -s recursive -X theirs FETCH_HEAD".format(GIT),
|
||||||
|
"{} branch -a -v".format(GIT),
|
||||||
|
]
|
||||||
|
for c in cmds:
|
||||||
|
p = subprocess.Popen(c, shell=True, cwd=LIEF_PACKAGE_DIR, stderr=subprocess.STDOUT)
|
||||||
|
p.wait()
|
||||||
|
else:
|
||||||
|
logger.critical("Can't push file on %s -> %s", LIEF_PACKAGE_SSH_REPO, target_branch)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
output_key_path.unlink()
|
||||||
|
print("ok")
|
||||||
|
|
195
.github/deploy.sh
vendored
195
.github/deploy.sh
vendored
@ -1,195 +0,0 @@
|
|||||||
#! /bin/bash
|
|
||||||
## vim:set ts=4 sw=4 et:
|
|
||||||
|
|
||||||
#
|
|
||||||
# Automatic build of LIEF
|
|
||||||
# Repo: https://github.com/lief-project/packages
|
|
||||||
# Mostly inspired by https://github.com/upx/upx-automatic-builds
|
|
||||||
|
|
||||||
set -e; set -o pipefail
|
|
||||||
|
|
||||||
if [[ $TRAVIS_OS_NAME == osx ]]; then
|
|
||||||
argv0=$0; argv0abs=$(greadlink -en -- "$0"); argv0dir=$(dirname "$argv0abs")
|
|
||||||
else
|
|
||||||
argv0=$0; argv0abs=$(readlink -en -- "$0"); argv0dir=$(dirname "$argv0abs")
|
|
||||||
fi
|
|
||||||
set -x # debug
|
|
||||||
|
|
||||||
if [[ $TRAVIS_OS_NAME == osx ]]; then
|
|
||||||
# use GNU coreutils ("brew install coreutils")
|
|
||||||
date() {
|
|
||||||
gdate "$@"
|
|
||||||
}
|
|
||||||
readlink() {
|
|
||||||
greadlink "$@"
|
|
||||||
}
|
|
||||||
sha256sum() {
|
|
||||||
gsha256sum "$@"
|
|
||||||
}
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -n $APPVEYOR_JOB_ID ]]; then
|
|
||||||
openssl() {
|
|
||||||
/usr/bin/openssl "$@"
|
|
||||||
}
|
|
||||||
sort() {
|
|
||||||
/usr/bin/sort "$@"
|
|
||||||
}
|
|
||||||
fi
|
|
||||||
|
|
||||||
fix_home_ssh_perms() {
|
|
||||||
if [[ -d ~/.ssh ]]; then
|
|
||||||
if [[ -x /usr/sbin/restorecon ]]; then
|
|
||||||
/usr/sbin/restorecon -v -R ~/.ssh || true
|
|
||||||
fi
|
|
||||||
chmod -c -R go-rwx ~/.ssh || true
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# =================
|
|
||||||
# SETUP BRANCH NAME
|
|
||||||
# =================
|
|
||||||
branch=
|
|
||||||
if [[ -n $APPVEYOR_JOB_ID ]]; then
|
|
||||||
branch=$APPVEYOR_REPO_BRANCH
|
|
||||||
if [[ -n $APPVEYOR_PULL_REQUEST_NUMBER ]]; then exit 0; fi
|
|
||||||
else
|
|
||||||
branch=$TRAVIS_BRANCH
|
|
||||||
if [[ "$TRAVIS_PULL_REQUEST" != "false" ]]; then exit 0; fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
case $branch in
|
|
||||||
devel*) ;;
|
|
||||||
master*) ;;
|
|
||||||
deploy*) ;;
|
|
||||||
*) exit 0;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
# get $rev, $branch and $git_user
|
|
||||||
LIEF_SRCDIR=
|
|
||||||
[[ -z $LIEF_SRCDIR ]] && LIEF_SRCDIR=$(readlink -mn -- $argv0dir/..)
|
|
||||||
cd / && cd $LIEF_SRCDIR || exit 1
|
|
||||||
rev=$(git rev-parse --verify HEAD)
|
|
||||||
timestamp=$(git log -n1 --format='%at' $rev)
|
|
||||||
date=$(TZ=UTC0 date -d "@$timestamp" '+%Y%m%d-%H%M%S')
|
|
||||||
#branch="$branch-$date-${rev:0:6}"
|
|
||||||
branch="gh-pages"
|
|
||||||
if [[ -n $APPVEYOR_JOB_ID ]]; then
|
|
||||||
branch="$branch"
|
|
||||||
git_user="AppVeyor CI"
|
|
||||||
else
|
|
||||||
branch="$branch"
|
|
||||||
git_user="Travis CI"
|
|
||||||
fi
|
|
||||||
unset timestamp date
|
|
||||||
|
|
||||||
# ========================
|
|
||||||
# SETUP 'deploy' DIRECTORY
|
|
||||||
# ========================
|
|
||||||
if [[ -n $APPVEYOR_JOB_ID ]]; then
|
|
||||||
[[ -z $LIEF_BUILDDIR ]] && LIEF_BUILDDIR=$(readlink -mn -- .)
|
|
||||||
else
|
|
||||||
[[ -z $LIEF_BUILDDIR ]] && LIEF_BUILDDIR=$(readlink -mn -- ./build)
|
|
||||||
fi
|
|
||||||
echo $LIEF_BUILDDIR
|
|
||||||
cd / && cd $LIEF_BUILDDIR || exit 1
|
|
||||||
|
|
||||||
mkdir deploy || exit 1
|
|
||||||
chmod 700 deploy
|
|
||||||
cd deploy || exit 1
|
|
||||||
|
|
||||||
# ==================
|
|
||||||
# CLONE - ADD - PUSH
|
|
||||||
# ==================
|
|
||||||
new_branch=0
|
|
||||||
if ! git clone -b "$branch" --single-branch https://github.com/lief-project/packages.git; then
|
|
||||||
git clone -b master --single-branch https://github.com/lief-project/packages.git
|
|
||||||
new_branch=1
|
|
||||||
fi
|
|
||||||
cd packages || exit 1
|
|
||||||
chmod 700 .git
|
|
||||||
|
|
||||||
git config user.name "$git_user"
|
|
||||||
git config user.email "lief@quarkslab.com"
|
|
||||||
|
|
||||||
if [[ $new_branch == 1 ]]; then
|
|
||||||
git checkout --orphan "$branch"
|
|
||||||
git reset --hard || true
|
|
||||||
fi
|
|
||||||
|
|
||||||
#git reset --soft `git rev-list --all | tail -1`
|
|
||||||
git reset --soft ebacb6adf12a5866db66346ce591f634333bde24
|
|
||||||
git ls-files -v
|
|
||||||
|
|
||||||
mkdir -p lief && cd lief
|
|
||||||
/bin/cp -rf ${LIEF_SRCDIR}/dist/*.whl . || true
|
|
||||||
|
|
||||||
${PYTHON_BINARY} ${LIEF_SRCDIR}/.github/make_index.py --output=./index.html --base "packages/lief" .
|
|
||||||
|
|
||||||
git add .
|
|
||||||
|
|
||||||
cd .. && mkdir -p sdk && cd sdk
|
|
||||||
|
|
||||||
if [[ -n $APPVEYOR_JOB_ID ]]; then
|
|
||||||
/bin/cp -rf ${LIEF_SRCDIR}/build/*.zip . || true
|
|
||||||
else
|
|
||||||
/bin/cp -rf ${LIEF_SRCDIR}/build/*.tar.gz . || true
|
|
||||||
fi
|
|
||||||
|
|
||||||
${PYTHON_BINARY} ${LIEF_SRCDIR}/.github/make_index.py --output=./index.html --base "packages/sdk" .
|
|
||||||
|
|
||||||
git add .
|
|
||||||
|
|
||||||
if git diff --cached --exit-code --quiet >/dev/null; then
|
|
||||||
# nothing to do ???
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
now=$(date '+%s')
|
|
||||||
|
|
||||||
git commit --date="$now" -m "Automatic build - ${rev:0:7} - Python ${PYTHON_VERSION}"
|
|
||||||
git ls-files -v
|
|
||||||
git log --pretty=fuller
|
|
||||||
|
|
||||||
cd ..
|
|
||||||
umask 077
|
|
||||||
[[ -d ~/.ssh ]] || mkdir ~/.ssh
|
|
||||||
fix_home_ssh_perms
|
|
||||||
repo=$(git config remote.origin.url)
|
|
||||||
ssh_repo=${repo/https:\/\/github.com\//git@github.com:}
|
|
||||||
eval $(ssh-agent -s)
|
|
||||||
set +x # IMPORTANT
|
|
||||||
openssl aes-256-cbc \
|
|
||||||
-K $LIEF_AUTOMATIC_BUILDS_KEY \
|
|
||||||
-iv $LIEF_AUTOMATIC_BUILDS_IV \
|
|
||||||
-in "$LIEF_SRCDIR/.github/deploy-key.enc" \
|
|
||||||
-out .git/deploy-key -d
|
|
||||||
set -x
|
|
||||||
fix_home_ssh_perms
|
|
||||||
cp .git/deploy-key ~/.ssh/id_rsa
|
|
||||||
chmod 400 ~/.ssh/id_rsa
|
|
||||||
ssh-add ~/.ssh/id_rsa
|
|
||||||
ssh-keyscan -H github.com >> ~/.ssh/known_hosts
|
|
||||||
fix_home_ssh_perms
|
|
||||||
#
|
|
||||||
let i=0 || true
|
|
||||||
while true; do
|
|
||||||
if [[ $i -ge 10 ]]; then
|
|
||||||
echo "ERROR: git push failed"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
if [[ $new_branch == 1 ]]; then
|
|
||||||
if git push --force -u $ssh_repo "$branch"; then break; fi
|
|
||||||
else
|
|
||||||
if git push --force $ssh_repo "$branch"; then break; fi
|
|
||||||
fi
|
|
||||||
git branch -a -v
|
|
||||||
git fetch -v origin "$branch"
|
|
||||||
git branch -a -v
|
|
||||||
git rebase -s recursive -X theirs FETCH_HEAD
|
|
||||||
git branch -a -v
|
|
||||||
sleep $((RANDOM % 5 + 1))
|
|
||||||
let i+=1
|
|
||||||
done
|
|
||||||
|
|
||||||
exit 0
|
|
63
.github/workflows/android.yml
vendored
Normal file
63
.github/workflows/android.yml
vendored
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
name: 'Android'
|
||||||
|
on: push
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Get Date
|
||||||
|
id: get-date
|
||||||
|
run: |
|
||||||
|
echo "::set-output name=date::$(/bin/date -u "+%Y-%m-%d-%H;%M;%S")"
|
||||||
|
shell: bash
|
||||||
|
- name: ccache cache files
|
||||||
|
uses: actions/cache@v1.1.0
|
||||||
|
with:
|
||||||
|
path: ~/.ccache
|
||||||
|
key: android-${{ runner.os }}-${{ steps.get-date.outputs.date }}
|
||||||
|
restore-keys: |
|
||||||
|
android-${{ runner.os }}-
|
||||||
|
- name: Build ARM SDK
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
docker run \
|
||||||
|
-e CCACHE_COMPRESS=1 \
|
||||||
|
-e CCACHE_MAXSIZE=10.0G \
|
||||||
|
-e CCACHE_CPP2=1 \
|
||||||
|
-e CCACHE_DIR=/ccache \
|
||||||
|
-v $GITHUB_WORKSPACE:/work \
|
||||||
|
-v $HOME/.ccache:/ccache \
|
||||||
|
--rm liefproject/android-arm bash /work/scripts/docker/android-arm.sh
|
||||||
|
- name: Build AArch64 SDK
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
docker run \
|
||||||
|
-e CCACHE_COMPRESS=1 \
|
||||||
|
-e CCACHE_MAXSIZE=10.0G \
|
||||||
|
-e CCACHE_CPP2=1 \
|
||||||
|
-e CCACHE_DIR=/ccache \
|
||||||
|
-v $GITHUB_WORKSPACE:/work \
|
||||||
|
-v $HOME/.ccache:/ccache \
|
||||||
|
--rm liefproject/android-arm64 bash /work/scripts/docker/android-aarch64.sh
|
||||||
|
- name: Deploy
|
||||||
|
env:
|
||||||
|
LIEF_AUTOMATIC_BUILDS_KEY: ${{ secrets.LIEF_AUTOMATIC_BUILDS_KEY }}
|
||||||
|
LIEF_AUTOMATIC_BUILDS_IV: ${{ secrets.LIEF_AUTOMATIC_BUILDS_IV }}
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
docker run \
|
||||||
|
-v $GITHUB_WORKSPACE:/src \
|
||||||
|
-e GITHUB_ACTIONS="true" \
|
||||||
|
-e GITHUB_WORKSPACE=$GITHUB_WORKSPACE \
|
||||||
|
-e GITHUB_REF=$GITHUB_REF \
|
||||||
|
-e GITHUB_REPOSITORY=$GITHUB_REPOSITORY \
|
||||||
|
-e LIEF_AUTOMATIC_BUILDS_KEY=$LIEF_AUTOMATIC_BUILDS_KEY \
|
||||||
|
-e LIEF_AUTOMATIC_BUILDS_IV=$LIEF_AUTOMATIC_BUILDS_IV \
|
||||||
|
--rm \
|
||||||
|
liefproject/deploy python3 /src/.github/deploy.py
|
||||||
|
|
||||||
|
|
||||||
|
|
54
.github/workflows/ios.yml
vendored
Normal file
54
.github/workflows/ios.yml
vendored
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
name: 'iOS'
|
||||||
|
on: push
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
osx-sdk:
|
||||||
|
runs-on: macos-11.0
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Set up Python 3.9
|
||||||
|
uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: 3.9
|
||||||
|
- name: Install system dependencies
|
||||||
|
run: |
|
||||||
|
brew install cmake ninja ccache
|
||||||
|
python -m pip install --upgrade pip setuptools wheel
|
||||||
|
- name: Get Date
|
||||||
|
id: get-date
|
||||||
|
run: |
|
||||||
|
echo "::set-output name=date::$(/bin/date -u "+%Y-%m-%d-%H;%M;%S")"
|
||||||
|
shell: bash
|
||||||
|
- name: Setup cache dir
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
mkdir -p ~/.ccache
|
||||||
|
- name: ccache cache files
|
||||||
|
uses: actions/cache@v1.1.0
|
||||||
|
with:
|
||||||
|
path: ~/.ccache
|
||||||
|
key: ios-${{ runner.os }}-${{ steps.get-date.outputs.date }}
|
||||||
|
restore-keys: |
|
||||||
|
ios-${{ runner.os }}-
|
||||||
|
- name: Build iOS SDK
|
||||||
|
shell: bash
|
||||||
|
env:
|
||||||
|
CCACHE_DIR: ~/.ccache
|
||||||
|
CCACHE_MAXSIZE: 10.0G
|
||||||
|
CCACHE_CPP2: 1
|
||||||
|
CCACHE_COMPRESS: 1
|
||||||
|
run: |
|
||||||
|
bash scripts/osx/package_ios.sh
|
||||||
|
- name: Deploy
|
||||||
|
env:
|
||||||
|
LIEF_AUTOMATIC_BUILDS_KEY: ${{ secrets.LIEF_AUTOMATIC_BUILDS_KEY }}
|
||||||
|
LIEF_AUTOMATIC_BUILDS_IV: ${{ secrets.LIEF_AUTOMATIC_BUILDS_IV }}
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
python -m pip install --upgrade requests mako
|
||||||
|
python .github/deploy.py
|
||||||
|
|
||||||
|
|
||||||
|
|
71
.github/workflows/linux-aarch64.yml
vendored
Normal file
71
.github/workflows/linux-aarch64.yml
vendored
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
name: 'Linux AArch64'
|
||||||
|
on: push
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
linux-sdk:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
python-version: [3.7, 3.8, 3.9]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Get Date
|
||||||
|
id: get-date
|
||||||
|
run: |
|
||||||
|
echo "::set-output name=date::$(/bin/date -u "+%Y-%m-%d-%H;%M;%S")"
|
||||||
|
shell: bash
|
||||||
|
- name: ccache cache files
|
||||||
|
uses: actions/cache@v1.1.0
|
||||||
|
with:
|
||||||
|
path: ~/.ccache
|
||||||
|
key: linux-aarch64-${{ runner.os }}-${{ steps.get-date.outputs.date }}
|
||||||
|
restore-keys: |
|
||||||
|
linux-aarch64-${{ runner.os }}-
|
||||||
|
- name: Build SDK
|
||||||
|
if: matrix.python-version == '3.9'
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
docker run \
|
||||||
|
-e CCACHE_COMPRESS=1 \
|
||||||
|
-e CCACHE_MAXSIZE=10.0G \
|
||||||
|
-e CCACHE_CPP2=1 \
|
||||||
|
-e CCACHE_DIR=/ccache \
|
||||||
|
-v $GITHUB_WORKSPACE:/work \
|
||||||
|
-v $HOME/.ccache:/ccache \
|
||||||
|
--rm liefproject/manylinux2014-aarch64 bash /work/scripts/docker/linux-aarch64.sh
|
||||||
|
- name: Build Python ${{ matrix.python-version }} wheel
|
||||||
|
shell: bash
|
||||||
|
env:
|
||||||
|
PYTHON_VERSION: ${{ matrix.python-version }}
|
||||||
|
run: |
|
||||||
|
PYTHON_VERSION2=$(echo "${PYTHON_VERSION}" | sed 's/\.//') # Transform 3.8 -> 38
|
||||||
|
docker run \
|
||||||
|
-e CCACHE_COMPRESS=1 \
|
||||||
|
-e CCACHE_MAXSIZE=10.0G \
|
||||||
|
-e CCACHE_CPP2=1 \
|
||||||
|
-e CCACHE_DIR=/ccache \
|
||||||
|
-e PYTHON_BINARY=/opt/python/cp${PYTHON_VERSION2}-cp${PYTHON_VERSION2}/bin/python${PYTHON_VERSION} \
|
||||||
|
-v $GITHUB_WORKSPACE:/work \
|
||||||
|
-v $HOME/.ccache:/ccache \
|
||||||
|
--rm liefproject/manylinux2014-aarch64 bash /work/scripts/docker/manylinux2014-aarch64.sh
|
||||||
|
- name: Deploy
|
||||||
|
env:
|
||||||
|
LIEF_AUTOMATIC_BUILDS_KEY: ${{ secrets.LIEF_AUTOMATIC_BUILDS_KEY }}
|
||||||
|
LIEF_AUTOMATIC_BUILDS_IV: ${{ secrets.LIEF_AUTOMATIC_BUILDS_IV }}
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
docker run \
|
||||||
|
-v $GITHUB_WORKSPACE:/src \
|
||||||
|
-e GITHUB_ACTIONS="true" \
|
||||||
|
-e GITHUB_WORKSPACE=$GITHUB_WORKSPACE \
|
||||||
|
-e GITHUB_REF=$GITHUB_REF \
|
||||||
|
-e GITHUB_REPOSITORY=$GITHUB_REPOSITORY \
|
||||||
|
-e LIEF_AUTOMATIC_BUILDS_KEY=$LIEF_AUTOMATIC_BUILDS_KEY \
|
||||||
|
-e LIEF_AUTOMATIC_BUILDS_IV=$LIEF_AUTOMATIC_BUILDS_IV \
|
||||||
|
--rm \
|
||||||
|
liefproject/deploy python3 /src/.github/deploy.py
|
||||||
|
|
||||||
|
|
||||||
|
|
70
.github/workflows/osx.yml
vendored
Normal file
70
.github/workflows/osx.yml
vendored
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
name: 'macOS'
|
||||||
|
on: push
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
osx-sdk:
|
||||||
|
runs-on: macos-11.0
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
python-version: [3.6, 3.7, 3.8, 3.9]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Set up Python ${{ matrix.python-version }}
|
||||||
|
uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: ${{ matrix.python-version }}
|
||||||
|
- name: Install system dependencies
|
||||||
|
run: |
|
||||||
|
brew install cmake ninja ccache
|
||||||
|
python -m pip install --upgrade pip setuptools wheel
|
||||||
|
- name: Get Date
|
||||||
|
id: get-date
|
||||||
|
run: |
|
||||||
|
echo "::set-output name=date::$(/bin/date -u "+%Y-%m-%d-%H;%M;%S")"
|
||||||
|
shell: bash
|
||||||
|
- name: Setup cache dir
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
mkdir -p ~/.ccache
|
||||||
|
- name: ccache cache files
|
||||||
|
uses: actions/cache@v1.1.0
|
||||||
|
with:
|
||||||
|
path: ~/.ccache
|
||||||
|
key: osx-${{ runner.os }}-${{ matrix.python-version }}-${{ steps.get-date.outputs.date }}
|
||||||
|
restore-keys: |
|
||||||
|
osx-${{ runner.os }}-${{ matrix.python-version }}-
|
||||||
|
osx-${{ runner.os }}-
|
||||||
|
- name: Build Python ${{ matrix.python-version }} wheel
|
||||||
|
shell: bash
|
||||||
|
env:
|
||||||
|
MACOSX_DEPLOYMENT_TARGET: "10.14"
|
||||||
|
CCACHE_DIR: ~/.ccache
|
||||||
|
CCACHE_MAXSIZE: 10.0G
|
||||||
|
CCACHE_CPP2: 1
|
||||||
|
CCACHE_COMPRESS: 1
|
||||||
|
run: |
|
||||||
|
python ./setup.py --ninja build bdist_wheel --skip-build --plat-name=macosx_${MACOSX_DEPLOYMENT_TARGET}_x86_64
|
||||||
|
- name: Build SDK
|
||||||
|
shell: bash
|
||||||
|
if: matrix.python-version == '3.9' # Build the SDk only with Python 3.9
|
||||||
|
env:
|
||||||
|
MACOSX_DEPLOYMENT_TARGET: "10.14"
|
||||||
|
CCACHE_DIR: ~/.ccache
|
||||||
|
CCACHE_MAXSIZE: 10.0G
|
||||||
|
CCACHE_CPP2: 1
|
||||||
|
CCACHE_COMPRESS: 1
|
||||||
|
run: |
|
||||||
|
bash scripts/osx/package_sdk.sh
|
||||||
|
- name: Deploy
|
||||||
|
env:
|
||||||
|
LIEF_AUTOMATIC_BUILDS_KEY: ${{ secrets.LIEF_AUTOMATIC_BUILDS_KEY }}
|
||||||
|
LIEF_AUTOMATIC_BUILDS_IV: ${{ secrets.LIEF_AUTOMATIC_BUILDS_IV }}
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
python -m pip install --upgrade requests mako
|
||||||
|
python .github/deploy.py
|
||||||
|
|
||||||
|
|
||||||
|
|
4
.github/workflows/windows.yml
vendored
4
.github/workflows/windows.yml
vendored
@ -7,7 +7,7 @@ jobs:
|
|||||||
runs-on: windows-latest
|
runs-on: windows-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
python-version: [3.6, 3.7, 3.8, 3.9]
|
python-version: [3.8]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Set up Python ${{ matrix.python-version }}
|
- name: Set up Python ${{ matrix.python-version }}
|
||||||
@ -24,7 +24,7 @@ jobs:
|
|||||||
toolset: "14.16"
|
toolset: "14.16"
|
||||||
- name: Build and Test
|
- name: Build and Test
|
||||||
run: |
|
run: |
|
||||||
python ./setup.py --ninja --sdk --lief-test bdist_wheel
|
python ./setup.py --ninja --lief-test bdist_wheel
|
||||||
shell: cmd
|
shell: cmd
|
||||||
|
|
||||||
|
|
||||||
|
411
.travis.yml
411
.travis.yml
@ -5,103 +5,265 @@ git:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
include:
|
include:
|
||||||
- os: linux
|
- if: branch = master AND tag IS present
|
||||||
dist: xenial
|
|
||||||
services: docker
|
services: docker
|
||||||
env: >
|
name: "Linux Python 3.5"
|
||||||
[
|
script:
|
||||||
PYTHON_VERSION=3.5 ,
|
- >
|
||||||
PYTHON_BINARY=/opt/python/cp35-cp35m/bin/python3.5 ,
|
docker run --name lief_35
|
||||||
]
|
-e PYTHON_BINARY=/opt/python/cp35-cp35m/bin/python3.5
|
||||||
|
-e CCACHE_DIR=/ccache
|
||||||
|
-v $HOME/.ccache:/ccache
|
||||||
|
-v $TRAVIS_BUILD_DIR:/src
|
||||||
|
liefproject/manylinux1_x86_64
|
||||||
|
bash /src/scripts/docker/travis-linux.sh
|
||||||
|
- >
|
||||||
|
if [[ "$TRAVIS_EVENT_TYPE" != "pull_request" ]]; then
|
||||||
|
docker run \
|
||||||
|
-v $TRAVIS_BUILD_DIR:/src \
|
||||||
|
-e TRAVIS="true" \
|
||||||
|
-e TRAVIS_EVENT_TYPE=$TRAVIS_EVENT_TYPE \
|
||||||
|
-e TRAVIS_REPO_SLUG=$TRAVIS_REPO_SLUG \
|
||||||
|
-e TRAVIS_BRANCH=$TRAVIS_BRANCH \
|
||||||
|
-e TRAVIS_BUILD_DIR=$TRAVIS_BUILD_DIR \
|
||||||
|
-e LIEF_AUTOMATIC_BUILDS_KEY=$LIEF_AUTOMATIC_BUILDS_KEY \
|
||||||
|
-e LIEF_AUTOMATIC_BUILDS_IV=$LIEF_AUTOMATIC_BUILDS_IV \
|
||||||
|
--rm \
|
||||||
|
liefproject/deploy python3 /src/.github/deploy.py;
|
||||||
|
fi
|
||||||
|
|
||||||
- os: linux
|
|
||||||
dist: xenial
|
|
||||||
services: docker
|
|
||||||
env: >
|
|
||||||
[
|
|
||||||
PYTHON_VERSION=3.6 ,
|
|
||||||
PYTHON_BINARY=/opt/python/cp36-cp36m/bin/python3.6 ,
|
|
||||||
]
|
|
||||||
|
|
||||||
- os: linux
|
- if: branch = master AND tag IS present
|
||||||
dist: xenial
|
|
||||||
services: docker
|
services: docker
|
||||||
env: >
|
name: "Linux Python 3.6"
|
||||||
[
|
script:
|
||||||
PYTHON_VERSION=3.7 ,
|
- >
|
||||||
PYTHON_BINARY=/opt/python/cp37-cp37m/bin/python3.7 ,
|
docker run --name lief_36
|
||||||
]
|
-e PYTHON_BINARY=/opt/python/cp36-cp36m/bin/python3.6
|
||||||
|
-e CCACHE_DIR=/ccache
|
||||||
|
-v $HOME/.ccache:/ccache
|
||||||
|
-v $TRAVIS_BUILD_DIR:/src
|
||||||
|
liefproject/manylinux1_x86_64
|
||||||
|
bash /src/scripts/docker/travis-linux.sh
|
||||||
|
- >
|
||||||
|
if [[ "$TRAVIS_EVENT_TYPE" != "pull_request" ]]; then
|
||||||
|
docker run \
|
||||||
|
-v $TRAVIS_BUILD_DIR:/src \
|
||||||
|
-e TRAVIS="true" \
|
||||||
|
-e TRAVIS_EVENT_TYPE=$TRAVIS_EVENT_TYPE \
|
||||||
|
-e TRAVIS_REPO_SLUG=$TRAVIS_REPO_SLUG \
|
||||||
|
-e TRAVIS_BRANCH=$TRAVIS_BRANCH \
|
||||||
|
-e TRAVIS_BUILD_DIR=$TRAVIS_BUILD_DIR \
|
||||||
|
-e LIEF_AUTOMATIC_BUILDS_KEY=$LIEF_AUTOMATIC_BUILDS_KEY \
|
||||||
|
-e LIEF_AUTOMATIC_BUILDS_IV=$LIEF_AUTOMATIC_BUILDS_IV \
|
||||||
|
--rm \
|
||||||
|
liefproject/deploy python3 /src/.github/deploy.py;
|
||||||
|
fi
|
||||||
|
|
||||||
- services: docker
|
- services: docker
|
||||||
env: >
|
name: "Linux Python 3.7 | SDK | Doc Trigger"
|
||||||
[
|
script:
|
||||||
PYTHON_VERSION=3.8 ,
|
- >
|
||||||
PYTHON_BINARY=/opt/python/cp38-cp38/bin/python3.8 ,
|
docker run --name lief_37
|
||||||
]
|
-e PYTHON_BINARY=/opt/python/cp37-cp37m/bin/python3.7
|
||||||
|
-e CCACHE_DIR=/ccache
|
||||||
|
-v $HOME/.ccache:/ccache
|
||||||
|
-v $TRAVIS_BUILD_DIR:/src
|
||||||
|
liefproject/manylinux1_x86_64
|
||||||
|
bash /src/scripts/docker/travis-linux.sh
|
||||||
|
- >
|
||||||
|
docker run --name lief_sdk
|
||||||
|
-e PYTHON_BINARY=$PYTHON_BINARY
|
||||||
|
-e CCACHE_DIR=/ccache
|
||||||
|
-v $HOME/.ccache:/ccache
|
||||||
|
-v $TRAVIS_BUILD_DIR:/src
|
||||||
|
liefproject/manylinux1_x86_64
|
||||||
|
bash /src/scripts/docker/travis-linux-sdk.sh
|
||||||
|
- >
|
||||||
|
sudo chmod -R 777 $TRAVIS_BUILD_DIR/build &&
|
||||||
|
sudo chown -R 1000:1000 $TRAVIS_BUILD_DIR/build
|
||||||
|
- >
|
||||||
|
if [[ "$TRAVIS_EVENT_TYPE" != "pull_request" ]]; then
|
||||||
|
docker run \
|
||||||
|
-v $TRAVIS_BUILD_DIR:/src \
|
||||||
|
-e TRAVIS="true" \
|
||||||
|
-e TRAVIS_EVENT_TYPE=$TRAVIS_EVENT_TYPE \
|
||||||
|
-e TRAVIS_REPO_SLUG=$TRAVIS_REPO_SLUG \
|
||||||
|
-e TRAVIS_BRANCH=$TRAVIS_BRANCH \
|
||||||
|
-e TRAVIS_BUILD_DIR=$TRAVIS_BUILD_DIR \
|
||||||
|
-e LIEF_AUTOMATIC_BUILDS_KEY=$LIEF_AUTOMATIC_BUILDS_KEY \
|
||||||
|
-e LIEF_AUTOMATIC_BUILDS_IV=$LIEF_AUTOMATIC_BUILDS_IV \
|
||||||
|
--rm \
|
||||||
|
liefproject/deploy python3 /src/.github/deploy.py;
|
||||||
|
fi
|
||||||
|
after_success:
|
||||||
|
- >
|
||||||
|
if [[ "$TRAVIS_EVENT_TYPE" != "pull_request" ]];
|
||||||
|
then
|
||||||
|
docker run --rm
|
||||||
|
-e CIRCLE_CI_TOKEN=$CIRCLE_CI_TOKEN
|
||||||
|
liefproject/manylinux1_x86_64
|
||||||
|
bash -c "curl --request POST --url https://circleci.com/api/v2/project/gh/lief-project/doc/pipeline --header 'Circle-Token: ${CIRCLE_CI_TOKEN}' --header 'content-type: application/json'";
|
||||||
|
fi
|
||||||
|
|
||||||
- services: docker
|
- services: docker
|
||||||
env: >
|
name: "Linux Python 3.8"
|
||||||
[
|
script:
|
||||||
PYTHON_VERSION=3.9 ,
|
- >
|
||||||
PYTHON_BINARY=/opt/python/cp39-cp39/bin/python3.9 ,
|
docker run --name lief_38
|
||||||
]
|
-e PYTHON_BINARY=/opt/python/cp38-cp38/bin/python3.8
|
||||||
|
-e CCACHE_DIR=/ccache
|
||||||
|
-v $HOME/.ccache:/ccache
|
||||||
|
-v $TRAVIS_BUILD_DIR:/src
|
||||||
|
liefproject/manylinux1_x86_64
|
||||||
|
bash /src/scripts/docker/travis-linux.sh
|
||||||
|
- >
|
||||||
|
sudo chmod -R 777 $TRAVIS_BUILD_DIR/build &&
|
||||||
|
sudo chown -R 1000:1000 $TRAVIS_BUILD_DIR/build
|
||||||
|
- >
|
||||||
|
if [[ "$TRAVIS_EVENT_TYPE" != "pull_request" ]]; then
|
||||||
|
docker run \
|
||||||
|
-v $TRAVIS_BUILD_DIR:/src \
|
||||||
|
-e TRAVIS="true" \
|
||||||
|
-e TRAVIS_EVENT_TYPE=$TRAVIS_EVENT_TYPE \
|
||||||
|
-e TRAVIS_REPO_SLUG=$TRAVIS_REPO_SLUG \
|
||||||
|
-e TRAVIS_BRANCH=$TRAVIS_BRANCH \
|
||||||
|
-e TRAVIS_BUILD_DIR=$TRAVIS_BUILD_DIR \
|
||||||
|
-e LIEF_AUTOMATIC_BUILDS_KEY=$LIEF_AUTOMATIC_BUILDS_KEY \
|
||||||
|
-e LIEF_AUTOMATIC_BUILDS_IV=$LIEF_AUTOMATIC_BUILDS_IV \
|
||||||
|
--rm \
|
||||||
|
liefproject/deploy python3 /src/.github/deploy.py;
|
||||||
|
fi
|
||||||
|
- services: docker
|
||||||
|
name: "Linux Python 3.9"
|
||||||
|
script:
|
||||||
|
- >
|
||||||
|
docker run --name lief_39
|
||||||
|
-e PYTHON_BINARY=/opt/python/cp39-cp39/bin/python3.9
|
||||||
|
-e CCACHE_DIR=/ccache
|
||||||
|
-v $HOME/.ccache:/ccache
|
||||||
|
-v $TRAVIS_BUILD_DIR:/src
|
||||||
|
liefproject/manylinux1_x86_64
|
||||||
|
bash /src/scripts/docker/travis-linux.sh
|
||||||
|
- >
|
||||||
|
sudo chmod -R 777 $TRAVIS_BUILD_DIR/build &&
|
||||||
|
sudo chown -R 1000:1000 $TRAVIS_BUILD_DIR/build
|
||||||
|
- >
|
||||||
|
if [[ "$TRAVIS_EVENT_TYPE" != "pull_request" ]]; then
|
||||||
|
docker run \
|
||||||
|
-v $TRAVIS_BUILD_DIR:/src \
|
||||||
|
-e TRAVIS="true" \
|
||||||
|
-e TRAVIS_EVENT_TYPE=$TRAVIS_EVENT_TYPE \
|
||||||
|
-e TRAVIS_REPO_SLUG=$TRAVIS_REPO_SLUG \
|
||||||
|
-e TRAVIS_BRANCH=$TRAVIS_BRANCH \
|
||||||
|
-e TRAVIS_BUILD_DIR=$TRAVIS_BUILD_DIR \
|
||||||
|
-e LIEF_AUTOMATIC_BUILDS_KEY=$LIEF_AUTOMATIC_BUILDS_KEY \
|
||||||
|
-e LIEF_AUTOMATIC_BUILDS_IV=$LIEF_AUTOMATIC_BUILDS_IV \
|
||||||
|
--rm \
|
||||||
|
liefproject/deploy python3 /src/.github/deploy.py;
|
||||||
|
fi
|
||||||
|
|
||||||
# OSX 10.12 - xcode 8.3 - Python 3.5
|
## macOS 10.14.6 - xcode 11 - Python 3.5
|
||||||
- os: osx
|
#- if: branch = master AND tag IS present AND type = push
|
||||||
osx_image: xcode11
|
# os: osx
|
||||||
compiler: clang
|
# osx_image: xcode11
|
||||||
env: >
|
# compiler: clang
|
||||||
[
|
# script:
|
||||||
CXX=clang++ ,
|
# - pyenv install --skip-existing 3.5.0
|
||||||
CC=clang ,
|
# - >
|
||||||
PYTHON_VERSION=3.5 ,
|
# export PYTHON_BINARY=$(pyenv root)/versions/3.5.0/bin/python3.5 &&
|
||||||
]
|
# sudo $PYTHON_BINARY -m pip install --upgrade pip setuptools wheel &&
|
||||||
|
# $PYTHON_BINARY ./setup.py --ninja --lief-test build bdist_wheel
|
||||||
|
# after_success:
|
||||||
|
# - >
|
||||||
|
# if [[ "$TRAVIS_EVENT_TYPE" != "pull_request" ]]; then
|
||||||
|
# export PYTHON_BINARY=$(pyenv root)/versions/3.5.0/bin/python3.5 &&
|
||||||
|
# sudo $PYTHON_BINARY -m pip install --upgrade pip setuptools requests mako wheel &&
|
||||||
|
# cd $TRAVIS_BUILD_DIR &&
|
||||||
|
# bash ./.github/deploy.sh;
|
||||||
|
# fi
|
||||||
|
|
||||||
|
## macOS 10.14.6 - xcode 11 - Python 3.6
|
||||||
|
#- if: branch = master AND tag IS present AND type = push
|
||||||
|
# os: osx
|
||||||
|
# osx_image: xcode11
|
||||||
|
# compiler: clang
|
||||||
|
# script:
|
||||||
|
# - pyenv install --skip-existing 3.6.0
|
||||||
|
# - >
|
||||||
|
# export PYTHON_BINARY=$(pyenv root)/versions/3.6.0/bin/python3.6 &&
|
||||||
|
# sudo $PYTHON_BINARY -m pip install --upgrade pip setuptools wheel &&
|
||||||
|
# $PYTHON_BINARY ./setup.py --ninja --lief-test build bdist_wheel
|
||||||
|
# after_success:
|
||||||
|
# - >
|
||||||
|
# if [[ "$TRAVIS_EVENT_TYPE" != "pull_request" ]]; then
|
||||||
|
# export PYTHON_BINARY=$(pyenv root)/versions/3.6.0/bin/python3.6 &&
|
||||||
|
# sudo $PYTHON_BINARY -m pip install --upgrade pip setuptools requests mako wheel &&
|
||||||
|
# cd $TRAVIS_BUILD_DIR &&
|
||||||
|
# bash ./.github/deploy.sh;
|
||||||
|
# fi
|
||||||
|
|
||||||
|
|
||||||
# OSX 10.12 - xcode 8.3 - Python 3.6
|
## macOS 10.14.6 - xcode 11 - Python 3.7
|
||||||
- os: osx
|
#- os: osx
|
||||||
osx_image: xcode11
|
# osx_image: xcode11
|
||||||
compiler: clang
|
# compiler: clang
|
||||||
env: >
|
# script:
|
||||||
[
|
# - pyenv install --skip-existing 3.7.0
|
||||||
CXX=clang++ ,
|
# - >
|
||||||
CC=clang ,
|
# export PYTHON_BINARY=$(pyenv root)/versions/3.7.0/bin/python3.7 &&
|
||||||
PYTHON_VERSION=3.6 ,
|
# sudo $PYTHON_BINARY -m pip install --upgrade pip setuptools wheel &&
|
||||||
]
|
# $PYTHON_BINARY ./setup.py --ninja --lief-test build bdist_wheel
|
||||||
|
# after_success:
|
||||||
|
# - >
|
||||||
|
# if [[ "$TRAVIS_EVENT_TYPE" != "pull_request" ]]; then
|
||||||
|
# export PYTHON_BINARY=$(pyenv root)/versions/3.7.0/bin/python3.7 &&
|
||||||
|
# sudo $PYTHON_BINARY -m pip install --upgrade pip setuptools requests mako wheel &&
|
||||||
|
# cd $TRAVIS_BUILD_DIR &&
|
||||||
|
# bash ./.github/deploy.sh;
|
||||||
|
# fi
|
||||||
|
|
||||||
|
# macOS 10.14.6 - xcode 11 - Python 3.8
|
||||||
|
#- os: osx
|
||||||
|
# osx_image: xcode11
|
||||||
|
# compiler: clang
|
||||||
|
# name: "OSX Python 3.8"
|
||||||
|
# script:
|
||||||
|
# - pyenv install --skip-existing 3.8.0
|
||||||
|
# - >
|
||||||
|
# export PYTHON_BINARY=$(pyenv root)/versions/3.8.0/bin/python3.8 &&
|
||||||
|
# sudo $PYTHON_BINARY -m pip install --upgrade pip setuptools wheel &&
|
||||||
|
# $PYTHON_BINARY ./setup.py --ninja --lief-test build bdist_wheel
|
||||||
|
# after_success:
|
||||||
|
# - >
|
||||||
|
# if [[ "$TRAVIS_EVENT_TYPE" != "pull_request" ]]; then
|
||||||
|
# export PYTHON_BINARY=$(pyenv root)/versions/3.8.0/bin/python3.8 &&
|
||||||
|
# sudo $PYTHON_BINARY -m pip install --upgrade pip setuptools requests mako wheel &&
|
||||||
|
# cd $TRAVIS_BUILD_DIR &&
|
||||||
|
# bash ./.github/deploy.sh;
|
||||||
|
# fi
|
||||||
|
|
||||||
# OSX 10.12 - xcode 10.1 - Python 3.7
|
## macOS 10.14.6 - xcode 11 - Python 3.9
|
||||||
- os: osx
|
#- os: osx
|
||||||
osx_image: xcode11
|
# osx_image: xcode11
|
||||||
compiler: clang
|
# compiler: clang
|
||||||
env: >
|
# name: "OSX Python 3.9 | SDK"
|
||||||
[
|
# script:
|
||||||
CXX=clang++ ,
|
# - pyenv install --skip-existing 3.9.0
|
||||||
CC=clang ,
|
# - >
|
||||||
PYTHON_VERSION=3.7 ,
|
# export PYTHON_BINARY=$(pyenv root)/versions/3.9.0/bin/python3.9 &&
|
||||||
]
|
# sudo $PYTHON_BINARY -m pip install --upgrade pip setuptools wheel &&
|
||||||
|
# $PYTHON_BINARY ./setup.py --ninja --lief-test build bdist_wheel
|
||||||
|
# - bash scripts/osx/package_sdk.sh
|
||||||
|
# after_success:
|
||||||
|
# - >
|
||||||
|
# if [[ "$TRAVIS_EVENT_TYPE" != "pull_request" ]]; then
|
||||||
|
# export PYTHON_BINARY=$(pyenv root)/versions/3.9.0/bin/python3.9 &&
|
||||||
|
# sudo $PYTHON_BINARY -m pip install --upgrade pip setuptools requests mako wheel &&
|
||||||
|
# cd $TRAVIS_BUILD_DIR &&
|
||||||
|
# bash ./.github/deploy.sh;
|
||||||
|
# fi
|
||||||
|
|
||||||
# OSX 10.12 - xcode 10.1 - Python 3.8
|
|
||||||
- os: osx
|
|
||||||
osx_image: xcode11
|
|
||||||
compiler: clang
|
|
||||||
env: >
|
|
||||||
[
|
|
||||||
CXX=clang++ ,
|
|
||||||
CC=clang ,
|
|
||||||
PYTHON_VERSION=3.8 ,
|
|
||||||
]
|
|
||||||
|
|
||||||
# OSX 10.12 - xcode 10.1 - Python 3.9
|
|
||||||
- os: osx
|
|
||||||
osx_image: xcode11
|
|
||||||
compiler: clang
|
|
||||||
env: >
|
|
||||||
[
|
|
||||||
CXX=clang++ ,
|
|
||||||
CC=clang ,
|
|
||||||
PYTHON_VERSION=3.9 ,
|
|
||||||
]
|
|
||||||
|
|
||||||
#branches:
|
#branches:
|
||||||
# only:
|
# only:
|
||||||
@ -113,91 +275,40 @@ notifications:
|
|||||||
on_failure: always
|
on_failure: always
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
- ccache
|
- ccache: true
|
||||||
- directories:
|
- directories:
|
||||||
- $HOME/.pyenv
|
- $HOME/.pyenv
|
||||||
- build/rang_cpp_color-prefix
|
- $HOME/.ccache
|
||||||
- build/mbed_tls
|
|
||||||
- build/libjson-prefix
|
|
||||||
- build/easyloggingpp-prefix
|
|
||||||
- build/tests/YAMLCPP
|
|
||||||
- build/tests/lief-samples
|
|
||||||
- build/tests/catch
|
|
||||||
- build/api/python/pybind11-prefix
|
|
||||||
|
|
||||||
|
env:
|
||||||
|
global:
|
||||||
|
- USE_CCACHE=1
|
||||||
|
- CCACHE_COMPRESS=1
|
||||||
|
- CCACHE_MAXSIZE=10.0G
|
||||||
|
- CCACHE_CPP2=1
|
||||||
|
|
||||||
addons:
|
addons:
|
||||||
homebrew:
|
homebrew:
|
||||||
packages:
|
packages:
|
||||||
- pyenv
|
- pyenv
|
||||||
- ccache
|
- ccache
|
||||||
|
- ninja
|
||||||
update: true
|
update: true
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
|
- ccache --set-config=max_size=10.0G
|
||||||
|
- ccache --zero-stats --version
|
||||||
|
- ccache --set-config=compiler_check=content
|
||||||
|
- ccache -p
|
||||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then docker pull liefproject/manylinux1_x86_64:latest; fi
|
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then docker pull liefproject/manylinux1_x86_64:latest; fi
|
||||||
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then export PREFIX="/usr/local"; fi
|
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then export PREFIX="/usr/local"; fi
|
||||||
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then export PATH="/usr/local/opt/ccache/libexec:$PATH"; fi
|
#- if [ "$TRAVIS_OS_NAME" == "osx" ]; then export PATH="/usr/local/opt/ccache/libexec:$PATH"; fi
|
||||||
|
|
||||||
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then export PYTHON_CONFIGURE_OPTS="--enable-shared --enable-unicode=ucs2"; fi
|
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then export PYTHON_CONFIGURE_OPTS="--enable-shared --enable-unicode=ucs2"; fi
|
||||||
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then pyenv root; fi
|
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then pyenv root; fi
|
||||||
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then pyenv install --list ;fi
|
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then pyenv install --list ;fi
|
||||||
|
|
||||||
- if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "2.7" ]]; then pyenv install 2.7.12; fi
|
after_script:
|
||||||
- if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.5" ]]; then pyenv install --skip-existing 3.5.9; fi
|
- ccache --show-stats
|
||||||
- if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.6" ]]; then pyenv install --skip-existing 3.6.0; fi
|
|
||||||
- if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.7" ]]; then pyenv install --skip-existing 3.7.0; fi
|
|
||||||
- if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.8" ]]; then pyenv install --skip-existing 3.8.0; fi
|
|
||||||
- if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.9" ]]; then pyenv install --skip-existing 3.9.0; fi
|
|
||||||
#- if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.7" ]]; then ls -alR $(pyenv root)/versions/3.7.0a1; fi
|
|
||||||
|
|
||||||
- if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "2.7" ]]; then export PYTHON_BINARY=$(pyenv root)/versions/2.7.12/bin/python2.7 ;fi
|
|
||||||
- if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.5" ]]; then export PYTHON_BINARY=$(pyenv root)/versions/3.5.9/bin/python3.5 ;fi
|
|
||||||
- if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.6" ]]; then export PYTHON_BINARY=$(pyenv root)/versions/3.6.0/bin/python3.6 ;fi
|
|
||||||
- if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.7" ]]; then export PYTHON_BINARY=$(pyenv root)/versions/3.7.0/bin/python3.7 ;fi
|
|
||||||
- if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.8" ]]; then export PYTHON_BINARY=$(pyenv root)/versions/3.8.0/bin/python3.8 ;fi
|
|
||||||
- if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.9" ]]; then export PYTHON_BINARY=$(pyenv root)/versions/3.9.0/bin/python3.9 ;fi
|
|
||||||
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then $PYTHON_BINARY -m pip install --upgrade pip ;fi
|
|
||||||
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then $PYTHON_BINARY -m pip install --upgrade setuptools ;fi
|
|
||||||
|
|
||||||
install:
|
|
||||||
- if [ "$GCOV" == "ON" ]; then sudo ln -sf /usr/bin/gcov-5 /usr/bin/gcov; fi
|
|
||||||
- if [ "$GCOV" == "ON" ]; then wget http://ftp.de.debian.org/debian/pool/main/l/lcov/lcov_1.13.orig.tar.gz; fi
|
|
||||||
- if [ "$GCOV" == "ON" ]; then tar xf lcov_1.13.orig.tar.gz; fi
|
|
||||||
- if [ "$GCOV" == "ON" ]; then sudo make -C lcov-1.13/ install; fi
|
|
||||||
|
|
||||||
script:
|
|
||||||
- >
|
|
||||||
if [[ "$TRAVIS_OS_NAME" == "linux" ]];
|
|
||||||
then docker run --name lief_$PYTHON_VERSION
|
|
||||||
-e PYTHON_BINARY=$PYTHON_BINARY
|
|
||||||
-e CCACHE_DIR=/ccache
|
|
||||||
-v $HOME/.ccache:/ccache
|
|
||||||
-v $TRAVIS_BUILD_DIR:/src
|
|
||||||
liefproject/manylinux1_x86_64
|
|
||||||
bash -c '$PYTHON_BINARY setup.py --lief-test --sdk build -j8 bdist_wheel --dist-dir wheel_stage && auditwheel repair -w dist --plat manylinux1_x86_64 wheel_stage/*.whl'
|
|
||||||
&& sudo chmod -R 777 dist/
|
|
||||||
&& sudo chmod -R 777 build/;
|
|
||||||
fi
|
|
||||||
- >
|
|
||||||
if [[ "$TRAVIS_OS_NAME" == "osx" ]];
|
|
||||||
then sudo $PYTHON_BINARY -m pip install -U pip setuptools wheel
|
|
||||||
&& $PYTHON_BINARY ./setup.py --lief-test --sdk build -j8 bdist_wheel;
|
|
||||||
fi
|
|
||||||
|
|
||||||
after_success:
|
|
||||||
- make package
|
|
||||||
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export PYTHON_BINARY=python3; sudo apt-get update && sudo apt-get install -y python3 python3-pip; fi
|
|
||||||
- sudo $PYTHON_BINARY -m pip install --upgrade pip
|
|
||||||
- sudo $PYTHON_BINARY -m pip install --upgrade setuptools
|
|
||||||
- sudo $PYTHON_BINARY -m pip install --upgrade requests mako wheel
|
|
||||||
- cd $TRAVIS_BUILD_DIR
|
|
||||||
- if [[ "$TRAVIS_EVENT_TYPE" != "pull_request" ]]; then bash ./.github/deploy.sh; fi
|
|
||||||
- >
|
|
||||||
if [[ "$TRAVIS_OS_NAME" == "linux" && "$PYTHON_VERSION" == "3.7" && "$TRAVIS_EVENT_TYPE" != "pull_request" ]];
|
|
||||||
then docker run -e CIRCLE_CI_TOKEN=$CIRCLE_CI_TOKEN liefproject/manylinux1_x86_64
|
|
||||||
bash -c "curl --request POST --url https://circleci.com/api/v2/project/gh/lief-project/doc/pipeline --header 'Circle-Token: ${CIRCLE_CI_TOKEN}' --header 'content-type: application/json'";
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
provider: releases
|
provider: releases
|
||||||
|
@ -66,6 +66,28 @@ endif()
|
|||||||
set(THIRD_PARTY_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/third-party/")
|
set(THIRD_PARTY_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/third-party/")
|
||||||
include(LIEFDependencies)
|
include(LIEFDependencies)
|
||||||
|
|
||||||
|
# iOS specific config
|
||||||
|
# ===================
|
||||||
|
if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
|
||||||
|
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED NO)
|
||||||
|
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED NO)
|
||||||
|
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
message(STATUS "CMAKE_CXX_FLAGS_RELEASE: ${CMAKE_CXX_FLAGS_RELEASE}")
|
||||||
|
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
|
||||||
|
message(STATUS "CMAKE_CXX_LINK_EXECUTABLE: ${CMAKE_CXX_LINK_EXECUTABLE}")
|
||||||
|
message(STATUS "CMAKE_CXX_LINK_FLAGS: ${CMAKE_CXX_LINK_FLAGS}")
|
||||||
|
message(STATUS "CMAKE_EXE_LINKER_FLAGS: ${CMAKE_EXE_LINKER_FLAGS}")
|
||||||
|
message(STATUS "CMAKE_EXE_LINKER_FLAGS_RELEASE: ${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
|
||||||
|
message(STATUS "CMAKE_SHARED_LINKER_FLAGS: ${CMAKE_SHARED_LINKER_FLAGS}")
|
||||||
|
message(STATUS "CMAKE_SHARED_LINKER_FLAGS_RELEASE: ${CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
|
||||||
|
message(STATUS "CMAKE_CXX_LINK_LIBRARY_FILE_FLAG: ${CMAKE_CXX_LINK_LIBRARY_FILE_FLAG}")
|
||||||
|
message(STATUS "CMAKE_LINK_LIBRARY_FILE_FLAG: ${CMAKE_LINK_LIBRARY_FILE_FLAG}")
|
||||||
|
message(STATUS "CMAKE_LINK_INTERFACE_LIBRARIES: ${CMAKE_LINK_INTERFACE_LIBRARIES}")
|
||||||
|
message(STATUS "CMAKE_CXX_IMPLICIT_LINK_LIBRARIES: ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES}")
|
||||||
|
message(STATUS "CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}")
|
||||||
|
|
||||||
# LIEF Source definition
|
# LIEF Source definition
|
||||||
# ======================
|
# ======================
|
||||||
set_source_files_properties(${mbedtls_src_crypto} PROPERTIES GENERATED TRUE)
|
set_source_files_properties(${mbedtls_src_crypto} PROPERTIES GENERATED TRUE)
|
||||||
@ -315,6 +337,13 @@ set_target_properties(
|
|||||||
C_VISIBILITY_PRESET hidden)
|
C_VISIBILITY_PRESET hidden)
|
||||||
# cmake-format: on
|
# cmake-format: on
|
||||||
|
|
||||||
|
if(UNIX AND NOT APPLE)
|
||||||
|
set_property(
|
||||||
|
TARGET LIB_LIEF
|
||||||
|
APPEND
|
||||||
|
PROPERTY LINK_FLAGS "-Wl,--gc-sections -Wl,--exclude-libs,ALL")
|
||||||
|
endif()
|
||||||
|
|
||||||
target_compile_definitions(LIB_LIEF PUBLIC -D_GLIBCXX_USE_CXX11_ABI=1)
|
target_compile_definitions(LIB_LIEF PUBLIC -D_GLIBCXX_USE_CXX11_ABI=1)
|
||||||
|
|
||||||
# Enable support for MD2 and MD4 for parsing the Authenticode sigs of older
|
# Enable support for MD2 and MD4 for parsing the Authenticode sigs of older
|
||||||
@ -490,6 +519,28 @@ write_basic_package_version_file(
|
|||||||
VERSION ${PROJECT_VERSION}
|
VERSION ${PROJECT_VERSION}
|
||||||
COMPATIBILITY AnyNewerVersion)
|
COMPATIBILITY AnyNewerVersion)
|
||||||
|
|
||||||
|
# Post-build operations
|
||||||
|
# ======================
|
||||||
|
if (BUILD_SHARED_LIBS AND CMAKE_BUILD_TYPE MATCHES "Release")
|
||||||
|
if (UNIX AND NOT APPLE)
|
||||||
|
add_custom_command(
|
||||||
|
TARGET LIB_LIEF
|
||||||
|
COMMENT "Strip LIEF shared library"
|
||||||
|
POST_BUILD
|
||||||
|
COMMAND ${CMAKE_STRIP} --strip-all $<TARGET_FILE:LIB_LIEF>
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (APPLE)
|
||||||
|
add_custom_command(
|
||||||
|
TARGET LIB_LIEF
|
||||||
|
COMMENT "Strip LIEF shared library"
|
||||||
|
POST_BUILD
|
||||||
|
COMMAND ${CMAKE_STRIP} -x -S $<TARGET_FILE:LIB_LIEF>
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
# Install Prefix
|
# Install Prefix
|
||||||
# ======================
|
# ======================
|
||||||
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND UNIX)
|
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND UNIX)
|
||||||
|
@ -1,18 +1,21 @@
|
|||||||
FROM quay.io/pypa/manylinux1_x86_64:latest
|
# Docker file used to compile LIEF on Linux x86-64 compliant with Python tag: manylinux1
|
||||||
|
# docker build -t liefproject/manylinux1_x86_64:latest -f ./Dockerfile .
|
||||||
|
FROM quay.io/pypa/manylinux1_x86_64:2020-12-30-e2b3664
|
||||||
|
|
||||||
RUN yum update -y \
|
RUN yum update -y \
|
||||||
&& yum install -y ccache \
|
&& yum install -y ccache \
|
||||||
&& yum clean all
|
&& yum clean all
|
||||||
|
|
||||||
RUN /opt/python/cp37-cp37m/bin/pip install cmake==3.13.3
|
RUN /opt/python/cp37-cp37m/bin/pip install cmake==3.13.3 ninja==1.10.0.post2
|
||||||
ENV PATH=$PATH:/opt/python/cp37-cp37m/bin/
|
ENV PATH=$PATH:/opt/python/cp37-cp37m/bin/
|
||||||
|
|
||||||
RUN curl --output /tmp/gcc-6.3.0-binutils-2.27-x86_64.tar.bz2 -L https://github.com/squeaky-pl/centos-devtools/releases/download/6.3/gcc-6.3.0-binutils-2.27-x86_64.tar.bz2 && \
|
RUN curl --output /tmp/gcc-6.3.0-binutils-2.27-x86_64.tar.bz2 -L https://github.com/squeaky-pl/centos-devtools/releases/download/6.3/gcc-6.3.0-binutils-2.27-x86_64.tar.bz2 && \
|
||||||
echo "ca3e9f92411507018c839c8cc2b496f14956a49fcf6df0cdcb356de7161bcbc5 /tmp/gcc-6.3.0-binutils-2.27-x86_64.tar.bz2" | sha256sum --check --status && \
|
echo "ca3e9f92411507018c839c8cc2b496f14956a49fcf6df0cdcb356de7161bcbc5 /tmp/gcc-6.3.0-binutils-2.27-x86_64.tar.bz2" | sha256sum --check --status && \
|
||||||
tar -C / -xj -f /tmp/gcc-6.3.0-binutils-2.27-x86_64.tar.bz2 && \
|
tar -C / -xj -f /tmp/gcc-6.3.0-binutils-2.27-x86_64.tar.bz2 && \
|
||||||
rm -rf /tmp/gcc-6.3.0-binutils-2.27-x86_64.tar.bz2
|
rm -rf /tmp/gcc-6.3.0-binutils-2.27-x86_64.tar.bz2
|
||||||
|
|
||||||
ENV CC=/opt/devtools-6.3/bin/gcc
|
ENV CC=/opt/devtools-6.3/bin/gcc
|
||||||
ENV CXX=/opt/devtools-6.3/bin/g++
|
ENV CXX=/opt/devtools-6.3/bin/g++
|
||||||
ENV CXXFLAGS=-static-libstdc++
|
ENV CXXFLAGS="-static-libstdc++ -static-libgcc"
|
||||||
|
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
@PACKAGE_INIT@
|
@PACKAGE_INIT@
|
||||||
|
|
||||||
set(LIEF_ROOT "${PACKAGE_PREFIX_DIR}")
|
set(LIEF_INSTALL_PATH "${PACKAGE_PREFIX_DIR}")
|
||||||
include("${CMAKE_CURRENT_LIST_DIR}/FindLIEF.cmake")
|
include("${CMAKE_CURRENT_LIST_DIR}/FindLIEF.cmake")
|
||||||
|
@ -2,6 +2,7 @@ if(__add_lief_options)
|
|||||||
return()
|
return()
|
||||||
endif()
|
endif()
|
||||||
set(__add_lief_options ON)
|
set(__add_lief_options ON)
|
||||||
|
include(CMakeDependentOption)
|
||||||
|
|
||||||
option(LIEF_TESTS "Enable tests" OFF)
|
option(LIEF_TESTS "Enable tests" OFF)
|
||||||
option(LIEF_DOC "Enable documentation" OFF)
|
option(LIEF_DOC "Enable documentation" OFF)
|
||||||
@ -40,6 +41,10 @@ option(LIEF_FUZZING "Fuzz LIEF" OFF)
|
|||||||
# Profiling
|
# Profiling
|
||||||
option(LIEF_PROFILING "Enable performance profiling" OFF)
|
option(LIEF_PROFILING "Enable performance profiling" OFF)
|
||||||
|
|
||||||
|
# Install options
|
||||||
|
cmake_dependent_option(LIEF_INSTALL_COMPILED_EXAMPLES "Install LIEF Compiled examples" OFF
|
||||||
|
"LIEF_EXAMPLES" OFF)
|
||||||
|
|
||||||
set(LIEF_ELF_SUPPORT 0)
|
set(LIEF_ELF_SUPPORT 0)
|
||||||
set(LIEF_PE_SUPPORT 0)
|
set(LIEF_PE_SUPPORT 0)
|
||||||
set(LIEF_MACHO_SUPPORT 0)
|
set(LIEF_MACHO_SUPPORT 0)
|
||||||
|
6
cmake/cpack.config.cmake
Normal file
6
cmake/cpack.config.cmake
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
include("static-release/CPackConfig.cmake")
|
||||||
|
|
||||||
|
set(CPACK_INSTALL_CMAKE_PROJECTS ${CPACK_INSTALL_CMAKE_PROJECTS}
|
||||||
|
static-release LIEF ALL /
|
||||||
|
shared-release LIEF ALL /
|
||||||
|
)
|
740
cmake/ios.toolchain.cmake
Normal file
740
cmake/ios.toolchain.cmake
Normal file
@ -0,0 +1,740 @@
|
|||||||
|
# This file is part of the ios-cmake project. It was retrieved from
|
||||||
|
# https://github.com/gerstrong/ios-cmake.git which is a fork of
|
||||||
|
# https://github.com/cristeab/ios-cmake.git, which again is a fork of
|
||||||
|
# https://code.google.com/p/ios-cmake/. Which in turn is based off of
|
||||||
|
# the Platform/Darwin.cmake and Platform/UnixPaths.cmake files which
|
||||||
|
# are included with CMake 2.8.4
|
||||||
|
#
|
||||||
|
# The ios-cmake project is licensed under the new BSD license.
|
||||||
|
#
|
||||||
|
# Copyright (c) 2014, Bogdan Cristea and LTE Engineering Software,
|
||||||
|
# Kitware, Inc., Insight Software Consortium. All rights reserved.
|
||||||
|
# Redistribution and use in source and binary forms, with or without
|
||||||
|
# modification, are permitted provided that the following conditions
|
||||||
|
# are met:
|
||||||
|
# 1. Redistributions of source code must retain the above copyright
|
||||||
|
# notice, this list of conditions and the following disclaimer.
|
||||||
|
#
|
||||||
|
# 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
# notice, this list of conditions and the following disclaimer in the
|
||||||
|
# documentation and/or other materials provided with the distribution.
|
||||||
|
#
|
||||||
|
# 3. Neither the name of the copyright holder nor the names of its
|
||||||
|
# contributors may be used to endorse or promote products derived from
|
||||||
|
# this software without specific prior written permission.
|
||||||
|
#
|
||||||
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
# POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
#
|
||||||
|
# This file is based off of the Platform/Darwin.cmake and
|
||||||
|
# Platform/UnixPaths.cmake files which are included with CMake 2.8.4
|
||||||
|
# It has been altered for iOS development.
|
||||||
|
#
|
||||||
|
# Updated by Alex Stewart (alexs.mac@gmail.com)
|
||||||
|
#
|
||||||
|
# *****************************************************************************
|
||||||
|
# Now maintained by Alexander Widerberg (widerbergaren [at] gmail.com)
|
||||||
|
# under the BSD-3-Clause license
|
||||||
|
# https://github.com/leetal/ios-cmake
|
||||||
|
# *****************************************************************************
|
||||||
|
#
|
||||||
|
# INFORMATION / HELP
|
||||||
|
#
|
||||||
|
# The following arguments control the behaviour of this toolchain:
|
||||||
|
#
|
||||||
|
# PLATFORM: (default "OS")
|
||||||
|
# OS = Build for iPhoneOS.
|
||||||
|
# OS64 = Build for arm64 iphoneOS.
|
||||||
|
# OS64COMBINED = Build for arm64 x86_64 iphoneOS. Combined into FAT STATIC lib (supported on 3.14+ of CMakewith "-G Xcode" argument ONLY)
|
||||||
|
# SIMULATOR = Build for x86 i386 iphoneOS Simulator.
|
||||||
|
# SIMULATOR64 = Build for x86_64 iphoneOS Simulator.
|
||||||
|
# TVOS = Build for arm64 tvOS.
|
||||||
|
# TVOSCOMBINED = Build for arm64 x86_64 tvOS. Combined into FAT STATIC lib (supported on 3.14+ of CMake with "-G Xcode" argument ONLY)
|
||||||
|
# SIMULATOR_TVOS = Build for x86_64 tvOS Simulator.
|
||||||
|
# WATCHOS = Build for armv7k arm64_32 for watchOS.
|
||||||
|
# WATCHOSCOMBINED = Build for armv7k arm64_32 x86_64 watchOS. Combined into FAT STATIC lib (supported on 3.14+ of CMake with "-G Xcode" argument ONLY)
|
||||||
|
# SIMULATOR_WATCHOS = Build for x86_64 for watchOS Simulator.
|
||||||
|
#
|
||||||
|
# CMAKE_OSX_SYSROOT: Path to the SDK to use. By default this is
|
||||||
|
# automatically determined from PLATFORM and xcodebuild, but
|
||||||
|
# can also be manually specified (although this should not be required).
|
||||||
|
#
|
||||||
|
# CMAKE_DEVELOPER_ROOT: Path to the Developer directory for the platform
|
||||||
|
# being compiled for. By default this is automatically determined from
|
||||||
|
# CMAKE_OSX_SYSROOT, but can also be manually specified (although this should
|
||||||
|
# not be required).
|
||||||
|
#
|
||||||
|
# DEPLOYMENT_TARGET: Minimum SDK version to target. Default 2.0 on watchOS and 9.0 on tvOS+iOS
|
||||||
|
#
|
||||||
|
# ENABLE_BITCODE: (1|0) Enables or disables bitcode support. Default 1 (true)
|
||||||
|
#
|
||||||
|
# ENABLE_ARC: (1|0) Enables or disables ARC support. Default 1 (true, ARC enabled by default)
|
||||||
|
#
|
||||||
|
# ENABLE_VISIBILITY: (1|0) Enables or disables symbol visibility support. Default 0 (false, visibility hidden by default)
|
||||||
|
#
|
||||||
|
# ENABLE_STRICT_TRY_COMPILE: (1|0) Enables or disables strict try_compile() on all Check* directives (will run linker
|
||||||
|
# to actually check if linking is possible). Default 0 (false, will set CMAKE_TRY_COMPILE_TARGET_TYPE to STATIC_LIBRARY)
|
||||||
|
#
|
||||||
|
# ARCHS: (armv7 armv7s armv7k arm64 arm64_32 i386 x86_64) If specified, will override the default architectures for the given PLATFORM
|
||||||
|
# OS = armv7 armv7s arm64 (if applicable)
|
||||||
|
# OS64 = arm64 (if applicable)
|
||||||
|
# SIMULATOR = i386
|
||||||
|
# SIMULATOR64 = x86_64
|
||||||
|
# TVOS = arm64
|
||||||
|
# SIMULATOR_TVOS = x86_64 (i386 has since long been deprecated)
|
||||||
|
# WATCHOS = armv7k arm64_32 (if applicable)
|
||||||
|
# SIMULATOR_WATCHOS = x86_64 (i386 has since long been deprecated)
|
||||||
|
#
|
||||||
|
# This toolchain defines the following variables for use externally:
|
||||||
|
#
|
||||||
|
# XCODE_VERSION: Version number (not including Build version) of Xcode detected.
|
||||||
|
# SDK_VERSION: Version of SDK being used.
|
||||||
|
# CMAKE_OSX_ARCHITECTURES: Architectures being compiled for (generated from PLATFORM).
|
||||||
|
# APPLE_TARGET_TRIPLE: Used by autoconf build systems. NOTE: If "ARCHS" are overridden, this will *NOT* be set!
|
||||||
|
#
|
||||||
|
# This toolchain defines the following macros for use externally:
|
||||||
|
#
|
||||||
|
# set_xcode_property (TARGET XCODE_PROPERTY XCODE_VALUE XCODE_VARIANT)
|
||||||
|
# A convenience macro for setting xcode specific properties on targets.
|
||||||
|
# Available variants are: All, Release, RelWithDebInfo, Debug, MinSizeRel
|
||||||
|
# example: set_xcode_property (myioslib IPHONEOS_DEPLOYMENT_TARGET "3.1" "all").
|
||||||
|
#
|
||||||
|
# find_host_package (PROGRAM ARGS)
|
||||||
|
# A macro used to find executable programs on the host system, not within the
|
||||||
|
# environment. Thanks to the android-cmake project for providing the
|
||||||
|
# command.
|
||||||
|
#
|
||||||
|
# ******************************** DEPRECATIONS *******************************
|
||||||
|
#
|
||||||
|
# IOS_DEPLOYMENT_TARGET: (Deprecated) Alias to DEPLOYMENT_TARGET
|
||||||
|
# CMAKE_IOS_DEVELOPER_ROOT: (Deprecated) Alias to CMAKE_DEVELOPER_ROOT
|
||||||
|
# IOS_PLATFORM: (Deprecated) Alias to PLATFORM
|
||||||
|
# IOS_ARCH: (Deprecated) Alias to ARCHS
|
||||||
|
#
|
||||||
|
# *****************************************************************************
|
||||||
|
#
|
||||||
|
|
||||||
|
# Fix for PThread library not in path
|
||||||
|
set(CMAKE_THREAD_LIBS_INIT "-lpthread")
|
||||||
|
set(CMAKE_HAVE_THREADS_LIBRARY 1)
|
||||||
|
set(CMAKE_USE_WIN32_THREADS_INIT 0)
|
||||||
|
set(CMAKE_USE_PTHREADS_INIT 1)
|
||||||
|
|
||||||
|
# Cache what generator is used
|
||||||
|
set(USED_CMAKE_GENERATOR "${CMAKE_GENERATOR}" CACHE STRING "Expose CMAKE_GENERATOR" FORCE)
|
||||||
|
|
||||||
|
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.14")
|
||||||
|
set(MODERN_CMAKE YES)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Get the Xcode version being used.
|
||||||
|
execute_process(COMMAND xcodebuild -version
|
||||||
|
OUTPUT_VARIABLE XCODE_VERSION
|
||||||
|
ERROR_QUIET
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
string(REGEX MATCH "Xcode [0-9\\.]+" XCODE_VERSION "${XCODE_VERSION}")
|
||||||
|
string(REGEX REPLACE "Xcode ([0-9\\.]+)" "\\1" XCODE_VERSION "${XCODE_VERSION}")
|
||||||
|
|
||||||
|
# Assuming that xcode 12.0 is installed you most probably have ios sdk 14.2 or later installed (tested on Big Sur)
|
||||||
|
# if you don't set a deployment target it will be set the way you only get 64-bit builds
|
||||||
|
if(NOT DEFINED DEPLOYMENT_TARGET AND XCODE_VERSION VERSION_GREATER 12.0)
|
||||||
|
option(DROP_32_BIT "Will make drop 32-bit support universally. On later sdks you won't be able to build 32-bit apps" yes)
|
||||||
|
# Temporarily fix the arm64 issues in CMake install-combined by excluding arm64 for simulator builds (needed for Apple Silicon...)
|
||||||
|
set(CMAKE_XCODE_ATTRIBUTE_EXCLUDED_ARCHS[sdk=iphonesimulator*] "arm64")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
######## ALIASES (DEPRECATION WARNINGS)
|
||||||
|
|
||||||
|
if(DEFINED IOS_PLATFORM)
|
||||||
|
set(PLATFORM ${IOS_PLATFORM})
|
||||||
|
message(DEPRECATION "IOS_PLATFORM argument is DEPRECATED. Consider using the new PLATFORM argument instead.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(DEFINED IOS_DEPLOYMENT_TARGET)
|
||||||
|
set(DEPLOYMENT_TARGET ${IOS_DEPLOYMENT_TARGET})
|
||||||
|
message(DEPRECATION "IOS_DEPLOYMENT_TARGET argument is DEPRECATED. Consider using the new DEPLOYMENT_TARGET argument instead.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(DEFINED CMAKE_IOS_DEVELOPER_ROOT)
|
||||||
|
set(CMAKE_DEVELOPER_ROOT ${CMAKE_IOS_DEVELOPER_ROOT})
|
||||||
|
message(DEPRECATION "CMAKE_IOS_DEVELOPER_ROOT argument is DEPRECATED. Consider using the new CMAKE_DEVELOPER_ROOT argument instead.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(DEFINED IOS_ARCH)
|
||||||
|
set(ARCHS ${IOS_ARCH})
|
||||||
|
message(DEPRECATION "IOS_ARCH argument is DEPRECATED. Consider using the new ARCHS argument instead.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
######## END ALIASES
|
||||||
|
|
||||||
|
# Unset the FORCE on cache variables if in try_compile()
|
||||||
|
set(FORCE_CACHE FORCE)
|
||||||
|
get_property(_CMAKE_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE)
|
||||||
|
if(_CMAKE_IN_TRY_COMPILE)
|
||||||
|
unset(FORCE_CACHE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Default to building for iPhoneOS if not specified otherwise, and we cannot
|
||||||
|
# determine the platform from the CMAKE_OSX_ARCHITECTURES variable. The use
|
||||||
|
# of CMAKE_OSX_ARCHITECTURES is such that try_compile() projects can correctly
|
||||||
|
# determine the value of PLATFORM from the root project, as
|
||||||
|
# CMAKE_OSX_ARCHITECTURES is propagated to them by CMake.
|
||||||
|
if(NOT DEFINED PLATFORM)
|
||||||
|
if (CMAKE_OSX_ARCHITECTURES)
|
||||||
|
if(CMAKE_OSX_ARCHITECTURES MATCHES "arm64" AND CMAKE_OSX_SYSROOT MATCHES ".*iphoneos.*")
|
||||||
|
set(PLATFORM "OS64")
|
||||||
|
elseif(CMAKE_OSX_ARCHITECTURES MATCHES ".*arm.*" AND CMAKE_OSX_SYSROOT MATCHES ".*iphoneos.*")
|
||||||
|
set(PLATFORM "OS")
|
||||||
|
elseif(CMAKE_OSX_ARCHITECTURES MATCHES "i386" AND CMAKE_OSX_SYSROOT MATCHES ".*iphonesimulator.*")
|
||||||
|
set(PLATFORM "SIMULATOR")
|
||||||
|
elseif(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64" AND CMAKE_OSX_SYSROOT MATCHES ".*iphonesimulator.*")
|
||||||
|
set(PLATFORM "SIMULATOR64")
|
||||||
|
elseif(CMAKE_OSX_ARCHITECTURES MATCHES "arm64" AND CMAKE_OSX_SYSROOT MATCHES ".*appletvos.*")
|
||||||
|
set(PLATFORM "TVOS")
|
||||||
|
elseif(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64" AND CMAKE_OSX_SYSROOT MATCHES ".*appletvsimulator.*")
|
||||||
|
set(PLATFORM "SIMULATOR_TVOS")
|
||||||
|
elseif(CMAKE_OSX_ARCHITECTURES MATCHES ".*armv7k.*" AND CMAKE_OSX_SYSROOT MATCHES ".*watchos.*")
|
||||||
|
set(PLATFORM "WATCHOS")
|
||||||
|
elseif(CMAKE_OSX_ARCHITECTURES MATCHES "i386" AND CMAKE_OSX_SYSROOT MATCHES ".*watchsimulator.*")
|
||||||
|
set(PLATFORM "SIMULATOR_WATCHOS")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
if (NOT PLATFORM)
|
||||||
|
if(DROP_32_BIT)
|
||||||
|
set(PLATFORM "OS64")
|
||||||
|
else()
|
||||||
|
set(PLATFORM "OS")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(PLATFORM_INT "${PLATFORM}" CACHE STRING "Type of platform for which the build targets.")
|
||||||
|
|
||||||
|
# Handle the case where we are targeting iOS and a version above 10.3.4 (32-bit support dropped officially)
|
||||||
|
if(PLATFORM_INT STREQUAL "OS" AND DEPLOYMENT_TARGET VERSION_GREATER_EQUAL 10.3.4)
|
||||||
|
set(PLATFORM_INT "OS64")
|
||||||
|
message(STATUS "Targeting minimum SDK version ${DEPLOYMENT_TARGET}. Dropping 32-bit support.")
|
||||||
|
elseif(PLATFORM_INT STREQUAL "SIMULATOR" AND DEPLOYMENT_TARGET VERSION_GREATER_EQUAL 10.3.4)
|
||||||
|
set(PLATFORM_INT "SIMULATOR64")
|
||||||
|
message(STATUS "Targeting minimum SDK version ${DEPLOYMENT_TARGET}. Dropping 32-bit support.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Determine the platform name and architectures for use in xcodebuild commands
|
||||||
|
# from the specified PLATFORM name.
|
||||||
|
if(PLATFORM_INT STREQUAL "OS")
|
||||||
|
set(SDK_NAME iphoneos)
|
||||||
|
if(NOT ARCHS)
|
||||||
|
set(ARCHS armv7 armv7s arm64)
|
||||||
|
set(APPLE_TARGET_TRIPLE_INT arm-apple-ios)
|
||||||
|
endif()
|
||||||
|
elseif(PLATFORM_INT STREQUAL "OS64")
|
||||||
|
set(SDK_NAME iphoneos)
|
||||||
|
if(NOT ARCHS)
|
||||||
|
if (XCODE_VERSION VERSION_GREATER 10.0)
|
||||||
|
set(ARCHS arm64) # Add arm64e when Apple have fixed the integration issues with it, libarclite_iphoneos.a is currently missung bitcode markers for example
|
||||||
|
else()
|
||||||
|
set(ARCHS arm64)
|
||||||
|
endif()
|
||||||
|
set(APPLE_TARGET_TRIPLE_INT aarch64-apple-ios)
|
||||||
|
endif()
|
||||||
|
elseif(PLATFORM_INT STREQUAL "OS64COMBINED")
|
||||||
|
set(SDK_NAME iphoneos)
|
||||||
|
if(MODERN_CMAKE)
|
||||||
|
if(NOT ARCHS)
|
||||||
|
if (XCODE_VERSION VERSION_GREATER 10.0)
|
||||||
|
set(ARCHS arm64 x86_64) # Add arm64e when Apple have fixed the integration issues with it, libarclite_iphoneos.a is currently missung bitcode markers for example
|
||||||
|
else()
|
||||||
|
set(ARCHS arm64 x86_64)
|
||||||
|
endif()
|
||||||
|
set(APPLE_TARGET_TRIPLE_INT aarch64-x86_64-apple-ios)
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "Please make sure that you are running CMake 3.14+ to make the OS64COMBINED setting work")
|
||||||
|
endif()
|
||||||
|
elseif(PLATFORM_INT STREQUAL "SIMULATOR")
|
||||||
|
set(SDK_NAME iphonesimulator)
|
||||||
|
if(NOT ARCHS)
|
||||||
|
set(ARCHS i386)
|
||||||
|
set(APPLE_TARGET_TRIPLE_INT i386-apple-ios)
|
||||||
|
endif()
|
||||||
|
message(DEPRECATION "SIMULATOR IS DEPRECATED. Consider using SIMULATOR64 instead.")
|
||||||
|
elseif(PLATFORM_INT STREQUAL "SIMULATOR64")
|
||||||
|
set(SDK_NAME iphonesimulator)
|
||||||
|
if(NOT ARCHS)
|
||||||
|
set(ARCHS x86_64)
|
||||||
|
set(APPLE_TARGET_TRIPLE_INT x86_64-apple-ios)
|
||||||
|
endif()
|
||||||
|
elseif(PLATFORM_INT STREQUAL "TVOS")
|
||||||
|
set(SDK_NAME appletvos)
|
||||||
|
if(NOT ARCHS)
|
||||||
|
set(ARCHS arm64)
|
||||||
|
set(APPLE_TARGET_TRIPLE_INT aarch64-apple-tvos)
|
||||||
|
endif()
|
||||||
|
elseif (PLATFORM_INT STREQUAL "TVOSCOMBINED")
|
||||||
|
set(SDK_NAME appletvos)
|
||||||
|
if(MODERN_CMAKE)
|
||||||
|
if(NOT ARCHS)
|
||||||
|
set(ARCHS arm64 x86_64)
|
||||||
|
set(APPLE_TARGET_TRIPLE_INT aarch64-x86_64-apple-tvos)
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "Please make sure that you are running CMake 3.14+ to make the TVOSCOMBINED setting work")
|
||||||
|
endif()
|
||||||
|
elseif(PLATFORM_INT STREQUAL "SIMULATOR_TVOS")
|
||||||
|
set(SDK_NAME appletvsimulator)
|
||||||
|
if(NOT ARCHS)
|
||||||
|
set(ARCHS x86_64)
|
||||||
|
set(APPLE_TARGET_TRIPLE_INT x86_64-apple-tvos)
|
||||||
|
endif()
|
||||||
|
elseif(PLATFORM_INT STREQUAL "WATCHOS")
|
||||||
|
set(SDK_NAME watchos)
|
||||||
|
if(NOT ARCHS)
|
||||||
|
if (XCODE_VERSION VERSION_GREATER 10.0)
|
||||||
|
set(ARCHS armv7k arm64_32)
|
||||||
|
set(APPLE_TARGET_TRIPLE_INT aarch64_32-apple-watchos)
|
||||||
|
else()
|
||||||
|
set(ARCHS armv7k)
|
||||||
|
set(APPLE_TARGET_TRIPLE_INT arm-apple-watchos)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
elseif(PLATFORM_INT STREQUAL "WATCHOSCOMBINED")
|
||||||
|
set(SDK_NAME watchos)
|
||||||
|
if(MODERN_CMAKE)
|
||||||
|
if(NOT ARCHS)
|
||||||
|
if (XCODE_VERSION VERSION_GREATER 10.0)
|
||||||
|
set(ARCHS armv7k arm64_32 i386)
|
||||||
|
set(APPLE_TARGET_TRIPLE_INT aarch64_32-i386-apple-watchos)
|
||||||
|
else()
|
||||||
|
set(ARCHS armv7k i386)
|
||||||
|
set(APPLE_TARGET_TRIPLE_INT arm-i386-apple-watchos)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "Please make sure that you are running CMake 3.14+ to make the WATCHOSCOMBINED setting work")
|
||||||
|
endif()
|
||||||
|
elseif(PLATFORM_INT STREQUAL "SIMULATOR_WATCHOS")
|
||||||
|
set(SDK_NAME watchsimulator)
|
||||||
|
if(NOT ARCHS)
|
||||||
|
set(ARCHS i386)
|
||||||
|
set(APPLE_TARGET_TRIPLE_INT i386-apple-watchos)
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "Invalid PLATFORM: ${PLATFORM_INT}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(MODERN_CMAKE AND PLATFORM_INT MATCHES ".*COMBINED" AND NOT USED_CMAKE_GENERATOR MATCHES "Xcode")
|
||||||
|
message(FATAL_ERROR "The COMBINED options only work with Xcode generator, -G Xcode")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# If user did not specify the SDK root to use, then query xcodebuild for it.
|
||||||
|
execute_process(COMMAND xcodebuild -version -sdk ${SDK_NAME} Path
|
||||||
|
OUTPUT_VARIABLE CMAKE_OSX_SYSROOT_INT
|
||||||
|
ERROR_QUIET
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
if (NOT DEFINED CMAKE_OSX_SYSROOT_INT AND NOT DEFINED CMAKE_OSX_SYSROOT)
|
||||||
|
message(SEND_ERROR "Please make sure that Xcode is installed and that the toolchain"
|
||||||
|
"is pointing to the correct path. Please run:"
|
||||||
|
"sudo xcode-select -s /Applications/Xcode.app/Contents/Developer"
|
||||||
|
"and see if that fixes the problem for you.")
|
||||||
|
message(FATAL_ERROR "Invalid CMAKE_OSX_SYSROOT: ${CMAKE_OSX_SYSROOT} "
|
||||||
|
"does not exist.")
|
||||||
|
elseif(DEFINED CMAKE_OSX_SYSROOT_INT)
|
||||||
|
set(CMAKE_OSX_SYSROOT "${CMAKE_OSX_SYSROOT_INT}" CACHE INTERNAL "")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Set Xcode property for SDKROOT as well if Xcode generator is used
|
||||||
|
if(USED_CMAKE_GENERATOR MATCHES "Xcode")
|
||||||
|
set(CMAKE_OSX_SYSROOT "${SDK_NAME}" CACHE INTERNAL "")
|
||||||
|
if(NOT DEFINED CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM)
|
||||||
|
set(CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM "123456789A")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Specify minimum version of deployment target.
|
||||||
|
if(NOT DEFINED DEPLOYMENT_TARGET)
|
||||||
|
if (PLATFORM_INT STREQUAL "WATCHOS" OR PLATFORM_INT STREQUAL "SIMULATOR_WATCHOS")
|
||||||
|
# Unless specified, SDK version 2.0 is used by default as minimum target version (watchOS).
|
||||||
|
set(DEPLOYMENT_TARGET "2.0"
|
||||||
|
CACHE STRING "Minimum SDK version to build for." )
|
||||||
|
else()
|
||||||
|
# Unless specified, SDK version 9.0 is used by default as minimum target version (iOS, tvOS).
|
||||||
|
set(DEPLOYMENT_TARGET "9.0"
|
||||||
|
CACHE STRING "Minimum SDK version to build for." )
|
||||||
|
endif()
|
||||||
|
message(STATUS "Using the default min-version since DEPLOYMENT_TARGET not provided!")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Use bitcode or not
|
||||||
|
if(NOT DEFINED ENABLE_BITCODE AND NOT ARCHS MATCHES "((^|;|, )(i386|x86_64))+")
|
||||||
|
# Unless specified, enable bitcode support by default
|
||||||
|
message(STATUS "Enabling bitcode support by default. ENABLE_BITCODE not provided!")
|
||||||
|
set(ENABLE_BITCODE TRUE)
|
||||||
|
elseif(NOT DEFINED ENABLE_BITCODE)
|
||||||
|
message(STATUS "Disabling bitcode support by default on simulators. ENABLE_BITCODE not provided for override!")
|
||||||
|
set(ENABLE_BITCODE FALSE)
|
||||||
|
endif()
|
||||||
|
set(ENABLE_BITCODE_INT ${ENABLE_BITCODE} CACHE BOOL "Whether or not to enable bitcode" ${FORCE_CACHE})
|
||||||
|
# Use ARC or not
|
||||||
|
if(NOT DEFINED ENABLE_ARC)
|
||||||
|
# Unless specified, enable ARC support by default
|
||||||
|
set(ENABLE_ARC TRUE)
|
||||||
|
message(STATUS "Enabling ARC support by default. ENABLE_ARC not provided!")
|
||||||
|
endif()
|
||||||
|
set(ENABLE_ARC_INT ${ENABLE_ARC} CACHE BOOL "Whether or not to enable ARC" ${FORCE_CACHE})
|
||||||
|
# Use hidden visibility or not
|
||||||
|
if(NOT DEFINED ENABLE_VISIBILITY)
|
||||||
|
# Unless specified, disable symbols visibility by default
|
||||||
|
set(ENABLE_VISIBILITY FALSE)
|
||||||
|
message(STATUS "Hiding symbols visibility by default. ENABLE_VISIBILITY not provided!")
|
||||||
|
endif()
|
||||||
|
set(ENABLE_VISIBILITY_INT ${ENABLE_VISIBILITY} CACHE BOOL "Whether or not to hide symbols (-fvisibility=hidden)" ${FORCE_CACHE})
|
||||||
|
# Set strict compiler checks or not
|
||||||
|
if(NOT DEFINED ENABLE_STRICT_TRY_COMPILE)
|
||||||
|
# Unless specified, disable strict try_compile()
|
||||||
|
set(ENABLE_STRICT_TRY_COMPILE FALSE)
|
||||||
|
message(STATUS "Using NON-strict compiler checks by default. ENABLE_STRICT_TRY_COMPILE not provided!")
|
||||||
|
endif()
|
||||||
|
set(ENABLE_STRICT_TRY_COMPILE_INT ${ENABLE_STRICT_TRY_COMPILE} CACHE BOOL "Whether or not to use strict compiler checks" ${FORCE_CACHE})
|
||||||
|
# Get the SDK version information.
|
||||||
|
execute_process(COMMAND xcodebuild -sdk ${CMAKE_OSX_SYSROOT} -version SDKVersion
|
||||||
|
OUTPUT_VARIABLE SDK_VERSION
|
||||||
|
ERROR_QUIET
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
|
||||||
|
# Find the Developer root for the specific iOS platform being compiled for
|
||||||
|
# from CMAKE_OSX_SYSROOT. Should be ../../ from SDK specified in
|
||||||
|
# CMAKE_OSX_SYSROOT. There does not appear to be a direct way to obtain
|
||||||
|
# this information from xcrun or xcodebuild.
|
||||||
|
if (NOT DEFINED CMAKE_DEVELOPER_ROOT AND NOT USED_CMAKE_GENERATOR MATCHES "Xcode")
|
||||||
|
get_filename_component(PLATFORM_SDK_DIR ${CMAKE_OSX_SYSROOT} PATH)
|
||||||
|
get_filename_component(CMAKE_DEVELOPER_ROOT ${PLATFORM_SDK_DIR} PATH)
|
||||||
|
if (NOT DEFINED CMAKE_DEVELOPER_ROOT)
|
||||||
|
message(FATAL_ERROR "Invalid CMAKE_DEVELOPER_ROOT: "
|
||||||
|
"${CMAKE_DEVELOPER_ROOT} does not exist.")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
# Find the C & C++ compilers for the specified SDK.
|
||||||
|
if(NOT CMAKE_C_COMPILER)
|
||||||
|
execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find clang
|
||||||
|
OUTPUT_VARIABLE CMAKE_C_COMPILER
|
||||||
|
ERROR_QUIET
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
message(STATUS "Using C compiler: ${CMAKE_C_COMPILER}")
|
||||||
|
endif()
|
||||||
|
if(NOT CMAKE_CXX_COMPILER)
|
||||||
|
execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find clang++
|
||||||
|
OUTPUT_VARIABLE CMAKE_CXX_COMPILER
|
||||||
|
ERROR_QUIET
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
message(STATUS "Using CXX compiler: ${CMAKE_CXX_COMPILER}")
|
||||||
|
endif()
|
||||||
|
# Find (Apple's) libtool.
|
||||||
|
execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find libtool
|
||||||
|
OUTPUT_VARIABLE BUILD_LIBTOOL
|
||||||
|
ERROR_QUIET
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
message(STATUS "Using libtool: ${BUILD_LIBTOOL}")
|
||||||
|
# Configure libtool to be used instead of ar + ranlib to build static libraries.
|
||||||
|
# This is required on Xcode 7+, but should also work on previous versions of
|
||||||
|
# Xcode.
|
||||||
|
set(CMAKE_C_CREATE_STATIC_LIBRARY
|
||||||
|
"${BUILD_LIBTOOL} -static -o <TARGET> <LINK_FLAGS> <OBJECTS> ")
|
||||||
|
set(CMAKE_CXX_CREATE_STATIC_LIBRARY
|
||||||
|
"${BUILD_LIBTOOL} -static -o <TARGET> <LINK_FLAGS> <OBJECTS> ")
|
||||||
|
# Find the toolchain's provided install_name_tool if none is found on the host
|
||||||
|
if(NOT CMAKE_INSTALL_NAME_TOOL)
|
||||||
|
execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find install_name_tool
|
||||||
|
OUTPUT_VARIABLE CMAKE_INSTALL_NAME_TOOL_INT
|
||||||
|
ERROR_QUIET
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
set(CMAKE_INSTALL_NAME_TOOL ${CMAKE_INSTALL_NAME_TOOL_INT} CACHE STRING "" ${FORCE_CACHE})
|
||||||
|
endif()
|
||||||
|
# Get the version of Darwin (OS X) of the host.
|
||||||
|
execute_process(COMMAND uname -r
|
||||||
|
OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION
|
||||||
|
ERROR_QUIET
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
if(SDK_NAME MATCHES "iphone")
|
||||||
|
set(CMAKE_SYSTEM_NAME iOS CACHE INTERNAL "" ${FORCE_CACHE})
|
||||||
|
endif()
|
||||||
|
# CMake 3.14+ support building for iOS, watchOS and tvOS out of the box.
|
||||||
|
if(MODERN_CMAKE)
|
||||||
|
if(SDK_NAME MATCHES "appletv")
|
||||||
|
set(CMAKE_SYSTEM_NAME tvOS CACHE INTERNAL "" ${FORCE_CACHE})
|
||||||
|
elseif(SDK_NAME MATCHES "watch")
|
||||||
|
set(CMAKE_SYSTEM_NAME watchOS CACHE INTERNAL "" ${FORCE_CACHE})
|
||||||
|
endif()
|
||||||
|
# Provide flags for a combined FAT library build on newer CMake versions
|
||||||
|
if(PLATFORM_INT MATCHES ".*COMBINED")
|
||||||
|
set(CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH "NO")
|
||||||
|
set(CMAKE_IOS_INSTALL_COMBINED YES CACHE INTERNAL "" ${FORCE_CACHE})
|
||||||
|
message(STATUS "Will combine built (static) artifacts into FAT lib...")
|
||||||
|
endif()
|
||||||
|
elseif(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.10")
|
||||||
|
# Legacy code path prior to CMake 3.14 or fallback if no SDK_NAME specified
|
||||||
|
set(CMAKE_SYSTEM_NAME iOS CACHE INTERNAL "" ${FORCE_CACHE})
|
||||||
|
else()
|
||||||
|
# Legacy code path prior to CMake 3.14 or fallback if no SDK_NAME specified
|
||||||
|
set(CMAKE_SYSTEM_NAME Darwin CACHE INTERNAL "" ${FORCE_CACHE})
|
||||||
|
endif()
|
||||||
|
# Standard settings.
|
||||||
|
set(CMAKE_SYSTEM_VERSION ${SDK_VERSION} CACHE INTERNAL "")
|
||||||
|
set(UNIX TRUE CACHE BOOL "")
|
||||||
|
set(APPLE TRUE CACHE BOOL "")
|
||||||
|
set(IOS TRUE CACHE BOOL "")
|
||||||
|
set(CMAKE_AR ar CACHE FILEPATH "" FORCE)
|
||||||
|
set(CMAKE_RANLIB ranlib CACHE FILEPATH "" FORCE)
|
||||||
|
set(CMAKE_STRIP strip CACHE FILEPATH "" FORCE)
|
||||||
|
# Set the architectures for which to build.
|
||||||
|
set(CMAKE_OSX_ARCHITECTURES ${ARCHS} CACHE STRING "Build architecture for iOS")
|
||||||
|
# Change the type of target generated for try_compile() so it'll work when cross-compiling, weak compiler checks
|
||||||
|
if(ENABLE_STRICT_TRY_COMPILE_INT)
|
||||||
|
message(STATUS "Using strict compiler checks (default in CMake).")
|
||||||
|
else()
|
||||||
|
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
|
||||||
|
endif()
|
||||||
|
# All iOS/Darwin specific settings - some may be redundant.
|
||||||
|
set(CMAKE_MACOSX_BUNDLE YES)
|
||||||
|
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO")
|
||||||
|
set(CMAKE_SHARED_LIBRARY_PREFIX "lib")
|
||||||
|
set(CMAKE_SHARED_LIBRARY_SUFFIX ".dylib")
|
||||||
|
set(CMAKE_SHARED_MODULE_PREFIX "lib")
|
||||||
|
set(CMAKE_SHARED_MODULE_SUFFIX ".so")
|
||||||
|
set(CMAKE_C_COMPILER_ABI ELF)
|
||||||
|
set(CMAKE_CXX_COMPILER_ABI ELF)
|
||||||
|
set(CMAKE_C_HAS_ISYSROOT 1)
|
||||||
|
set(CMAKE_CXX_HAS_ISYSROOT 1)
|
||||||
|
set(CMAKE_MODULE_EXISTS 1)
|
||||||
|
set(CMAKE_DL_LIBS "")
|
||||||
|
set(CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG "-compatibility_version ")
|
||||||
|
set(CMAKE_C_OSX_CURRENT_VERSION_FLAG "-current_version ")
|
||||||
|
set(CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}")
|
||||||
|
set(CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}")
|
||||||
|
|
||||||
|
if(ARCHS MATCHES "((^|;|, )(arm64|arm64e|x86_64))+")
|
||||||
|
set(CMAKE_C_SIZEOF_DATA_PTR 8)
|
||||||
|
set(CMAKE_CXX_SIZEOF_DATA_PTR 8)
|
||||||
|
if(ARCHS MATCHES "((^|;|, )(arm64|arm64e))+")
|
||||||
|
set(CMAKE_SYSTEM_PROCESSOR "aarch64")
|
||||||
|
else()
|
||||||
|
set(CMAKE_SYSTEM_PROCESSOR "x86_64")
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
set(CMAKE_C_SIZEOF_DATA_PTR 4)
|
||||||
|
set(CMAKE_CXX_SIZEOF_DATA_PTR 4)
|
||||||
|
set(CMAKE_SYSTEM_PROCESSOR "arm")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Note that only Xcode 7+ supports the newer more specific:
|
||||||
|
# -m${SDK_NAME}-version-min flags, older versions of Xcode use:
|
||||||
|
# -m(ios/ios-simulator)-version-min instead.
|
||||||
|
if(${CMAKE_VERSION} VERSION_LESS "3.11")
|
||||||
|
if(PLATFORM_INT STREQUAL "OS" OR PLATFORM_INT STREQUAL "OS64")
|
||||||
|
if(XCODE_VERSION VERSION_LESS 7.0)
|
||||||
|
set(SDK_NAME_VERSION_FLAGS
|
||||||
|
"-mios-version-min=${DEPLOYMENT_TARGET}")
|
||||||
|
else()
|
||||||
|
# Xcode 7.0+ uses flags we can build directly from SDK_NAME.
|
||||||
|
set(SDK_NAME_VERSION_FLAGS
|
||||||
|
"-m${SDK_NAME}-version-min=${DEPLOYMENT_TARGET}")
|
||||||
|
endif()
|
||||||
|
elseif(PLATFORM_INT STREQUAL "TVOS")
|
||||||
|
set(SDK_NAME_VERSION_FLAGS
|
||||||
|
"-mtvos-version-min=${DEPLOYMENT_TARGET}")
|
||||||
|
elseif(PLATFORM_INT STREQUAL "SIMULATOR_TVOS")
|
||||||
|
set(SDK_NAME_VERSION_FLAGS
|
||||||
|
"-mtvos-simulator-version-min=${DEPLOYMENT_TARGET}")
|
||||||
|
elseif(PLATFORM_INT STREQUAL "WATCHOS")
|
||||||
|
set(SDK_NAME_VERSION_FLAGS
|
||||||
|
"-mwatchos-version-min=${DEPLOYMENT_TARGET}")
|
||||||
|
elseif(PLATFORM_INT STREQUAL "SIMULATOR_WATCHOS")
|
||||||
|
set(SDK_NAME_VERSION_FLAGS
|
||||||
|
"-mwatchos-simulator-version-min=${DEPLOYMENT_TARGET}")
|
||||||
|
else()
|
||||||
|
# SIMULATOR or SIMULATOR64 both use -mios-simulator-version-min.
|
||||||
|
set(SDK_NAME_VERSION_FLAGS
|
||||||
|
"-mios-simulator-version-min=${DEPLOYMENT_TARGET}")
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
# Newer versions of CMake sets the version min flags correctly
|
||||||
|
set(CMAKE_OSX_DEPLOYMENT_TARGET ${DEPLOYMENT_TARGET} CACHE STRING
|
||||||
|
"Set CMake deployment target" ${FORCE_CACHE})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(DEFINED APPLE_TARGET_TRIPLE_INT)
|
||||||
|
set(APPLE_TARGET_TRIPLE ${APPLE_TARGET_TRIPLE_INT} CACHE STRING
|
||||||
|
"Autoconf target triple compatible variable" ${FORCE_CACHE})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(ENABLE_BITCODE_INT)
|
||||||
|
set(BITCODE "-fembed-bitcode")
|
||||||
|
set(CMAKE_XCODE_ATTRIBUTE_BITCODE_GENERATION_MODE "bitcode")
|
||||||
|
set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE "YES")
|
||||||
|
else()
|
||||||
|
set(BITCODE "")
|
||||||
|
set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE "NO")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(ENABLE_ARC_INT)
|
||||||
|
set(FOBJC_ARC "-fobjc-arc")
|
||||||
|
set(CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC "YES")
|
||||||
|
else()
|
||||||
|
set(FOBJC_ARC "-fno-objc-arc")
|
||||||
|
set(CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC "NO")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT ENABLE_VISIBILITY_INT)
|
||||||
|
set(VISIBILITY "-fvisibility=hidden")
|
||||||
|
set(CMAKE_XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN "YES")
|
||||||
|
else()
|
||||||
|
set(VISIBILITY "")
|
||||||
|
set(CMAKE_XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN "NO")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT IOS_TOOLCHAIN_HAS_RUN)
|
||||||
|
#Check if Xcode generator is used, since that will handle these flags automagically
|
||||||
|
if(USED_CMAKE_GENERATOR MATCHES "Xcode")
|
||||||
|
message(STATUS "Not setting any manual command-line buildflags, since Xcode is selected as generator.")
|
||||||
|
else()
|
||||||
|
set(CMAKE_C_FLAGS
|
||||||
|
"${SDK_NAME_VERSION_FLAGS} ${BITCODE} -fobjc-abi-version=2 ${FOBJC_ARC} ${CMAKE_C_FLAGS}")
|
||||||
|
# Hidden visibilty is required for C++ on iOS.
|
||||||
|
set(CMAKE_CXX_FLAGS
|
||||||
|
"${SDK_NAME_VERSION_FLAGS} ${BITCODE} ${VISIBILITY} -fvisibility-inlines-hidden -fobjc-abi-version=2 ${FOBJC_ARC} ${CMAKE_CXX_FLAGS}")
|
||||||
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -O0 -g ${CMAKE_CXX_FLAGS_DEBUG}")
|
||||||
|
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS} -DNDEBUG -Os -ffast-math ${CMAKE_CXX_FLAGS_MINSIZEREL}")
|
||||||
|
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS} -DNDEBUG -O2 -g -ffast-math ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
|
||||||
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -DNDEBUG -O3 -ffast-math ${CMAKE_CXX_FLAGS_RELEASE}")
|
||||||
|
set(CMAKE_C_LINK_FLAGS "${SDK_NAME_VERSION_FLAGS} -Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}")
|
||||||
|
set(CMAKE_CXX_LINK_FLAGS "${SDK_NAME_VERSION_FLAGS} -Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}")
|
||||||
|
set(CMAKE_ASM_FLAGS "${CFLAGS} -x assembler-with-cpp -arch ${CMAKE_OSX_ARCHITECTURES}")
|
||||||
|
|
||||||
|
# In order to ensure that the updated compiler flags are used in try_compile()
|
||||||
|
# tests, we have to forcibly set them in the CMake cache, not merely set them
|
||||||
|
# in the local scope.
|
||||||
|
set(VARS_TO_FORCE_IN_CACHE
|
||||||
|
CMAKE_C_FLAGS
|
||||||
|
CMAKE_CXX_FLAGS
|
||||||
|
CMAKE_CXX_FLAGS_DEBUG
|
||||||
|
CMAKE_CXX_FLAGS_RELWITHDEBINFO
|
||||||
|
CMAKE_CXX_FLAGS_MINSIZEREL
|
||||||
|
CMAKE_CXX_FLAGS_RELEASE
|
||||||
|
CMAKE_C_LINK_FLAGS
|
||||||
|
CMAKE_CXX_LINK_FLAGS)
|
||||||
|
foreach(VAR_TO_FORCE ${VARS_TO_FORCE_IN_CACHE})
|
||||||
|
set(${VAR_TO_FORCE} "${${VAR_TO_FORCE}}" CACHE STRING "" ${FORCE_CACHE})
|
||||||
|
endforeach()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
## Print status messages to inform of the current state
|
||||||
|
message(STATUS "Configuring ${SDK_NAME} build for platform: ${PLATFORM_INT}, architecture(s): ${ARCHS}")
|
||||||
|
message(STATUS "Using SDK: ${CMAKE_OSX_SYSROOT_INT}")
|
||||||
|
if(DEFINED APPLE_TARGET_TRIPLE)
|
||||||
|
message(STATUS "Autoconf target triple: ${APPLE_TARGET_TRIPLE}")
|
||||||
|
endif()
|
||||||
|
message(STATUS "Using minimum deployment version: ${DEPLOYMENT_TARGET}"
|
||||||
|
" (SDK version: ${SDK_VERSION})")
|
||||||
|
if(MODERN_CMAKE)
|
||||||
|
message(STATUS "Merging integrated CMake 3.14+ iOS,tvOS,watchOS,macOS toolchain(s) with this toolchain!")
|
||||||
|
endif()
|
||||||
|
if(USED_CMAKE_GENERATOR MATCHES "Xcode")
|
||||||
|
message(STATUS "Using Xcode version: ${XCODE_VERSION}")
|
||||||
|
endif()
|
||||||
|
if(DEFINED SDK_NAME_VERSION_FLAGS)
|
||||||
|
message(STATUS "Using version flags: ${SDK_NAME_VERSION_FLAGS}")
|
||||||
|
endif()
|
||||||
|
message(STATUS "Using a data_ptr size of: ${CMAKE_CXX_SIZEOF_DATA_PTR}")
|
||||||
|
message(STATUS "Using install_name_tool: ${CMAKE_INSTALL_NAME_TOOL}")
|
||||||
|
if(ENABLE_BITCODE_INT)
|
||||||
|
message(STATUS "Enabling bitcode support.")
|
||||||
|
else()
|
||||||
|
message(STATUS "Disabling bitcode support.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(ENABLE_ARC_INT)
|
||||||
|
message(STATUS "Enabling ARC support.")
|
||||||
|
else()
|
||||||
|
message(STATUS "Disabling ARC support.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT ENABLE_VISIBILITY_INT)
|
||||||
|
message(STATUS "Hiding symbols (-fvisibility=hidden).")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(CMAKE_PLATFORM_HAS_INSTALLNAME 1)
|
||||||
|
set(CMAKE_SHARED_LINKER_FLAGS "-rpath @executable_path/Frameworks -rpath @loader_path/Frameworks")
|
||||||
|
set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-dynamiclib -Wl,-headerpad_max_install_names")
|
||||||
|
set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle -Wl,-headerpad_max_install_names")
|
||||||
|
set(CMAKE_SHARED_MODULE_LOADER_C_FLAG "-Wl,-bundle_loader,")
|
||||||
|
set(CMAKE_SHARED_MODULE_LOADER_CXX_FLAG "-Wl,-bundle_loader,")
|
||||||
|
set(CMAKE_FIND_LIBRARY_SUFFIXES ".tbd" ".dylib" ".so" ".a")
|
||||||
|
set(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-install_name")
|
||||||
|
|
||||||
|
# Set the find root to the iOS developer roots and to user defined paths.
|
||||||
|
set(CMAKE_FIND_ROOT_PATH ${CMAKE_OSX_SYSROOT_INT} ${CMAKE_PREFIX_PATH} CACHE STRING "Root path that will be prepended
|
||||||
|
to all search paths")
|
||||||
|
# Default to searching for frameworks first.
|
||||||
|
set(CMAKE_FIND_FRAMEWORK FIRST)
|
||||||
|
# Set up the default search directories for frameworks.
|
||||||
|
set(CMAKE_FRAMEWORK_PATH
|
||||||
|
${CMAKE_DEVELOPER_ROOT}/Library/PrivateFrameworks
|
||||||
|
${CMAKE_OSX_SYSROOT_INT}/System/Library/Frameworks
|
||||||
|
${CMAKE_FRAMEWORK_PATH} CACHE STRING "Frameworks search paths" ${FORCE_CACHE})
|
||||||
|
|
||||||
|
set(IOS_TOOLCHAIN_HAS_RUN TRUE CACHE BOOL "Has the CMake toolchain run already?" ${FORCE_CACHE})
|
||||||
|
|
||||||
|
# By default, search both the specified iOS SDK and the remainder of the host filesystem.
|
||||||
|
if(NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM)
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH CACHE STRING "" ${FORCE_CACHE})
|
||||||
|
endif()
|
||||||
|
if(NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY)
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH CACHE STRING "" ${FORCE_CACHE})
|
||||||
|
endif()
|
||||||
|
if(NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE)
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH CACHE STRING "" ${FORCE_CACHE})
|
||||||
|
endif()
|
||||||
|
if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE)
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH CACHE STRING "" ${FORCE_CACHE})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
#
|
||||||
|
# Some helper-macros below to simplify and beautify the CMakeFile
|
||||||
|
#
|
||||||
|
|
||||||
|
# This little macro lets you set any Xcode specific property.
|
||||||
|
macro(set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE XCODE_RELVERSION)
|
||||||
|
set(XCODE_RELVERSION_I "${XCODE_RELVERSION}")
|
||||||
|
if(XCODE_RELVERSION_I STREQUAL "All")
|
||||||
|
set_property(TARGET ${TARGET} PROPERTY
|
||||||
|
XCODE_ATTRIBUTE_${XCODE_PROPERTY} "${XCODE_VALUE}")
|
||||||
|
else()
|
||||||
|
set_property(TARGET ${TARGET} PROPERTY
|
||||||
|
XCODE_ATTRIBUTE_${XCODE_PROPERTY}[variant=${XCODE_RELVERSION_I}] "${XCODE_VALUE}")
|
||||||
|
endif()
|
||||||
|
endmacro(set_xcode_property)
|
||||||
|
|
||||||
|
# This macro lets you find executable programs on the host system.
|
||||||
|
macro(find_host_package)
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE NEVER)
|
||||||
|
set(IOS FALSE)
|
||||||
|
find_package(${ARGN})
|
||||||
|
set(IOS TRUE)
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH)
|
||||||
|
endmacro(find_host_package)
|
@ -18,7 +18,7 @@ set(LIB_LIEF
|
|||||||
set(LIEF_GIT_URL "https://github.com/lief-project/LIEF.git")
|
set(LIEF_GIT_URL "https://github.com/lief-project/LIEF.git")
|
||||||
|
|
||||||
# LIEF's version to be used (can be 'master')
|
# LIEF's version to be used (can be 'master')
|
||||||
set(LIEF_VERSION 0.10.1)
|
set(LIEF_VERSION 0.11.0)
|
||||||
|
|
||||||
# LIEF compilation config
|
# LIEF compilation config
|
||||||
set(LIEF_CMAKE_ARGS
|
set(LIEF_CMAKE_ARGS
|
||||||
@ -31,12 +31,12 @@ set(LIEF_CMAKE_ARGS
|
|||||||
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
|
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
|
||||||
)
|
)
|
||||||
|
|
||||||
if (MSVC)
|
if(MSVC)
|
||||||
list(APPEND ${LIEF_CMAKE_ARGS} -DLIEF_USE_CRT_RELEASE=MT)
|
list(APPEND ${LIEF_CMAKE_ARGS} -DLIEF_USE_CRT_RELEASE=MT)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
ExternalProject_Add(LIEF
|
ExternalProject_Add(LIEF
|
||||||
PREFIX "${PACKER_LIEF_PREFIX}"
|
PREFIX "${LIEF_PREFIX}"
|
||||||
GIT_REPOSITORY ${LIEF_GIT_URL}
|
GIT_REPOSITORY ${LIEF_GIT_URL}
|
||||||
GIT_TAG ${LIEF_VERSION}
|
GIT_TAG ${LIEF_VERSION}
|
||||||
INSTALL_DIR ${LIEF_INSTALL_DIR}
|
INSTALL_DIR ${LIEF_INSTALL_DIR}
|
||||||
@ -50,7 +50,7 @@ ExternalProject_Add(LIEF
|
|||||||
# ==================
|
# ==================
|
||||||
add_executable(HelloLIEF main.cpp)
|
add_executable(HelloLIEF main.cpp)
|
||||||
|
|
||||||
if (MSVC)
|
if(MSVC)
|
||||||
# Used for the 'and', 'or' ... keywords - See: http://www.cplusplus.com/reference/ciso646/
|
# Used for the 'and', 'or' ... keywords - See: http://www.cplusplus.com/reference/ciso646/
|
||||||
target_compile_options(HelloLIEF PUBLIC /FIiso646.h)
|
target_compile_options(HelloLIEF PUBLIC /FIiso646.h)
|
||||||
set_property(TARGET HelloLIEF PROPERTY LINK_FLAGS /NODEFAULTLIB:MSVCRT)
|
set_property(TARGET HelloLIEF PROPERTY LINK_FLAGS /NODEFAULTLIB:MSVCRT)
|
||||||
@ -63,8 +63,9 @@ target_include_directories(HelloLIEF
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Enable C++11
|
# Enable C++11
|
||||||
set_property(TARGET HelloLIEF PROPERTY CXX_STANDARD 11)
|
set_property(TARGET HelloLIEF
|
||||||
set_property(TARGET HelloLIEF PROPERTY CXX_STANDARD_REQUIRED ON)
|
PROPERTY CXX_STANDARD 11
|
||||||
|
CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
# Link the executable with LIEF
|
# Link the executable with LIEF
|
||||||
target_link_libraries(HelloLIEF PUBLIC ${LIB_LIEF})
|
target_link_libraries(HelloLIEF PUBLIC ${LIB_LIEF})
|
||||||
|
@ -6,10 +6,10 @@ project(CMakeLIEF)
|
|||||||
# ==============================
|
# ==============================
|
||||||
|
|
||||||
# Custom path to the LIEF install directory
|
# Custom path to the LIEF install directory
|
||||||
set(LIEF_ROOT CACHE PATH ${CMAKE_INSTALL_PREFIX})
|
set(LIEF_INSTALL_PATH CACHE PATH ${CMAKE_INSTALL_PREFIX})
|
||||||
|
|
||||||
# Directory to 'FindLIEF.cmake'
|
# Directory to 'FindLIEF.cmake'
|
||||||
list(APPEND CMAKE_MODULE_PATH ${LIEF_ROOT}/share/LIEF/cmake)
|
list(APPEND CMAKE_MODULE_PATH ${LIEF_INSTALL_PATH}/share/LIEF/cmake)
|
||||||
|
|
||||||
# include 'FindLIEF.cmake'
|
# include 'FindLIEF.cmake'
|
||||||
include(FindLIEF)
|
include(FindLIEF)
|
||||||
@ -17,16 +17,20 @@ include(FindLIEF)
|
|||||||
# Find LIEF
|
# Find LIEF
|
||||||
find_package(LIEF REQUIRED COMPONENTS STATIC) # COMPONENTS: <SHARED | STATIC> - Default: STATIC
|
find_package(LIEF REQUIRED COMPONENTS STATIC) # COMPONENTS: <SHARED | STATIC> - Default: STATIC
|
||||||
|
|
||||||
|
message(STATUS "LIEF include directory: ${LIEF_INCLUDE_DIRS}")
|
||||||
|
message(STATUS "LIEF library: ${LIEF_LIBRARIES}")
|
||||||
|
|
||||||
# Add our executable
|
# Add our executable
|
||||||
# ==================
|
# ==================
|
||||||
add_executable(HelloLIEF main.cpp)
|
add_executable(HelloLIEF main.cpp)
|
||||||
|
|
||||||
if (MSVC)
|
if(MSVC)
|
||||||
# Used for the 'and', 'or' ... keywords - See: http://www.cplusplus.com/reference/ciso646/
|
# Used for the 'and', 'or' ... keywords - See: http://www.cplusplus.com/reference/ciso646/
|
||||||
target_compile_options(HelloLIEF PUBLIC /FIiso646.h)
|
target_compile_options(HelloLIEF PUBLIC /FIiso646.h)
|
||||||
set_property(TARGET HelloLIEF PROPERTY LINK_FLAGS /NODEFAULTLIB:MSVCRT)
|
set_property(TARGET HelloLIEF PROPERTY LINK_FLAGS /NODEFAULTLIB:MSVCRT)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
# Setup the LIEF include directory
|
# Setup the LIEF include directory
|
||||||
target_include_directories(HelloLIEF
|
target_include_directories(HelloLIEF
|
||||||
PUBLIC
|
PUBLIC
|
||||||
@ -34,8 +38,9 @@ target_include_directories(HelloLIEF
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Enable C++11
|
# Enable C++11
|
||||||
set_property(TARGET HelloLIEF PROPERTY CXX_STANDARD 11)
|
set_property(TARGET HelloLIEF
|
||||||
set_property(TARGET HelloLIEF PROPERTY CXX_STANDARD_REQUIRED ON)
|
PROPERTY CXX_STANDARD 11
|
||||||
|
PROPERTY CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
# Link the executable with LIEF
|
# Link the executable with LIEF
|
||||||
target_link_libraries(HelloLIEF PUBLIC ${LIEF_LIBRARIES})
|
target_link_libraries(HelloLIEF PUBLIC ${LIEF_LIBRARIES})
|
||||||
|
@ -67,7 +67,6 @@ if (LIEF_DEX)
|
|||||||
set(LIEF_CPP_EXAMPLES ${LIEF_CPP_EXAMPLES} ${LIEF_DEX_CPP_EXAMPLES})
|
set(LIEF_CPP_EXAMPLES ${LIEF_CPP_EXAMPLES} ${LIEF_DEX_CPP_EXAMPLES})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
foreach(example ${LIEF_CPP_EXAMPLES})
|
foreach(example ${LIEF_CPP_EXAMPLES})
|
||||||
string(REGEX REPLACE ".cpp\$" "" output_name "${example}")
|
string(REGEX REPLACE ".cpp\$" "" output_name "${example}")
|
||||||
add_executable("${output_name}" "${example}")
|
add_executable("${output_name}" "${example}")
|
||||||
@ -83,8 +82,11 @@ foreach(example ${LIEF_CPP_EXAMPLES})
|
|||||||
target_compile_options("${output_name}" PUBLIC ${LIEF_CRT})
|
target_compile_options("${output_name}" PUBLIC ${LIEF_CRT})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set_property(TARGET "${output_name}" PROPERTY CXX_STANDARD 11)
|
set_target_properties(
|
||||||
set_property(TARGET "${output_name}" PROPERTY CXX_STANDARD_REQUIRED ON)
|
${output_name}
|
||||||
|
PROPERTIES POSITION_INDEPENDENT_CODE ON
|
||||||
|
CXX_STANDARD 11
|
||||||
|
CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||||
if (UNIX)
|
if (UNIX)
|
||||||
@ -97,6 +99,33 @@ foreach(example ${LIEF_CPP_EXAMPLES})
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_link_libraries("${output_name}" PUBLIC LIB_LIEF)
|
target_link_libraries("${output_name}" PUBLIC LIB_LIEF)
|
||||||
|
|
||||||
|
if (CMAKE_BUILD_TYPE MATCHES "Release")
|
||||||
|
if (UNIX AND NOT APPLE)
|
||||||
|
add_custom_command(
|
||||||
|
TARGET ${output_name}
|
||||||
|
COMMENT "Strip ${output_name}"
|
||||||
|
POST_BUILD
|
||||||
|
COMMAND ${CMAKE_STRIP} --strip-all $<TARGET_FILE:${output_name}>
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (APPLE)
|
||||||
|
add_custom_command(
|
||||||
|
TARGET ${output_name}
|
||||||
|
COMMENT "Strip ${output_name}"
|
||||||
|
POST_BUILD
|
||||||
|
COMMAND ${CMAKE_STRIP} -x -S $<TARGET_FILE:${output_name}>
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
if(LIEF_INSTALL_COMPILED_EXAMPLES)
|
||||||
|
install(
|
||||||
|
TARGETS ${output_name}
|
||||||
|
RUNTIME DESTINATION bin
|
||||||
|
BUNDLE DESTINATION bin
|
||||||
|
COMPONENT examples)
|
||||||
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
|
|
||||||
@ -107,3 +136,4 @@ install(
|
|||||||
FILES_MATCHING REGEX "(.*).(hpp|h|cpp)$"
|
FILES_MATCHING REGEX "(.*).(hpp|h|cpp)$"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ class LIEF_API Parser : public LIEF::Parser {
|
|||||||
//! @param[in] count_mtd Method used to count dynamic symbols. Default: LIEF::ELF::DYNSYM_COUNT_METHODS::COUNT_AUTO
|
//! @param[in] count_mtd Method used to count dynamic symbols. Default: LIEF::ELF::DYNSYM_COUNT_METHODS::COUNT_AUTO
|
||||||
//!
|
//!
|
||||||
//! @return LIEF::ELF::Binary
|
//! @return LIEF::ELF::Binary
|
||||||
LIEF_API static std::unique_ptr<Binary> parse(const std::string& file, DYNSYM_COUNT_METHODS count_mtd = DYNSYM_COUNT_METHODS::COUNT_AUTO);
|
static std::unique_ptr<Binary> parse(const std::string& file, DYNSYM_COUNT_METHODS count_mtd = DYNSYM_COUNT_METHODS::COUNT_AUTO);
|
||||||
|
|
||||||
//! Parse the given raw data as an ELF binary and return a LIEF::ELF::Binary object
|
//! Parse the given raw data as an ELF binary and return a LIEF::ELF::Binary object
|
||||||
//!
|
//!
|
||||||
@ -74,7 +74,7 @@ class LIEF_API Parser : public LIEF::Parser {
|
|||||||
//! @param[in] count_mtd Method used to count dynamic symbols. Default: LIEF::ELF::DYNSYM_COUNT_METHODS::COUNT_AUTO
|
//! @param[in] count_mtd Method used to count dynamic symbols. Default: LIEF::ELF::DYNSYM_COUNT_METHODS::COUNT_AUTO
|
||||||
//!
|
//!
|
||||||
//! @return LIEF::ELF::Binary
|
//! @return LIEF::ELF::Binary
|
||||||
LIEF_API static std::unique_ptr<Binary> parse(const std::vector<uint8_t>& data, const std::string& name = "", DYNSYM_COUNT_METHODS count_mtd = DYNSYM_COUNT_METHODS::COUNT_AUTO);
|
static std::unique_ptr<Binary> parse(const std::vector<uint8_t>& data, const std::string& name = "", DYNSYM_COUNT_METHODS count_mtd = DYNSYM_COUNT_METHODS::COUNT_AUTO);
|
||||||
|
|
||||||
Parser& operator=(const Parser&) = delete;
|
Parser& operator=(const Parser&) = delete;
|
||||||
Parser(const Parser&) = delete;
|
Parser(const Parser&) = delete;
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include "LIEF/PE/TLS.hpp"
|
#include "LIEF/PE/TLS.hpp"
|
||||||
#include "LIEF/PE/Export.hpp"
|
#include "LIEF/PE/Export.hpp"
|
||||||
#include "LIEF/PE/Debug.hpp"
|
#include "LIEF/PE/Debug.hpp"
|
||||||
|
#include "LIEF/PE/Symbol.hpp"
|
||||||
#include "LIEF/PE/signature/Signature.hpp"
|
#include "LIEF/PE/signature/Signature.hpp"
|
||||||
|
|
||||||
#include "LIEF/Abstract/Binary.hpp"
|
#include "LIEF/Abstract/Binary.hpp"
|
||||||
|
@ -1,29 +1,30 @@
|
|||||||
set(CPACK_PACKAGE_NAME "LIEF")
|
set(CPACK_PACKAGE_NAME "LIEF")
|
||||||
set(CPACK_PACKAGE_VENDOR "Quarkslab")
|
set(CPACK_PACKAGE_VENDOR "Quarkslab")
|
||||||
|
|
||||||
set(CPACK_PACKAGE_VERSION_MAJOR "${LIEF_VERSION_MAJOR}")
|
set(CPACK_PACKAGE_VERSION_MAJOR "${LIEF_VERSION_MAJOR}")
|
||||||
set(CPACK_PACKAGE_VERSION_MINOR "${LIEF_VERSION_MINOR}")
|
set(CPACK_PACKAGE_VERSION_MINOR "${LIEF_VERSION_MINOR}")
|
||||||
set(CPACK_PACKAGE_VERSION_PATCH "${LIEF_VERSION_PATCH}")
|
set(CPACK_PACKAGE_VERSION_PATCH "${LIEF_VERSION_PATCH}")
|
||||||
|
set(CPACK_PACKAGE_VERSION "${LIEF_VERSION_MAJOR}.${LIEF_VERSION_MINOR}.${LIEF_VERSION_PATCH}")
|
||||||
|
|
||||||
set(CPACK_SYSTEM_NAME ${PLATFORM})
|
|
||||||
set(CPACK_PACKAGE_CONTACT "rthomas@quarkslab.com")
|
set(CPACK_PACKAGE_CONTACT "rthomas@quarkslab.com")
|
||||||
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "LIEF - Library to Instrument Executable Formats")
|
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "LIEF - Library to Instrument Executable Formats")
|
||||||
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
|
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
|
||||||
set(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_CURRENT_SOURCE_DIR}/Welcome")
|
set(CPACK_PACKAGE_HOMEPAGE_URL "https://lief.quarkslab.com")
|
||||||
|
|
||||||
|
if (UNIX)
|
||||||
|
set(CPACK_SYSTEM_NAME "${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
|
||||||
|
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME}")
|
||||||
|
endif()
|
||||||
|
|
||||||
if (UNIX AND NOT APPLE)
|
if(UNIX AND NOT APPLE) # Linux
|
||||||
#set(CPACK_GENERATOR "TGZ;STGZ;DEB")
|
|
||||||
set(CPACK_GENERATOR "TGZ")
|
set(CPACK_GENERATOR "TGZ")
|
||||||
set(CPACK_SOURCE_GENERATOR "TGZ")
|
set(CPACK_SOURCE_GENERATOR "TGZ")
|
||||||
#set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Romain Thomas")
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (UNIX AND APPLE)
|
if(UNIX AND APPLE) # OSX / iOS
|
||||||
set(CPACK_GENERATOR "TGZ")
|
set(CPACK_GENERATOR "TGZ")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (WIN32)
|
if(WIN32) # Windows
|
||||||
set(CPACK_GENERATOR "ZIP")
|
set(CPACK_GENERATOR "ZIP")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
@ -31,25 +31,31 @@
|
|||||||
# Hints
|
# Hints
|
||||||
# ^^^^^
|
# ^^^^^
|
||||||
#
|
#
|
||||||
# A user may set ``LIEF_ROOT`` to a LIEF installation root to tell this
|
# A user may set ``LIEF_INSTALL_PATH`` to a LIEF installation root to tell this
|
||||||
# module where to look.
|
# module where to look.
|
||||||
#
|
#
|
||||||
# To choose between STATIC and SHARED version of LIEF library, one
|
# To choose between STATIC and SHARED version of LIEF library, one
|
||||||
# can use ``COMPONENTS STATIC`` of ``COMPONENTS SHARED``
|
# can use ``COMPONENTS STATIC`` of ``COMPONENTS SHARED``
|
||||||
#
|
#
|
||||||
# .. code-block:: cmake
|
# .. code-block:: cmake
|
||||||
#
|
#
|
||||||
# find_package(LIEF 0.8.0 REQUIRED COMPONENTS STATIC)
|
# find_package(LIEF 0.11.0 REQUIRED COMPONENTS STATIC)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
set(_LIEF_SEARCHES)
|
set(_LIEF_SEARCHES)
|
||||||
# Search LIEF_ROOT first if it is set.
|
# Search LIEF_ROOT first if it is set.
|
||||||
if(LIEF_ROOT)
|
if(LIEF_ROOT)
|
||||||
|
message(DEPRECATION "LIEF_ROOT is deprecated. Please use LIEF_INSTALL_PATH")
|
||||||
set(_LIEF_SEARCH_ROOT PATHS ${LIEF_ROOT} NO_DEFAULT_PATH)
|
set(_LIEF_SEARCH_ROOT PATHS ${LIEF_ROOT} NO_DEFAULT_PATH)
|
||||||
list(APPEND _LIEF_SEARCHES _LIEF_SEARCH_ROOT)
|
list(APPEND _LIEF_SEARCHES _LIEF_SEARCH_ROOT)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(LIEF_INSTALL_PATH)
|
||||||
|
set(_LIEF_SEARCH_ROOT PATHS ${LIEF_INSTALL_PATH} NO_DEFAULT_PATH)
|
||||||
|
list(APPEND _LIEF_SEARCHES _LIEF_SEARCH_ROOT)
|
||||||
|
endif()
|
||||||
|
|
||||||
set(LIEF_NAMES LIEF)
|
set(LIEF_NAMES LIEF)
|
||||||
|
|
||||||
if (LIEF_FIND_COMPONENTS AND LIEF_FIND_REQUIRED_STATIC AND LIEF_FIND_REQUIRED_SHARED)
|
if (LIEF_FIND_COMPONENTS AND LIEF_FIND_REQUIRED_STATIC AND LIEF_FIND_REQUIRED_SHARED)
|
||||||
|
10
scripts/cmake-config/lief-ios-aarch64.sh
Executable file
10
scripts/cmake-config/lief-ios-aarch64.sh
Executable file
@ -0,0 +1,10 @@
|
|||||||
|
#!/usr/bin/sh
|
||||||
|
set -ex
|
||||||
|
cmake .. \
|
||||||
|
-G Ninja -DCMAKE_TOOLCHAIN_FILE=../cmake/ios.toolchain.cmake \
|
||||||
|
-DLIEF_PYTHON_API=off \
|
||||||
|
-DPLATFORM=OS64 \
|
||||||
|
-DBUILD_SHARED_LIBS=off \
|
||||||
|
-DCMAKE_INSTALL_PREFIX=$(pwd)/install
|
||||||
|
|
||||||
|
#cmake --build . --config Release --target install
|
43
scripts/docker/android-aarch64.sh
Executable file
43
scripts/docker/android-aarch64.sh
Executable file
@ -0,0 +1,43 @@
|
|||||||
|
#!/usr/bin/bash
|
||||||
|
set -ex
|
||||||
|
CXXFLAGS='-ffunction-sections -fdata-sections -fvisibility-inlines-hidden '
|
||||||
|
CFLAGS='-ffunction-sections -fdata-sections'
|
||||||
|
export LDFLAGS='-Wl,--gc-sections -Wl,--exclude-libs,ALL'
|
||||||
|
|
||||||
|
ARCH_DIR="android-aarch64"
|
||||||
|
|
||||||
|
mkdir -p build/$ARCH_DIR/static-release && mkdir -p build/$ARCH_DIR/shared-release
|
||||||
|
pushd build/$ARCH_DIR/shared-release
|
||||||
|
|
||||||
|
cmake ../../.. -GNinja \
|
||||||
|
-DCMAKE_CXX_FLAGS="$CXXFLAGS" \
|
||||||
|
-DCMAKE_C_FLAGS="$CFLAGS" \
|
||||||
|
-DCMAKE_SHARED_LINKER_FLAGS="-Wl,-Bdynamic -llog -Wl,-Bstatic" \
|
||||||
|
-DCMAKE_LINK_WHAT_YOU_USE=on \
|
||||||
|
-DBUILD_SHARED_LIBS=on \
|
||||||
|
-DLIEF_PYTHON_API=off \
|
||||||
|
-DLIEF_INSTALL_COMPILED_EXAMPLES=off \
|
||||||
|
-DCMAKE_BUILD_TYPE=Release
|
||||||
|
|
||||||
|
ninja
|
||||||
|
|
||||||
|
popd
|
||||||
|
pushd build/$ARCH_DIR/static-release
|
||||||
|
|
||||||
|
cmake ../../.. -GNinja \
|
||||||
|
-DCMAKE_LINK_WHAT_YOU_USE=on \
|
||||||
|
-DBUILD_SHARED_LIBS=off \
|
||||||
|
-DCMAKE_EXE_LINKER_FLAGS="-Wl,-Bdynamic -llog -lc -Wl,-Bstatic" \
|
||||||
|
-DLIEF_PYTHON_API=off \
|
||||||
|
-DLIEF_INSTALL_COMPILED_EXAMPLES=on \
|
||||||
|
-DCMAKE_BUILD_TYPE=Release
|
||||||
|
|
||||||
|
ninja
|
||||||
|
popd
|
||||||
|
|
||||||
|
pushd build/$ARCH_DIR
|
||||||
|
cpack --config ../../cmake/cpack.config.cmake
|
||||||
|
popd
|
||||||
|
|
||||||
|
/bin/mv build/$ARCH_DIR/*.tar.gz build/
|
||||||
|
chown -R 1000:1000 build/$ARCH_DIR
|
43
scripts/docker/android-arm.sh
Executable file
43
scripts/docker/android-arm.sh
Executable file
@ -0,0 +1,43 @@
|
|||||||
|
#!/usr/bin/bash
|
||||||
|
set -ex
|
||||||
|
CXXFLAGS='-ffunction-sections -fdata-sections -fvisibility-inlines-hidden '
|
||||||
|
CFLAGS='-ffunction-sections -fdata-sections'
|
||||||
|
export LDFLAGS='-Wl,--gc-sections -Wl,--exclude-libs,ALL'
|
||||||
|
|
||||||
|
ARCH_DIR="android-arm"
|
||||||
|
|
||||||
|
mkdir -p build/$ARCH_DIR/static-release && mkdir -p build/$ARCH_DIR/shared-release
|
||||||
|
pushd build/$ARCH_DIR/shared-release
|
||||||
|
|
||||||
|
cmake ../../.. -GNinja \
|
||||||
|
-DCMAKE_CXX_FLAGS="$CXXFLAGS" \
|
||||||
|
-DCMAKE_C_FLAGS="$CFLAGS" \
|
||||||
|
-DCMAKE_SHARED_LINKER_FLAGS="-Wl,-Bdynamic -llog -lc -Wl,-Bstatic" \
|
||||||
|
-DCMAKE_LINK_WHAT_YOU_USE=on \
|
||||||
|
-DBUILD_SHARED_LIBS=on \
|
||||||
|
-DLIEF_PYTHON_API=off \
|
||||||
|
-DLIEF_INSTALL_COMPILED_EXAMPLES=off \
|
||||||
|
-DCMAKE_BUILD_TYPE=Release
|
||||||
|
|
||||||
|
ninja
|
||||||
|
|
||||||
|
popd
|
||||||
|
pushd build/$ARCH_DIR/static-release
|
||||||
|
|
||||||
|
cmake ../../.. -GNinja \
|
||||||
|
-DCMAKE_LINK_WHAT_YOU_USE=on \
|
||||||
|
-DBUILD_SHARED_LIBS=off \
|
||||||
|
-DCMAKE_EXE_LINKER_FLAGS="-Wl,-Bdynamic -llog -lc -Wl,-Bstatic" \
|
||||||
|
-DLIEF_PYTHON_API=off \
|
||||||
|
-DLIEF_INSTALL_COMPILED_EXAMPLES=on \
|
||||||
|
-DCMAKE_BUILD_TYPE=Release
|
||||||
|
|
||||||
|
ninja
|
||||||
|
popd
|
||||||
|
|
||||||
|
pushd build/$ARCH_DIR
|
||||||
|
cpack --config ../../cmake/cpack.config.cmake
|
||||||
|
popd
|
||||||
|
|
||||||
|
/bin/mv build/$ARCH_DIR/*.tar.gz build/
|
||||||
|
chown -R 1000:1000 build/$ARCH_DIR
|
56
scripts/docker/linux-aarch64.sh
Executable file
56
scripts/docker/linux-aarch64.sh
Executable file
@ -0,0 +1,56 @@
|
|||||||
|
#!/usr/bin/bash
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
# Script to be run with liefproject/manylinux2014-aarch64:
|
||||||
|
# ==============================================================================================
|
||||||
|
# docker run \
|
||||||
|
# -e CCACHE_DIR=/ccache \
|
||||||
|
# -v $LIEF_SRC:/work \
|
||||||
|
# -v $HOME/.ccache:/ccache \
|
||||||
|
# --rm liefproject/manylinux2014-aarch64 bash /work/scripts/docker/linux-aarch64.sh
|
||||||
|
# ==============================================================================================
|
||||||
|
#
|
||||||
|
|
||||||
|
CXXFLAGS='-ffunction-sections -fdata-sections -fvisibility-inlines-hidden -static-libgcc -static-libstdc++'
|
||||||
|
CFLAGS='-ffunction-sections -fdata-sections -static-libgcc -static-libstdc++'
|
||||||
|
export LDFLAGS='-Wl,--gc-sections -Wl,--exclude-libs,ALL'
|
||||||
|
|
||||||
|
ARCH_DIR="linux-aarch64"
|
||||||
|
|
||||||
|
mkdir -p build/$ARCH_DIR/static-release && mkdir -p build/$ARCH_DIR/shared-release
|
||||||
|
pushd build/$ARCH_DIR/shared-release
|
||||||
|
|
||||||
|
cmake ../../.. -GNinja \
|
||||||
|
-DCMAKE_CXX_FLAGS="$CXXFLAGS" \
|
||||||
|
-DCMAKE_C_FLAGS="$CFLAGS" \
|
||||||
|
-DCMAKE_LINK_WHAT_YOU_USE=on \
|
||||||
|
-DBUILD_SHARED_LIBS=on \
|
||||||
|
-DLIEF_PYTHON_API=off \
|
||||||
|
-DLIEF_INSTALL_COMPILED_EXAMPLES=off \
|
||||||
|
-DCMAKE_BUILD_TYPE=Release
|
||||||
|
|
||||||
|
ninja
|
||||||
|
|
||||||
|
popd
|
||||||
|
pushd build/$ARCH_DIR/static-release
|
||||||
|
|
||||||
|
cmake ../../.. -GNinja \
|
||||||
|
-DCMAKE_CXX_FLAGS="$CXXFLAGS" \
|
||||||
|
-DCMAKE_C_FLAGS="$CFLAGS" \
|
||||||
|
-DCMAKE_LINK_WHAT_YOU_USE=on \
|
||||||
|
-DBUILD_SHARED_LIBS=off \
|
||||||
|
-DLIEF_PYTHON_API=off \
|
||||||
|
-DLIEF_INSTALL_COMPILED_EXAMPLES=on \
|
||||||
|
-DCMAKE_BUILD_TYPE=Release
|
||||||
|
|
||||||
|
ninja
|
||||||
|
|
||||||
|
popd
|
||||||
|
|
||||||
|
pushd build/$ARCH_DIR
|
||||||
|
cpack --config ../../cmake/cpack.config.cmake
|
||||||
|
popd
|
||||||
|
|
||||||
|
/bin/mv build/$ARCH_DIR/*.tar.gz build/
|
||||||
|
|
||||||
|
chown -R 1000:1000 build/
|
@ -1,8 +1,22 @@
|
|||||||
#!/usr/bin/bash
|
#!/usr/bin/bash
|
||||||
|
|
||||||
|
# Script to be run with liefproject/manylinux2014-aarch64. Example with Python 3.9:
|
||||||
|
# ==============================================================================================
|
||||||
|
# docker run \
|
||||||
|
# -e CCACHE_DIR=/ccache \
|
||||||
|
# -e PYTHON_BINARY=/opt/python/cp39-cp39/bin/python3.9 \
|
||||||
|
# -v $LIEF_SRC:/work \
|
||||||
|
# -v $HOME/.ccache:/ccache \
|
||||||
|
# --rm liefproject/manylinux2014-aarch64 bash /work/scripts/docker/manylinux2014-aarch64.sh
|
||||||
|
# ==============================================================================================
|
||||||
|
# --lief-no-elf --lief-no-android --lief-no-macho --lief-no-json --lief-no-logging \
|
||||||
|
#
|
||||||
set -ex
|
set -ex
|
||||||
CXXFLAGS='-static-libgcc -static-libstdc++' \
|
CXXFLAGS='-static-libgcc -static-libstdc++' \
|
||||||
|
LIEF_PY_XARCH='aarch64' \
|
||||||
$PYTHON_BINARY setup.py --ninja \
|
$PYTHON_BINARY setup.py --ninja \
|
||||||
build -t /tmp bdist_wheel \
|
build -t /tmp bdist_wheel --skip-build \
|
||||||
--plat-name manylinux2014_aarch64 \
|
--plat-name "manylinux2014-aarch64"
|
||||||
chown -R 1000:1000 /work/dist && \
|
|
||||||
chown -R 1000:1000 /work/build
|
chown -R 1000:1000 /work/dist
|
||||||
|
chown -R 1000:1000 /work/build
|
||||||
|
41
scripts/docker/travis-linux-sdk.sh
Normal file
41
scripts/docker/travis-linux-sdk.sh
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#!/usr/bin/sh
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
export CXXFLAGS='-ffunction-sections -fdata-sections -fvisibility-inlines-hidden -static-libstdc++ -static-libgcc'
|
||||||
|
export CFLAGS='-ffunction-sections -fdata-sections -static-libstdc++ -static-libgcc'
|
||||||
|
export LDFLAGS='-Wl,--gc-sections -Wl,--exclude-libs,ALL'
|
||||||
|
|
||||||
|
mkdir -p build/linux-x86-64/static-release && mkdir -p build/linux-x86-64/shared-release
|
||||||
|
pushd build/linux-x86-64/shared-release
|
||||||
|
|
||||||
|
cmake ../../.. -GNinja \
|
||||||
|
-DCMAKE_LINK_WHAT_YOU_USE=on \
|
||||||
|
-DBUILD_SHARED_LIBS=on \
|
||||||
|
-DLIEF_PYTHON_API=off \
|
||||||
|
-DLIEF_INSTALL_COMPILED_EXAMPLES=off \
|
||||||
|
-DCMAKE_BUILD_TYPE=Release
|
||||||
|
|
||||||
|
ninja
|
||||||
|
|
||||||
|
popd
|
||||||
|
pushd build/linux-x86-64/static-release
|
||||||
|
|
||||||
|
cmake ../../.. -GNinja \
|
||||||
|
-DCMAKE_LINK_WHAT_YOU_USE=on \
|
||||||
|
-DBUILD_SHARED_LIBS=off \
|
||||||
|
-DLIEF_PYTHON_API=off \
|
||||||
|
-DLIEF_INSTALL_COMPILED_EXAMPLES=on \
|
||||||
|
-DCMAKE_BUILD_TYPE=Release
|
||||||
|
|
||||||
|
ninja
|
||||||
|
|
||||||
|
popd
|
||||||
|
|
||||||
|
pushd build/linux-x86-64
|
||||||
|
cpack --config ../../cmake/cpack.config.cmake
|
||||||
|
popd
|
||||||
|
|
||||||
|
/bin/mv build/linux-x86-64/*.tar.gz build/
|
||||||
|
ls -alh build
|
||||||
|
|
||||||
|
chown -R 1000:1000 build dist wheel_stage
|
13
scripts/docker/travis-linux.sh
Normal file
13
scripts/docker/travis-linux.sh
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#!/usr/bin/sh
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
export CXXFLAGS='-ffunction-sections -fdata-sections -fvisibility-inlines-hidden -static-libstdc++ -static-libgcc'
|
||||||
|
export CFLAGS='-ffunction-sections -fdata-sections -static-libstdc++ -static-libgcc'
|
||||||
|
export LDFLAGS='-Wl,--gc-sections -Wl,--exclude-libs,ALL'
|
||||||
|
|
||||||
|
$PYTHON_BINARY setup.py --ninja --lief-test build \
|
||||||
|
bdist_wheel --skip-build --dist-dir wheel_stage
|
||||||
|
|
||||||
|
auditwheel repair -w dist --plat manylinux1_x86_64 wheel_stage/*.whl
|
||||||
|
|
||||||
|
chown -R 1000:1000 build dist wheel_stage
|
38
scripts/osx/package_ios.sh
Normal file
38
scripts/osx/package_ios.sh
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#!/usr/bin/sh
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
ARCH_DIR="ios-aarch64"
|
||||||
|
|
||||||
|
mkdir -p build/$ARCH_DIR/static-release && mkdir -p build/$ARCH_DIR/shared-release
|
||||||
|
pushd build/$ARCH_DIR/shared-release
|
||||||
|
|
||||||
|
cmake ../../.. -GNinja \
|
||||||
|
-DCMAKE_TOOLCHAIN_FILE=../../../cmake/ios.toolchain.cmake \
|
||||||
|
-DBUILD_SHARED_LIBS=on \
|
||||||
|
-DENABLE_BITCODE=0 \
|
||||||
|
-DLIEF_PYTHON_API=off \
|
||||||
|
-DLIEF_INSTALL_COMPILED_EXAMPLES=off \
|
||||||
|
-DCMAKE_BUILD_TYPE=Release
|
||||||
|
|
||||||
|
ninja
|
||||||
|
|
||||||
|
|
||||||
|
popd
|
||||||
|
pushd build/$ARCH_DIR/static-release
|
||||||
|
|
||||||
|
cmake ../../.. -GNinja \
|
||||||
|
-DCMAKE_TOOLCHAIN_FILE=../../../cmake/ios.toolchain.cmake \
|
||||||
|
-DBUILD_SHARED_LIBS=off \
|
||||||
|
-DENABLE_BITCODE=0 \
|
||||||
|
-DLIEF_PYTHON_API=off \
|
||||||
|
-DLIEF_INSTALL_COMPILED_EXAMPLES=on \
|
||||||
|
-DCMAKE_BUILD_TYPE=Release
|
||||||
|
|
||||||
|
ninja
|
||||||
|
|
||||||
|
popd
|
||||||
|
pushd build/$ARCH_DIR
|
||||||
|
cpack --config ../../cmake/cpack.config.cmake
|
||||||
|
popd
|
||||||
|
|
||||||
|
/bin/mv build/$ARCH_DIR/*.tar.gz build/
|
32
scripts/osx/package_sdk.sh
Normal file
32
scripts/osx/package_sdk.sh
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#!/usr/bin/sh
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
mkdir -p build/osx-x86-64/static-release && mkdir -p build/osx-x86-64/shared-release
|
||||||
|
pushd build/osx-x86-64/shared-release
|
||||||
|
|
||||||
|
cmake ../../.. -GNinja \
|
||||||
|
-DBUILD_SHARED_LIBS=on \
|
||||||
|
-DLIEF_PYTHON_API=off \
|
||||||
|
-DLIEF_INSTALL_COMPILED_EXAMPLES=off \
|
||||||
|
-DCMAKE_BUILD_TYPE=Release
|
||||||
|
|
||||||
|
ninja
|
||||||
|
|
||||||
|
|
||||||
|
popd
|
||||||
|
pushd build/osx-x86-64/static-release
|
||||||
|
|
||||||
|
cmake ../../.. -GNinja \
|
||||||
|
-DBUILD_SHARED_LIBS=off \
|
||||||
|
-DLIEF_PYTHON_API=off \
|
||||||
|
-DLIEF_INSTALL_COMPILED_EXAMPLES=on \
|
||||||
|
-DCMAKE_BUILD_TYPE=Release
|
||||||
|
|
||||||
|
ninja
|
||||||
|
|
||||||
|
popd
|
||||||
|
pushd build/osx-x86-64
|
||||||
|
cpack --config ../../cmake/cpack.config.cmake
|
||||||
|
popd
|
||||||
|
|
||||||
|
/bin/mv build/osx-x86-64/*.tar.gz build/
|
68
scripts/windows/package_sdk.py
Normal file
68
scripts/windows/package_sdk.py
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
from setuptools import msvc
|
||||||
|
import pathlib
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import subprocess
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
env = os.environ
|
||||||
|
|
||||||
|
CWD = pathlib.Path(__file__).parent
|
||||||
|
LIEF_SRC = CWD / ".." / ".."
|
||||||
|
|
||||||
|
BUILD_PATH = LIEF_SRC / "build"
|
||||||
|
BUILD_STATIC_PATH = BUILD_PATH / "static-release"
|
||||||
|
BUILD_SHARED_PATH = BUILD_PATH / "shared-release"
|
||||||
|
CPACK_CONFIG_PATH = (LIEF_SRC / "cmake" / "cpack.config.cmake").resolve()
|
||||||
|
|
||||||
|
CMAKE_PATH = pathlib.Path(shutil.which("cmake.exe"))
|
||||||
|
CPACK_PATH = CMAKE_PATH.parent / "cpack.exe"
|
||||||
|
|
||||||
|
if not CPACK_PATH.is_file():
|
||||||
|
print("Can't find cpack.exe at: {}".format(CPACK_PATH), file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
CPACK_BIN = CPACK_PATH.as_posix()
|
||||||
|
|
||||||
|
BUILD_PATH.mkdir(exist_ok=True)
|
||||||
|
BUILD_STATIC_PATH.mkdir(exist_ok=True)
|
||||||
|
BUILD_SHARED_PATH.mkdir(exist_ok=True)
|
||||||
|
|
||||||
|
is64 = sys.maxsize > 2**32
|
||||||
|
arch = 'x64' if is64 else 'x86'
|
||||||
|
|
||||||
|
ninja_env = msvc.msvc14_get_vc_env(arch)
|
||||||
|
env.update(ninja_env)
|
||||||
|
|
||||||
|
cmake_config_static = [
|
||||||
|
"-G", "Ninja",
|
||||||
|
"-DCMAKE_BUILD_TYPE=Release",
|
||||||
|
"-DBUILD_SHARED_LIBS=off",
|
||||||
|
"-DLIEF_PYTHON_API=off",
|
||||||
|
"-DLIEF_INSTALL_COMPILED_EXAMPLES=on",
|
||||||
|
"-DLIEF_USE_CRT_RELEASE=MT",
|
||||||
|
]
|
||||||
|
|
||||||
|
cmake_config_shared = [
|
||||||
|
"-G", "Ninja",
|
||||||
|
"-DCMAKE_BUILD_TYPE=Release",
|
||||||
|
"-DBUILD_SHARED_LIBS=on",
|
||||||
|
"-DLIEF_PYTHON_API=off",
|
||||||
|
"-DLIEF_INSTALL_COMPILED_EXAMPLES=off",
|
||||||
|
"-DLIEF_USE_CRT_RELEASE=MT",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
build_args = ['--config', 'Release']
|
||||||
|
|
||||||
|
|
||||||
|
configure_cmd = ['cmake', LIEF_SRC.resolve().as_posix()]
|
||||||
|
|
||||||
|
subprocess.check_call(configure_cmd + cmake_config_shared, cwd=BUILD_SHARED_PATH.resolve().as_posix(), env=env)
|
||||||
|
subprocess.check_call(['cmake', '--build', '.', '--target', "all"] + build_args, cwd=BUILD_SHARED_PATH.resolve().as_posix(), env=env)
|
||||||
|
|
||||||
|
|
||||||
|
subprocess.check_call(configure_cmd + cmake_config_static, cwd=BUILD_STATIC_PATH.resolve().as_posix(), env=env)
|
||||||
|
subprocess.check_call(['cmake', '--build', '.', '--target', "all"] + build_args, cwd=BUILD_STATIC_PATH.resolve().as_posix(), env=env)
|
||||||
|
|
||||||
|
subprocess.check_call([CPACK_BIN, '--config', CPACK_CONFIG_PATH.resolve().as_posix()], cwd=BUILD_PATH.resolve().as_posix(), env=env)
|
71
setup.py
71
setup.py
@ -4,6 +4,9 @@ import platform
|
|||||||
import subprocess
|
import subprocess
|
||||||
import setuptools
|
import setuptools
|
||||||
import pathlib
|
import pathlib
|
||||||
|
import sysconfig
|
||||||
|
import copy
|
||||||
|
import distutils
|
||||||
from pkg_resources import Distribution, get_distribution
|
from pkg_resources import Distribution, get_distribution
|
||||||
from setuptools import setup, Extension
|
from setuptools import setup, Extension
|
||||||
from setuptools.command.build_ext import build_ext, copy_file
|
from setuptools.command.build_ext import build_ext, copy_file
|
||||||
@ -18,6 +21,11 @@ assert (LooseVersion(setuptools.__version__) >= LooseVersion(MIN_SETUPTOOLS_VERS
|
|||||||
CURRENT_DIR = os.path.dirname(os.path.realpath(__file__))
|
CURRENT_DIR = os.path.dirname(os.path.realpath(__file__))
|
||||||
PACKAGE_NAME = "lief"
|
PACKAGE_NAME = "lief"
|
||||||
|
|
||||||
|
get_config_var_backup = sysconfig.get_config_var
|
||||||
|
get_platform_backup = sysconfig.get_platform
|
||||||
|
get_config_vars_backup = sysconfig.get_config_vars
|
||||||
|
distutils_get_config_vars_backup = distutils.sysconfig.get_config_vars
|
||||||
|
|
||||||
class LiefDistribution(setuptools.Distribution):
|
class LiefDistribution(setuptools.Distribution):
|
||||||
global_options = setuptools.Distribution.global_options + [
|
global_options = setuptools.Distribution.global_options + [
|
||||||
('lief-test', None, 'Build and make tests'),
|
('lief-test', None, 'Build and make tests'),
|
||||||
@ -93,8 +101,6 @@ class BuildLibrary(build_ext):
|
|||||||
return "zip"
|
return "zip"
|
||||||
return "tar.gz"
|
return "tar.gz"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def build_extension(self, ext):
|
def build_extension(self, ext):
|
||||||
if self.distribution.lief_test:
|
if self.distribution.lief_test:
|
||||||
log.info("LIEF tests enabled!")
|
log.info("LIEF tests enabled!")
|
||||||
@ -206,7 +212,8 @@ class BuildLibrary(build_ext):
|
|||||||
if not os.path.exists(self.build_temp):
|
if not os.path.exists(self.build_temp):
|
||||||
os.makedirs(self.build_temp)
|
os.makedirs(self.build_temp)
|
||||||
|
|
||||||
|
log.info("Platform: %s", platform.system())
|
||||||
|
log.info("Wheel library: %s", self.get_ext_fullname(ext.name))
|
||||||
|
|
||||||
# 1. Configure
|
# 1. Configure
|
||||||
configure_cmd = ['cmake', ext.sourcedir] + cmake_args
|
configure_cmd = ['cmake', ext.sourcedir] + cmake_args
|
||||||
@ -278,8 +285,6 @@ class BuildLibrary(build_ext):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.error("Documentation failed: %s" % e)
|
log.error("Documentation failed: %s" % e)
|
||||||
pylief_dst = os.path.join(self.build_lib, self.get_ext_filename(self.get_ext_fullname(ext.name)))
|
pylief_dst = os.path.join(self.build_lib, self.get_ext_filename(self.get_ext_fullname(ext.name)))
|
||||||
|
|
||||||
|
|
||||||
libsuffix = pylief_dst.split(".")[-1]
|
libsuffix = pylief_dst.split(".")[-1]
|
||||||
|
|
||||||
pylief_path = os.path.join(cmake_library_output_directory, "{}.{}".format(PACKAGE_NAME, libsuffix))
|
pylief_path = os.path.join(cmake_library_output_directory, "{}.{}".format(PACKAGE_NAME, libsuffix))
|
||||||
@ -315,7 +320,63 @@ class BuildLibrary(build_ext):
|
|||||||
sdk_path, sdk_output, verbose=self.verbose,
|
sdk_path, sdk_output, verbose=self.verbose,
|
||||||
dry_run=self.dry_run)
|
dry_run=self.dry_run)
|
||||||
|
|
||||||
|
def get_platform():
|
||||||
|
out = get_platform_backup()
|
||||||
|
lief_arch = os.environ.get("LIEF_PY_XARCH", None)
|
||||||
|
if lief_arch is not None and isinstance(out, str):
|
||||||
|
original_out = out
|
||||||
|
out = out.replace("x86_64", lief_arch)
|
||||||
|
log.info(" Replace %s -> %s", original_out, out)
|
||||||
|
return out
|
||||||
|
|
||||||
|
def get_config_vars(*args):
|
||||||
|
out = get_config_vars_backup(*args)
|
||||||
|
lief_arch = os.environ.get("LIEF_PY_XARCH", None)
|
||||||
|
if lief_arch is None:
|
||||||
|
return out
|
||||||
|
out_xfix = copy.deepcopy(out)
|
||||||
|
for k, v in out.items():
|
||||||
|
if not (isinstance(v, str) and "x86_64" in v):
|
||||||
|
continue
|
||||||
|
if k not in {"SO", "SOABI", "EXT_SUFFIX", "BUILD_GNU_TYPE"}:
|
||||||
|
continue
|
||||||
|
fix = v.replace("x86_64", lief_arch)
|
||||||
|
log.info(" Replace %s: %s -> %s", k, v, fix)
|
||||||
|
out_xfix[k] = fix
|
||||||
|
|
||||||
|
return out_xfix
|
||||||
|
|
||||||
|
|
||||||
|
def distutils_get_config_vars(*args):
|
||||||
|
out = distutils_get_config_vars_backup(*args)
|
||||||
|
lief_arch = os.environ.get("LIEF_PY_XARCH", None)
|
||||||
|
if lief_arch is None:
|
||||||
|
return out
|
||||||
|
|
||||||
|
if isinstance(out, list):
|
||||||
|
fixes = []
|
||||||
|
for item in out:
|
||||||
|
if not (isinstance(item, str) and "x86_64" in item):
|
||||||
|
fixes.append(item)
|
||||||
|
else:
|
||||||
|
fixes.append(item.replace("x86_64", lief_arch))
|
||||||
|
return fixes
|
||||||
|
|
||||||
|
out_xfix = copy.deepcopy(out)
|
||||||
|
for k, v in out.items():
|
||||||
|
if not (isinstance(v, str) and "x86_64" in v):
|
||||||
|
continue
|
||||||
|
if k not in {"SO", "SOABI", "EXT_SUFFIX", "BUILD_GNU_TYPE"}:
|
||||||
|
continue
|
||||||
|
fix = v.replace("x86_64", lief_arch)
|
||||||
|
log.info(" Replace %s: %s -> %s", k, v, fix)
|
||||||
|
out_xfix[k] = fix
|
||||||
|
|
||||||
|
return out_xfix
|
||||||
|
|
||||||
|
sysconfig.get_platform = get_platform
|
||||||
|
sysconfig.get_config_vars = get_config_vars
|
||||||
|
distutils.sysconfig.get_config_vars = distutils_get_config_vars
|
||||||
|
|
||||||
# From setuptools-git-version
|
# From setuptools-git-version
|
||||||
command = 'git describe --tags --long --dirty'
|
command = 'git describe --tags --long --dirty'
|
||||||
|
@ -106,10 +106,9 @@ endif()
|
|||||||
|
|
||||||
# Fuzzing
|
# Fuzzing
|
||||||
# =======
|
# =======
|
||||||
if(UNIX AND NOT APPLE)
|
if(UNIX AND NOT APPLE)
|
||||||
|
set(MELKOR_VERSION 1d62ccc) # From the fork: https://github.com/romainthomas/elf_fuzzer
|
||||||
set(MELKOR_VERSION master)
|
set(MELKOR_SHA256 SHA256=2653d4ec1dca51621757e6946f4af18fcd100f905183a4692b68ad0cd65392ba)
|
||||||
set(MELKOR_SHA256 SHA256=8d8115117e87ee1fad81cb09e53524f7bee9a4803632ae3b0b1cfbb66c86a6f4)
|
|
||||||
set(MELKOR_URL "${THIRD_PARTY_DIRECTORY}/Melkor_ELF_Fuzzer-${MELKOR_VERSION}.zip" CACHE STRING "URL to the Melkor package")
|
set(MELKOR_URL "${THIRD_PARTY_DIRECTORY}/Melkor_ELF_Fuzzer-${MELKOR_VERSION}.zip" CACHE STRING "URL to the Melkor package")
|
||||||
|
|
||||||
set(MELKOR_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/Melkor")
|
set(MELKOR_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/Melkor")
|
||||||
@ -123,16 +122,15 @@ endif()
|
|||||||
CONFIGURE_COMMAND ""
|
CONFIGURE_COMMAND ""
|
||||||
INSTALL_COMMAND ""
|
INSTALL_COMMAND ""
|
||||||
BUILD_COMMAND make clean && make
|
BUILD_COMMAND make clean && make
|
||||||
BUILD_IN_SOURCE ON
|
BUILD_IN_SOURCE ON)
|
||||||
PATCH_COMMAND patch -p1 < ${THIRD_PARTY_DIRECTORY}/melkor-makefile-old-find.patch)
|
|
||||||
|
|
||||||
ExternalProject_get_property(MELKOR SOURCE_DIR)
|
ExternalProject_get_property(MELKOR SOURCE_DIR)
|
||||||
set(MELKOR_BINARY "${SOURCE_DIR}/melkor")
|
set(MELKOR_BINARY "${SOURCE_DIR}/melkor")
|
||||||
message(STATUS "${MELKOR_BINARY}")
|
message(STATUS "${MELKOR_BINARY}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Tests
|
# Tests
|
||||||
# =====
|
# =====
|
||||||
add_executable(test_iterators "${CMAKE_CURRENT_SOURCE_DIR}/test_iterators.cpp")
|
add_executable(test_iterators "${CMAKE_CURRENT_SOURCE_DIR}/test_iterators.cpp")
|
||||||
|
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
@ -140,8 +138,10 @@ if (MSVC)
|
|||||||
set_property(TARGET test_iterators PROPERTY LINK_FLAGS /NODEFAULTLIB:MSVCRT)
|
set_property(TARGET test_iterators PROPERTY LINK_FLAGS /NODEFAULTLIB:MSVCRT)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set_property(TARGET test_iterators PROPERTY CXX_STANDARD 11)
|
set_target_properties(
|
||||||
set_property(TARGET test_iterators PROPERTY CXX_STANDARD_REQUIRED ON)
|
test_iterators
|
||||||
|
PROPERTIES CXX_STANDARD 11
|
||||||
|
CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
target_include_directories(test_iterators PUBLIC
|
target_include_directories(test_iterators PUBLIC
|
||||||
$<TARGET_PROPERTY:LIB_LIEF,INCLUDE_DIRECTORIES>
|
$<TARGET_PROPERTY:LIB_LIEF,INCLUDE_DIRECTORIES>
|
||||||
|
@ -14,10 +14,17 @@ import lief
|
|||||||
from lief.ELF import Section
|
from lief.ELF import Section
|
||||||
|
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from utils import get_sample, get_compiler
|
from utils import get_sample, get_compiler, is_aarch64, is_x86_64, is_linux
|
||||||
|
|
||||||
CURRENT_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
|
CURRENT_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
|
||||||
STUB = lief.parse(os.path.join(CURRENT_DIRECTORY, "hello_lief.bin"))
|
STUB_FILE = None
|
||||||
|
if is_x86_64():
|
||||||
|
STUB_FILE = "hello_lief.bin"
|
||||||
|
elif is_aarch64():
|
||||||
|
STUB_FILE = "hello_lief_aarch64.bin"
|
||||||
|
|
||||||
|
STUB = lief.parse(os.path.join(CURRENT_DIRECTORY, STUB_FILE))
|
||||||
|
|
||||||
|
|
||||||
LIBADD_C = """\
|
LIBADD_C = """\
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -95,7 +102,7 @@ class TestAddContent(TestCase):
|
|||||||
self.logger.debug(stdout)
|
self.logger.debug(stdout)
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
@unittest.skipUnless(is_linux(), "requires Linux")
|
||||||
def test_simple(self):
|
def test_simple(self):
|
||||||
self.compile_libadd(self.libadd_path)
|
self.compile_libadd(self.libadd_path)
|
||||||
self.compile_binadd(self.binadd_path)
|
self.compile_binadd(self.binadd_path)
|
||||||
|
@ -14,10 +14,17 @@ import lief
|
|||||||
from lief.ELF import Section
|
from lief.ELF import Section
|
||||||
|
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from utils import get_sample, has_recent_glibc
|
from utils import get_sample, has_recent_glibc, is_linux, is_x86_64, is_aarch64
|
||||||
|
|
||||||
CURRENT_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
|
CURRENT_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
|
||||||
STUB = lief.parse(os.path.join(CURRENT_DIRECTORY, "hello_lief.bin"))
|
|
||||||
|
STUB_FILE = None
|
||||||
|
if is_x86_64():
|
||||||
|
STUB_FILE = "hello_lief.bin"
|
||||||
|
elif is_aarch64():
|
||||||
|
STUB_FILE = "hello_lief_aarch64.bin"
|
||||||
|
|
||||||
|
STUB = lief.parse(os.path.join(CURRENT_DIRECTORY, STUB_FILE))
|
||||||
|
|
||||||
class TestAddSection(TestCase):
|
class TestAddSection(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -26,7 +33,7 @@ class TestAddSection(TestCase):
|
|||||||
self.logger.debug("temp dir: {}".format(self.tmp_dir))
|
self.logger.debug("temp dir: {}".format(self.tmp_dir))
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
@unittest.skipUnless(is_linux() and is_x86_64(), "requires Linux x86-64")
|
||||||
@unittest.skipUnless(has_recent_glibc(), "Need a recent GLIBC version")
|
@unittest.skipUnless(has_recent_glibc(), "Need a recent GLIBC version")
|
||||||
def test_simple(self):
|
def test_simple(self):
|
||||||
sample_path = get_sample('ELF/ELF64_x86-64_binary_ls.bin')
|
sample_path = get_sample('ELF/ELF64_x86-64_binary_ls.bin')
|
||||||
@ -55,7 +62,7 @@ class TestAddSection(TestCase):
|
|||||||
self.assertIsNotNone(re.search(r'LIEF is Working', stdout.decode("utf8")))
|
self.assertIsNotNone(re.search(r'LIEF is Working', stdout.decode("utf8")))
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
@unittest.skipUnless(is_linux() and is_x86_64(), "requires Linux x86-64")
|
||||||
@unittest.skipUnless(has_recent_glibc(), "Need a recent GLIBC version")
|
@unittest.skipUnless(has_recent_glibc(), "Need a recent GLIBC version")
|
||||||
def test_gcc(self):
|
def test_gcc(self):
|
||||||
sample_path = get_sample('ELF/ELF64_x86-64_binary_gcc.bin')
|
sample_path = get_sample('ELF/ELF64_x86-64_binary_gcc.bin')
|
||||||
|
@ -13,7 +13,7 @@ from unittest import TestCase
|
|||||||
|
|
||||||
import lief
|
import lief
|
||||||
from lief.ELF import Segment
|
from lief.ELF import Segment
|
||||||
from utils import get_sample, has_recent_glibc
|
from utils import get_sample, has_recent_glibc, is_linux, is_x86_64, is_aarch64
|
||||||
|
|
||||||
lief.logging.set_level(lief.logging.LOGGING_LEVEL.INFO)
|
lief.logging.set_level(lief.logging.LOGGING_LEVEL.INFO)
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ class TestAddSegment(TestCase):
|
|||||||
self.tmp_dir = tempfile.mkdtemp(suffix='_lief_test_add_segment')
|
self.tmp_dir = tempfile.mkdtemp(suffix='_lief_test_add_segment')
|
||||||
self.logger.debug("temp dir: {}".format(self.tmp_dir))
|
self.logger.debug("temp dir: {}".format(self.tmp_dir))
|
||||||
|
|
||||||
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
@unittest.skipUnless(is_linux() and is_x86_64(), "requires Linux x86-64")
|
||||||
@unittest.skipUnless(has_recent_glibc(), "Need a recent GLIBC version")
|
@unittest.skipUnless(has_recent_glibc(), "Need a recent GLIBC version")
|
||||||
def test_simple(self):
|
def test_simple(self):
|
||||||
sample_path = get_sample('ELF/ELF64_x86-64_binary_ls.bin')
|
sample_path = get_sample('ELF/ELF64_x86-64_binary_ls.bin')
|
||||||
@ -52,7 +52,7 @@ class TestAddSegment(TestCase):
|
|||||||
self.assertIsNotNone(re.search(r'LIEF is Working', stdout.decode("utf8")))
|
self.assertIsNotNone(re.search(r'LIEF is Working', stdout.decode("utf8")))
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
@unittest.skipUnless(is_linux() and is_x86_64(), "requires Linux x86-64")
|
||||||
@unittest.skipUnless(has_recent_glibc(), "Need a recent GLIBC version")
|
@unittest.skipUnless(has_recent_glibc(), "Need a recent GLIBC version")
|
||||||
def test_gcc(self):
|
def test_gcc(self):
|
||||||
sample_path = get_sample('ELF/ELF64_x86-64_binary_gcc.bin')
|
sample_path = get_sample('ELF/ELF64_x86-64_binary_gcc.bin')
|
||||||
@ -78,7 +78,7 @@ class TestAddSegment(TestCase):
|
|||||||
self.assertIsNotNone(re.search(r'LIEF is Working', stdout.decode("utf8")))
|
self.assertIsNotNone(re.search(r'LIEF is Working', stdout.decode("utf8")))
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
@unittest.skipUnless(is_linux() and is_x86_64(), "requires Linux x86-64")
|
||||||
def test_static(self):
|
def test_static(self):
|
||||||
sample_path = get_sample('ELF/ELF64_x86-64_binary_static-binary.bin')
|
sample_path = get_sample('ELF/ELF64_x86-64_binary_static-binary.bin')
|
||||||
stub = lief.parse(os.path.join(CURRENT_DIRECTORY, "hello_lief.bin"))
|
stub = lief.parse(os.path.join(CURRENT_DIRECTORY, "hello_lief.bin"))
|
||||||
@ -102,7 +102,7 @@ class TestAddSegment(TestCase):
|
|||||||
self.logger.debug(stdout.decode("utf8"))
|
self.logger.debug(stdout.decode("utf8"))
|
||||||
self.assertIsNotNone(re.search(r'LIEF is Working', stdout.decode("utf8")))
|
self.assertIsNotNone(re.search(r'LIEF is Working', stdout.decode("utf8")))
|
||||||
|
|
||||||
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
@unittest.skipUnless(is_linux(), "requires Linux")
|
||||||
def test_misc(self):
|
def test_misc(self):
|
||||||
list_binaries = [
|
list_binaries = [
|
||||||
'/usr/bin/ls',
|
'/usr/bin/ls',
|
||||||
@ -122,18 +122,28 @@ class TestAddSegment(TestCase):
|
|||||||
|
|
||||||
def run_add_segment(self, target):
|
def run_add_segment(self, target):
|
||||||
if not os.path.isfile(target):
|
if not os.path.isfile(target):
|
||||||
|
self.logger.debug("%s does not exists. Skip!", target)
|
||||||
return
|
return
|
||||||
|
|
||||||
name = os.path.basename(target)
|
stub = None
|
||||||
|
if is_x86_64():
|
||||||
stub = lief.parse(os.path.join(CURRENT_DIRECTORY, "hello_lief.bin"))
|
stub = lief.parse(os.path.join(CURRENT_DIRECTORY, "hello_lief.bin"))
|
||||||
|
elif is_aarch64():
|
||||||
|
stub = lief.parse(os.path.join(CURRENT_DIRECTORY, "hello_lief_aarch64.bin"))
|
||||||
|
|
||||||
|
name = os.path.basename(target)
|
||||||
target = lief.parse(target)
|
target = lief.parse(target)
|
||||||
output = os.path.join(self.tmp_dir, "{}.segment".format(name))
|
output = os.path.join(self.tmp_dir, "{}.segment".format(name))
|
||||||
for i in range(6):
|
for i in range(6):
|
||||||
segment = stub.segments[0]
|
stub_segment = stub.segments[0]
|
||||||
original_va = segment.virtual_address
|
segment = lief.ELF.Segment()
|
||||||
segment.virtual_address = 0
|
segment.content = stub.segments[0].content
|
||||||
segment = target.add(segment)
|
segment.type = stub_segment.type
|
||||||
new_ep = (stub.header.entrypoint - original_va) + segment.virtual_address
|
segment.alignment = stub_segment.alignment
|
||||||
|
segment.flags = stub_segment.flags
|
||||||
|
|
||||||
|
new_segment = target.add(segment)
|
||||||
|
new_ep = (stub.header.entrypoint - stub.imagebase - stub_segment.file_offset) + new_segment.virtual_address
|
||||||
|
|
||||||
target.header.entrypoint = new_ep
|
target.header.entrypoint = new_ep
|
||||||
target.write(output)
|
target.write(output)
|
||||||
@ -146,56 +156,68 @@ class TestAddSegment(TestCase):
|
|||||||
self.logger.debug(stdout.decode("utf8"))
|
self.logger.debug(stdout.decode("utf8"))
|
||||||
self.assertIsNotNone(re.search(r'LIEF is Working', stdout.decode("utf8")))
|
self.assertIsNotNone(re.search(r'LIEF is Working', stdout.decode("utf8")))
|
||||||
|
|
||||||
@unittest.skipUnless(False, "requires Linux")
|
# TODO(romain): To fix
|
||||||
def test_libc(self):
|
#@unittest.skipUnless(is_linux(), "requires Linux x86-64")
|
||||||
stub = lief.parse(os.path.join(CURRENT_DIRECTORY, "hello_lief.bin"))
|
#def test_libc(self):
|
||||||
tmp_dir = tempfile.mkdtemp(suffix='_lief_test_add_segment_libc')
|
# stub = None
|
||||||
self.logger.debug("temp dir: {}".format(tmp_dir))
|
# if is_x86_64():
|
||||||
|
# stub = lief.parse(os.path.join(CURRENT_DIRECTORY, "hello_lief.bin"))
|
||||||
|
# elif is_aarch64():
|
||||||
|
# stub = lief.parse(os.path.join(CURRENT_DIRECTORY, "hello_lief_aarch64.bin"))
|
||||||
|
# tmp_dir = tempfile.mkdtemp(suffix='_lief_test_add_segment_libc')
|
||||||
|
# self.logger.debug("temp dir: {}".format(tmp_dir))
|
||||||
|
|
||||||
libc_name = "libc.so.6"
|
# libc_name = "libc.so.6"
|
||||||
for e in lief.parse("/bin/ls").libraries:
|
# for e in lief.parse("/bin/ls").libraries:
|
||||||
if e.startswith("libc."):
|
# if e.startswith("libc."):
|
||||||
libc_name = e
|
# libc_name = e
|
||||||
break;
|
# break
|
||||||
|
|
||||||
self.logger.debug("libc used: {}".format(libc_name))
|
# libc_path = '/usr/lib/{}'.format(libc_name)
|
||||||
|
# if not os.path.isfile(libc_path):
|
||||||
|
# libc_path = '/usr/lib/aarch64-linux-gnu/{}'.format(libc_name)
|
||||||
|
|
||||||
|
# self.logger.debug("libc used: {}".format(libc_path))
|
||||||
|
|
||||||
libc = lief.parse('/usr/lib/{}'.format(libc_name))
|
# libc = lief.parse(libc_path)
|
||||||
out = os.path.join(tmp_dir, libc_name)
|
# out = os.path.join(tmp_dir, libc_name)
|
||||||
|
|
||||||
for i in range(10):
|
# stub_segment = stub.segments[0]
|
||||||
segment = stub.segments[0]
|
# for i in range(10):
|
||||||
original_va = segment.virtual_address
|
# segment = lief.ELF.Segment()
|
||||||
segment.virtual_address = 0
|
# segment.content = stub.segments[0].content
|
||||||
|
# segment.type = stub_segment.type
|
||||||
|
# segment.alignment = stub_segment.alignment
|
||||||
|
# segment.flags = stub_segment.flags
|
||||||
|
|
||||||
segment = libc.add(segment)
|
# new_segment = libc.add(segment)
|
||||||
|
# new_ep = (stub.header.entrypoint - stub.imagebase - stub_segment.file_offset) + new_segment.virtual_address
|
||||||
|
|
||||||
new_ep = (stub.header.entrypoint - original_va) + segment.virtual_address
|
# libc.header.entrypoint = new_ep
|
||||||
|
|
||||||
if libc.has(lief.ELF.DYNAMIC_TAGS.INIT_ARRAY):
|
# if libc.has(lief.ELF.DYNAMIC_TAGS.INIT_ARRAY):
|
||||||
init_array = libc.get(lief.ELF.DYNAMIC_TAGS.INIT_ARRAY)
|
# init_array = libc.get(lief.ELF.DYNAMIC_TAGS.INIT_ARRAY)
|
||||||
callbacks = init_array.array
|
# callbacks = init_array.array
|
||||||
callbacks[0] = new_ep
|
# callbacks[0] = new_ep
|
||||||
init_array.array = callbacks
|
# init_array.array = callbacks
|
||||||
|
|
||||||
if libc.has(lief.ELF.DYNAMIC_TAGS.INIT):
|
# if libc.has(lief.ELF.DYNAMIC_TAGS.INIT):
|
||||||
init = libc.get(lief.ELF.DYNAMIC_TAGS.INIT)
|
# init = libc.get(lief.ELF.DYNAMIC_TAGS.INIT)
|
||||||
init.value = new_ep
|
# init.value = new_ep
|
||||||
|
|
||||||
libc.write(out)
|
# libc.write(out)
|
||||||
|
|
||||||
st = os.stat(out)
|
# st = os.stat(out)
|
||||||
os.chmod(out, st.st_mode | stat.S_IEXEC)
|
# os.chmod(out, st.st_mode | stat.S_IEXEC)
|
||||||
|
|
||||||
p = Popen(["/usr/bin/ls"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env={"LD_LIBRARY_PATH": tmp_dir})
|
# p = Popen(["/usr/bin/ls"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env={"LD_LIBRARY_PATH": tmp_dir})
|
||||||
stdout, _ = p.communicate()
|
# stdout, _ = p.communicate()
|
||||||
self.logger.debug(stdout.decode("utf8"))
|
# self.logger.debug(stdout.decode("utf8"))
|
||||||
|
|
||||||
self.assertIsNotNone(re.search(r'LIEF is Working', stdout.decode("utf8")))
|
# self.assertIsNotNone(re.search(r'LIEF is Working', stdout.decode("utf8")))
|
||||||
|
|
||||||
if os.path.isdir(tmp_dir):
|
# if os.path.isdir(tmp_dir):
|
||||||
shutil.rmtree(tmp_dir)
|
# shutil.rmtree(tmp_dir)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ from subprocess import Popen
|
|||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
import lief
|
import lief
|
||||||
from utils import get_sample, has_recent_glibc
|
from utils import get_sample, has_recent_glibc, is_linux, is_x86_64
|
||||||
|
|
||||||
lief.logging.set_level(lief.logging.LOGGING_LEVEL.INFO)
|
lief.logging.set_level(lief.logging.LOGGING_LEVEL.INFO)
|
||||||
|
|
||||||
@ -80,6 +80,7 @@ class TestELF(TestCase):
|
|||||||
self.assertFalse(gnu_hash.check("foofdsfdsfds"))
|
self.assertFalse(gnu_hash.check("foofdsfdsfds"))
|
||||||
self.assertFalse(gnu_hash.check("fazertrvkdfsrezklqpfjeopqdi"))
|
self.assertFalse(gnu_hash.check("fazertrvkdfsrezklqpfjeopqdi"))
|
||||||
|
|
||||||
|
@unittest.skipUnless(is_linux() and is_x86_64(), "requires Linux x86-64")
|
||||||
@unittest.skipUnless(has_recent_glibc(), "Need a recent GLIBC version")
|
@unittest.skipUnless(has_recent_glibc(), "Need a recent GLIBC version")
|
||||||
def test_permutation(self):
|
def test_permutation(self):
|
||||||
samples = [
|
samples = [
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
import lief
|
import lief
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import argparse
|
import argparse
|
||||||
|
from utils import is_linux, is_x86_64
|
||||||
|
|
||||||
MELKOR_BIN = "@MELKOR_BINARY@"
|
MELKOR_BIN = "@MELKOR_BINARY@"
|
||||||
|
|
||||||
@ -36,6 +38,10 @@ def fuzz(seed, nb):
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
|
if not is_linux() and not is_x86_64():
|
||||||
|
print("Melkor fuzzing is currently only supported on Linux x86-64", file=sys.stderr)
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description = "LIEF ELF Fuzzer")
|
parser = argparse.ArgumentParser(description = "LIEF ELF Fuzzer")
|
||||||
parser.add_argument("--input-seed",
|
parser.add_argument("--input-seed",
|
||||||
dest = 'input_seed',
|
dest = 'input_seed',
|
||||||
@ -48,7 +54,6 @@ if __name__ == '__main__':
|
|||||||
default = 100)
|
default = 100)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
fuzz(args.input_seed, args.nb_samples)
|
fuzz(args.input_seed, args.nb_samples)
|
||||||
print(lief)
|
print(lief)
|
||||||
|
|
||||||
|
BIN
tests/elf/hello_lief_aarch64.bin
Executable file
BIN
tests/elf/hello_lief_aarch64.bin
Executable file
Binary file not shown.
@ -14,7 +14,7 @@ import lief
|
|||||||
from lief.ELF import Section
|
from lief.ELF import Section
|
||||||
|
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from utils import get_sample, has_recent_glibc
|
from utils import get_sample, has_recent_glibc, is_linux, is_x86_64
|
||||||
|
|
||||||
class TestRelocations(TestCase):
|
class TestRelocations(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -23,7 +23,7 @@ class TestRelocations(TestCase):
|
|||||||
self.logger.debug("temp dir: {}".format(self.tmp_dir))
|
self.logger.debug("temp dir: {}".format(self.tmp_dir))
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
@unittest.skipUnless(is_linux() and is_x86_64(), "requires Linux x86-64")
|
||||||
@unittest.skipUnless(has_recent_glibc(), "Need a recent GLIBC version")
|
@unittest.skipUnless(has_recent_glibc(), "Need a recent GLIBC version")
|
||||||
def test_simple(self):
|
def test_simple(self):
|
||||||
sample_path = get_sample('ELF/ELF64_x86-64_binary_ls.bin')
|
sample_path = get_sample('ELF/ELF64_x86-64_binary_ls.bin')
|
||||||
@ -50,7 +50,7 @@ class TestRelocations(TestCase):
|
|||||||
self.logger.debug(stdout.decode("utf8"))
|
self.logger.debug(stdout.decode("utf8"))
|
||||||
self.assertIsNotNone(re.search(r'ls \(GNU coreutils\) ', stdout.decode("utf8")))
|
self.assertIsNotNone(re.search(r'ls \(GNU coreutils\) ', stdout.decode("utf8")))
|
||||||
|
|
||||||
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
@unittest.skipUnless(is_linux() and is_x86_64(), "requires Linux x86-64")
|
||||||
def test_all(self):
|
def test_all(self):
|
||||||
sample_path = get_sample('ELF/ELF64_x86-64_binary_all.bin')
|
sample_path = get_sample('ELF/ELF64_x86-64_binary_all.bin')
|
||||||
output = os.path.join(self.tmp_dir, "all.relocation")
|
output = os.path.join(self.tmp_dir, "all.relocation")
|
||||||
@ -76,7 +76,7 @@ class TestRelocations(TestCase):
|
|||||||
self.assertIsNotNone(re.search(r'Hello World: 1', stdout.decode("utf8")))
|
self.assertIsNotNone(re.search(r'Hello World: 1', stdout.decode("utf8")))
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
@unittest.skipUnless(is_linux() and is_x86_64(), "requires Linux x86-64")
|
||||||
def test_all32(self):
|
def test_all32(self):
|
||||||
sample_path = get_sample('ELF/ELF32_x86_binary_all.bin')
|
sample_path = get_sample('ELF/ELF32_x86_binary_all.bin')
|
||||||
output = os.path.join(self.tmp_dir, "all32.relocation")
|
output = os.path.join(self.tmp_dir, "all32.relocation")
|
||||||
|
@ -14,7 +14,7 @@ import lief
|
|||||||
from lief.ELF import Section
|
from lief.ELF import Section
|
||||||
|
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from utils import get_sample, has_recent_glibc
|
from utils import get_sample, has_recent_glibc, is_linux, is_x86_64
|
||||||
|
|
||||||
CURRENT_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
|
CURRENT_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ class TestRemoveSection(TestCase):
|
|||||||
self.tmp_dir = tempfile.mkdtemp(suffix='_lief_test_section')
|
self.tmp_dir = tempfile.mkdtemp(suffix='_lief_test_section')
|
||||||
self.logger.debug("temp dir: {}".format(self.tmp_dir))
|
self.logger.debug("temp dir: {}".format(self.tmp_dir))
|
||||||
|
|
||||||
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
@unittest.skipUnless(is_linux() and is_x86_64(), "requires Linux x86-64")
|
||||||
@unittest.skipUnless(has_recent_glibc(), "Need a recent GLIBC version")
|
@unittest.skipUnless(has_recent_glibc(), "Need a recent GLIBC version")
|
||||||
def test_simple(self):
|
def test_simple(self):
|
||||||
sample_path = get_sample('ELF/ELF64_x86-64_binary_ls.bin')
|
sample_path = get_sample('ELF/ELF64_x86-64_binary_ls.bin')
|
||||||
|
@ -13,7 +13,7 @@ from unittest import TestCase
|
|||||||
|
|
||||||
import lief
|
import lief
|
||||||
from lief.ELF import Segment
|
from lief.ELF import Segment
|
||||||
from utils import get_sample, has_recent_glibc
|
from utils import get_sample, has_recent_glibc, is_linux, is_x86_64, is_aarch64
|
||||||
|
|
||||||
lief.logging.set_level(lief.logging.LOGGING_LEVEL.INFO)
|
lief.logging.set_level(lief.logging.LOGGING_LEVEL.INFO)
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ class TestAddSegment(TestCase):
|
|||||||
self.logger.debug("temp dir: {}".format(self.tmp_dir))
|
self.logger.debug("temp dir: {}".format(self.tmp_dir))
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
@unittest.skipUnless(is_linux() and is_x86_64(), "requires Linux x86-64")
|
||||||
@unittest.skipUnless(has_recent_glibc(), "Need a recent GLIBC version")
|
@unittest.skipUnless(has_recent_glibc(), "Need a recent GLIBC version")
|
||||||
def test_simple(self):
|
def test_simple(self):
|
||||||
sample_path = get_sample('ELF/ELF64_x86-64_binary_ls.bin')
|
sample_path = get_sample('ELF/ELF64_x86-64_binary_ls.bin')
|
||||||
@ -57,7 +57,7 @@ class TestAddSegment(TestCase):
|
|||||||
self.assertIsNotNone(re.search(r'LIEF is Working', stdout.decode("utf8")))
|
self.assertIsNotNone(re.search(r'LIEF is Working', stdout.decode("utf8")))
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
@unittest.skipUnless(is_linux() and is_x86_64(), "requires Linux x86-64")
|
||||||
@unittest.skipUnless(has_recent_glibc(), "Need a recent GLIBC version")
|
@unittest.skipUnless(has_recent_glibc(), "Need a recent GLIBC version")
|
||||||
def test_gcc(self):
|
def test_gcc(self):
|
||||||
sample_path = get_sample('ELF/ELF64_x86-64_binary_gcc.bin')
|
sample_path = get_sample('ELF/ELF64_x86-64_binary_gcc.bin')
|
||||||
@ -88,10 +88,15 @@ class TestAddSegment(TestCase):
|
|||||||
self.assertIsNotNone(re.search(r'LIEF is Working', stdout.decode("utf8")))
|
self.assertIsNotNone(re.search(r'LIEF is Working', stdout.decode("utf8")))
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
@unittest.skipUnless(is_linux(), "requires Linux")
|
||||||
@unittest.skipUnless(has_recent_glibc(), "Need a recent GLIBC version")
|
@unittest.skipUnless(has_recent_glibc(), "Need a recent GLIBC version")
|
||||||
def test_ssh(self):
|
def test_ssh(self):
|
||||||
|
stub = None
|
||||||
|
if is_x86_64():
|
||||||
stub = lief.parse(os.path.join(CURRENT_DIRECTORY, "hello_lief.bin"))
|
stub = lief.parse(os.path.join(CURRENT_DIRECTORY, "hello_lief.bin"))
|
||||||
|
elif is_aarch64():
|
||||||
|
stub = lief.parse(os.path.join(CURRENT_DIRECTORY, "hello_lief_aarch64.bin"))
|
||||||
|
|
||||||
output = os.path.join(self.tmp_dir, "ssh.replace_segment")
|
output = os.path.join(self.tmp_dir, "ssh.replace_segment")
|
||||||
target = lief.parse("/usr/bin/ssh")
|
target = lief.parse("/usr/bin/ssh")
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ import lief
|
|||||||
from lief.ELF import Section
|
from lief.ELF import Section
|
||||||
|
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from utils import get_sample, has_recent_glibc
|
from utils import get_sample, has_recent_glibc, is_linux, is_x86_64
|
||||||
|
|
||||||
class TestGOTPatch(TestCase):
|
class TestGOTPatch(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -23,7 +23,7 @@ class TestGOTPatch(TestCase):
|
|||||||
self.logger.debug("temp dir: {}".format(self.tmp_dir))
|
self.logger.debug("temp dir: {}".format(self.tmp_dir))
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
@unittest.skipUnless(is_linux() and is_x86_64(), "requires Linux x86-64")
|
||||||
@unittest.skipUnless(has_recent_glibc(), "Need a recent GLIBC version")
|
@unittest.skipUnless(has_recent_glibc(), "Need a recent GLIBC version")
|
||||||
def test_freebl(self):
|
def test_freebl(self):
|
||||||
libfreebl3_path = get_sample('ELF/ELF64_x86-64_library_libfreebl3.so')
|
libfreebl3_path = get_sample('ELF/ELF64_x86-64_library_libfreebl3.so')
|
||||||
|
@ -10,7 +10,7 @@ import unittest
|
|||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
import lief
|
import lief
|
||||||
from utils import get_compiler
|
from utils import get_compiler, is_linux, is_x86_64, is_aarch64
|
||||||
|
|
||||||
lief.logging.set_level(lief.logging.LOGGING_LEVEL.INFO)
|
lief.logging.set_level(lief.logging.LOGGING_LEVEL.INFO)
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ class TestBin2Lib(unittest.TestCase):
|
|||||||
|
|
||||||
return CommandResult(stdout, stderr, p.returncode)
|
return CommandResult(stdout, stderr, p.returncode)
|
||||||
|
|
||||||
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
@unittest.skipUnless(is_linux(), "requires Linux")
|
||||||
def test_libadd(self):
|
def test_libadd(self):
|
||||||
|
|
||||||
|
|
||||||
@ -125,8 +125,15 @@ class TestBin2Lib(unittest.TestCase):
|
|||||||
|
|
||||||
compiler = get_compiler()
|
compiler = get_compiler()
|
||||||
|
|
||||||
|
fmt = ""
|
||||||
|
if is_x86_64():
|
||||||
|
fmt = "{compiler} -Wl,--export-dynamic -mcmodel=large -fPIE -pie -o {output} {input}"
|
||||||
|
|
||||||
|
if is_aarch64():
|
||||||
|
fmt = "{compiler} -Wl,--export-dynamic -fPIE -pie -o {output} {input}"
|
||||||
|
|
||||||
# Compile libadd
|
# Compile libadd
|
||||||
r = self.run_cmd("{compiler} -Wl,--export-dynamic -mcmodel=large -fPIE -pie -o {output} {input}".format(
|
r = self.run_cmd(fmt.format(
|
||||||
compiler=compiler,
|
compiler=compiler,
|
||||||
output=libadd,
|
output=libadd,
|
||||||
input=libaddc))
|
input=libaddc))
|
||||||
@ -138,6 +145,9 @@ class TestBin2Lib(unittest.TestCase):
|
|||||||
libadd_hidden.binding = lief.ELF.SYMBOL_BINDINGS.GLOBAL
|
libadd_hidden.binding = lief.ELF.SYMBOL_BINDINGS.GLOBAL
|
||||||
libadd_hidden.visibility = lief.ELF.SYMBOL_VISIBILITY.DEFAULT
|
libadd_hidden.visibility = lief.ELF.SYMBOL_VISIBILITY.DEFAULT
|
||||||
libadd_hidden = libadd.add_dynamic_symbol(libadd_hidden, lief.ELF.SymbolVersion.global_)
|
libadd_hidden = libadd.add_dynamic_symbol(libadd_hidden, lief.ELF.SymbolVersion.global_)
|
||||||
|
if libadd.has(lief.ELF.DYNAMIC_TAGS.FLAGS_1):
|
||||||
|
libadd[lief.ELF.DYNAMIC_TAGS.FLAGS_1].remove(lief.ELF.DYNAMIC_FLAGS_1.PIE)
|
||||||
|
|
||||||
self._logger.debug(libadd_hidden)
|
self._logger.debug(libadd_hidden)
|
||||||
|
|
||||||
libadd.add(lief.ELF.DynamicSharedObject(os.path.basename(libadd2)))
|
libadd.add(lief.ELF.DynamicSharedObject(os.path.basename(libadd2)))
|
||||||
@ -147,7 +157,14 @@ class TestBin2Lib(unittest.TestCase):
|
|||||||
lib_directory = os.path.dirname(libadd2)
|
lib_directory = os.path.dirname(libadd2)
|
||||||
libname = os.path.basename(libadd2)[3:-3] # libadd.so ---> add
|
libname = os.path.basename(libadd2)[3:-3] # libadd.so ---> add
|
||||||
|
|
||||||
r = self.run_cmd("{compiler} -Wl,--export-dynamic -mcmodel=large -fPIE -pie -Wl,-rpath={libdir} -L{libdir} -o {output} {input} -l{libadd2}".format(
|
fmt = ""
|
||||||
|
if is_x86_64():
|
||||||
|
fmt = "{compiler} -Wl,--export-dynamic -mcmodel=large -fPIE -pie -Wl,-rpath={libdir} -L{libdir} -o {output} {input} -l{libadd2}"
|
||||||
|
|
||||||
|
if is_aarch64():
|
||||||
|
fmt = "{compiler} -Wl,--export-dynamic -fPIE -pie -Wl,-rpath={libdir} -L{libdir} -o {output} {input} -l{libadd2}"
|
||||||
|
|
||||||
|
r = self.run_cmd(fmt.format(
|
||||||
compiler=compiler,
|
compiler=compiler,
|
||||||
libdir=lib_directory,
|
libdir=lib_directory,
|
||||||
libadd2=libname,
|
libadd2=libname,
|
||||||
@ -164,7 +181,7 @@ class TestBin2Lib(unittest.TestCase):
|
|||||||
self.assertIn("From add_hidden@libadd.so a + b = 3", r.output)
|
self.assertIn("From add_hidden@libadd.so a + b = 3", r.output)
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
@unittest.skipUnless(is_linux() and is_x86_64(), "requires Linux")
|
||||||
def test_libadd_api(self):
|
def test_libadd_api(self):
|
||||||
_, binaddc = tempfile.mkstemp(prefix="binadd_", suffix=".c")
|
_, binaddc = tempfile.mkstemp(prefix="binadd_", suffix=".c")
|
||||||
_, libaddc = tempfile.mkstemp(prefix="libadd_", suffix=".c")
|
_, libaddc = tempfile.mkstemp(prefix="libadd_", suffix=".c")
|
||||||
@ -190,7 +207,14 @@ class TestBin2Lib(unittest.TestCase):
|
|||||||
compiler = get_compiler()
|
compiler = get_compiler()
|
||||||
|
|
||||||
# Compile libadd
|
# Compile libadd
|
||||||
r = self.run_cmd("{compiler} -Wl,--export-dynamic -mcmodel=large -fPIE -pie -o {output} {input}".format(
|
fmt = ""
|
||||||
|
if is_x86_64():
|
||||||
|
fmt = "{compiler} -Wl,--export-dynamic -mcmodel=large -fPIE -pie -o {output} {input}"
|
||||||
|
|
||||||
|
if is_aarch64():
|
||||||
|
fmt = "{compiler} -Wl,--export-dynamic -fPIE -pie -o {output} {input}"
|
||||||
|
|
||||||
|
r = self.run_cmd(fmt.format(
|
||||||
compiler=compiler,
|
compiler=compiler,
|
||||||
output=libadd,
|
output=libadd,
|
||||||
input=libaddc))
|
input=libaddc))
|
||||||
@ -203,7 +227,14 @@ class TestBin2Lib(unittest.TestCase):
|
|||||||
lib_directory = os.path.dirname(libadd2)
|
lib_directory = os.path.dirname(libadd2)
|
||||||
libname = os.path.basename(libadd2)[3:-3] # libadd.so ---> add
|
libname = os.path.basename(libadd2)[3:-3] # libadd.so ---> add
|
||||||
|
|
||||||
r = self.run_cmd("{compiler} -Wl,--export-dynamic -mcmodel=large -fPIE -pie -Wl,-rpath={libdir} -L{libdir} -o {output} {input} -l{libadd2}".format(
|
fmt = ""
|
||||||
|
if is_x86_64():
|
||||||
|
fmt = "{compiler} -Wl,--export-dynamic -mcmodel=large -fPIE -pie -Wl,-rpath={libdir} -L{libdir} -o {output} {input} -l{libadd2}"
|
||||||
|
|
||||||
|
if is_aarch64():
|
||||||
|
fmt = "{compiler} -Wl,--export-dynamic -fPIE -pie -Wl,-rpath={libdir} -L{libdir} -o {output} {input} -l{libadd2}"
|
||||||
|
|
||||||
|
r = self.run_cmd(fmt.format(
|
||||||
compiler=compiler,
|
compiler=compiler,
|
||||||
libdir=lib_directory,
|
libdir=lib_directory,
|
||||||
libadd2=libname,
|
libadd2=libname,
|
||||||
@ -220,7 +251,7 @@ class TestBin2Lib(unittest.TestCase):
|
|||||||
self.assertIn("From add_hidden@libadd.so a + b = 3", r.output)
|
self.assertIn("From add_hidden@libadd.so a + b = 3", r.output)
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
@unittest.skipUnless(is_linux() and is_x86_64(), "requires Linux")
|
||||||
def test_libadd_api2(self):
|
def test_libadd_api2(self):
|
||||||
_, binaddc = tempfile.mkstemp(prefix="binadd_", suffix=".c")
|
_, binaddc = tempfile.mkstemp(prefix="binadd_", suffix=".c")
|
||||||
_, libaddc = tempfile.mkstemp(prefix="libadd_", suffix=".c")
|
_, libaddc = tempfile.mkstemp(prefix="libadd_", suffix=".c")
|
||||||
@ -245,8 +276,16 @@ class TestBin2Lib(unittest.TestCase):
|
|||||||
|
|
||||||
compiler = get_compiler()
|
compiler = get_compiler()
|
||||||
|
|
||||||
|
fmt = ""
|
||||||
|
if is_x86_64():
|
||||||
|
fmt = "{compiler} -Wl,--export-dynamic -mcmodel=large -fPIE -pie -o {output} {input}"
|
||||||
|
|
||||||
|
if is_aarch64():
|
||||||
|
fmt = "{compiler} -Wl,--export-dynamic -fPIE -pie -o {output} {input}"
|
||||||
|
|
||||||
|
|
||||||
# Compile libadd
|
# Compile libadd
|
||||||
r = self.run_cmd("{compiler} -Wl,--export-dynamic -mcmodel=large -fPIE -pie -o {output} {input}".format(
|
r = self.run_cmd(fmt.format(
|
||||||
compiler=compiler,
|
compiler=compiler,
|
||||||
output=libadd,
|
output=libadd,
|
||||||
input=libaddc))
|
input=libaddc))
|
||||||
|
@ -3,6 +3,7 @@ import unittest
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import platform
|
||||||
import stat
|
import stat
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
@ -13,7 +14,7 @@ import ctypes
|
|||||||
import lief
|
import lief
|
||||||
|
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from utils import get_sample, has_recent_glibc
|
from utils import get_sample, has_recent_glibc, is_linux, is_x86_64
|
||||||
|
|
||||||
class TestEmptyGNUHash(TestCase):
|
class TestEmptyGNUHash(TestCase):
|
||||||
SYMBOLS = {
|
SYMBOLS = {
|
||||||
@ -29,7 +30,7 @@ class TestEmptyGNUHash(TestCase):
|
|||||||
self.logger.debug("temp dir: {}".format(self.tmp_dir))
|
self.logger.debug("temp dir: {}".format(self.tmp_dir))
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(sys.platform.startswith("linux"), "requires Linux")
|
@unittest.skipUnless(is_linux() and is_x86_64(), "requires Linux x86-64")
|
||||||
@unittest.skipUnless(has_recent_glibc(), "Need a recent GLIBC version")
|
@unittest.skipUnless(has_recent_glibc(), "Need a recent GLIBC version")
|
||||||
def test_export(self):
|
def test_export(self):
|
||||||
target_path = get_sample('ELF/ELF64_x86-64_binary_empty-gnu-hash.bin')
|
target_path = get_sample('ELF/ELF64_x86-64_binary_empty-gnu-hash.bin')
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
import platform
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
@ -17,6 +19,15 @@ def get_compiler():
|
|||||||
raise RuntimeError("Unable to find a compiler")
|
raise RuntimeError("Unable to find a compiler")
|
||||||
return compiler
|
return compiler
|
||||||
|
|
||||||
|
def is_linux():
|
||||||
|
return sys.platform.startswith("linux")
|
||||||
|
|
||||||
|
def is_x86_64():
|
||||||
|
machine = platform.machine().lower()
|
||||||
|
return machine in ("x86_64", "amd64")
|
||||||
|
|
||||||
|
def is_aarch64():
|
||||||
|
return platform.machine() == "aarch64"
|
||||||
|
|
||||||
def has_recent_glibc():
|
def has_recent_glibc():
|
||||||
"""Check if we have at least GLIBC 2.17 (2012)"""
|
"""Check if we have at least GLIBC 2.17 (2012)"""
|
||||||
|
BIN
third-party/Melkor_ELF_Fuzzer-1d62ccc.zip
vendored
Normal file
BIN
third-party/Melkor_ELF_Fuzzer-1d62ccc.zip
vendored
Normal file
Binary file not shown.
BIN
third-party/Melkor_ELF_Fuzzer-master.zip
vendored
BIN
third-party/Melkor_ELF_Fuzzer-master.zip
vendored
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user