xref: /aosp_15_r20/external/capstone/COMPILE_CMAKE.TXT (revision 9a0e4156d50a75a99ec4f1653a0e9602a5d45c18)
1*9a0e4156SSadaf EbrahimiThis documentation explains how to compile Capstone with CMake, focus on
2*9a0e4156SSadaf Ebrahimiusing Microsoft Visual C as the compiler.
3*9a0e4156SSadaf Ebrahimi
4*9a0e4156SSadaf EbrahimiTo compile Capstone on *nix, see COMPILE.TXT.
5*9a0e4156SSadaf Ebrahimi
6*9a0e4156SSadaf EbrahimiTo compile Capstone on Windows using Visual Studio, see COMPILE_MSVC.TXT.
7*9a0e4156SSadaf Ebrahimi
8*9a0e4156SSadaf Ebrahimi                        *-*-*-*-*-*
9*9a0e4156SSadaf Ebrahimi
10*9a0e4156SSadaf EbrahimiThis documentation requires CMake & Windows SDK or MS Visual Studio installed on
11*9a0e4156SSadaf Ebrahimiyour machine.
12*9a0e4156SSadaf Ebrahimi
13*9a0e4156SSadaf EbrahimiGet CMake for free from http://www.cmake.org.
14*9a0e4156SSadaf Ebrahimi
15*9a0e4156SSadaf Ebrahimi
16*9a0e4156SSadaf Ebrahimi
17*9a0e4156SSadaf Ebrahimi(0) Tailor Capstone to your need.
18*9a0e4156SSadaf Ebrahimi
19*9a0e4156SSadaf Ebrahimi  Out of archtitectures supported by Capstone, if you just need several selected archs,
20*9a0e4156SSadaf Ebrahimi  run "cmake" with the unwanted archs disabled (set to 0) as followings.
21*9a0e4156SSadaf Ebrahimi
22*9a0e4156SSadaf Ebrahimi  - CAPSTONE_ARM_SUPPORT: support ARM. Run cmake with -DCAPSTONE_ARM_SUPPORT=0 to remove ARM.
23*9a0e4156SSadaf Ebrahimi  - CAPSTONE_ARM64_SUPPORT: support ARM64. Run cmake with -DCAPSTONE_ARM64_SUPPORT=0 to remove ARM64.
24*9a0e4156SSadaf Ebrahimi  - CAPSTONE_M680X_SUPPORT: support M680X. Run cmake with -DCAPSTONE_M680X_SUPPORT=0 to remove M680X.
25*9a0e4156SSadaf Ebrahimi  - CAPSTONE_M68K_SUPPORT: support M68K. Run cmake with -DCAPSTONE_M68K_SUPPORT=0 to remove M68K.
26*9a0e4156SSadaf Ebrahimi  - CAPSTONE_MIPS_SUPPORT: support Mips. Run cmake with -DCAPSTONE_MIPS_SUPPORT=0 to remove Mips.
27*9a0e4156SSadaf Ebrahimi  - CAPSTONE_MOS65XX_SUPPORT: support MOS65XX. Run cmake with -DCAPSTONE_MOS65XX_SUPPORT=0 to remove MOS65XX.
28*9a0e4156SSadaf Ebrahimi  - CAPSTONE_PPC_SUPPORT: support PPC. Run cmake with -DCAPSTONE_PPC_SUPPORT=0 to remove PPC.
29*9a0e4156SSadaf Ebrahimi  - CAPSTONE_SPARC_SUPPORT: support Sparc. Run cmake with -DCAPSTONE_SPARC_SUPPORT=0 to remove Sparc.
30*9a0e4156SSadaf Ebrahimi  - CAPSTONE_SYSZ_SUPPORT: support SystemZ. Run cmake with -DCAPSTONE_SYSZ_SUPPORT=0 to remove SystemZ.
31*9a0e4156SSadaf Ebrahimi  - CAPSTONE_XCORE_SUPPORT: support XCore. Run cmake with -DCAPSTONE_XCORE_SUPPORT=0 to remove XCore.
32*9a0e4156SSadaf Ebrahimi  - CAPSTONE_X86_SUPPORT: support X86. Run cmake with -DCAPSTONE_X86_SUPPORT=0 to remove X86.
33*9a0e4156SSadaf Ebrahimi  - CAPSTONE_TMS320C64X_SUPPORT: support TMS320C64X. Run cmake with -DCAPSTONE_TMS320C64X_SUPPORT=0 to remove TMS320C64X.
34*9a0e4156SSadaf Ebrahimi  - CAPSTONE_EVM_SUPPORT: support EVM. Run cmake with -DCAPSTONE_EVM_SUPPORT=0 to remove EVM.
35*9a0e4156SSadaf Ebrahimi  - CAPSTONE_ARCHITECTURE_DEFAULT: Whether architectures are enabled by default.
36*9a0e4156SSadaf Ebrahimi      Set this of OFF with -DCAPSTONE_ARCHITECTURE_DEFAULT=OFF to disable all architectures by default.
37*9a0e4156SSadaf Ebrahimi      You can then enable them again with one of the CAPSTONE_<ARCH>_SUPPORT options.
38*9a0e4156SSadaf Ebrahimi
39*9a0e4156SSadaf Ebrahimi  By default, all architectures are compiled in.
40*9a0e4156SSadaf Ebrahimi
41*9a0e4156SSadaf Ebrahimi
42*9a0e4156SSadaf Ebrahimi  Besides, Capstone also allows some more customization via following macros.
43*9a0e4156SSadaf Ebrahimi
44*9a0e4156SSadaf Ebrahimi  - CAPSTONE_USE_SYS_DYN_MEM: change this to OFF to use your own dynamic memory management.
45*9a0e4156SSadaf Ebrahimi  - CAPSTONE_BUILD_DIET: change this to ON to make the binaries more compact.
46*9a0e4156SSadaf Ebrahimi  - CAPSTONE_X86_REDUCE: change this to ON to make X86 binary smaller.
47*9a0e4156SSadaf Ebrahimi  - CAPSTONE_X86_ATT_DISABLE: change this to ON to disable AT&T syntax on x86.
48*9a0e4156SSadaf Ebrahimi
49*9a0e4156SSadaf Ebrahimi  By default, Capstone use system dynamic memory management, and both DIET and X86_REDUCE
50*9a0e4156SSadaf Ebrahimi  modes are disabled. To use your own memory allocations, turn ON both DIET &
51*9a0e4156SSadaf Ebrahimi  X86_REDUCE, run "cmake" with: -DCAPSTONE_USE_SYS_DYN_MEM=0 -DCAPSTONE_BUILD_DIET=1 -DCAPSTONE_X86_REDUCE=1
52*9a0e4156SSadaf Ebrahimi
53*9a0e4156SSadaf Ebrahimi
54*9a0e4156SSadaf Ebrahimi  For each option, refer to docs/README for more details.
55*9a0e4156SSadaf Ebrahimi
56*9a0e4156SSadaf Ebrahimi
57*9a0e4156SSadaf Ebrahimi
58*9a0e4156SSadaf Ebrahimi(1) CMake allows you to generate different generators to build Capstone. Below is
59*9a0e4156SSadaf Ebrahimi    some examples on how to build Capstone on Windows with CMake.
60*9a0e4156SSadaf Ebrahimi
61*9a0e4156SSadaf Ebrahimi  (*) You can let CMake select a generator for you. Do:
62*9a0e4156SSadaf Ebrahimi
63*9a0e4156SSadaf Ebrahimi      mkdir build
64*9a0e4156SSadaf Ebrahimi      cd build
65*9a0e4156SSadaf Ebrahimi      cmake ..
66*9a0e4156SSadaf Ebrahimi
67*9a0e4156SSadaf Ebrahimi    This last command is also where you can pass additional CMake configuration flags
68*9a0e4156SSadaf Ebrahimi    using `-D<key>=<value>`. Then to build use:
69*9a0e4156SSadaf Ebrahimi
70*9a0e4156SSadaf Ebrahimi      cmake --build . --config Release
71*9a0e4156SSadaf Ebrahimi
72*9a0e4156SSadaf Ebrahimi
73*9a0e4156SSadaf Ebrahimi  (*) To build Capstone using Nmake of Windows SDK, do:
74*9a0e4156SSadaf Ebrahimi
75*9a0e4156SSadaf Ebrahimi      mkdir build
76*9a0e4156SSadaf Ebrahimi      cd build
77*9a0e4156SSadaf Ebrahimi      ..\nmake.bat
78*9a0e4156SSadaf Ebrahimi
79*9a0e4156SSadaf Ebrahimi  After this, find the samples test*.exe, capstone.lib & capstone.dll
80*9a0e4156SSadaf Ebrahimi  in the same directory.
81*9a0e4156SSadaf Ebrahimi
82*9a0e4156SSadaf Ebrahimi
83*9a0e4156SSadaf Ebrahimi
84*9a0e4156SSadaf Ebrahimi  (*) To build Capstone using Visual Studio, choose the generator accordingly to the
85*9a0e4156SSadaf Ebrahimi  version of Visual Studio on your machine. For example, with Visual Studio 2013, do:
86*9a0e4156SSadaf Ebrahimi
87*9a0e4156SSadaf Ebrahimi      mkdir build
88*9a0e4156SSadaf Ebrahimi      cd build
89*9a0e4156SSadaf Ebrahimi      cmake -G "Visual Studio 12" ..
90*9a0e4156SSadaf Ebrahimi
91*9a0e4156SSadaf Ebrahimi  After this, find capstone.sln in the same directory. Open it with Visual Studio
92*9a0e4156SSadaf Ebrahimi  and build the solution including libraries & all test as usual.
93*9a0e4156SSadaf Ebrahimi
94*9a0e4156SSadaf Ebrahimi
95*9a0e4156SSadaf Ebrahimi
96*9a0e4156SSadaf Ebrahimi(2) You can make sure the prior steps successfully worked by launching one of the
97*9a0e4156SSadaf Ebrahimi  testing binary (test*.exe).
98*9a0e4156SSadaf Ebrahimi
99*9a0e4156SSadaf Ebrahimi(3) You can also enable just one specific architecture by passing the architecture name
100*9a0e4156SSadaf Ebrahimi  to either the cmake.sh or nmake.bat scripts. e.g.:
101*9a0e4156SSadaf Ebrahimi
102*9a0e4156SSadaf Ebrahimi    ../cmake.sh x86
103*9a0e4156SSadaf Ebrahimi
104*9a0e4156SSadaf Ebrahimi  Will just target the x86 architecture. The list of available architectures is: ARM,
105*9a0e4156SSadaf Ebrahimi  ARM64, M68K, MIPS, PowerPC, Sparc, SystemZ, XCore, x86, TMS320C64x, M680x, EVM, MOS65XX.
106*9a0e4156SSadaf Ebrahimi
107*9a0e4156SSadaf Ebrahimi(4) You can also create an installation image with cmake, by using the 'install' target.
108*9a0e4156SSadaf Ebrahimi  Use:
109*9a0e4156SSadaf Ebrahimi
110*9a0e4156SSadaf Ebrahimi    cmake --build . --config Release --target install
111*9a0e4156SSadaf Ebrahimi
112*9a0e4156SSadaf Ebrahimi  This will normally install an image in a default location (`C:\Program Files` on Windows),
113*9a0e4156SSadaf Ebrahimi  so it's good to explicitly set this location when configuring CMake. Use: `-DCMAKE_INSTALL_PREFIX=image`
114*9a0e4156SSadaf Ebrahimi  for instance, to put the installation in the 'image' subdirectory of the build directory.
115