Merge branch 'cmake2' of https://github.com/arizvisa/capstone into cmake3

v2
Nguyen Anh Quynh 11 years ago
commit 1d06943318
  1. 45
      CMakeLists.txt
  2. 20
      include/capstone.h

@ -8,6 +8,7 @@ set(VERSION_PATCH 0)
# to configure the options specify them in in the command line or change them in the cmake UI. # to configure the options specify them in in the command line or change them in the cmake UI.
# Don't edit the makefile! # Don't edit the makefile!
option(BUILD_STATIC "Build static library" ON) option(BUILD_STATIC "Build static library" ON)
option(BUILD_SHARED "Build shared library" ON)
option(BUILD_DIET "Build diet library" OFF) option(BUILD_DIET "Build diet library" OFF)
option(BUILD_TESTS "Build tests" ON) option(BUILD_TESTS "Build tests" ON)
option(USE_DEFAULT_ALLOC "Use default memory allocation functions" ON) option(USE_DEFAULT_ALLOC "Use default memory allocation functions" ON)
@ -34,6 +35,7 @@ if (X86_REDUCE)
add_definitions(-DCAPSTONE_X86_REDUCE) add_definitions(-DCAPSTONE_X86_REDUCE)
endif () endif ()
## sources
set(SOURCES set(SOURCES
cs.c cs.c
MCInst.c MCInst.c
@ -45,6 +47,7 @@ set(SOURCES
set(TEST_SOURCES test.c test_detail.c test_skipdata.c) set(TEST_SOURCES test.c test_detail.c test_skipdata.c)
## architecture support
if (ARM_SUPPORT) if (ARM_SUPPORT)
add_definitions(-DCAPSTONE_HAS_ARM) add_definitions(-DCAPSTONE_HAS_ARM)
set(SOURCES set(SOURCES
@ -149,32 +152,54 @@ endif ()
include_directories("${PROJECT_SOURCE_DIR}/include") include_directories("${PROJECT_SOURCE_DIR}/include")
## properties
# version info
set_property(GLOBAL PROPERTY VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
set_property(GLOBAL PROPERTY SOVERSION SOVERSION ${VERSION_MAJOR})
## targets
if (BUILD_STATIC) if (BUILD_STATIC)
add_definitions(-DCAPSTONE_STATIC) add_library(capstone-static STATIC ${SOURCES})
add_library(capstone STATIC ${SOURCES}) set_property(TARGET capstone-static PROPERTY OUTPUT_NAME capstone)
else () set_property(TARGET capstone-static PROPERTY PREFIX lib)
add_definitions(-DCAPSTONE_SHARED) set(default-target capstone-static)
add_library(capstone SHARED ${SOURCES})
endif () endif ()
set_target_properties(capstone PROPERTIES if (BUILD_SHARED)
VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH} add_library(capstone-shared SHARED ${SOURCES})
SOVERSION ${VERSION_MAJOR}) set_property(TARGET capstone-shared PROPERTY OUTPUT_NAME capstone)
set_property(TARGET capstone-shared PROPERTY COMPILE_FLAGS -DCAPSTONE_SHARED)
if(NOT DEFINED default-target) # honor `capstone-static` for tests first.
set(default-target capstone-shared)
add_definitions(-DCAPSTONE_SHARED)
endif ()
endif ()
if (BUILD_TESTS) if (BUILD_TESTS)
foreach (TSRC ${TEST_SOURCES}) foreach (TSRC ${TEST_SOURCES})
STRING(REGEX REPLACE ".c$" "" TBIN ${TSRC}) STRING(REGEX REPLACE ".c$" "" TBIN ${TSRC})
add_executable(${TBIN} "tests/${TSRC}") add_executable(${TBIN} "tests/${TSRC}")
target_link_libraries(${TBIN} capstone) target_link_libraries(${TBIN} ${default-target})
endforeach () endforeach ()
endif () endif ()
## installation
set(INCLUDES arm64.h arm.h capstone.h mips.h ppc.h x86.h sparc.h systemz.h xcore.h) set(INCLUDES arm64.h arm.h capstone.h mips.h ppc.h x86.h sparc.h systemz.h xcore.h)
foreach (INC ${INCLUDES}) foreach (INC ${INCLUDES})
install(FILES "include/${INC}" DESTINATION include/capstone) install(FILES "include/${INC}" DESTINATION include/capstone)
endforeach () endforeach ()
install(TARGETS capstone if (BUILD_STATIC)
install(TARGETS capstone-static
RUNTIME DESTINATION bin RUNTIME DESTINATION bin
LIBRARY DESTINATION lib LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib) ARCHIVE DESTINATION lib)
endif ()
if (BUILD_SHARED)
install(TARGETS capstone-shared
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
endif ()

@ -16,17 +16,15 @@ extern "C" {
#include "platform.h" #include "platform.h"
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(disable:4201) #pragma warning(disable:4201)
#pragma warning(disable:4100) #pragma warning(disable:4100)
#ifdef CAPSTONE_SHARED // compiling DLL file #ifdef CAPSTONE_SHARED
#define CAPSTONE_EXPORT __declspec(dllexport) #define CAPSTONE_EXPORT __declspec(dllexport)
#elif defined(CAPSTONE_STATIC) #else // defined(CAPSTONE_STATIC)
#define CAPSTONE_EXPORT #define CAPSTONE_EXPORT
#else // code uses our DLL #endif
#define CAPSTONE_EXPORT __declspec(dllimport) #else
#endif #define CAPSTONE_EXPORT
#else // not MSVC
#define CAPSTONE_EXPORT
#endif #endif
// Capstone API version // Capstone API version

Loading…
Cancel
Save