blob: 057b45c0ca9618f09383d8d8aaf9d4a741f369b9 [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
8option(BUILD_STATIC "Build static library" ON)
9option(BUILD_TESTS "Build tests" ON)
10option(USE_DEFAULT_ALLOC "Use default memory allocation functions" ON)
11option(ARM_SUPPORT "ARM support" ON)
12option(ARM64_SUPPORT "ARM64 support" ON)
13option(MIPS_SUPPORT "MIPS support" ON)
14option(PPC_SUPPORT "PowerPC support" ON)
15option(X86_SUPPORT "x86 support" ON)
16
17if (USE_DEFAULT_ALLOC)
18 add_definitions(-DUSE_SYS_DYN_MEM)
19endif ()
20
21set(SOURCES
22 cs.c
23 MCInst.c
24 MCInstrDesc.c
25 MCRegisterInfo.c
26 SStream.c
27 utils.c
28 )
29
30set(TEST_SOURCES test.c test_detail.c)
31
32if (ARM_SUPPORT)
33 add_definitions(-DCAPSTONE_HAS_ARM)
34 set(SOURCES
35 ${SOURCES}
36 arch/ARM/ARMDisassembler.c
37 arch/ARM/ARMInstPrinter.c
38 arch/ARM/ARMMapping.c
39 arch/ARM/ARMModule.c
40 )
41 set(TEST_SOURCES ${TEST_SOURCES} test_arm.c)
42endif ()
43
44if (ARM64_SUPPORT)
45 add_definitions(-DCAPSTONE_HAS_ARM64)
46 set(SOURCES
47 ${SOURCES}
48 arch/AArch64/AArch64BaseInfo.c
49 arch/AArch64/AArch64Disassembler.c
50 arch/AArch64/AArch64InstPrinter.c
51 arch/AArch64/AArch64Mapping.c
52 arch/AArch64/AArch64Module.c
53 )
54 set(TEST_SOURCES ${TEST_SOURCES} test_arm64.c)
55endif ()
56
57if (MIPS_SUPPORT)
58 add_definitions(-DCAPSTONE_HAS_MIPS)
59 set(SOURCES
60 ${SOURCES}
61 arch/Mips/MipsDisassembler.c
62 arch/Mips/MipsInstPrinter.c
63 arch/Mips/MipsMapping.c
64 arch/Mips/MipsModule.c
65 )
66 set(TEST_SOURCES ${TEST_SOURCES} test_mips.c)
67endif ()
68
69if (PPC_SUPPORT)
70 add_definitions(-DCAPSTONE_HAS_POWERPC)
71 set(SOURCES
72 ${SOURCES}
73 arch/PowerPC/PPCDisassembler.c
74 arch/PowerPC/PPCInstPrinter.c
75 arch/PowerPC/PPCMapping.c
76 arch/PowerPC/PPCModule.c
77 )
78 set(TEST_SOURCES ${TEST_SOURCES} test_ppc.c)
79endif ()
80
81if (X86_SUPPORT)
82 add_definitions(-DCAPSTONE_HAS_X86)
83 set(SOURCES
84 ${SOURCES}
85 arch/X86/X86ATTInstPrinter.c
86 arch/X86/X86Disassembler.c
87 arch/X86/X86DisassemblerDecoder.c
88 arch/X86/X86IntelInstPrinter.c
89 arch/X86/X86Mapping.c
90 arch/X86/X86Module.c
91 )
92 set(TEST_SOURCES ${TEST_SOURCES} test_x86.c)
93endif ()
94
95include_directories("${PROJECT_SOURCE_DIR}/include")
96
97if (BUILD_STATIC)
98 add_library(capstone STATIC ${SOURCES})
99else ()
100 add_library(capstone SHARED ${SOURCES})
101endif ()
102set_target_properties(capstone PROPERTIES
103 VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
104 SOVERSION ${VERSION_MAJOR})
105
106if (BUILD_TESTS)
107 foreach (TSRC ${TEST_SOURCES})
108 STRING(REGEX REPLACE ".c$" "" TBIN ${TSRC})
109 add_executable(${TBIN} "tests/${TSRC}")
110 target_link_libraries(${TBIN} capstone)
111 endforeach ()
112endif ()
113
114set(INCLUDES arm64.h arm.h capstone.h mips.h ppc.h x86.h)
115foreach (INC ${INCLUDES})
116 install(FILES "include/${INC}" DESTINATION include/capstone)
117endforeach ()
118install(TARGETS capstone
119 RUNTIME DESTINATION bin
120 LIBRARY DESTINATION lib
121 ARCHIVE DESTINATION lib)