mirror of
https://gitlab.com/qemu-project/capstone.git
synced 2025-11-11 08:16:15 +08:00
Add cmake option to tell whether architectures should be included by default (#1463)
* Add cmake option to disable architectures by default * Add cmake option to disable architectures by default * Remove CAPSTONE_X86_ONLY cmake variable, and update build scripts to use the CAPSTONE_ARCHITECUTRE_DEFAULT option, which can be used with any architecture. * Updated cmake and nmake files to replace cmake-x86 and nmake-x86 * Simplified cmake wrapper scripts * Updated cmake build instructions * Tab to space in doc
This commit is contained in:
committed by
Nguyen Anh Quynh
parent
c8716f516a
commit
e5d7120345
@@ -27,6 +27,7 @@ option(CAPSTONE_BUILD_DIET "Build diet library" OFF)
|
||||
option(CAPSTONE_BUILD_TESTS "Build tests" ON)
|
||||
option(CAPSTONE_BUILD_CSTOOL "Build cstool" ON)
|
||||
option(CAPSTONE_USE_DEFAULT_ALLOC "Use default memory allocation functions" ON)
|
||||
option(CAPSTONE_ARCHITECTURE_DEFAULT "Whether architectures are enabled by default" ON)
|
||||
|
||||
set(SUPPORTED_ARCHITECTURES ARM ARM64 M68K MIPS PPC SPARC SYSZ XCORE X86 TMS320C64X M680X EVM MOS65XX)
|
||||
set(SUPPORTED_ARCHITECTURE_LABELS ARM ARM64 M68K MIPS PowerPC Sparc SystemZ XCore x86 TMS320C64x M680x EVM MOS65XX)
|
||||
@@ -37,7 +38,7 @@ math(EXPR count "${count}-1")
|
||||
foreach(i RANGE ${count})
|
||||
list(GET SUPPORTED_ARCHITECTURES ${i} supported_architecture)
|
||||
list(GET SUPPORTED_ARCHITECTURE_LABELS ${i} supported_architecture_label)
|
||||
option("CAPSTONE_${supported_architecture}_SUPPORT" "${supported_architecture_label} support" ON)
|
||||
option("CAPSTONE_${supported_architecture}_SUPPORT" "${supported_architecture_label} support" ${CAPSTONE_ARCHITECTURE_DEFAULT})
|
||||
endforeach(i)
|
||||
|
||||
# propagate architecture support variables to preprocessor
|
||||
@@ -49,7 +50,6 @@ foreach(supported_architecture ${SUPPORTED_ARCHITECTURES})
|
||||
endif()
|
||||
endforeach(supported_architecture)
|
||||
|
||||
option(CAPSTONE_X86_ONLY "Enable just x86, and disable building every other architectures" OFF)
|
||||
option(CAPSTONE_X86_REDUCE "x86 with reduce instruction sets to minimize library" OFF)
|
||||
option(CAPSTONE_X86_ATT_DISABLE "Disable x86 AT&T syntax" OFF)
|
||||
option(CAPSTONE_OSXKERNEL_SUPPORT "Support to embed Capstone into OS X Kernel extensions" OFF)
|
||||
@@ -120,7 +120,7 @@ set(HEADERS_COMMON
|
||||
set(TEST_SOURCES test_basic.c test_detail.c test_skipdata.c test_iter.c)
|
||||
|
||||
## architecture support
|
||||
if (NOT CAPSTONE_X86_ONLY AND CAPSTONE_ARM_SUPPORT)
|
||||
if (CAPSTONE_ARM_SUPPORT)
|
||||
add_definitions(-DCAPSTONE_HAS_ARM)
|
||||
set(SOURCES_ARM
|
||||
arch/ARM/ARMDisassembler.c
|
||||
@@ -157,7 +157,7 @@ if (NOT CAPSTONE_X86_ONLY AND CAPSTONE_ARM_SUPPORT)
|
||||
set(TEST_SOURCES ${TEST_SOURCES} test_arm.c)
|
||||
endif ()
|
||||
|
||||
if (NOT CAPSTONE_X86_ONLY AND CAPSTONE_ARM64_SUPPORT)
|
||||
if (CAPSTONE_ARM64_SUPPORT)
|
||||
add_definitions(-DCAPSTONE_HAS_ARM64)
|
||||
set(SOURCES_ARM64
|
||||
arch/AArch64/AArch64BaseInfo.c
|
||||
@@ -194,7 +194,7 @@ if (NOT CAPSTONE_X86_ONLY AND CAPSTONE_ARM64_SUPPORT)
|
||||
set(TEST_SOURCES ${TEST_SOURCES} test_arm64.c)
|
||||
endif ()
|
||||
|
||||
if (NOT CAPSTONE_X86_ONLY AND CAPSTONE_MIPS_SUPPORT)
|
||||
if (CAPSTONE_MIPS_SUPPORT)
|
||||
add_definitions(-DCAPSTONE_HAS_MIPS)
|
||||
set(SOURCES_MIPS
|
||||
arch/Mips/MipsDisassembler.c
|
||||
@@ -226,7 +226,7 @@ if (NOT CAPSTONE_X86_ONLY AND CAPSTONE_MIPS_SUPPORT)
|
||||
set(TEST_SOURCES ${TEST_SOURCES} test_mips.c)
|
||||
endif ()
|
||||
|
||||
if (NOT CAPSTONE_X86_ONLY AND CAPSTONE_PPC_SUPPORT)
|
||||
if (CAPSTONE_PPC_SUPPORT)
|
||||
add_definitions(-DCAPSTONE_HAS_POWERPC)
|
||||
set(SOURCES_PPC
|
||||
arch/PowerPC/PPCDisassembler.c
|
||||
@@ -313,7 +313,7 @@ if (CAPSTONE_X86_SUPPORT)
|
||||
set(TEST_SOURCES ${TEST_SOURCES} test_x86.c test_customized_mnem.c)
|
||||
endif ()
|
||||
|
||||
if (NOT CAPSTONE_X86_ONLY AND CAPSTONE_SPARC_SUPPORT)
|
||||
if (CAPSTONE_SPARC_SUPPORT)
|
||||
add_definitions(-DCAPSTONE_HAS_SPARC)
|
||||
set(SOURCES_SPARC
|
||||
arch/Sparc/SparcDisassembler.c
|
||||
@@ -336,7 +336,7 @@ if (NOT CAPSTONE_X86_ONLY AND CAPSTONE_SPARC_SUPPORT)
|
||||
set(TEST_SOURCES ${TEST_SOURCES} test_sparc.c)
|
||||
endif ()
|
||||
|
||||
if (NOT CAPSTONE_X86_ONLY AND CAPSTONE_SYSZ_SUPPORT)
|
||||
if (CAPSTONE_SYSZ_SUPPORT)
|
||||
add_definitions(-DCAPSTONE_HAS_SYSZ)
|
||||
set(SOURCES_SYSZ
|
||||
arch/SystemZ/SystemZDisassembler.c
|
||||
@@ -361,7 +361,7 @@ if (NOT CAPSTONE_X86_ONLY AND CAPSTONE_SYSZ_SUPPORT)
|
||||
set(TEST_SOURCES ${TEST_SOURCES} test_systemz.c)
|
||||
endif ()
|
||||
|
||||
if (NOT CAPSTONE_X86_ONLY AND CAPSTONE_XCORE_SUPPORT)
|
||||
if (CAPSTONE_XCORE_SUPPORT)
|
||||
add_definitions(-DCAPSTONE_HAS_XCORE)
|
||||
set(SOURCES_XCORE
|
||||
arch/XCore/XCoreDisassembler.c
|
||||
@@ -382,7 +382,7 @@ if (NOT CAPSTONE_X86_ONLY AND CAPSTONE_XCORE_SUPPORT)
|
||||
set(TEST_SOURCES ${TEST_SOURCES} test_xcore.c)
|
||||
endif ()
|
||||
|
||||
if (NOT CAPSTONE_X86_ONLY AND CAPSTONE_M68K_SUPPORT)
|
||||
if (CAPSTONE_M68K_SUPPORT)
|
||||
add_definitions(-DCAPSTONE_HAS_M68K)
|
||||
set(SOURCES_M68K
|
||||
arch/M68K/M68KDisassembler.c
|
||||
@@ -395,7 +395,7 @@ if (NOT CAPSTONE_X86_ONLY AND CAPSTONE_M68K_SUPPORT)
|
||||
set(TEST_SOURCES ${TEST_SOURCES} test_m68k.c)
|
||||
endif ()
|
||||
|
||||
if (NOT CAPSTONE_X86_ONLY AND CAPSTONE_TMS320C64X_SUPPORT)
|
||||
if (CAPSTONE_TMS320C64X_SUPPORT)
|
||||
add_definitions(-DCAPSTONE_HAS_TMS320C64X)
|
||||
set(SOURCES_TMS320C64X
|
||||
arch/TMS320C64x/TMS320C64xDisassembler.c
|
||||
@@ -415,7 +415,7 @@ if (NOT CAPSTONE_X86_ONLY AND CAPSTONE_TMS320C64X_SUPPORT)
|
||||
set(TEST_SOURCES ${TEST_SOURCES} test_tms320c64x.c)
|
||||
endif ()
|
||||
|
||||
if (NOT CAPSTONE_X86_ONLY AND CAPSTONE_M680X_SUPPORT)
|
||||
if (CAPSTONE_M680X_SUPPORT)
|
||||
add_definitions(-DCAPSTONE_HAS_M680X)
|
||||
set(SOURCES_M680X
|
||||
arch/M680X/M680XDisassembler.c
|
||||
@@ -430,7 +430,7 @@ if (NOT CAPSTONE_X86_ONLY AND CAPSTONE_M680X_SUPPORT)
|
||||
set(TEST_SOURCES ${TEST_SOURCES} test_m680x.c)
|
||||
endif ()
|
||||
|
||||
if (NOT CAPSTONE_X86_ONLY AND CAPSTONE_EVM_SUPPORT)
|
||||
if (CAPSTONE_EVM_SUPPORT)
|
||||
add_definitions(-DCAPSTONE_HAS_EVM)
|
||||
set(SOURCES_EVM
|
||||
arch/EVM/EVMDisassembler.c
|
||||
@@ -447,7 +447,7 @@ if (NOT CAPSTONE_X86_ONLY AND CAPSTONE_EVM_SUPPORT)
|
||||
set(TEST_SOURCES ${TEST_SOURCES} test_evm.c)
|
||||
endif ()
|
||||
|
||||
if (NOT CAPSTONE_X86_ONLY AND CAPSTONE_MOS65XX_SUPPORT)
|
||||
if (CAPSTONE_MOS65XX_SUPPORT)
|
||||
add_definitions(-DCAPSTONE_HAS_MOS65XX)
|
||||
set(SOURCES_MOS65XX
|
||||
arch/MOS65XX/MOS65XXModule.c
|
||||
|
||||
@@ -33,6 +33,9 @@ Get CMake for free from http://www.cmake.org.
|
||||
- CAPSTONE_X86_TMS320C64X: support TMS320C64X. Run cmake with -DCAPSTONE_TMS320C64X_SUPPORT=0 to remove TMS320C64X.
|
||||
- CAPSTONE_X86_M680X: support M680X. Run cmake with -DCAPSTONE_M680X_SUPPORT=0 to remove M680X.
|
||||
- CAPSTONE_X86_EVM: support EVM. Run cmake with -DCAPSTONE_EVM_SUPPORT=0 to remove EVM.
|
||||
- CAPSTONE_ARCHITECUTRE_DEFAULT: Whether architectures are enabled by default.
|
||||
Set this of OFF with -DCAPSTONE_ARCHITECUTRE_DEFAULT=OFF to dissable all architectures by default.
|
||||
You can then enable them again with one of the CAPSTONE_<ARCH>_SUPPORT options.
|
||||
|
||||
By default, all architectures are compiled in.
|
||||
|
||||
@@ -56,6 +59,17 @@ Get CMake for free from http://www.cmake.org.
|
||||
(1) CMake allows you to generate different generators to build Capstone. Below is
|
||||
some examples on how to build Capstone on Windows with CMake.
|
||||
|
||||
(*) You can let CMake select a generator for you. Do:
|
||||
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
|
||||
This last command is also where you can pass additional CMake configuration flags
|
||||
using `-D<key>=<value>`. Then to build use:
|
||||
|
||||
cmake --build . --config Release
|
||||
|
||||
|
||||
(*) To build Capstone using Nmake of Windows SDK, do:
|
||||
|
||||
@@ -83,3 +97,19 @@ Get CMake for free from http://www.cmake.org.
|
||||
(2) You can make sure the prior steps successfully worked by launching one of the
|
||||
testing binary (test*.exe).
|
||||
|
||||
(3) You can also enable just one specific architecture by passing the architecture name
|
||||
to either the cmake.sh or nmake.bat scripts. e.g.:
|
||||
|
||||
../cmake.sh x86
|
||||
|
||||
Will just target the x86 architecture. The list of available architectures is: ARM,
|
||||
ARM64, M68K, MIPS, PowerPC, Sparc, SystemZ, XCore, x86, TMS320C64x, M680x, EVM, MOS65XX.
|
||||
|
||||
(4) You can also create an installation image with cmake, by using the 'install' target.
|
||||
Use:
|
||||
|
||||
cmake --build . --config Release --target install
|
||||
|
||||
This will normally install an image in a default location (`C:\Program Files` on Windows),
|
||||
so it's good to explicitly set this location when configuring CMake. Use: `-DCMAKE_INSTALL_PREFIX=image`
|
||||
for instance, to put the installation in the 'image' subdirectory of the build directory.
|
||||
|
||||
10
cmake-x86.sh
10
cmake-x86.sh
@@ -1,10 +0,0 @@
|
||||
# Capstone disassembler engine (www.capstone-engine.org)
|
||||
# Build Capstone libs for X86 only (libcapstone.so & libcapstone.a) on *nix with CMake & make
|
||||
# By Nguyen Anh Quynh, 2019
|
||||
|
||||
# Uncomment below line to compile in Diet mode
|
||||
# cmake -DCMAKE_BUILD_TYPE=Release -DCAPSTONE_BUILD_DIET=ON -DCAPSTONE_X86_ONLY=1 ..
|
||||
|
||||
cmake -DCMAKE_BUILD_TYPE=Release -DCAPSTONE_X86_ONLY=1 ..
|
||||
|
||||
make -j8
|
||||
59
cmake.sh
Normal file
59
cmake.sh
Normal file
@@ -0,0 +1,59 @@
|
||||
# Capstone disassembler engine (www.capstone-engine.org)
|
||||
# Build Capstone libs for specified architecture, or all if none is specified (libcapstone.so & libcapstone.a) on *nix with CMake & make
|
||||
# By Nguyen Anh Quynh, Jorn Vernee, 2019
|
||||
|
||||
FLAGS="-DCMAKE_BUILD_TYPE=Release"
|
||||
# Uncomment below line to compile in Diet mode
|
||||
# FLAGS+=" -DCAPSTONE_BUILD_DIET=ON"
|
||||
|
||||
case $1 in
|
||||
ARM)
|
||||
ARCH=ARM
|
||||
;;
|
||||
ARM64)
|
||||
ARCH=ARM64
|
||||
;;
|
||||
M68K)
|
||||
ARCH=M68K
|
||||
;;
|
||||
MIPS)
|
||||
ARCH=MIPS
|
||||
;;
|
||||
PowerPC)
|
||||
ARCH=PPC
|
||||
;;
|
||||
Sparc)
|
||||
ARCH=SPARC
|
||||
;;
|
||||
SystemZ)
|
||||
ARCH=SYSZ
|
||||
;;
|
||||
XCore)
|
||||
ARCH=XCORE
|
||||
;;
|
||||
x86)
|
||||
ARCH=X86
|
||||
;;
|
||||
TMS320C64x)
|
||||
ARCH=TMS320C64X
|
||||
;;
|
||||
M680x)
|
||||
ARCH=M680X
|
||||
;;
|
||||
EVM)
|
||||
ARCH=EVM
|
||||
;;
|
||||
MOS65XX)
|
||||
ARCH=MOS65XX
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
|
||||
if test "x$ARCH" = "x"; then
|
||||
FLAGS+=" -DCAPSTONE_ARCHITECTURE_DEFAULT=OFF -DCAPSTONE_$ARCH_SUPPORT=ON"
|
||||
fi
|
||||
|
||||
cmake $FLAGS ..
|
||||
|
||||
make -j8
|
||||
@@ -1,10 +0,0 @@
|
||||
:: Capstone disassembler engine (www.capstone-engine.org)
|
||||
:: Build Capstone libs for X86 only (capstone.dll & capstone.lib) on Windows with CMake & Nmake
|
||||
:: By Nguyen Anh Quynh, 2017
|
||||
|
||||
:: Uncomment below line to compile in Diet mode
|
||||
:: cmake -DCMAKE_BUILD_TYPE=Release -DCAPSTONE_BUILD_DIET=ON -DCAPSTONE_X86_ONLY=1 -DCAPSTONE_BUILD_STATIC_RUNTIME=ON -G "NMake Makefiles" ..
|
||||
|
||||
cmake -DCMAKE_BUILD_TYPE=Release -DCAPSTONE_X86_ONLY=1 -DCAPSTONE_BUILD_STATIC_RUNTIME=ON -G "NMake Makefiles" ..
|
||||
|
||||
nmake
|
||||
24
nmake.bat
24
nmake.bat
@@ -1,7 +1,27 @@
|
||||
:: Capstone disassembler engine (www.capstone-engine.org)
|
||||
:: Build Capstone libs (capstone.dll & capstone.lib) on Windows with CMake & Nmake
|
||||
:: By Nguyen Anh Quynh, 2017
|
||||
:: By Nguyen Anh Quynh, Jorn Vernee, 2017, 2019
|
||||
|
||||
cmake -DCMAKE_BUILD_TYPE=Release -DCAPSTONE_BUILD_STATIC_RUNTIME=ON -G "NMake Makefiles" ..
|
||||
@echo off
|
||||
|
||||
set flags="-DCMAKE_BUILD_TYPE=Release -DCAPSTONE_BUILD_STATIC_RUNTIME=ON"
|
||||
|
||||
if "%1"=="ARM" set %arch%=ARM
|
||||
if "%1"=="ARM64" set %arch%=ARM64
|
||||
if "%1"=="M68K" set %arch%=M68K
|
||||
if "%1"=="MIPS" set %arch%=MIPS
|
||||
if "%1"=="PowerPC" set %arch%=PPC
|
||||
if "%1"=="Sparc" set %arch%=SPARC
|
||||
if "%1"=="SystemZ" set %arch%=SYSZ
|
||||
if "%1"=="XCore" set %arch%=XCORE
|
||||
if "%1"=="x86" set %arch%=X86
|
||||
if "%1"=="TMS320C64x" set %arch%=TMS320C64X
|
||||
if "%1"=="M680x" set %arch%=M680X
|
||||
if "%1"=="EVM" set %arch%=EVM
|
||||
if "%1"=="MOS65XX" set %arch%=MOS65XX
|
||||
|
||||
if not "%arch%"=="" set flags=%flags% and " -DCAPSTONE_ARCHITECTURE_DEFAULT=OFF -DCAPSTONE_%arch%_SUPPORT=ON"
|
||||
|
||||
cmake %flags% -G "NMake Makefiles" ..
|
||||
nmake
|
||||
|
||||
|
||||
Reference in New Issue
Block a user