Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

capstone: conan v2 support #14262

Merged
merged 2 commits into from
Nov 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions recipes/capstone/all/CMakeLists.txt

This file was deleted.

2 changes: 1 addition & 1 deletion recipes/capstone/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sources:
"4.0.2":
url: "https://github.com/aquynh/capstone/archive/refs/tags/4.0.2.tar.gz"
url: "https://github.com/capstone-engine/capstone/archive/refs/tags/4.0.2.tar.gz"
sha256: "7c81d798022f81e7507f1a60d6817f63aa76e489aa4e7055255f21a22f5e526a"
113 changes: 59 additions & 54 deletions recipes/capstone/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,81 +1,86 @@
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import copy, get
from conan.tools.microsoft import is_msvc, is_msvc_static_runtime
import os
from conans import ConanFile, CMake, tools

required_conan_version = ">=1.53.0"


class CapstoneConan(ConanFile):
name = "capstone"
license = "BSD-3-Clause"
url = "https://github.com/conan-io/conan-center-index"
homepage = "http://www.capstone-engine.org"
description = "Capstone disassembly/disassembler framework: Core (Arm, Arm64, BPF, EVM, M68K, M680X, MOS65xx, Mips, PPC, RISCV, Sparc, SystemZ, TMS320C64x, Web Assembly, X86, X86_64, XCore) + bindings."
topics = ("conan", 'reverse-engineering', 'disassembler', 'security', 'framework', 'arm', 'arm64', 'x86', 'sparc', 'powerpc', 'mips', 'x86-64', 'ethereum', 'systemz', 'webassembly', 'm68k', 'm0s65xx', 'm680x', 'tms320c64x', 'bpf', 'riscv')
description = (
"Capstone disassembly/disassembler framework: Core (Arm, Arm64, BPF, "
"EVM, M68K, M680X, MOS65xx, Mips, PPC, RISCV, Sparc, SystemZ, "
"TMS320C64x, Web Assembly, X86, X86_64, XCore) + bindings."
)
topics = (
"reverse-engineering", "disassembler", "security", "framework", "arm", "arm64",
"x86", "sparc", "powerpc", "mips", "x86-64", "ethereum", "systemz",
"webassembly", "m68k", "m0s65xx", "m680x", "tms320c64x", "bpf", "riscv",
)

settings = "os", "arch", "compiler", "build_type"
options = {"shared": [True, False],
"fPIC": [True, False],
"use_default_alloc": [True, False]}
default_options = {"shared": False,
"fPIC": True,
"use_default_alloc": True}
exports_sources = ["CMakeLists.txt"]
generators = "cmake",
_cmake = None
_archs = ['arm', 'm68k', 'mips', 'ppc', 'sparc', 'sysz', 'xcore', 'x86', 'tms320c64x', 'm680x', 'evm']
options = {
"shared": [True, False],
"fPIC": [True, False],
"use_default_alloc": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"use_default_alloc": True,
}

_archs = ["arm", "m68k", "mips", "ppc", "sparc", "sysz", "xcore", "x86", "tms320c64x", "m680x", "evm"]
options.update({a: [True, False] for a in _archs})
default_options.update({a: True for a in _archs})

@property
def _source_subfolder(self):
return "source_subfolder"

def source(self):
tools.get(**self.conan_data["sources"][self.version], strip_root=True, destination=self._source_subfolder)
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
del self.options.fPIC
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
self.options.rm_safe("fPIC")
self.settings.rm_safe("compiler.cppstd")
self.settings.rm_safe("compiler.libcxx")

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
def layout(self):
cmake_layout(self, src_folder="src")

def _configure_cmake(self):
if self._cmake:
return self._cmake
cmake = CMake(self)
cmake.definitions['CAPSTONE_BUILD_STATIC'] = not self.options.shared
cmake.definitions['CAPSTONE_BUILD_SHARED'] = self.options.shared
cmake.definitions['CAPSTONE_BUILD_TESTS'] = False
cmake.definitions['CAPSTONE_BUILD_CSTOOL'] = False
cmake.definitions['CAPSTONE_ARCHITECUTRE_DEFAULT'] = False
cmake.definitions['CAPSTONE_USE_SYS_DYN_MEM'] = self.options.use_default_alloc
def source(self):
get(self, **self.conan_data["sources"][self.version],
destination=self.source_folder, strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["CAPSTONE_BUILD_STATIC"] = not self.options.shared
tc.variables["CAPSTONE_BUILD_SHARED"] = self.options.shared
tc.variables["CAPSTONE_BUILD_TESTS"] = False
tc.variables["CAPSTONE_BUILD_CSTOOL"] = False
tc.variables["CAPSTONE_ARCHITECUTRE_DEFAULT"] = False
tc.variables["CAPSTONE_USE_SYS_DYN_MEM"] = self.options.use_default_alloc
for a in self._archs:
cmake.definitions['CAPSTONE_%s_SUPPORT' % a.upper()] = self.options.get_safe(a)
runtime = self.settings.get_safe("compiler.runtime")
if runtime:
cmake.definitions['CAPSTONE_BUILD_STATIC_RUNTIME'] = 'MT' in runtime
cmake.configure()
self._cmake = cmake
return self._cmake
tc.variables[f"CAPSTONE_{a.upper()}_SUPPORT"] = self.options.get_safe(a)
tc.variables["CAPSTONE_BUILD_STATIC_RUNTIME"] = is_msvc_static_runtime(self)
tc.generate()

def build(self):
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
self.copy("LICENSE_LLVM.txt", dst="licenses", src=self._source_subfolder)
self.copy("LICENSE.txt", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
copy(self, "LICENSE*.txt", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
# FIXME : add components, if needed

def package_info(self):
suffix = "_dll" if is_msvc(self) and self.options.shared else ""
self.cpp_info.libs = [f"capstone{suffix}"]
if self.options.shared:
self.cpp_info.defines.append('CAPSTONE_SHARED')
if self.settings.compiler == "Visual Studio" and self.options.shared:
self.cpp_info.libs = ["capstone_dll"]
else:
self.cpp_info.libs = ["capstone"]
self.cpp_info.defines.append("CAPSTONE_SHARED")
7 changes: 3 additions & 4 deletions recipes/capstone/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)
project(test_package LANGUAGES C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
find_package(capstone REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
target_link_libraries(${PROJECT_NAME} PRIVATE capstone::capstone)
21 changes: 15 additions & 6 deletions recipes/capstone/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package"
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"

def layout(self):
cmake_layout(self)

def requirements(self):
self.requires(self.tested_reference_str)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self.settings):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
8 changes: 8 additions & 0 deletions recipes/capstone/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package
${CMAKE_CURRENT_BINARY_DIR}/test_package)
17 changes: 17 additions & 0 deletions recipes/capstone/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)