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