daniel | 96ecc33 | 2014-05-18 02:03:15 -0700 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 2.6) |
| 2 | project(capstone) |
| 3 | |
Nguyen Anh Quynh | 758fcbe | 2014-05-31 10:44:27 +0800 | [diff] [blame] | 4 | set(VERSION_MAJOR 2) |
Nguyen Anh Quynh | de8c689 | 2014-05-31 10:45:15 +0800 | [diff] [blame] | 5 | set(VERSION_MINOR 2) |
| 6 | set(VERSION_PATCH 0) |
Nguyen Anh Quynh | 56e4efd | 2014-05-28 16:27:53 +0800 | [diff] [blame] | 7 | |
Nguyen Anh Quynh | 758fcbe | 2014-05-31 10:44:27 +0800 | [diff] [blame] | 8 | # to configure the options specify them in in the command line or change them in the cmake UI. |
| 9 | # Don't edit the makefile! |
Yegor Derevenets | b4d78d9 | 2014-09-19 18:39:22 +0200 | [diff] [blame] | 10 | option(CAPSTONE_BUILD_STATIC "Build static library" ON) |
| 11 | option(CAPSTONE_BUILD_SHARED "Build shared library" ON) |
| 12 | option(CAPSTONE_BUILD_DIET "Build diet library" OFF) |
| 13 | option(CAPSTONE_BUILD_TESTS "Build tests" ON) |
| 14 | option(CAPSTONE_USE_DEFAULT_ALLOC "Use default memory allocation functions" ON) |
Nguyen Anh Quynh | a71a27b | 2014-05-28 21:20:30 +0800 | [diff] [blame] | 15 | |
Yegor Derevenets | b4d78d9 | 2014-09-19 18:39:22 +0200 | [diff] [blame] | 16 | option(CAPSTONE_ARM_SUPPORT "ARM support" ON) |
| 17 | option(CAPSTONE_ARM64_SUPPORT "ARM64 support" ON) |
| 18 | option(CAPSTONE_MIPS_SUPPORT "MIPS support" ON) |
| 19 | option(CAPSTONE_PPC_SUPPORT "PowerPC support" ON) |
Yegor Derevenets | ebc4ced | 2014-09-21 19:52:57 +0200 | [diff] [blame] | 20 | option(CAPSTONE_SPARC_SUPPORT "Sparc support" ON) |
Yegor Derevenets | b4d78d9 | 2014-09-19 18:39:22 +0200 | [diff] [blame] | 21 | option(CAPSTONE_SYSZ_SUPPORT "SystemZ support" ON) |
| 22 | option(CAPSTONE_XCORE_SUPPORT "XCore support" ON) |
| 23 | option(CAPSTONE_X86_SUPPORT "x86 support" ON) |
| 24 | option(CAPSTONE_X86_REDUCE "x86 with reduce instruction sets to minimize library" OFF) |
| 25 | option(CAPSTONE_X86_ATT_DISABLE, "Disable x86 AT&T syntax" OFF) |
Nguyen Anh Quynh | a71a27b | 2014-05-28 21:20:30 +0800 | [diff] [blame] | 26 | |
Yegor Derevenets | b4d78d9 | 2014-09-19 18:39:22 +0200 | [diff] [blame] | 27 | if (CAPSTONE_BUILD_DIET) |
Nguyen Anh Quynh | 758fcbe | 2014-05-31 10:44:27 +0800 | [diff] [blame] | 28 | add_definitions(-DCAPSTONE_DIET) |
| 29 | endif () |
daniel | 96ecc33 | 2014-05-18 02:03:15 -0700 | [diff] [blame] | 30 | |
Yegor Derevenets | b4d78d9 | 2014-09-19 18:39:22 +0200 | [diff] [blame] | 31 | if (CAPSTONE_USE_DEFAULT_ALLOC) |
Nguyen Anh Quynh | d765ab2 | 2014-06-03 17:38:29 +0800 | [diff] [blame] | 32 | add_definitions(-DCAPSTONE_USE_SYS_DYN_MEM) |
Nguyen Anh Quynh | 758fcbe | 2014-05-31 10:44:27 +0800 | [diff] [blame] | 33 | endif () |
| 34 | |
Yegor Derevenets | b4d78d9 | 2014-09-19 18:39:22 +0200 | [diff] [blame] | 35 | if (CAPSTONE_X86_REDUCE) |
Nguyen Anh Quynh | 758fcbe | 2014-05-31 10:44:27 +0800 | [diff] [blame] | 36 | add_definitions(-DCAPSTONE_X86_REDUCE) |
daniel | 96ecc33 | 2014-05-18 02:03:15 -0700 | [diff] [blame] | 37 | endif () |
| 38 | |
Yegor Derevenets | b4d78d9 | 2014-09-19 18:39:22 +0200 | [diff] [blame] | 39 | if (CAPSTONE_X86_ATT_DISABLE) |
baguette | 86e8450 | 2014-08-17 20:59:05 +0200 | [diff] [blame] | 40 | add_definitions(-DCAPSTONE_X86_ATT_DISABLE) |
| 41 | endif () |
| 42 | |
Ali Rizvi-Santiago | 10053ba | 2014-06-03 21:04:23 +0000 | [diff] [blame] | 43 | ## sources |
daniel | 96ecc33 | 2014-05-18 02:03:15 -0700 | [diff] [blame] | 44 | set(SOURCES |
| 45 | cs.c |
| 46 | MCInst.c |
| 47 | MCInstrDesc.c |
| 48 | MCRegisterInfo.c |
| 49 | SStream.c |
| 50 | utils.c |
| 51 | ) |
Nguyen Anh Quynh | f6af509 | 2014-05-28 14:29:20 +0800 | [diff] [blame] | 52 | |
Nguyen Anh Quynh | 0a2eca7 | 2014-10-11 00:36:16 +0800 | [diff] [blame] | 53 | set(TEST_SOURCES test.c test_detail.c test_skipdata.c test_iter.c) |
Nguyen Anh Quynh | f6af509 | 2014-05-28 14:29:20 +0800 | [diff] [blame] | 54 | |
Ali Rizvi-Santiago | 10053ba | 2014-06-03 21:04:23 +0000 | [diff] [blame] | 55 | ## architecture support |
Yegor Derevenets | b4d78d9 | 2014-09-19 18:39:22 +0200 | [diff] [blame] | 56 | if (CAPSTONE_ARM_SUPPORT) |
daniel | 96ecc33 | 2014-05-18 02:03:15 -0700 | [diff] [blame] | 57 | add_definitions(-DCAPSTONE_HAS_ARM) |
| 58 | set(SOURCES |
| 59 | ${SOURCES} |
| 60 | arch/ARM/ARMDisassembler.c |
| 61 | arch/ARM/ARMInstPrinter.c |
| 62 | arch/ARM/ARMMapping.c |
| 63 | arch/ARM/ARMModule.c |
| 64 | ) |
| 65 | set(TEST_SOURCES ${TEST_SOURCES} test_arm.c) |
| 66 | endif () |
Nguyen Anh Quynh | f6af509 | 2014-05-28 14:29:20 +0800 | [diff] [blame] | 67 | |
Yegor Derevenets | b4d78d9 | 2014-09-19 18:39:22 +0200 | [diff] [blame] | 68 | if (CAPSTONE_ARM64_SUPPORT) |
daniel | 96ecc33 | 2014-05-18 02:03:15 -0700 | [diff] [blame] | 69 | add_definitions(-DCAPSTONE_HAS_ARM64) |
| 70 | set(SOURCES |
| 71 | ${SOURCES} |
| 72 | arch/AArch64/AArch64BaseInfo.c |
| 73 | arch/AArch64/AArch64Disassembler.c |
| 74 | arch/AArch64/AArch64InstPrinter.c |
| 75 | arch/AArch64/AArch64Mapping.c |
| 76 | arch/AArch64/AArch64Module.c |
| 77 | ) |
| 78 | set(TEST_SOURCES ${TEST_SOURCES} test_arm64.c) |
| 79 | endif () |
| 80 | |
Yegor Derevenets | b4d78d9 | 2014-09-19 18:39:22 +0200 | [diff] [blame] | 81 | if (CAPSTONE_MIPS_SUPPORT) |
daniel | 96ecc33 | 2014-05-18 02:03:15 -0700 | [diff] [blame] | 82 | add_definitions(-DCAPSTONE_HAS_MIPS) |
| 83 | set(SOURCES |
| 84 | ${SOURCES} |
| 85 | arch/Mips/MipsDisassembler.c |
Nguyen Anh Quynh | f6af509 | 2014-05-28 14:29:20 +0800 | [diff] [blame] | 86 | arch/Mips/MipsInstPrinter.c |
daniel | 96ecc33 | 2014-05-18 02:03:15 -0700 | [diff] [blame] | 87 | arch/Mips/MipsMapping.c |
| 88 | arch/Mips/MipsModule.c |
| 89 | ) |
| 90 | set(TEST_SOURCES ${TEST_SOURCES} test_mips.c) |
| 91 | endif () |
| 92 | |
Yegor Derevenets | b4d78d9 | 2014-09-19 18:39:22 +0200 | [diff] [blame] | 93 | if (CAPSTONE_PPC_SUPPORT) |
daniel | 96ecc33 | 2014-05-18 02:03:15 -0700 | [diff] [blame] | 94 | add_definitions(-DCAPSTONE_HAS_POWERPC) |
| 95 | set(SOURCES |
| 96 | ${SOURCES} |
| 97 | arch/PowerPC/PPCDisassembler.c |
| 98 | arch/PowerPC/PPCInstPrinter.c |
| 99 | arch/PowerPC/PPCMapping.c |
| 100 | arch/PowerPC/PPCModule.c |
| 101 | ) |
| 102 | set(TEST_SOURCES ${TEST_SOURCES} test_ppc.c) |
| 103 | endif () |
| 104 | |
Yegor Derevenets | b4d78d9 | 2014-09-19 18:39:22 +0200 | [diff] [blame] | 105 | if (CAPSTONE_X86_SUPPORT) |
daniel | 96ecc33 | 2014-05-18 02:03:15 -0700 | [diff] [blame] | 106 | add_definitions(-DCAPSTONE_HAS_X86) |
Nguyen Anh Quynh | a71a27b | 2014-05-28 21:20:30 +0800 | [diff] [blame] | 107 | set(SOURCES |
| 108 | ${SOURCES} |
| 109 | arch/X86/X86Disassembler.c |
| 110 | arch/X86/X86DisassemblerDecoder.c |
| 111 | arch/X86/X86IntelInstPrinter.c |
| 112 | arch/X86/X86Mapping.c |
| 113 | arch/X86/X86Module.c |
| 114 | ) |
Yegor Derevenets | b4d78d9 | 2014-09-19 18:39:22 +0200 | [diff] [blame] | 115 | if (NOT CAPSTONE_BUILD_DIET) |
Nguyen Anh Quynh | 758fcbe | 2014-05-31 10:44:27 +0800 | [diff] [blame] | 116 | set(SOURCES ${SOURCES} arch/X86/X86ATTInstPrinter.c) |
| 117 | endif () |
daniel | 96ecc33 | 2014-05-18 02:03:15 -0700 | [diff] [blame] | 118 | set(TEST_SOURCES ${TEST_SOURCES} test_x86.c) |
| 119 | endif () |
Nguyen Anh Quynh | f6af509 | 2014-05-28 14:29:20 +0800 | [diff] [blame] | 120 | |
Yegor Derevenets | ebc4ced | 2014-09-21 19:52:57 +0200 | [diff] [blame] | 121 | if (CAPSTONE_SPARC_SUPPORT) |
Nguyen Anh Quynh | d002319 | 2014-05-28 15:15:00 +0800 | [diff] [blame] | 122 | add_definitions(-DCAPSTONE_HAS_SPARC) |
| 123 | set(SOURCES |
| 124 | ${SOURCES} |
| 125 | arch/Sparc/SparcDisassembler.c |
| 126 | arch/Sparc/SparcInstPrinter.c |
| 127 | arch/Sparc/SparcMapping.c |
| 128 | arch/Sparc/SparcModule.c |
| 129 | ) |
| 130 | set(TEST_SOURCES ${TEST_SOURCES} test_sparc.c) |
| 131 | endif () |
| 132 | |
Yegor Derevenets | b4d78d9 | 2014-09-19 18:39:22 +0200 | [diff] [blame] | 133 | if (CAPSTONE_SYSZ_SUPPORT) |
Nguyen Anh Quynh | d002319 | 2014-05-28 15:15:00 +0800 | [diff] [blame] | 134 | add_definitions(-DCAPSTONE_HAS_SYSZ) |
| 135 | set(SOURCES |
| 136 | ${SOURCES} |
| 137 | arch/SystemZ/SystemZDisassembler.c |
| 138 | arch/SystemZ/SystemZInstPrinter.c |
| 139 | arch/SystemZ/SystemZMapping.c |
| 140 | arch/SystemZ/SystemZModule.c |
| 141 | arch/SystemZ/SystemZMCTargetDesc.c |
| 142 | ) |
| 143 | set(TEST_SOURCES ${TEST_SOURCES} test_systemz.c) |
| 144 | endif () |
| 145 | |
Yegor Derevenets | b4d78d9 | 2014-09-19 18:39:22 +0200 | [diff] [blame] | 146 | if (CAPSTONE_XCORE_SUPPORT) |
Nguyen Anh Quynh | d002319 | 2014-05-28 15:15:00 +0800 | [diff] [blame] | 147 | add_definitions(-DCAPSTONE_HAS_XCORE) |
| 148 | set(SOURCES |
| 149 | ${SOURCES} |
| 150 | arch/XCore/XCoreDisassembler.c |
| 151 | arch/XCore/XCoreInstPrinter.c |
| 152 | arch/XCore/XCoreMapping.c |
| 153 | arch/XCore/XCoreModule.c |
| 154 | ) |
| 155 | set(TEST_SOURCES ${TEST_SOURCES} test_xcore.c) |
| 156 | endif () |
| 157 | |
daniel | 96ecc33 | 2014-05-18 02:03:15 -0700 | [diff] [blame] | 158 | include_directories("${PROJECT_SOURCE_DIR}/include") |
| 159 | |
Ali Rizvi-Santiago | 10053ba | 2014-06-03 21:04:23 +0000 | [diff] [blame] | 160 | ## properties |
| 161 | # version info |
| 162 | set_property(GLOBAL PROPERTY VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}) |
| 163 | set_property(GLOBAL PROPERTY SOVERSION SOVERSION ${VERSION_MAJOR}) |
| 164 | |
| 165 | ## targets |
Yegor Derevenets | b4d78d9 | 2014-09-19 18:39:22 +0200 | [diff] [blame] | 166 | if (CAPSTONE_BUILD_STATIC) |
Ali Rizvi-Santiago | 10053ba | 2014-06-03 21:04:23 +0000 | [diff] [blame] | 167 | add_library(capstone-static STATIC ${SOURCES}) |
| 168 | set_property(TARGET capstone-static PROPERTY OUTPUT_NAME capstone) |
Ali Rizvi-Santiago | 10053ba | 2014-06-03 21:04:23 +0000 | [diff] [blame] | 169 | set(default-target capstone-static) |
Nguyen Anh Quynh | d002319 | 2014-05-28 15:15:00 +0800 | [diff] [blame] | 170 | endif () |
| 171 | |
Yegor Derevenets | b4d78d9 | 2014-09-19 18:39:22 +0200 | [diff] [blame] | 172 | if (CAPSTONE_BUILD_SHARED) |
Ali Rizvi-Santiago | 10053ba | 2014-06-03 21:04:23 +0000 | [diff] [blame] | 173 | add_library(capstone-shared SHARED ${SOURCES}) |
| 174 | set_property(TARGET capstone-shared PROPERTY OUTPUT_NAME capstone) |
| 175 | set_property(TARGET capstone-shared PROPERTY COMPILE_FLAGS -DCAPSTONE_SHARED) |
| 176 | |
| 177 | if(NOT DEFINED default-target) # honor `capstone-static` for tests first. |
| 178 | set(default-target capstone-shared) |
| 179 | add_definitions(-DCAPSTONE_SHARED) |
| 180 | endif () |
| 181 | endif () |
daniel | 96ecc33 | 2014-05-18 02:03:15 -0700 | [diff] [blame] | 182 | |
Yegor Derevenets | b4d78d9 | 2014-09-19 18:39:22 +0200 | [diff] [blame] | 183 | if (CAPSTONE_BUILD_TESTS) |
daniel | 96ecc33 | 2014-05-18 02:03:15 -0700 | [diff] [blame] | 184 | foreach (TSRC ${TEST_SOURCES}) |
Ali Rizvi-Santiago | 10053ba | 2014-06-03 21:04:23 +0000 | [diff] [blame] | 185 | STRING(REGEX REPLACE ".c$" "" TBIN ${TSRC}) |
| 186 | add_executable(${TBIN} "tests/${TSRC}") |
| 187 | target_link_libraries(${TBIN} ${default-target}) |
daniel | 96ecc33 | 2014-05-18 02:03:15 -0700 | [diff] [blame] | 188 | endforeach () |
| 189 | endif () |
| 190 | |
Ali Rizvi-Santiago | 10053ba | 2014-06-03 21:04:23 +0000 | [diff] [blame] | 191 | ## installation |
Yegor Derevenets | 17176cd | 2014-09-20 18:44:21 +0200 | [diff] [blame] | 192 | set(INCLUDES arm64.h arm.h capstone.h mips.h ppc.h x86.h sparc.h systemz.h xcore.h platform.h) |
daniel | 96ecc33 | 2014-05-18 02:03:15 -0700 | [diff] [blame] | 193 | foreach (INC ${INCLUDES}) |
| 194 | install(FILES "include/${INC}" DESTINATION include/capstone) |
| 195 | endforeach () |
Nguyen Anh Quynh | 7343848 | 2014-05-28 21:55:37 +0800 | [diff] [blame] | 196 | |
Yegor Derevenets | b4d78d9 | 2014-09-19 18:39:22 +0200 | [diff] [blame] | 197 | if (CAPSTONE_BUILD_STATIC) |
Ali Rizvi-Santiago | 10053ba | 2014-06-03 21:04:23 +0000 | [diff] [blame] | 198 | install(TARGETS capstone-static |
| 199 | RUNTIME DESTINATION bin |
| 200 | LIBRARY DESTINATION lib |
| 201 | ARCHIVE DESTINATION lib) |
| 202 | endif () |
| 203 | |
Yegor Derevenets | b4d78d9 | 2014-09-19 18:39:22 +0200 | [diff] [blame] | 204 | if (CAPSTONE_BUILD_SHARED) |
Ali Rizvi-Santiago | 10053ba | 2014-06-03 21:04:23 +0000 | [diff] [blame] | 205 | install(TARGETS capstone-shared |
| 206 | RUNTIME DESTINATION bin |
| 207 | LIBRARY DESTINATION lib |
| 208 | ARCHIVE DESTINATION lib) |
| 209 | endif () |