blob: 7ff397c6b2cc26795aaa495f7066a95318c6dbc9 [file] [log] [blame]
daniel96ecc332014-05-18 02:03:15 -07001cmake_minimum_required(VERSION 2.6)
2project(capstone)
3
4set(VERSION_MAJOR 2)
5set(VERSION_MINOR 1)
6set(VERSION_PATCH 2)
7
Nguyen Anh Quynhd0023192014-05-28 15:15:00 +08008option(BUILD_DIET "Build diet library" ON)
daniel96ecc332014-05-18 02:03:15 -07009option(BUILD_STATIC "Build static library" ON)
10option(BUILD_TESTS "Build tests" ON)
11option(USE_DEFAULT_ALLOC "Use default memory allocation functions" ON)
12option(ARM_SUPPORT "ARM support" ON)
13option(ARM64_SUPPORT "ARM64 support" ON)
14option(MIPS_SUPPORT "MIPS support" ON)
15option(PPC_SUPPORT "PowerPC support" ON)
Nguyen Anh Quynhd0023192014-05-28 15:15:00 +080016option(X86_SUPPORT "X86 support" ON)
17option(SPARC_SUPPORT "Sparc support" ON)
18option(SYSZ_SUPPORT "SystemZ support" ON)
19option(XCORE_SUPPORT "XCore support" ON)
daniel96ecc332014-05-18 02:03:15 -070020
21if (USE_DEFAULT_ALLOC)
Nguyen Anh Quynh2f661e02014-05-28 14:41:39 +080022 add_definitions(-DCAPSTONE_USE_SYS_DYN_MEM)
daniel96ecc332014-05-18 02:03:15 -070023endif ()
24
25set(SOURCES
26 cs.c
27 MCInst.c
28 MCInstrDesc.c
29 MCRegisterInfo.c
30 SStream.c
31 utils.c
32 )
Nguyen Anh Quynhf6af5092014-05-28 14:29:20 +080033
daniel96ecc332014-05-18 02:03:15 -070034set(TEST_SOURCES test.c test_detail.c)
Nguyen Anh Quynhf6af5092014-05-28 14:29:20 +080035
daniel96ecc332014-05-18 02:03:15 -070036if (ARM_SUPPORT)
37 add_definitions(-DCAPSTONE_HAS_ARM)
38 set(SOURCES
39 ${SOURCES}
40 arch/ARM/ARMDisassembler.c
41 arch/ARM/ARMInstPrinter.c
42 arch/ARM/ARMMapping.c
43 arch/ARM/ARMModule.c
44 )
45 set(TEST_SOURCES ${TEST_SOURCES} test_arm.c)
46endif ()
Nguyen Anh Quynhf6af5092014-05-28 14:29:20 +080047
daniel96ecc332014-05-18 02:03:15 -070048if (ARM64_SUPPORT)
49 add_definitions(-DCAPSTONE_HAS_ARM64)
50 set(SOURCES
51 ${SOURCES}
52 arch/AArch64/AArch64BaseInfo.c
53 arch/AArch64/AArch64Disassembler.c
54 arch/AArch64/AArch64InstPrinter.c
55 arch/AArch64/AArch64Mapping.c
56 arch/AArch64/AArch64Module.c
57 )
58 set(TEST_SOURCES ${TEST_SOURCES} test_arm64.c)
59endif ()
60
61if (MIPS_SUPPORT)
62 add_definitions(-DCAPSTONE_HAS_MIPS)
63 set(SOURCES
64 ${SOURCES}
65 arch/Mips/MipsDisassembler.c
Nguyen Anh Quynhf6af5092014-05-28 14:29:20 +080066 arch/Mips/MipsInstPrinter.c
daniel96ecc332014-05-18 02:03:15 -070067 arch/Mips/MipsMapping.c
68 arch/Mips/MipsModule.c
69 )
70 set(TEST_SOURCES ${TEST_SOURCES} test_mips.c)
71endif ()
72
73if (PPC_SUPPORT)
74 add_definitions(-DCAPSTONE_HAS_POWERPC)
75 set(SOURCES
76 ${SOURCES}
77 arch/PowerPC/PPCDisassembler.c
78 arch/PowerPC/PPCInstPrinter.c
79 arch/PowerPC/PPCMapping.c
80 arch/PowerPC/PPCModule.c
81 )
82 set(TEST_SOURCES ${TEST_SOURCES} test_ppc.c)
83endif ()
84
85if (X86_SUPPORT)
86 add_definitions(-DCAPSTONE_HAS_X86)
87 set(SOURCES
88 ${SOURCES}
89 arch/X86/X86ATTInstPrinter.c
90 arch/X86/X86Disassembler.c
91 arch/X86/X86DisassemblerDecoder.c
92 arch/X86/X86IntelInstPrinter.c
93 arch/X86/X86Mapping.c
94 arch/X86/X86Module.c
95 )
96 set(TEST_SOURCES ${TEST_SOURCES} test_x86.c)
97endif ()
Nguyen Anh Quynhf6af5092014-05-28 14:29:20 +080098
Nguyen Anh Quynhd0023192014-05-28 15:15:00 +080099if (SPARC_SUPPORT)
100 add_definitions(-DCAPSTONE_HAS_SPARC)
101 set(SOURCES
102 ${SOURCES}
103 arch/Sparc/SparcDisassembler.c
104 arch/Sparc/SparcInstPrinter.c
105 arch/Sparc/SparcMapping.c
106 arch/Sparc/SparcModule.c
107 )
108 set(TEST_SOURCES ${TEST_SOURCES} test_sparc.c)
109endif ()
110
111if (SYSZ_SUPPORT)
112 add_definitions(-DCAPSTONE_HAS_SYSZ)
113 set(SOURCES
114 ${SOURCES}
115 arch/SystemZ/SystemZDisassembler.c
116 arch/SystemZ/SystemZInstPrinter.c
117 arch/SystemZ/SystemZMapping.c
118 arch/SystemZ/SystemZModule.c
119 arch/SystemZ/SystemZMCTargetDesc.c
120 )
121 set(TEST_SOURCES ${TEST_SOURCES} test_systemz.c)
122endif ()
123
124if (XCORE_SUPPORT)
125 add_definitions(-DCAPSTONE_HAS_XCORE)
126 set(SOURCES
127 ${SOURCES}
128 arch/XCore/XCoreDisassembler.c
129 arch/XCore/XCoreInstPrinter.c
130 arch/XCore/XCoreMapping.c
131 arch/XCore/XCoreModule.c
132 )
133 set(TEST_SOURCES ${TEST_SOURCES} test_xcore.c)
134endif ()
135
daniel96ecc332014-05-18 02:03:15 -0700136include_directories("${PROJECT_SOURCE_DIR}/include")
137
Nguyen Anh Quynhd0023192014-05-28 15:15:00 +0800138if (BUILD_DIET)
139 add_definitions(-DCAPSTONE_DIET)
140endif ()
141
daniel96ecc332014-05-18 02:03:15 -0700142if (BUILD_STATIC)
Nguyen Anh Quynhf6af5092014-05-28 14:29:20 +0800143 add_library(libcapstone STATIC ${SOURCES})
daniel96ecc332014-05-18 02:03:15 -0700144else ()
Nguyen Anh Quynhf6af5092014-05-28 14:29:20 +0800145 add_library(libcapstone SHARED ${SOURCES})
daniel96ecc332014-05-18 02:03:15 -0700146endif ()
Nguyen Anh Quynhd0023192014-05-28 15:15:00 +0800147
Nguyen Anh Quynhf6af5092014-05-28 14:29:20 +0800148set_target_properties(libcapstone PROPERTIES
daniel96ecc332014-05-18 02:03:15 -0700149 VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
150 SOVERSION ${VERSION_MAJOR})
151
152if (BUILD_TESTS)
153 foreach (TSRC ${TEST_SOURCES})
154 STRING(REGEX REPLACE ".c$" "" TBIN ${TSRC})
155 add_executable(${TBIN} "tests/${TSRC}")
Nguyen Anh Quynhf6af5092014-05-28 14:29:20 +0800156 target_link_libraries(${TBIN} libcapstone)
daniel96ecc332014-05-18 02:03:15 -0700157 endforeach ()
158endif ()
159
Nguyen Anh Quynhd0023192014-05-28 15:15:00 +0800160set(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 -0700161foreach (INC ${INCLUDES})
162 install(FILES "include/${INC}" DESTINATION include/capstone)
163endforeach ()
Nguyen Anh Quynhf6af5092014-05-28 14:29:20 +0800164install(TARGETS libcapstone
daniel96ecc332014-05-18 02:03:15 -0700165 RUNTIME DESTINATION bin
166 LIBRARY DESTINATION lib
167 ARCHIVE DESTINATION lib)