• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1cmake_minimum_required(VERSION 2.8.12)
2project(capstone)
3
4set(VERSION_MAJOR 5)
5set(VERSION_MINOR 0)
6set(VERSION_PATCH 0)
7
8if(POLICY CMP0042)
9  # http://www.cmake.org/cmake/help/v3.0/policy/CMP0042.html
10  cmake_policy(SET CMP0042 NEW)
11endif(POLICY CMP0042)
12
13if (POLICY CMP0048)
14  # use old policy to honor version set using VERSION_* variables to preserve backwards
15  # compatibility. change OLD to NEW when minimum cmake version is updated to 3.* and
16  # set VERSION using project(capstone VERSION 4.0.0).
17  # http://www.cmake.org/cmake/help/v3.0/policy/CMP0048.html
18  cmake_policy (SET CMP0048 OLD)
19endif()
20
21# to configure the options specify them in in the command line or change them in the cmake UI.
22# Don't edit the makefile!
23option(CAPSTONE_BUILD_STATIC_RUNTIME "Embed static runtime" ON)
24option(CAPSTONE_BUILD_STATIC "Build static library" ON)
25option(CAPSTONE_BUILD_SHARED "Build shared library" ON)
26option(CAPSTONE_BUILD_DIET "Build diet library" OFF)
27option(CAPSTONE_BUILD_TESTS "Build tests" ON)
28option(CAPSTONE_BUILD_CSTOOL "Build cstool" ON)
29option(CAPSTONE_USE_DEFAULT_ALLOC "Use default memory allocation functions" ON)
30option(CAPSTONE_ARCHITECTURE_DEFAULT "Whether architectures are enabled by default" ON)
31option(CAPSTONE_INSTALL "Generate install target" ON)
32
33set(SUPPORTED_ARCHITECTURES ARM ARM64 M68K MIPS PPC SPARC SYSZ XCORE X86 TMS320C64X M680X EVM MOS65XX)
34set(SUPPORTED_ARCHITECTURE_LABELS ARM ARM64 M68K MIPS PowerPC Sparc SystemZ XCore x86 TMS320C64x M680x EVM MOS65XX)
35
36list(LENGTH SUPPORTED_ARCHITECTURES count)
37math(EXPR count "${count}-1")
38# create options controlling whether support for a particular architecture is needed
39foreach(i RANGE ${count})
40  list(GET SUPPORTED_ARCHITECTURES ${i} supported_architecture)
41  list(GET SUPPORTED_ARCHITECTURE_LABELS ${i} supported_architecture_label)
42  option("CAPSTONE_${supported_architecture}_SUPPORT" "${supported_architecture_label} support" ${CAPSTONE_ARCHITECTURE_DEFAULT})
43endforeach(i)
44
45# propagate architecture support variables to preprocessor
46foreach(supported_architecture ${SUPPORTED_ARCHITECTURES})
47  set(option_name "CAPSTONE_${supported_architecture}_SUPPORT")
48  if(${option_name})
49    message("Enabling ${option_name}")
50    add_definitions("-D${option_name}")
51  endif()
52endforeach(supported_architecture)
53
54option(CAPSTONE_X86_REDUCE "x86 with reduce instruction sets to minimize library" OFF)
55option(CAPSTONE_X86_ATT_DISABLE "Disable x86 AT&T syntax" OFF)
56option(CAPSTONE_OSXKERNEL_SUPPORT "Support to embed Capstone into OS X Kernel extensions" OFF)
57
58if (MSVC)
59    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
60    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
61endif ()
62
63enable_testing()
64
65if (CAPSTONE_BUILD_DIET)
66    add_definitions(-DCAPSTONE_DIET)
67endif ()
68
69if (CAPSTONE_USE_DEFAULT_ALLOC)
70    add_definitions(-DCAPSTONE_USE_SYS_DYN_MEM)
71endif ()
72
73if (CAPSTONE_X86_REDUCE)
74    add_definitions(-DCAPSTONE_X86_REDUCE)
75endif ()
76
77if (CAPSTONE_X86_ATT_DISABLE)
78    add_definitions(-DCAPSTONE_X86_ATT_DISABLE)
79endif ()
80
81## sources
82set(SOURCES_ENGINE
83    cs.c
84    MCInst.c
85    MCInstrDesc.c
86    MCRegisterInfo.c
87    SStream.c
88    utils.c
89)
90set(HEADERS_ENGINE
91    cs_priv.h
92    LEB128.h
93    MathExtras.h
94    MCDisassembler.h
95    MCFixedLenDisassembler.h
96    MCInst.h
97    MCInstrDesc.h
98    MCRegisterInfo.h
99    SStream.h
100    utils.h
101    )
102
103set(HEADERS_COMMON
104    include/capstone/arm64.h
105    include/capstone/arm.h
106    include/capstone/capstone.h
107    include/capstone/evm.h
108    include/capstone/mips.h
109    include/capstone/ppc.h
110    include/capstone/x86.h
111    include/capstone/sparc.h
112    include/capstone/systemz.h
113    include/capstone/xcore.h
114    include/capstone/m68k.h
115    include/capstone/tms320c64x.h
116    include/capstone/m680x.h
117    include/capstone/mos65xx.h
118    include/capstone/platform.h
119    )
120
121set(TEST_SOURCES test_basic.c test_detail.c test_skipdata.c test_iter.c)
122
123## architecture support
124if (CAPSTONE_ARM_SUPPORT)
125    add_definitions(-DCAPSTONE_HAS_ARM)
126    set(SOURCES_ARM
127        arch/ARM/ARMDisassembler.c
128        arch/ARM/ARMInstPrinter.c
129        arch/ARM/ARMMapping.c
130        arch/ARM/ARMModule.c
131    )
132    set(HEADERS_ARM
133        arch/ARM/ARMAddressingModes.h
134        arch/ARM/ARMBaseInfo.h
135        arch/ARM/ARMDisassembler.h
136        arch/ARM/ARMGenAsmWriter.inc
137        arch/ARM/ARMGenDisassemblerTables.inc
138        arch/ARM/ARMGenInstrInfo.inc
139        arch/ARM/ARMGenRegisterInfo.inc
140        arch/ARM/ARMGenSubtargetInfo.inc
141        arch/ARM/ARMInstPrinter.h
142        arch/ARM/ARMMapping.h
143        arch/ARM/ARMMappingInsn.inc
144        arch/ARM/ARMMappingInsnOp.inc
145        )
146    set(HEADERS_ARM
147        arch/ARM/ARMAddressingModes.h
148        arch/ARM/ARMBaseInfo.h
149        arch/ARM/ARMDisassembler.h
150        arch/ARM/ARMGenAsmWriter.inc
151        arch/ARM/ARMGenDisassemblerTables.inc
152        arch/ARM/ARMGenInstrInfo.inc
153        arch/ARM/ARMGenRegisterInfo.inc
154        arch/ARM/ARMGenSubtargetInfo.inc
155        arch/ARM/ARMInstPrinter.h
156        arch/ARM/ARMMapping.h
157        )
158    set(TEST_SOURCES ${TEST_SOURCES} test_arm.c)
159endif ()
160
161if (CAPSTONE_ARM64_SUPPORT)
162    add_definitions(-DCAPSTONE_HAS_ARM64)
163    set(SOURCES_ARM64
164        arch/AArch64/AArch64BaseInfo.c
165        arch/AArch64/AArch64Disassembler.c
166        arch/AArch64/AArch64InstPrinter.c
167        arch/AArch64/AArch64Mapping.c
168        arch/AArch64/AArch64Module.c
169    )
170    set(HEADERS_ARM64
171        arch/AArch64/AArch64AddressingModes.h
172        arch/AArch64/AArch64BaseInfo.h
173        arch/AArch64/AArch64Disassembler.h
174        arch/AArch64/AArch64GenAsmWriter.inc
175        arch/AArch64/AArch64GenDisassemblerTables.inc
176        arch/AArch64/AArch64GenInstrInfo.inc
177        arch/AArch64/AArch64GenRegisterInfo.inc
178        arch/AArch64/AArch64GenSubtargetInfo.inc
179        arch/AArch64/AArch64InstPrinter.h
180        arch/AArch64/AArch64Mapping.h
181        arch/AArch64/AArch64MappingInsn.inc
182        )
183    set(HEADERS_ARM64
184        arch/AArch64/AArch64AddressingModes.h
185        arch/AArch64/AArch64BaseInfo.h
186        arch/AArch64/AArch64Disassembler.h
187        arch/AArch64/AArch64GenAsmWriter.inc
188        arch/AArch64/AArch64GenDisassemblerTables.inc
189        arch/AArch64/AArch64GenInstrInfo.inc
190        arch/AArch64/AArch64GenRegisterInfo.inc
191        arch/AArch64/AArch64GenSubtargetInfo.inc
192        arch/AArch64/AArch64InstPrinter.h
193        arch/AArch64/AArch64Mapping.h
194        )
195    set(TEST_SOURCES ${TEST_SOURCES} test_arm64.c)
196endif ()
197
198if (CAPSTONE_MIPS_SUPPORT)
199    add_definitions(-DCAPSTONE_HAS_MIPS)
200    set(SOURCES_MIPS
201        arch/Mips/MipsDisassembler.c
202        arch/Mips/MipsInstPrinter.c
203        arch/Mips/MipsMapping.c
204        arch/Mips/MipsModule.c
205    )
206    set(HEADERS_MIPS
207        arch/Mips/MipsDisassembler.h
208        arch/Mips/MipsGenAsmWriter.inc
209        arch/Mips/MipsGenDisassemblerTables.inc
210        arch/Mips/MipsGenInstrInfo.inc
211        arch/Mips/MipsGenRegisterInfo.inc
212        arch/Mips/MipsGenSubtargetInfo.inc
213        arch/Mips/MipsInstPrinter.h
214        arch/Mips/MipsMapping.h
215        arch/Mips/MipsMappingInsn.inc
216        )
217    set(HEADERS_MIPS
218        arch/Mips/MipsDisassembler.h
219        arch/Mips/MipsGenAsmWriter.inc
220        arch/Mips/MipsGenDisassemblerTables.inc
221        arch/Mips/MipsGenInstrInfo.inc
222        arch/Mips/MipsGenRegisterInfo.inc
223        arch/Mips/MipsGenSubtargetInfo.inc
224        arch/Mips/MipsInstPrinter.h
225        arch/Mips/MipsMapping.h
226        )
227    set(TEST_SOURCES ${TEST_SOURCES} test_mips.c)
228endif ()
229
230if (CAPSTONE_PPC_SUPPORT)
231    add_definitions(-DCAPSTONE_HAS_POWERPC)
232    set(SOURCES_PPC
233        arch/PowerPC/PPCDisassembler.c
234        arch/PowerPC/PPCInstPrinter.c
235        arch/PowerPC/PPCMapping.c
236        arch/PowerPC/PPCModule.c
237    )
238    set(HEADERS_PPC
239        arch/PowerPC/PPCDisassembler.h
240        arch/PowerPC/PPCGenAsmWriter.inc
241        arch/PowerPC/PPCGenDisassemblerTables.inc
242        arch/PowerPC/PPCGenInstrInfo.inc
243        arch/PowerPC/PPCGenRegisterInfo.inc
244        arch/PowerPC/PPCGenSubtargetInfo.inc
245        arch/PowerPC/PPCInstPrinter.h
246        arch/PowerPC/PPCMapping.h
247        arch/PowerPC/PPCMappingInsn.inc
248        arch/PowerPC/PPCPredicates.h
249        )
250    set(HEADERS_PPC
251        arch/PowerPC/PPCDisassembler.h
252        arch/PowerPC/PPCGenAsmWriter.inc
253        arch/PowerPC/PPCGenDisassemblerTables.inc
254        arch/PowerPC/PPCGenInstrInfo.inc
255        arch/PowerPC/PPCGenRegisterInfo.inc
256        arch/PowerPC/PPCGenSubtargetInfo.inc
257        arch/PowerPC/PPCInstPrinter.h
258        arch/PowerPC/PPCMapping.h
259        arch/PowerPC/PPCPredicates.h
260        )
261    set(TEST_SOURCES ${TEST_SOURCES} test_ppc.c)
262endif ()
263
264if (CAPSTONE_X86_SUPPORT)
265    add_definitions(-DCAPSTONE_HAS_X86)
266    set(SOURCES_X86
267        arch/X86/X86Disassembler.c
268        arch/X86/X86DisassemblerDecoder.c
269        arch/X86/X86IntelInstPrinter.c
270        arch/X86/X86Mapping.c
271        arch/X86/X86Module.c
272    )
273    set(HEADERS_X86
274        arch/X86/X86BaseInfo.h
275        arch/X86/X86Disassembler.h
276        arch/X86/X86DisassemblerDecoder.h
277        arch/X86/X86DisassemblerDecoderCommon.h
278        arch/X86/X86GenAsmWriter.inc
279        arch/X86/X86GenAsmWriter1.inc
280        arch/X86/X86GenAsmWriter1_reduce.inc
281        arch/X86/X86GenAsmWriter_reduce.inc
282        arch/X86/X86GenDisassemblerTables.inc
283        arch/X86/X86GenDisassemblerTables_reduce.inc
284        arch/X86/X86GenInstrInfo.inc
285        arch/X86/X86GenInstrInfo_reduce.inc
286        arch/X86/X86GenRegisterInfo.inc
287        arch/X86/X86InstPrinter.h
288        arch/X86/X86Mapping.h
289        arch/X86/X86MappingInsn.inc
290        arch/X86/X86MappingInsnOp.inc
291        arch/X86/X86MappingInsnOp_reduce.inc
292        arch/X86/X86MappingInsn_reduce.inc
293        )
294    set(HEADERS_X86
295        arch/X86/X86BaseInfo.h
296        arch/X86/X86Disassembler.h
297        arch/X86/X86DisassemblerDecoder.h
298        arch/X86/X86DisassemblerDecoderCommon.h
299        arch/X86/X86GenAsmWriter.inc
300        arch/X86/X86GenAsmWriter1.inc
301        arch/X86/X86GenAsmWriter1_reduce.inc
302        arch/X86/X86GenAsmWriter_reduce.inc
303        arch/X86/X86GenDisassemblerTables.inc
304        arch/X86/X86GenDisassemblerTables_reduce.inc
305        arch/X86/X86GenInstrInfo.inc
306        arch/X86/X86GenInstrInfo_reduce.inc
307        arch/X86/X86GenRegisterInfo.inc
308        arch/X86/X86InstPrinter.h
309        arch/X86/X86Mapping.h
310        )
311    if (NOT CAPSTONE_BUILD_DIET)
312        set(SOURCES_X86 ${SOURCES_X86} arch/X86/X86ATTInstPrinter.c)
313    endif ()
314    set(TEST_SOURCES ${TEST_SOURCES} test_x86.c test_customized_mnem.c)
315endif ()
316
317if (CAPSTONE_SPARC_SUPPORT)
318    add_definitions(-DCAPSTONE_HAS_SPARC)
319    set(SOURCES_SPARC
320        arch/Sparc/SparcDisassembler.c
321        arch/Sparc/SparcInstPrinter.c
322        arch/Sparc/SparcMapping.c
323        arch/Sparc/SparcModule.c
324        )
325    set(HEADERS_SPARC
326        arch/Sparc/Sparc.h
327        arch/Sparc/SparcDisassembler.h
328        arch/Sparc/SparcGenAsmWriter.inc
329        arch/Sparc/SparcGenDisassemblerTables.inc
330        arch/Sparc/SparcGenInstrInfo.inc
331        arch/Sparc/SparcGenRegisterInfo.inc
332        arch/Sparc/SparcGenSubtargetInfo.inc
333        arch/Sparc/SparcInstPrinter.h
334        arch/Sparc/SparcMapping.h
335        arch/Sparc/SparcMappingInsn.inc
336        )
337    set(TEST_SOURCES ${TEST_SOURCES} test_sparc.c)
338endif ()
339
340if (CAPSTONE_SYSZ_SUPPORT)
341    add_definitions(-DCAPSTONE_HAS_SYSZ)
342    set(SOURCES_SYSZ
343        arch/SystemZ/SystemZDisassembler.c
344        arch/SystemZ/SystemZInstPrinter.c
345        arch/SystemZ/SystemZMapping.c
346        arch/SystemZ/SystemZModule.c
347        arch/SystemZ/SystemZMCTargetDesc.c
348        )
349    set(HEADERS_SYSZ
350        arch/SystemZ/SystemZDisassembler.h
351        arch/SystemZ/SystemZGenAsmWriter.inc
352        arch/SystemZ/SystemZGenDisassemblerTables.inc
353        arch/SystemZ/SystemZGenInsnNameMaps.inc
354        arch/SystemZ/SystemZGenInstrInfo.inc
355        arch/SystemZ/SystemZGenRegisterInfo.inc
356        arch/SystemZ/SystemZGenSubtargetInfo.inc
357        arch/SystemZ/SystemZInstPrinter.h
358        arch/SystemZ/SystemZMapping.h
359        arch/SystemZ/SystemZMappingInsn.inc
360        arch/SystemZ/SystemZMCTargetDesc.h
361        )
362    set(TEST_SOURCES ${TEST_SOURCES} test_systemz.c)
363endif ()
364
365if (CAPSTONE_XCORE_SUPPORT)
366    add_definitions(-DCAPSTONE_HAS_XCORE)
367    set(SOURCES_XCORE
368        arch/XCore/XCoreDisassembler.c
369        arch/XCore/XCoreInstPrinter.c
370        arch/XCore/XCoreMapping.c
371        arch/XCore/XCoreModule.c
372        )
373    set(HEADERS_XCORE
374        arch/XCore/XCoreDisassembler.h
375        arch/XCore/XCoreGenAsmWriter.inc
376        arch/XCore/XCoreGenDisassemblerTables.inc
377        arch/XCore/XCoreGenInstrInfo.inc
378        arch/XCore/XCoreGenRegisterInfo.inc
379        arch/XCore/XCoreInstPrinter.h
380        arch/XCore/XCoreMapping.h
381        arch/XCore/XCoreMappingInsn.inc
382        )
383    set(TEST_SOURCES ${TEST_SOURCES} test_xcore.c)
384endif ()
385
386if (CAPSTONE_M68K_SUPPORT)
387    add_definitions(-DCAPSTONE_HAS_M68K)
388    set(SOURCES_M68K
389		arch/M68K/M68KDisassembler.c
390		arch/M68K/M68KInstPrinter.c
391		arch/M68K/M68KModule.c
392    )
393    set(HEADERS_M68K
394		arch/M68K/M68KDisassembler.h
395        )
396    set(TEST_SOURCES ${TEST_SOURCES} test_m68k.c)
397endif ()
398
399if (CAPSTONE_TMS320C64X_SUPPORT)
400    add_definitions(-DCAPSTONE_HAS_TMS320C64X)
401    set(SOURCES_TMS320C64X
402        arch/TMS320C64x/TMS320C64xDisassembler.c
403        arch/TMS320C64x/TMS320C64xInstPrinter.c
404        arch/TMS320C64x/TMS320C64xMapping.c
405        arch/TMS320C64x/TMS320C64xModule.c
406        )
407    set(HEADERS_TMS320C64X
408        arch/TMS320C64x/TMS320C64xDisassembler.h
409        arch/TMS320C64x/TMS320C64xGenAsmWriter.inc
410        arch/TMS320C64x/TMS320C64xGenDisassemblerTables.inc
411        arch/TMS320C64x/TMS320C64xGenInstrInfo.inc
412        arch/TMS320C64x/TMS320C64xGenRegisterInfo.inc
413        arch/TMS320C64x/TMS320C64xInstPrinter.h
414        arch/TMS320C64x/TMS320C64xMapping.h
415        )
416    set(TEST_SOURCES ${TEST_SOURCES} test_tms320c64x.c)
417endif ()
418
419if (CAPSTONE_M680X_SUPPORT)
420    add_definitions(-DCAPSTONE_HAS_M680X)
421    set(SOURCES_M680X
422		arch/M680X/M680XDisassembler.c
423		arch/M680X/M680XInstPrinter.c
424		arch/M680X/M680XModule.c
425    )
426    set(HEADERS_M680X
427		arch/M680X/M680XInstPrinter.h
428		arch/M680X/M680XDisassembler.h
429		arch/M680X/M680XDisassemblerInternals.h
430        )
431    set(TEST_SOURCES ${TEST_SOURCES} test_m680x.c)
432endif ()
433
434if (CAPSTONE_EVM_SUPPORT)
435    add_definitions(-DCAPSTONE_HAS_EVM)
436    set(SOURCES_EVM
437        arch/EVM/EVMDisassembler.c
438        arch/EVM/EVMInstPrinter.c
439        arch/EVM/EVMMapping.c
440        arch/EVM/EVMModule.c
441    )
442    set(HEADERS_EVM
443        arch/EVM/EVMDisassembler.h
444        arch/EVM/EVMInstPrinter.h
445        arch/EVM/EVMMapping.h
446        arch/EVM/EVMMappingInsn.inc
447        )
448    set(TEST_SOURCES ${TEST_SOURCES} test_evm.c)
449endif ()
450
451if (CAPSTONE_MOS65XX_SUPPORT)
452    add_definitions(-DCAPSTONE_HAS_MOS65XX)
453    set(SOURCES_MOS65XX
454            arch/MOS65XX/MOS65XXModule.c
455            arch/MOS65XX/MOS65XXDisassembler.c)
456    set(HEADERS_SOURCES_MOS65XX
457            arch/MOS65XX/MOS65XXDisassembler.h
458    )
459    set(TEST_SOURCES ${TEST_SOURCES} test_mos65xx.c)
460endif ()
461
462if (CAPSTONE_OSXKERNEL_SUPPORT)
463    add_definitions(-DCAPSTONE_HAS_OSXKERNEL)
464endif ()
465
466set(ALL_SOURCES
467    ${SOURCES_ENGINE}
468    ${SOURCES_ARM}
469    ${SOURCES_ARM64}
470    ${SOURCES_MIPS}
471    ${SOURCES_PPC}
472    ${SOURCES_X86}
473    ${SOURCES_SPARC}
474    ${SOURCES_SYSZ}
475    ${SOURCES_XCORE}
476    ${SOURCES_M68K}
477    ${SOURCES_TMS320C64X}
478    ${SOURCES_M680X}
479    ${SOURCES_EVM}
480    ${SOURCES_MOS65XX}
481    )
482
483set(ALL_HEADERS
484    ${HEADERS_COMMON}
485    ${HEADERS_ENGINE}
486    ${HEADERS_ARM}
487    ${HEADERS_ARM64}
488    ${HEADERS_MIPS}
489    ${HEADERS_PPC}
490    ${HEADERS_X86}
491    ${HEADERS_SPARC}
492    ${HEADERS_SYSZ}
493    ${HEADERS_XCORE}
494    ${HEADERS_M68K}
495    ${HEADERS_TMS320C64X}
496    ${HEADERS_M680X}
497    ${HEADERS_EVM}
498    ${HEADERS_MOS65XX}
499    )
500
501include_directories("${PROJECT_SOURCE_DIR}/include")
502
503## properties
504# version info
505set_property(GLOBAL PROPERTY VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
506
507## targets
508if (CAPSTONE_BUILD_STATIC)
509    add_library(capstone-static STATIC ${ALL_SOURCES} ${ALL_HEADERS})
510    set_property(TARGET capstone-static PROPERTY OUTPUT_NAME capstone)
511    set(default-target capstone-static)
512endif ()
513
514# Force static runtime libraries
515if (CAPSTONE_BUILD_STATIC_RUNTIME)
516    FOREACH(flag
517	CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELWITHDEBINFO
518	CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_DEBUG_INIT
519	CMAKE_CXX_FLAGS_RELEASE  CMAKE_CXX_FLAGS_RELWITHDEBINFO
520	CMAKE_CXX_FLAGS_DEBUG  CMAKE_CXX_FLAGS_DEBUG_INIT)
521	if (MSVC)
522	    STRING(REPLACE "/MD"  "/MT" "${flag}" "${${flag}}")
523	    SET("${flag}" "${${flag}} /EHsc")
524	endif (MSVC)
525    ENDFOREACH()
526endif ()
527
528if (CAPSTONE_BUILD_SHARED)
529    add_library(capstone-shared SHARED ${ALL_SOURCES} ${ALL_HEADERS})
530    set_property(TARGET capstone-shared PROPERTY OUTPUT_NAME capstone)
531    set_property(TARGET capstone-shared PROPERTY COMPILE_FLAGS -DCAPSTONE_SHARED)
532
533    if (MSVC)
534        set_target_properties(capstone-shared PROPERTIES IMPORT_SUFFIX _dll.lib)
535    else()
536        set_target_properties(capstone-shared PROPERTIES
537	    VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
538	    SOVERSION ${VERSION_MAJOR})
539    endif ()
540
541    if(NOT DEFINED default-target)      # honor `capstone-static` for tests first.
542        set(default-target capstone-shared)
543        add_definitions(-DCAPSTONE_SHARED)
544    endif ()
545endif ()
546
547if (CAPSTONE_BUILD_TESTS)
548    foreach (TSRC ${TEST_SOURCES})
549        STRING(REGEX REPLACE ".c$" "" TBIN ${TSRC})
550        add_executable(${TBIN} "tests/${TSRC}")
551        target_link_libraries(${TBIN} ${default-target})
552        add_test(NAME "capstone_${TBIN}" COMMAND ${TBIN})
553    endforeach ()
554    if (CAPSTONE_ARM_SUPPORT)
555        set(ARM_REGRESS_TEST test_arm_regression.c)
556        STRING(REGEX REPLACE ".c$" "" ARM_REGRESS_BIN ${ARM_REGRESS_TEST})
557        add_executable(${ARM_REGRESS_BIN} "suite/arm/${ARM_REGRESS_TEST}")
558        target_link_libraries(${ARM_REGRESS_BIN} ${default-target})
559        add_test(NAME "capstone_${ARM_REGRESS_BIN}" COMMAND ${ARM_REGRESS_BIN})
560    endif()
561    # fuzz target built with the tests
562    add_executable(fuzz_disasm suite/fuzz/onefile.c suite/fuzz/fuzz_disasm.c)
563    target_link_libraries(fuzz_disasm ${default-target})
564endif ()
565
566source_group("Source\\Engine" FILES ${SOURCES_ENGINE})
567source_group("Source\\ARM" FILES ${SOURCES_ARM})
568source_group("Source\\ARM64" FILES ${SOURCES_ARM64})
569source_group("Source\\Mips" FILES ${SOURCES_MIPS})
570source_group("Source\\PowerPC" FILES ${SOURCES_PPC})
571source_group("Source\\Sparc" FILES ${SOURCES_SPARC})
572source_group("Source\\SystemZ" FILES ${SOURCES_SYSZ})
573source_group("Source\\X86" FILES ${SOURCES_X86})
574source_group("Source\\XCore" FILES ${SOURCES_XCORE})
575source_group("Source\\M68K" FILES ${SOURCES_M68K})
576source_group("Source\\TMS320C64x" FILES ${SOURCES_TMS320C64X})
577source_group("Source\\M680X" FILES ${SOURCES_M680X})
578source_group("Source\\EVM" FILES ${SOURCES_EVM})
579source_group("Source\\MOS65XX" FILES ${SOURCES_MOS65XX})
580
581source_group("Include\\Common" FILES ${HEADERS_COMMON})
582source_group("Include\\Engine" FILES ${HEADERS_ENGINE})
583source_group("Include\\ARM" FILES ${HEADERS_ARM})
584source_group("Include\\ARM64" FILES ${HEADERS_ARM64})
585source_group("Include\\Mips" FILES ${HEADERS_MIPS})
586source_group("Include\\PowerPC" FILES ${HEADERS_PPC})
587source_group("Include\\Sparc" FILES ${HEADERS_SPARC})
588source_group("Include\\SystemZ" FILES ${HEADERS_SYSZ})
589source_group("Include\\X86" FILES ${HEADERS_X86})
590source_group("Include\\XCore" FILES ${HEADERS_XCORE})
591source_group("Include\\M68K" FILES ${HEADERS_M68K})
592source_group("Include\\TMS320C64x" FILES ${HEADERS_TMS320C64X})
593source_group("Include\\M680X" FILES ${HEADERS_MC680X})
594source_group("Include\\EVM" FILES ${HEADERS_EVM})
595source_group("Include\\MOS65XX" FILES ${HEADERS_MOS65XX})
596
597### test library 64bit routine:
598include("GNUInstallDirs")
599
600## installation
601if (CAPSTONE_INSTALL)
602    install(FILES ${HEADERS_COMMON} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/capstone)
603endif ()
604configure_file(capstone.pc.in ${CMAKE_BINARY_DIR}/capstone.pc @ONLY)
605
606if (CAPSTONE_BUILD_STATIC AND CAPSTONE_INSTALL)
607    install(TARGETS capstone-static
608            RUNTIME DESTINATION bin
609            LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
610            ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
611endif ()
612
613if (CAPSTONE_BUILD_SHARED AND CAPSTONE_INSTALL)
614    install(TARGETS capstone-shared
615            RUNTIME DESTINATION bin
616            LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
617            ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
618endif ()
619
620if (CAPSTONE_BUILD_SHARED AND CAPSTONE_BUILD_CSTOOL)
621FILE(GLOB CSTOOL_SRC cstool/*.c)
622add_executable(cstool ${CSTOOL_SRC})
623target_link_libraries(cstool ${default-target})
624
625if (CAPSTONE_INSTALL)
626    install(TARGETS cstool DESTINATION bin)
627    install(FILES ${CMAKE_BINARY_DIR}/capstone.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
628endif ()
629endif ()
630