|
| 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 |
1 | 5 | import os
|
2 |
| -from conans import ConanFile, CMake, tools |
| 6 | + |
| 7 | +required_conan_version = ">=1.53.0" |
3 | 8 |
|
4 | 9 |
|
5 | 10 | class CapstoneConan(ConanFile):
|
6 | 11 | name = "capstone"
|
7 | 12 | license = "BSD-3-Clause"
|
8 | 13 | url = "https://github.com/conan-io/conan-center-index"
|
9 | 14 | 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 | + |
12 | 26 | 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"] |
23 | 39 | options.update({a: [True, False] for a in _archs})
|
24 | 40 | default_options.update({a: True for a in _archs})
|
25 | 41 |
|
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 |
32 | 45 |
|
33 | 46 | def configure(self):
|
34 | 47 | 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") |
38 | 51 |
|
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") |
42 | 54 |
|
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 |
53 | 67 | 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() |
61 | 71 |
|
62 | 72 | def build(self):
|
63 |
| - cmake = self._configure_cmake() |
| 73 | + cmake = CMake(self) |
| 74 | + cmake.configure() |
64 | 75 | cmake.build()
|
65 | 76 |
|
66 | 77 | 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) |
70 | 80 | 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 |
74 | 81 |
|
75 | 82 | def package_info(self):
|
| 83 | + suffix = "_dll" if is_msvc(self) and self.options.shared else "" |
| 84 | + self.cpp_info.libs = [f"capstone{suffix}"] |
76 | 85 | 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") |
0 commit comments