Home | History | Annotate | Download | only in capstone
      1 cmake_minimum_required(VERSION 2.6)
      2 project(capstone)
      3 
      4 set(VERSION_MAJOR 3)
      5 set(VERSION_MINOR 0)
      6 set(VERSION_PATCH 5)
      7 
      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!
     10 option(CAPSTONE_BUILD_STATIC_RUNTIME "Embed static runtime" OFF)
     11 option(CAPSTONE_BUILD_STATIC "Build static library" ON)
     12 option(CAPSTONE_BUILD_SHARED "Build shared library" ON)
     13 option(CAPSTONE_BUILD_DIET "Build diet library" OFF)
     14 option(CAPSTONE_BUILD_TESTS "Build tests" ON)
     15 option(CAPSTONE_USE_DEFAULT_ALLOC "Use default memory allocation functions" ON)
     16 
     17 option(CAPSTONE_ARM_SUPPORT "ARM support" ON)
     18 option(CAPSTONE_ARM64_SUPPORT "ARM64 support" ON)
     19 option(CAPSTONE_MIPS_SUPPORT "MIPS support" ON)
     20 option(CAPSTONE_PPC_SUPPORT "PowerPC support" ON)
     21 option(CAPSTONE_SPARC_SUPPORT "Sparc support" ON)
     22 option(CAPSTONE_SYSZ_SUPPORT "SystemZ support" ON)
     23 option(CAPSTONE_XCORE_SUPPORT "XCore support" ON)
     24 option(CAPSTONE_X86_SUPPORT "x86 support" ON)
     25 option(CAPSTONE_X86_REDUCE "x86 with reduce instruction sets to minimize library" OFF)
     26 option(CAPSTONE_X86_ATT_DISABLE "Disable x86 AT&T syntax" OFF)
     27 option(CAPSTONE_OSXKERNEL_SUPPORT "Support to embed Capstone into OS X Kernel extensions" OFF)
     28 
     29 if (CAPSTONE_BUILD_DIET)
     30     add_definitions(-DCAPSTONE_DIET)
     31 endif ()
     32 
     33 if (CAPSTONE_USE_DEFAULT_ALLOC)
     34     add_definitions(-DCAPSTONE_USE_SYS_DYN_MEM)
     35 endif ()
     36 
     37 if (CAPSTONE_X86_REDUCE)
     38     add_definitions(-DCAPSTONE_X86_REDUCE)
     39 endif ()
     40 
     41 if (CAPSTONE_X86_ATT_DISABLE)
     42     add_definitions(-DCAPSTONE_X86_ATT_DISABLE)
     43 endif ()
     44 
     45 ## sources
     46 set(SOURCES_ENGINE
     47     cs.c
     48     MCInst.c
     49     MCInstrDesc.c
     50     MCRegisterInfo.c
     51     SStream.c
     52     utils.c
     53     )
     54 
     55 set(HEADERS_ENGINE
     56     include/capstone.h
     57     utils.h
     58     MCRegisterInfo.h
     59     MCInst.h
     60     MCInstrDesc.h
     61     SStream.h
     62     cs_priv.h
     63     include/platform.h
     64     )
     65 
     66 set(HEADERS_COMMON
     67     include/arm64.h
     68     include/arm.h
     69     include/capstone.h
     70     include/mips.h
     71     include/ppc.h
     72     include/x86.h
     73     include/sparc.h
     74     include/systemz.h
     75     include/xcore.h
     76     include/platform.h
     77     )
     78 
     79 
     80 set(TEST_SOURCES test_basic.c test_detail.c test_skipdata.c test_iter.c)
     81 
     82 ## architecture support
     83 if (CAPSTONE_ARM_SUPPORT)
     84     add_definitions(-DCAPSTONE_HAS_ARM)
     85     set(SOURCES_ARM
     86         arch/ARM/ARMDisassembler.c
     87         arch/ARM/ARMInstPrinter.c
     88         arch/ARM/ARMMapping.c
     89         arch/ARM/ARMModule.c
     90         )
     91     set(HEADERS_ARM
     92         arch/ARM/ARMAddressingModes.h
     93         arch/ARM/ARMBaseInfo.h
     94         arch/ARM/ARMDisassembler.h
     95         arch/ARM/ARMGenAsmWriter.inc
     96         arch/ARM/ARMGenDisassemblerTables.inc
     97         arch/ARM/ARMGenInstrInfo.inc
     98         arch/ARM/ARMGenRegisterInfo.inc
     99         arch/ARM/ARMGenSubtargetInfo.inc
    100         arch/ARM/ARMInstPrinter.h
    101         arch/ARM/ARMMapping.h
    102         )
    103     set(TEST_SOURCES ${TEST_SOURCES} test_arm.c)
    104 endif ()
    105 
    106 if (CAPSTONE_ARM64_SUPPORT)
    107     add_definitions(-DCAPSTONE_HAS_ARM64)
    108     set(SOURCES_ARM64
    109         arch/AArch64/AArch64BaseInfo.c
    110         arch/AArch64/AArch64Disassembler.c
    111         arch/AArch64/AArch64InstPrinter.c
    112         arch/AArch64/AArch64Mapping.c
    113         arch/AArch64/AArch64Module.c
    114         )
    115     set(HEADERS_ARM64
    116         arch/AArch64/AArch64AddressingModes.h
    117         arch/AArch64/AArch64BaseInfo.h
    118         arch/AArch64/AArch64Disassembler.h
    119         arch/AArch64/AArch64GenAsmWriter.inc
    120         arch/AArch64/AArch64GenDisassemblerTables.inc
    121         arch/AArch64/AArch64GenInstrInfo.inc
    122         arch/AArch64/AArch64GenRegisterInfo.inc
    123         arch/AArch64/AArch64GenSubtargetInfo.inc
    124         arch/AArch64/AArch64InstPrinter.h
    125         arch/AArch64/AArch64Mapping.h
    126         )
    127     set(TEST_SOURCES ${TEST_SOURCES} test_arm64.c)
    128 endif ()
    129 
    130 if (CAPSTONE_MIPS_SUPPORT)
    131     add_definitions(-DCAPSTONE_HAS_MIPS)
    132     set(SOURCES_MIPS
    133         arch/Mips/MipsDisassembler.c
    134         arch/Mips/MipsInstPrinter.c
    135         arch/Mips/MipsMapping.c
    136         arch/Mips/MipsModule.c
    137         )
    138     set(HEADERS_MIPS
    139         arch/Mips/MipsDisassembler.h
    140         arch/Mips/MipsGenAsmWriter.inc
    141         arch/Mips/MipsGenDisassemblerTables.inc
    142         arch/Mips/MipsGenInstrInfo.inc
    143         arch/Mips/MipsGenRegisterInfo.inc
    144         arch/Mips/MipsGenSubtargetInfo.inc
    145         arch/Mips/MipsInstPrinter.h
    146         arch/Mips/MipsMapping.h
    147         )
    148     set(TEST_SOURCES ${TEST_SOURCES} test_mips.c)
    149 endif ()
    150 
    151 if (CAPSTONE_PPC_SUPPORT)
    152     add_definitions(-DCAPSTONE_HAS_POWERPC)
    153     set(SOURCES_PPC
    154         arch/PowerPC/PPCDisassembler.c
    155         arch/PowerPC/PPCInstPrinter.c
    156         arch/PowerPC/PPCMapping.c
    157         arch/PowerPC/PPCModule.c
    158         )
    159     set(HEADERS_PPC
    160         arch/PowerPC/PPCDisassembler.h
    161         arch/PowerPC/PPCGenAsmWriter.inc
    162         arch/PowerPC/PPCGenDisassemblerTables.inc
    163         arch/PowerPC/PPCGenInstrInfo.inc
    164         arch/PowerPC/PPCGenRegisterInfo.inc
    165         arch/PowerPC/PPCGenSubtargetInfo.inc
    166         arch/PowerPC/PPCInstPrinter.h
    167         arch/PowerPC/PPCMapping.h
    168         arch/PowerPC/PPCPredicates.h
    169         )
    170     set(TEST_SOURCES ${TEST_SOURCES} test_ppc.c)
    171 endif ()
    172 
    173 if (CAPSTONE_X86_SUPPORT)
    174     add_definitions(-DCAPSTONE_HAS_X86)
    175     set(SOURCES_X86
    176         arch/X86/X86Disassembler.c
    177         arch/X86/X86DisassemblerDecoder.c
    178         arch/X86/X86IntelInstPrinter.c
    179         arch/X86/X86Mapping.c
    180         arch/X86/X86Module.c
    181         )
    182     set(HEADERS_X86
    183         arch/X86/X86BaseInfo.h
    184         arch/X86/X86Disassembler.h
    185         arch/X86/X86DisassemblerDecoder.h
    186         arch/X86/X86DisassemblerDecoderCommon.h
    187         arch/X86/X86GenAsmWriter.inc
    188         arch/X86/X86GenAsmWriter1.inc
    189         arch/X86/X86GenAsmWriter1_reduce.inc
    190         arch/X86/X86GenAsmWriter_reduce.inc
    191         arch/X86/X86GenDisassemblerTables.inc
    192         arch/X86/X86GenDisassemblerTables_reduce.inc
    193         arch/X86/X86GenInstrInfo.inc
    194         arch/X86/X86GenInstrInfo_reduce.inc
    195         arch/X86/X86GenRegisterInfo.inc
    196         arch/X86/X86InstPrinter.h
    197         arch/X86/X86Mapping.h
    198         )
    199     if (NOT CAPSTONE_BUILD_DIET)
    200         set(SOURCES_X86 ${SOURCES_X86} arch/X86/X86ATTInstPrinter.c)
    201     endif ()
    202     set(TEST_SOURCES ${TEST_SOURCES} test_x86.c)
    203 endif ()
    204 
    205 if (CAPSTONE_SPARC_SUPPORT)
    206     add_definitions(-DCAPSTONE_HAS_SPARC)
    207     set(SOURCES_SPARC
    208         arch/Sparc/SparcDisassembler.c
    209         arch/Sparc/SparcInstPrinter.c
    210         arch/Sparc/SparcMapping.c
    211         arch/Sparc/SparcModule.c
    212         )
    213     set(HEADERS_SPARC
    214         arch/Sparc/Sparc.h
    215         arch/Sparc/SparcDisassembler.h
    216         arch/Sparc/SparcGenAsmWriter.inc
    217         arch/Sparc/SparcGenDisassemblerTables.inc
    218         arch/Sparc/SparcGenInstrInfo.inc
    219         arch/Sparc/SparcGenRegisterInfo.inc
    220         arch/Sparc/SparcGenSubtargetInfo.inc
    221         arch/Sparc/SparcInstPrinter.h
    222         arch/Sparc/SparcMapping.h
    223         )
    224     set(TEST_SOURCES ${TEST_SOURCES} test_sparc.c)
    225 endif ()
    226 
    227 if (CAPSTONE_SYSZ_SUPPORT)
    228     add_definitions(-DCAPSTONE_HAS_SYSZ)
    229     set(SOURCES_SYSZ
    230         arch/SystemZ/SystemZDisassembler.c
    231         arch/SystemZ/SystemZInstPrinter.c
    232         arch/SystemZ/SystemZMapping.c
    233         arch/SystemZ/SystemZModule.c
    234         arch/SystemZ/SystemZMCTargetDesc.c
    235         )
    236     set(HEADERS_SYSZ
    237         arch/SystemZ/SystemZDisassembler.h
    238         arch/SystemZ/SystemZGenAsmWriter.inc
    239         arch/SystemZ/SystemZGenDisassemblerTables.inc
    240         arch/SystemZ/SystemZGenInstrInfo.inc
    241         arch/SystemZ/SystemZGenRegisterInfo.inc
    242         arch/SystemZ/SystemZGenSubtargetInfo.inc
    243         arch/SystemZ/SystemZInstPrinter.h
    244         arch/SystemZ/SystemZMCTargetDesc.h
    245         arch/SystemZ/SystemZMapping.h
    246         )
    247     set(TEST_SOURCES ${TEST_SOURCES} test_systemz.c)
    248 endif ()
    249 
    250 if (CAPSTONE_XCORE_SUPPORT)
    251     add_definitions(-DCAPSTONE_HAS_XCORE)
    252     set(SOURCES_XCORE
    253         arch/XCore/XCoreDisassembler.c
    254         arch/XCore/XCoreInstPrinter.c
    255         arch/XCore/XCoreMapping.c
    256         arch/XCore/XCoreModule.c
    257         )
    258     set(HEADERS_XCORE
    259         arch/XCore/XCoreDisassembler.h
    260         arch/XCore/XCoreGenAsmWriter.inc
    261         arch/XCore/XCoreGenDisassemblerTables.inc
    262         arch/XCore/XCoreGenInstrInfo.inc
    263         arch/XCore/XCoreGenRegisterInfo.inc
    264         arch/XCore/XCoreInstPrinter.h
    265         arch/XCore/XCoreMapping.h
    266         )
    267     set(TEST_SOURCES ${TEST_SOURCES} test_xcore.c)
    268 endif ()
    269 
    270 if (CAPSTONE_OSXKERNEL_SUPPORT)
    271     add_definitions(-DCAPSTONE_HAS_OSXKERNEL)
    272 endif ()
    273 
    274 set(ALL_SOURCES
    275     ${SOURCES_ENGINE}
    276     ${SOURCES_ARM}
    277     ${SOURCES_ARM64}
    278     ${SOURCES_MIPS}
    279     ${SOURCES_PPC}
    280     ${SOURCES_X86}
    281     ${SOURCES_SPARC}
    282     ${SOURCES_SYSZ}
    283     ${SOURCES_XCORE}
    284     )
    285 
    286 set(ALL_HEADERS
    287     ${HEADERS_COMMON}
    288     ${HEADERS_ENGINE}
    289     ${HEADERS_ARM}
    290     ${HEADERS_ARM64}
    291     ${HEADERS_MIPS}
    292     ${HEADERS_PPC}
    293     ${HEADERS_X86}
    294     ${HEADERS_SPARC}
    295     ${HEADERS_SYSZ}
    296     ${HEADERS_XCORE}
    297     )
    298 
    299 include_directories("${PROJECT_SOURCE_DIR}/include")
    300 
    301 ## properties
    302 # version info
    303 set_property(GLOBAL PROPERTY VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
    304 
    305 ## targets
    306 if (CAPSTONE_BUILD_STATIC)
    307     add_library(capstone-static STATIC ${ALL_SOURCES} ${ALL_HEADERS})
    308     set_property(TARGET capstone-static PROPERTY OUTPUT_NAME capstone)
    309     set(default-target capstone-static)
    310 endif ()
    311 
    312 # Force static runtime libraries
    313 if (CAPSTONE_BUILD_STATIC_RUNTIME)
    314     FOREACH(flag
    315         CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELWITHDEBINFO
    316         CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_DEBUG_INIT
    317         CMAKE_CXX_FLAGS_RELEASE  CMAKE_CXX_FLAGS_RELWITHDEBINFO
    318         CMAKE_CXX_FLAGS_DEBUG  CMAKE_CXX_FLAGS_DEBUG_INIT)
    319         if (MSVC)
    320             STRING(REPLACE "/MD"  "/MT" "${flag}" "${${flag}}")
    321             SET("${flag}" "${${flag}} /EHsc")
    322         endif (MSVC)
    323     ENDFOREACH()
    324 endif ()
    325 
    326 if (CAPSTONE_BUILD_SHARED)
    327     add_library(capstone-shared SHARED ${ALL_SOURCES} ${ALL_HEADERS})
    328     set_property(TARGET capstone-shared PROPERTY OUTPUT_NAME capstone)
    329     set_property(TARGET capstone-shared PROPERTY COMPILE_FLAGS -DCAPSTONE_SHARED)
    330 
    331     if (MSVC)
    332         set_target_properties(capstone-shared PROPERTIES IMPORT_SUFFIX _dll.lib)
    333     else()
    334         set_target_properties(capstone-shared PROPERTIES
    335 	    VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
    336 	    SOVERSION ${VERSION_MAJOR})
    337     endif ()
    338 
    339     if(NOT DEFINED default-target)      # honor `capstone-static` for tests first.
    340         set(default-target capstone-shared)
    341         add_definitions(-DCAPSTONE_SHARED)
    342     endif ()
    343 endif ()
    344 
    345 if (CAPSTONE_BUILD_TESTS)
    346     foreach (TSRC ${TEST_SOURCES})
    347         STRING(REGEX REPLACE ".c$" "" TBIN ${TSRC})
    348         add_executable(${TBIN} "tests/${TSRC}")
    349         target_link_libraries(${TBIN} ${default-target})
    350     endforeach ()
    351     if (CAPSTONE_ARM_SUPPORT)
    352         set(ARM_REGRESS_TEST test_arm_regression.c)
    353         STRING(REGEX REPLACE ".c$" "" ARM_REGRESS_BIN ${ARM_REGRESS_TEST})
    354         add_executable(${ARM_REGRESS_BIN} "suite/arm/${ARM_REGRESS_TEST}")
    355         target_link_libraries(${ARM_REGRESS_BIN} ${default-target})
    356     endif()
    357 endif ()
    358 
    359 source_group("Source\\Engine" FILES ${SOURCES_ENGINE})
    360 source_group("Source\\ARM" FILES ${SOURCES_ARM})
    361 source_group("Source\\ARM64" FILES ${SOURCES_ARM64})
    362 source_group("Source\\Mips" FILES ${SOURCES_MIPS})
    363 source_group("Source\\PowerPC" FILES ${SOURCES_PPC})
    364 source_group("Source\\Sparc" FILES ${SOURCES_SPARC})
    365 source_group("Source\\SystemZ" FILES ${SOURCES_SYSZ})
    366 source_group("Source\\X86" FILES ${SOURCES_X86})
    367 source_group("Source\\XCore" FILES ${SOURCES_XCORE})
    368 
    369 source_group("Include\\Common" FILES ${HEADERS_COMMON})
    370 source_group("Include\\Engine" FILES ${HEADERS_ENGINE})
    371 source_group("Include\\ARM" FILES ${HEADERS_ARM})
    372 source_group("Include\\ARM64" FILES ${HEADERS_ARM64})
    373 source_group("Include\\Mips" FILES ${HEADERS_MIPS})
    374 source_group("Include\\PowerPC" FILES ${HEADERS_PPC})
    375 source_group("Include\\Sparc" FILES ${HEADERS_SPARC})
    376 source_group("Include\\SystemZ" FILES ${HEADERS_SYSZ})
    377 source_group("Include\\X86" FILES ${HEADERS_X86})
    378 source_group("Include\\XCore" FILES ${HEADERS_XCORE})
    379 
    380 ### test library 64bit routine:
    381 get_property(LIB64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS)
    382 
    383 if (NOT APPLE AND "${LIB64}" STREQUAL "TRUE")
    384     set(LIBSUFFIX 64)
    385 else()
    386     set(LIBSUFFIX "")
    387 endif()
    388 
    389 set(INSTALL_LIB_DIR     lib${LIBSUFFIX} CACHE PATH "Installation directory for libraries")
    390 mark_as_advanced(INSTALL_LIB_DIR)
    391 
    392 ## installation
    393 install(FILES ${HEADERS_COMMON} DESTINATION include/capstone)
    394 configure_file(capstone.pc.in capstone.pc)
    395 
    396 if (CAPSTONE_BUILD_STATIC)
    397     install(TARGETS capstone-static
    398             RUNTIME DESTINATION bin
    399             LIBRARY DESTINATION ${INSTALL_LIB_DIR}
    400             ARCHIVE DESTINATION ${INSTALL_LIB_DIR})
    401 endif ()
    402 
    403 if (CAPSTONE_BUILD_SHARED)
    404     install(TARGETS capstone-shared
    405             RUNTIME DESTINATION bin
    406             LIBRARY DESTINATION ${INSTALL_LIB_DIR}
    407             ARCHIVE DESTINATION ${INSTALL_LIB_DIR})
    408 endif ()
    409 
    410 if (CAPSTONE_BUILD_SHARED)
    411 FILE(GLOB CSTOOL_SRC cstool/*.c)
    412 add_executable(cstool ${CSTOOL_SRC})
    413 target_link_libraries(cstool ${default-target})
    414 
    415 install(TARGETS cstool DESTINATION bin)
    416 install(FILES ${CMAKE_BINARY_DIR}/capstone.pc DESTINATION lib/pkgconfig)
    417 endif ()
    418