blob: 2cb71170222c46e6a7571882e9e4bf8270c35896 [file] [log] [blame]
daniel96ecc332014-05-18 02:03:15 -07001cmake_minimum_required(VERSION 2.6)
2project(capstone)
3
Nguyen Anh Quynh758fcbe2014-05-31 10:44:27 +08004set(VERSION_MAJOR 2)
Nguyen Anh Quynhde8c6892014-05-31 10:45:15 +08005set(VERSION_MINOR 2)
6set(VERSION_PATCH 0)
Nguyen Anh Quynh56e4efd2014-05-28 16:27:53 +08007
Nguyen Anh Quynh758fcbe2014-05-31 10:44:27 +08008# to configure the options specify them in in the command line or change them in the cmake UI.
9# Don't edit the makefile!
10option(BUILD_STATIC "Build static library" ON)
Nguyen Anh Quynh56e4efd2014-05-28 16:27:53 +080011option(BUILD_DIET "Build diet library" OFF)
daniel96ecc332014-05-18 02:03:15 -070012option(BUILD_TESTS "Build tests" ON)
Nguyen Anh Quynhd765ab22014-06-03 17:38:29 +080013option(USE_DEFAULT_ALLOC "Use default memory allocation functions" ON)
Nguyen Anh Quynha71a27b2014-05-28 21:20:30 +080014
daniel96ecc332014-05-18 02:03:15 -070015option(ARM_SUPPORT "ARM support" ON)
16option(ARM64_SUPPORT "ARM64 support" ON)
17option(MIPS_SUPPORT "MIPS support" ON)
18option(PPC_SUPPORT "PowerPC support" ON)
Nguyen Anh Quynhd0023192014-05-28 15:15:00 +080019option(SPARC_SUPPORT "Sparc support" ON)
20option(SYSZ_SUPPORT "SystemZ support" ON)
21option(XCORE_SUPPORT "XCore support" ON)
Nguyen Anh Quynh758fcbe2014-05-31 10:44:27 +080022option(X86_SUPPORT "x86 support" ON)
23option(X86_REDUCE "x86 with reduce instruction sets to minimize library" OFF)
Nguyen Anh Quynha71a27b2014-05-28 21:20:30 +080024
Nguyen Anh Quynh758fcbe2014-05-31 10:44:27 +080025if (BUILD_DIET)
26 add_definitions(-DCAPSTONE_DIET)
27endif ()
daniel96ecc332014-05-18 02:03:15 -070028
Nguyen Anh Quynh758fcbe2014-05-31 10:44:27 +080029if (USE_DEFAULT_ALLOC)
Nguyen Anh Quynhd765ab22014-06-03 17:38:29 +080030 add_definitions(-DCAPSTONE_USE_SYS_DYN_MEM)
Nguyen Anh Quynh758fcbe2014-05-31 10:44:27 +080031endif ()
32
33if (X86_REDUCE)
34 add_definitions(-DCAPSTONE_X86_REDUCE)
daniel96ecc332014-05-18 02:03:15 -070035endif ()
36
37set(SOURCES
38 cs.c
39 MCInst.c
40 MCInstrDesc.c
41 MCRegisterInfo.c
42 SStream.c
43 utils.c
44 )
Nguyen Anh Quynhf6af5092014-05-28 14:29:20 +080045
Nguyen Anh Quynh6a899ff2014-05-28 16:09:09 +080046set(TEST_SOURCES test.c test_detail.c test_skipdata.c)
Nguyen Anh Quynhf6af5092014-05-28 14:29:20 +080047
daniel96ecc332014-05-18 02:03:15 -070048if (ARM_SUPPORT)
49 add_definitions(-DCAPSTONE_HAS_ARM)
50 set(SOURCES
51 ${SOURCES}
52 arch/ARM/ARMDisassembler.c
53 arch/ARM/ARMInstPrinter.c
54 arch/ARM/ARMMapping.c
55 arch/ARM/ARMModule.c
56 )
57 set(TEST_SOURCES ${TEST_SOURCES} test_arm.c)
58endif ()
Nguyen Anh Quynhf6af5092014-05-28 14:29:20 +080059
daniel96ecc332014-05-18 02:03:15 -070060if (ARM64_SUPPORT)
61 add_definitions(-DCAPSTONE_HAS_ARM64)
62 set(SOURCES
63 ${SOURCES}
64 arch/AArch64/AArch64BaseInfo.c
65 arch/AArch64/AArch64Disassembler.c
66 arch/AArch64/AArch64InstPrinter.c
67 arch/AArch64/AArch64Mapping.c
68 arch/AArch64/AArch64Module.c
69 )
70 set(TEST_SOURCES ${TEST_SOURCES} test_arm64.c)
71endif ()
72
73if (MIPS_SUPPORT)
74 add_definitions(-DCAPSTONE_HAS_MIPS)
75 set(SOURCES
76 ${SOURCES}
77 arch/Mips/MipsDisassembler.c
Nguyen Anh Quynhf6af5092014-05-28 14:29:20 +080078 arch/Mips/MipsInstPrinter.c
daniel96ecc332014-05-18 02:03:15 -070079 arch/Mips/MipsMapping.c
80 arch/Mips/MipsModule.c
81 )
82 set(TEST_SOURCES ${TEST_SOURCES} test_mips.c)
83endif ()
84
85if (PPC_SUPPORT)
86 add_definitions(-DCAPSTONE_HAS_POWERPC)
87 set(SOURCES
88 ${SOURCES}
89 arch/PowerPC/PPCDisassembler.c
90 arch/PowerPC/PPCInstPrinter.c
91 arch/PowerPC/PPCMapping.c
92 arch/PowerPC/PPCModule.c
93 )
94 set(TEST_SOURCES ${TEST_SOURCES} test_ppc.c)
95endif ()
96
97if (X86_SUPPORT)
98 add_definitions(-DCAPSTONE_HAS_X86)
Nguyen Anh Quynha71a27b2014-05-28 21:20:30 +080099 set(SOURCES
100 ${SOURCES}
101 arch/X86/X86Disassembler.c
102 arch/X86/X86DisassemblerDecoder.c
103 arch/X86/X86IntelInstPrinter.c
104 arch/X86/X86Mapping.c
105 arch/X86/X86Module.c
106 )
Nguyen Anh Quynh758fcbe2014-05-31 10:44:27 +0800107 if (NOT BUILD_DIET)
108 set(SOURCES ${SOURCES} arch/X86/X86ATTInstPrinter.c)
109 endif ()
daniel96ecc332014-05-18 02:03:15 -0700110 set(TEST_SOURCES ${TEST_SOURCES} test_x86.c)
111endif ()
Nguyen Anh Quynhf6af5092014-05-28 14:29:20 +0800112
Nguyen Anh Quynhd0023192014-05-28 15:15:00 +0800113if (SPARC_SUPPORT)
114 add_definitions(-DCAPSTONE_HAS_SPARC)
115 set(SOURCES
116 ${SOURCES}
117 arch/Sparc/SparcDisassembler.c
118 arch/Sparc/SparcInstPrinter.c
119 arch/Sparc/SparcMapping.c
120 arch/Sparc/SparcModule.c
121 )
122 set(TEST_SOURCES ${TEST_SOURCES} test_sparc.c)
123endif ()
124
125if (SYSZ_SUPPORT)
126 add_definitions(-DCAPSTONE_HAS_SYSZ)
127 set(SOURCES
128 ${SOURCES}
129 arch/SystemZ/SystemZDisassembler.c
130 arch/SystemZ/SystemZInstPrinter.c
131 arch/SystemZ/SystemZMapping.c
132 arch/SystemZ/SystemZModule.c
133 arch/SystemZ/SystemZMCTargetDesc.c
134 )
135 set(TEST_SOURCES ${TEST_SOURCES} test_systemz.c)
136endif ()
137
138if (XCORE_SUPPORT)
139 add_definitions(-DCAPSTONE_HAS_XCORE)
140 set(SOURCES
141 ${SOURCES}
142 arch/XCore/XCoreDisassembler.c
143 arch/XCore/XCoreInstPrinter.c
144 arch/XCore/XCoreMapping.c
145 arch/XCore/XCoreModule.c
146 )
147 set(TEST_SOURCES ${TEST_SOURCES} test_xcore.c)
148endif ()
149
daniel96ecc332014-05-18 02:03:15 -0700150include_directories("${PROJECT_SOURCE_DIR}/include")
151
Nguyen Anh Quynh758fcbe2014-05-31 10:44:27 +0800152if (BUILD_STATIC)
Nguyen Anh Quynh1969b832014-06-03 23:10:07 +0800153 add_definitions(-DCAPSTONE_STATIC)
Nguyen Anh Quynh758fcbe2014-05-31 10:44:27 +0800154 add_library(capstone STATIC ${SOURCES})
155else ()
Nguyen Anh Quynh07c36932014-06-03 18:33:15 +0800156 add_definitions(-DCAPSTONE_SHARED)
Nguyen Anh Quynh758fcbe2014-05-31 10:44:27 +0800157 add_library(capstone SHARED ${SOURCES})
Nguyen Anh Quynhd0023192014-05-28 15:15:00 +0800158endif ()
159
Nguyen Anh Quynh758fcbe2014-05-31 10:44:27 +0800160set_target_properties(capstone PROPERTIES
daniel96ecc332014-05-18 02:03:15 -0700161 VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
162 SOVERSION ${VERSION_MAJOR})
163
164if (BUILD_TESTS)
165 foreach (TSRC ${TEST_SOURCES})
166 STRING(REGEX REPLACE ".c$" "" TBIN ${TSRC})
167 add_executable(${TBIN} "tests/${TSRC}")
Nguyen Anh Quynh758fcbe2014-05-31 10:44:27 +0800168 target_link_libraries(${TBIN} capstone)
daniel96ecc332014-05-18 02:03:15 -0700169 endforeach ()
170endif ()
171
Nguyen Anh Quynhd0023192014-05-28 15:15:00 +0800172set(INCLUDES arm64.h arm.h capstone.h mips.h ppc.h x86.h sparc.h systemz.h xcore.h)
daniel96ecc332014-05-18 02:03:15 -0700173foreach (INC ${INCLUDES})
174 install(FILES "include/${INC}" DESTINATION include/capstone)
175endforeach ()
Nguyen Anh Quynh73438482014-05-28 21:55:37 +0800176
Nguyen Anh Quynh758fcbe2014-05-31 10:44:27 +0800177install(TARGETS capstone
daniel96ecc332014-05-18 02:03:15 -0700178 RUNTIME DESTINATION bin
179 LIBRARY DESTINATION lib
180 ARCHIVE DESTINATION lib)