Skip to content

Commit 2860ffe

Browse files
authored
(#14262) capstone: conan v2 support
* conan v2 support * update download url
1 parent 3dd7a73 commit 2860ffe

File tree

7 files changed

+103
-72
lines changed

7 files changed

+103
-72
lines changed

recipes/capstone/all/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
This file was deleted.

recipes/capstone/all/conandata.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
sources:
22
"4.0.2":
3-
url: "https://github.com/aquynh/capstone/archive/refs/tags/4.0.2.tar.gz"
3+
url: "https://github.com/capstone-engine/capstone/archive/refs/tags/4.0.2.tar.gz"
44
sha256: "7c81d798022f81e7507f1a60d6817f63aa76e489aa4e7055255f21a22f5e526a"

recipes/capstone/all/conanfile.py

Lines changed: 59 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,86 @@
1+
from conan import ConanFile
2+
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
3+
from conan.tools.files import copy, get
4+
from conan.tools.microsoft import is_msvc, is_msvc_static_runtime
15
import os
2-
from conans import ConanFile, CMake, tools
6+
7+
required_conan_version = ">=1.53.0"
38

49

510
class CapstoneConan(ConanFile):
611
name = "capstone"
712
license = "BSD-3-Clause"
813
url = "https://github.com/conan-io/conan-center-index"
914
homepage = "http://www.capstone-engine.org"
10-
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."
11-
topics = ("conan", 'reverse-engineering', 'disassembler', 'security', 'framework', 'arm', 'arm64', 'x86', 'sparc', 'powerpc', 'mips', 'x86-64', 'ethereum', 'systemz', 'webassembly', 'm68k', 'm0s65xx', 'm680x', 'tms320c64x', 'bpf', 'riscv')
15+
description = (
16+
"Capstone disassembly/disassembler framework: Core (Arm, Arm64, BPF, "
17+
"EVM, M68K, M680X, MOS65xx, Mips, PPC, RISCV, Sparc, SystemZ, "
18+
"TMS320C64x, Web Assembly, X86, X86_64, XCore) + bindings."
19+
)
20+
topics = (
21+
"reverse-engineering", "disassembler", "security", "framework", "arm", "arm64",
22+
"x86", "sparc", "powerpc", "mips", "x86-64", "ethereum", "systemz",
23+
"webassembly", "m68k", "m0s65xx", "m680x", "tms320c64x", "bpf", "riscv",
24+
)
25+
1226
settings = "os", "arch", "compiler", "build_type"
13-
options = {"shared": [True, False],
14-
"fPIC": [True, False],
15-
"use_default_alloc": [True, False]}
16-
default_options = {"shared": False,
17-
"fPIC": True,
18-
"use_default_alloc": True}
19-
exports_sources = ["CMakeLists.txt"]
20-
generators = "cmake",
21-
_cmake = None
22-
_archs = ['arm', 'm68k', 'mips', 'ppc', 'sparc', 'sysz', 'xcore', 'x86', 'tms320c64x', 'm680x', 'evm']
27+
options = {
28+
"shared": [True, False],
29+
"fPIC": [True, False],
30+
"use_default_alloc": [True, False],
31+
}
32+
default_options = {
33+
"shared": False,
34+
"fPIC": True,
35+
"use_default_alloc": True,
36+
}
37+
38+
_archs = ["arm", "m68k", "mips", "ppc", "sparc", "sysz", "xcore", "x86", "tms320c64x", "m680x", "evm"]
2339
options.update({a: [True, False] for a in _archs})
2440
default_options.update({a: True for a in _archs})
2541

26-
@property
27-
def _source_subfolder(self):
28-
return "source_subfolder"
29-
30-
def source(self):
31-
tools.get(**self.conan_data["sources"][self.version], strip_root=True, destination=self._source_subfolder)
42+
def config_options(self):
43+
if self.settings.os == "Windows":
44+
del self.options.fPIC
3245

3346
def configure(self):
3447
if self.options.shared:
35-
del self.options.fPIC
36-
del self.settings.compiler.libcxx
37-
del self.settings.compiler.cppstd
48+
self.options.rm_safe("fPIC")
49+
self.settings.rm_safe("compiler.cppstd")
50+
self.settings.rm_safe("compiler.libcxx")
3851

39-
def config_options(self):
40-
if self.settings.os == "Windows":
41-
del self.options.fPIC
52+
def layout(self):
53+
cmake_layout(self, src_folder="src")
4254

43-
def _configure_cmake(self):
44-
if self._cmake:
45-
return self._cmake
46-
cmake = CMake(self)
47-
cmake.definitions['CAPSTONE_BUILD_STATIC'] = not self.options.shared
48-
cmake.definitions['CAPSTONE_BUILD_SHARED'] = self.options.shared
49-
cmake.definitions['CAPSTONE_BUILD_TESTS'] = False
50-
cmake.definitions['CAPSTONE_BUILD_CSTOOL'] = False
51-
cmake.definitions['CAPSTONE_ARCHITECUTRE_DEFAULT'] = False
52-
cmake.definitions['CAPSTONE_USE_SYS_DYN_MEM'] = self.options.use_default_alloc
55+
def source(self):
56+
get(self, **self.conan_data["sources"][self.version],
57+
destination=self.source_folder, strip_root=True)
58+
59+
def generate(self):
60+
tc = CMakeToolchain(self)
61+
tc.variables["CAPSTONE_BUILD_STATIC"] = not self.options.shared
62+
tc.variables["CAPSTONE_BUILD_SHARED"] = self.options.shared
63+
tc.variables["CAPSTONE_BUILD_TESTS"] = False
64+
tc.variables["CAPSTONE_BUILD_CSTOOL"] = False
65+
tc.variables["CAPSTONE_ARCHITECUTRE_DEFAULT"] = False
66+
tc.variables["CAPSTONE_USE_SYS_DYN_MEM"] = self.options.use_default_alloc
5367
for a in self._archs:
54-
cmake.definitions['CAPSTONE_%s_SUPPORT' % a.upper()] = self.options.get_safe(a)
55-
runtime = self.settings.get_safe("compiler.runtime")
56-
if runtime:
57-
cmake.definitions['CAPSTONE_BUILD_STATIC_RUNTIME'] = 'MT' in runtime
58-
cmake.configure()
59-
self._cmake = cmake
60-
return self._cmake
68+
tc.variables[f"CAPSTONE_{a.upper()}_SUPPORT"] = self.options.get_safe(a)
69+
tc.variables["CAPSTONE_BUILD_STATIC_RUNTIME"] = is_msvc_static_runtime(self)
70+
tc.generate()
6171

6272
def build(self):
63-
cmake = self._configure_cmake()
73+
cmake = CMake(self)
74+
cmake.configure()
6475
cmake.build()
6576

6677
def package(self):
67-
self.copy("LICENSE_LLVM.txt", dst="licenses", src=self._source_subfolder)
68-
self.copy("LICENSE.txt", dst="licenses", src=self._source_subfolder)
69-
cmake = self._configure_cmake()
78+
copy(self, "LICENSE*.txt", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
79+
cmake = CMake(self)
7080
cmake.install()
71-
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
72-
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
73-
# FIXME : add components, if needed
7481

7582
def package_info(self):
83+
suffix = "_dll" if is_msvc(self) and self.options.shared else ""
84+
self.cpp_info.libs = [f"capstone{suffix}"]
7685
if self.options.shared:
77-
self.cpp_info.defines.append('CAPSTONE_SHARED')
78-
if self.settings.compiler == "Visual Studio" and self.options.shared:
79-
self.cpp_info.libs = ["capstone_dll"]
80-
else:
81-
self.cpp_info.libs = ["capstone"]
86+
self.cpp_info.defines.append("CAPSTONE_SHARED")
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
cmake_minimum_required(VERSION 3.1)
2-
project(test_package)
2+
project(test_package LANGUAGES C)
33

4-
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
5-
conan_basic_setup()
4+
find_package(capstone REQUIRED CONFIG)
65

76
add_executable(${PROJECT_NAME} test_package.c)
8-
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
7+
target_link_libraries(${PROJECT_NAME} PRIVATE capstone::capstone)
Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
1-
from conans import ConanFile, CMake, tools
1+
from conan import ConanFile
2+
from conan.tools.build import can_run
3+
from conan.tools.cmake import CMake, cmake_layout
24
import os
35

46

57
class TestPackageConan(ConanFile):
6-
settings = "os", "compiler", "build_type", "arch"
7-
generators = "cmake", "cmake_find_package"
8+
settings = "os", "arch", "compiler", "build_type"
9+
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"
10+
test_type = "explicit"
11+
12+
def layout(self):
13+
cmake_layout(self)
14+
15+
def requirements(self):
16+
self.requires(self.tested_reference_str)
817

918
def build(self):
1019
cmake = CMake(self)
1120
cmake.configure()
1221
cmake.build()
1322

1423
def test(self):
15-
if not tools.cross_building(self.settings):
16-
bin_path = os.path.join("bin", "test_package")
17-
self.run(bin_path, run_environment=True)
24+
if can_run(self):
25+
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
26+
self.run(bin_path, env="conanrun")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cmake_minimum_required(VERSION 3.1)
2+
project(test_package)
3+
4+
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
5+
conan_basic_setup(TARGETS)
6+
7+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package
8+
${CMAKE_CURRENT_BINARY_DIR}/test_package)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from conans import ConanFile, CMake, tools
2+
import os
3+
4+
5+
class TestPackageConan(ConanFile):
6+
settings = "os", "arch", "compiler", "build_type"
7+
generators = "cmake", "cmake_find_package_multi"
8+
9+
def build(self):
10+
cmake = CMake(self)
11+
cmake.configure()
12+
cmake.build()
13+
14+
def test(self):
15+
if not tools.cross_building(self):
16+
bin_path = os.path.join("bin", "test_package")
17+
self.run(bin_path, run_environment=True)

0 commit comments

Comments
 (0)