2017-07-06 19:12:43 +08:00
|
|
|
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
|
2015-03-17 00:58:07 +08:00
|
|
|
include(GenerateExportHeader)
|
2017-07-03 09:21:24 +08:00
|
|
|
include(GNUInstallDirs)
|
2014-11-18 03:54:30 +08:00
|
|
|
|
2017-07-02 14:40:41 +08:00
|
|
|
project(Zydis VERSION 2.0)
|
2014-11-18 03:54:30 +08:00
|
|
|
|
2017-07-02 14:40:41 +08:00
|
|
|
# =============================================================================================== #
|
|
|
|
# Overridable options #
|
|
|
|
# =============================================================================================== #
|
|
|
|
|
|
|
|
# Features
|
2017-07-06 19:12:43 +08:00
|
|
|
option(ZYDIS_FEATURE_DECODER
|
2017-11-24 05:42:25 +08:00
|
|
|
"Enable instruction decoding functionality"
|
|
|
|
ON)
|
|
|
|
option(ZYDIS_FEATURE_FORMATTER
|
|
|
|
"Enable instruction formatting functionality"
|
2017-07-06 19:12:43 +08:00
|
|
|
ON)
|
2018-03-01 03:06:43 +08:00
|
|
|
option(ZYDIS_FEATURE_EVEX
|
|
|
|
"Enable support for EVEX instructions"
|
2017-06-22 00:25:53 +08:00
|
|
|
ON)
|
2018-03-01 03:06:43 +08:00
|
|
|
option(ZYDIS_FEATURE_MVEX
|
|
|
|
"Enable support for MVEX instructions"
|
2017-06-22 00:25:53 +08:00
|
|
|
ON)
|
2017-07-02 14:40:41 +08:00
|
|
|
|
|
|
|
# Build configuration
|
2017-09-06 23:05:05 +08:00
|
|
|
option(BUILD_SHARED_LIBS
|
|
|
|
"Build shared libraries"
|
|
|
|
OFF)
|
2018-03-01 03:06:43 +08:00
|
|
|
option(ZYDIS_WHOLE_PROGRAM_OPTIMIZATION
|
2018-02-28 06:56:43 +08:00
|
|
|
"Enable whole program optimization"
|
|
|
|
OFF)
|
2017-11-25 02:25:48 +08:00
|
|
|
option(ZYDIS_NO_LIBC
|
|
|
|
"Don't use any C standard library functions (for exotic build-envs like kernel drivers)"
|
|
|
|
OFF)
|
2018-03-01 03:06:43 +08:00
|
|
|
option(ZYDIS_BUILD_EXAMPLES
|
|
|
|
"Build examples"
|
2017-07-02 14:40:41 +08:00
|
|
|
ON)
|
2018-03-01 03:06:43 +08:00
|
|
|
option(ZYDIS_BUILD_TOOLS
|
|
|
|
"Build tools"
|
2017-07-02 14:40:41 +08:00
|
|
|
ON)
|
2017-11-27 07:32:15 +08:00
|
|
|
option(ZYDIS_FUZZ_AFL_FAST
|
2018-03-01 03:06:43 +08:00
|
|
|
"Enables AFL persistent mode and reduces prints in ZydisFuzzIn"
|
|
|
|
OFF)
|
2017-07-02 14:40:41 +08:00
|
|
|
option(ZYDIS_DEV_MODE
|
|
|
|
"Enable developer mode (-Wall, -Werror, ...)"
|
|
|
|
OFF)
|
2014-11-18 03:54:30 +08:00
|
|
|
|
2017-07-02 14:40:41 +08:00
|
|
|
# =============================================================================================== #
|
|
|
|
# Developer mode #
|
|
|
|
# =============================================================================================== #
|
|
|
|
|
|
|
|
# If in developer mode, hack global compiler flags.
|
|
|
|
if (ZYDIS_DEV_MODE)
|
2017-07-03 09:37:38 +08:00
|
|
|
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
2016-06-20 07:33:29 +08:00
|
|
|
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR
|
2017-01-06 09:06:08 +08:00
|
|
|
"${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR
|
2017-04-10 04:54:53 +08:00
|
|
|
"${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang")
|
2017-07-02 14:40:41 +08:00
|
|
|
set(compiler_specific "-pedantic -Wextra -Werror")
|
2015-03-17 01:30:14 +08:00
|
|
|
elseif (MSVC)
|
2017-01-10 13:01:04 +08:00
|
|
|
set(compiler_specific "/WX /W4 /TC")
|
2014-11-18 03:54:30 +08:00
|
|
|
endif ()
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${compiler_specific}"
|
|
|
|
CACHE STRING "Flags used by the compiler during all build types." FORCE)
|
|
|
|
endif ()
|
|
|
|
|
2017-07-02 14:40:41 +08:00
|
|
|
# =============================================================================================== #
|
|
|
|
# Library configuration #
|
|
|
|
# =============================================================================================== #
|
2015-03-17 01:30:14 +08:00
|
|
|
|
2017-07-02 14:40:41 +08:00
|
|
|
add_library("Zydis")
|
2015-05-20 03:45:53 +08:00
|
|
|
|
2018-03-01 03:06:43 +08:00
|
|
|
target_include_directories("Zydis"
|
2017-07-03 10:16:38 +08:00
|
|
|
PUBLIC "include" ${PROJECT_BINARY_DIR}
|
|
|
|
PRIVATE "src")
|
2017-01-10 13:01:04 +08:00
|
|
|
target_compile_definitions("Zydis" PRIVATE "_CRT_SECURE_NO_WARNINGS" "ZYDIS_EXPORTS")
|
2018-03-01 03:06:43 +08:00
|
|
|
if (ZYDIS_WHOLE_PROGRAM_OPTIMIZATION AND MSVC)
|
2018-02-28 06:56:43 +08:00
|
|
|
set_target_properties("Zydis" PROPERTIES COMPILE_FLAGS "/GL")
|
|
|
|
set_target_properties("Zydis" PROPERTIES LINK_FLAGS_RELEASE "/LTCG")
|
|
|
|
set_target_properties("Zydis" PROPERTIES STATIC_LIBRARY_FLAGS_RELEASE "/LTCG")
|
|
|
|
endif ()
|
2017-01-06 09:06:08 +08:00
|
|
|
generate_export_header("Zydis" BASE_NAME "ZYDIS" EXPORT_FILE_NAME "ZydisExportConfig.h")
|
2015-02-06 09:28:51 +08:00
|
|
|
|
2017-07-06 19:12:43 +08:00
|
|
|
if (NOT ZYDIS_FEATURE_ENCODER AND NOT ZYDIS_FEATURE_DECODER)
|
2017-09-15 06:42:05 +08:00
|
|
|
message(
|
|
|
|
FATAL_ERROR
|
|
|
|
"\nIt's dangerous to go alone! Take at least one of these:\n"
|
|
|
|
"[ ] ZYDIS_FEATURE_ENCODER [ ] ZYDIS_FEATURE_DECODER"
|
|
|
|
)
|
2017-07-06 19:12:43 +08:00
|
|
|
endif ()
|
|
|
|
|
2018-03-01 04:16:32 +08:00
|
|
|
if (ZYDIS_FEATURE_FORMATTER AND NOT ZYDIS_FEATURE_DECODER)
|
|
|
|
message(
|
|
|
|
FATAL_ERROR
|
|
|
|
"\nZYDIS_FEATURE_FORMATTER requires ZYDIS_FEATURE_DECODER to be enabled"
|
|
|
|
)
|
|
|
|
endif ()
|
|
|
|
|
2017-11-24 05:42:25 +08:00
|
|
|
if (NOT ZYDIS_FEATURE_DECODER)
|
|
|
|
target_compile_definitions("Zydis" PUBLIC "ZYDIS_DISABLE_DECODER")
|
2016-11-12 05:03:26 +08:00
|
|
|
endif ()
|
2017-11-24 05:42:25 +08:00
|
|
|
if (NOT ZYDIS_FEATURE_FORMATTER)
|
|
|
|
target_compile_definitions("Zydis" PUBLIC "ZYDIS_DISABLE_FORMATTER")
|
2016-11-12 05:03:26 +08:00
|
|
|
endif ()
|
2017-11-24 05:42:25 +08:00
|
|
|
if (NOT ZYDIS_FEATURE_EVEX)
|
|
|
|
target_compile_definitions("Zydis" PUBLIC "ZYDIS_DISABLE_EVEX")
|
2016-11-12 05:03:26 +08:00
|
|
|
endif ()
|
2017-11-24 05:42:25 +08:00
|
|
|
if (NOT ZYDIS_FEATURE_MVEX)
|
|
|
|
target_compile_definitions("Zydis" PUBLIC "ZYDIS_DISABLE_MVEX")
|
2017-07-06 15:52:14 +08:00
|
|
|
endif ()
|
2017-11-25 02:25:48 +08:00
|
|
|
if (ZYDIS_NO_LIBC)
|
|
|
|
target_compile_definitions("Zydis" PUBLIC "ZYDIS_NO_LIBC")
|
|
|
|
endif ()
|
2016-11-12 05:03:26 +08:00
|
|
|
|
2017-07-02 14:40:41 +08:00
|
|
|
target_sources("Zydis"
|
2018-01-20 06:35:34 +08:00
|
|
|
PRIVATE
|
2017-07-06 06:34:36 +08:00
|
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/CommonTypes.h"
|
2017-07-02 14:40:41 +08:00
|
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Defines.h"
|
2017-09-05 23:35:23 +08:00
|
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/MetaInfo.h"
|
2017-07-02 14:40:41 +08:00
|
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Mnemonic.h"
|
|
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Register.h"
|
2017-07-06 06:34:36 +08:00
|
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/SharedTypes.h"
|
2017-12-02 13:36:12 +08:00
|
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Status.h"
|
|
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/String.h"
|
2017-07-02 14:40:41 +08:00
|
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Utils.h"
|
|
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Zydis.h"
|
2017-12-02 13:54:47 +08:00
|
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Internal/LibC.h"
|
2017-12-03 02:26:26 +08:00
|
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Internal/SharedData.h"
|
2017-09-05 23:35:23 +08:00
|
|
|
"src/MetaInfo.c"
|
2017-07-02 14:40:41 +08:00
|
|
|
"src/Mnemonic.c"
|
|
|
|
"src/Register.c"
|
2017-07-06 06:34:36 +08:00
|
|
|
"src/SharedData.c"
|
2017-12-02 13:36:12 +08:00
|
|
|
"src/String.c"
|
2017-07-02 14:40:41 +08:00
|
|
|
"src/Utils.c"
|
|
|
|
"src/Zydis.c")
|
|
|
|
|
2017-07-06 15:52:14 +08:00
|
|
|
if (ZYDIS_FEATURE_DECODER)
|
2018-03-01 03:06:43 +08:00
|
|
|
target_sources("Zydis"
|
|
|
|
PRIVATE
|
2017-07-06 15:52:14 +08:00
|
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Decoder.h"
|
|
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/DecoderTypes.h"
|
2018-03-01 03:06:43 +08:00
|
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Internal/DecoderData.h"
|
2017-07-06 15:52:14 +08:00
|
|
|
"src/Decoder.c"
|
2018-03-01 04:16:32 +08:00
|
|
|
"src/DecoderData.c")
|
|
|
|
if (ZYDIS_FEATURE_FORMATTER)
|
|
|
|
target_sources("Zydis"
|
|
|
|
PRIVATE
|
|
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Formatter.h"
|
|
|
|
"src/Formatter.c")
|
|
|
|
endif ()
|
2017-07-02 14:40:41 +08:00
|
|
|
endif ()
|
|
|
|
|
2017-07-06 15:52:14 +08:00
|
|
|
if (BUILD_SHARED_LIBS AND WIN32)
|
|
|
|
target_sources("Zydis" PRIVATE "src/VersionInfo.rc")
|
|
|
|
endif ()
|
|
|
|
|
2017-07-03 09:21:24 +08:00
|
|
|
# TODO: Install CMake config.
|
|
|
|
install(TARGETS "Zydis"
|
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
2018-02-07 02:47:50 +08:00
|
|
|
install(FILES
|
|
|
|
"${PROJECT_BINARY_DIR}/ZydisExportConfig.h"
|
|
|
|
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
|
2018-02-07 02:10:19 +08:00
|
|
|
install(DIRECTORY "include/" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
2017-07-03 09:21:24 +08:00
|
|
|
|
2017-07-02 14:40:41 +08:00
|
|
|
# =============================================================================================== #
|
|
|
|
# Examples #
|
|
|
|
# =============================================================================================== #
|
|
|
|
|
2017-01-10 13:01:04 +08:00
|
|
|
if (ZYDIS_BUILD_EXAMPLES)
|
2018-03-01 04:16:32 +08:00
|
|
|
if (ZYDIS_FEATURE_DECODER AND ZYDIS_FEATURE_FORMATTER)
|
2017-12-02 13:36:12 +08:00
|
|
|
add_executable("FormatterHooks" "examples/FormatterHooks.c")
|
2017-09-15 06:42:05 +08:00
|
|
|
target_link_libraries("FormatterHooks" "Zydis")
|
|
|
|
set_target_properties("FormatterHooks" PROPERTIES FOLDER "Examples/Formatter")
|
|
|
|
target_compile_definitions("FormatterHooks" PRIVATE "_CRT_SECURE_NO_WARNINGS")
|
2017-07-25 03:59:54 +08:00
|
|
|
|
|
|
|
add_executable("ZydisFuzzIn" "examples/ZydisFuzzIn.c")
|
|
|
|
target_link_libraries("ZydisFuzzIn" "Zydis")
|
|
|
|
set_target_properties("FormatterHooks" PROPERTIES FOLDER "Examples")
|
|
|
|
target_compile_definitions("ZydisFuzzIn" PRIVATE "_CRT_SECURE_NO_WARNINGS")
|
2018-03-01 03:06:43 +08:00
|
|
|
if (ZYDIS_WHOLE_PROGRAM_OPTIMIZATION AND MSVC)
|
2018-02-28 06:56:43 +08:00
|
|
|
set_target_properties("ZydisFuzzIn" PROPERTIES COMPILE_FLAGS "/GL")
|
|
|
|
set_target_properties("ZydisFuzzIn" PROPERTIES LINK_FLAGS_RELEASE "/LTCG")
|
|
|
|
endif ()
|
2018-03-01 03:06:43 +08:00
|
|
|
if (ZYDIS_FUZZ_AFL_FAST)
|
|
|
|
target_compile_definitions("ZydisFuzzIn" PRIVATE "ZYDIS_FUZZ_AFL_FAST")
|
|
|
|
endif ()
|
2017-07-25 03:59:54 +08:00
|
|
|
|
2017-09-15 06:42:05 +08:00
|
|
|
add_executable("ZydisPerfTest" "examples/ZydisPerfTest.c")
|
|
|
|
target_link_libraries("ZydisPerfTest" "Zydis")
|
|
|
|
set_target_properties("FormatterHooks" PROPERTIES FOLDER "Examples")
|
|
|
|
target_compile_definitions("ZydisPerfTest" PRIVATE "_CRT_SECURE_NO_WARNINGS")
|
2018-03-01 03:06:43 +08:00
|
|
|
if (ZYDIS_WHOLE_PROGRAM_OPTIMIZATION AND MSVC)
|
2018-02-28 06:56:43 +08:00
|
|
|
set_target_properties("ZydisPerfTest" PROPERTIES COMPILE_FLAGS "/GL")
|
|
|
|
set_target_properties("ZydisPerfTest" PROPERTIES LINK_FLAGS_RELEASE "/LTCG")
|
|
|
|
endif ()
|
2017-09-15 06:42:05 +08:00
|
|
|
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
|
|
|
target_compile_definitions("ZydisPerfTest" PRIVATE "_GNU_SOURCE")
|
|
|
|
find_package(Threads REQUIRED)
|
|
|
|
target_link_libraries("ZydisPerfTest" Threads::Threads)
|
2017-07-25 03:59:54 +08:00
|
|
|
endif ()
|
2017-09-15 06:42:05 +08:00
|
|
|
endif ()
|
2014-11-18 03:54:30 +08:00
|
|
|
endif ()
|
|
|
|
|
2017-07-02 14:40:41 +08:00
|
|
|
# =============================================================================================== #
|
|
|
|
# Tools #
|
|
|
|
# =============================================================================================== #
|
|
|
|
|
2017-01-10 13:01:04 +08:00
|
|
|
if (ZYDIS_BUILD_TOOLS)
|
2018-03-01 04:16:32 +08:00
|
|
|
if (ZYDIS_FEATURE_DECODER AND ZYDIS_FEATURE_FORMATTER)
|
2017-09-15 06:42:05 +08:00
|
|
|
add_executable("ZydisDisasm" "tools/ZydisDisasm.c")
|
|
|
|
target_link_libraries("ZydisDisasm" "Zydis")
|
|
|
|
set_target_properties ("ZydisDisasm" PROPERTIES FOLDER "Tools")
|
|
|
|
target_compile_definitions("ZydisDisasm" PRIVATE "_CRT_SECURE_NO_WARNINGS")
|
2018-03-01 03:06:43 +08:00
|
|
|
if (ZYDIS_WHOLE_PROGRAM_OPTIMIZATION AND MSVC)
|
2018-02-28 06:56:43 +08:00
|
|
|
set_target_properties("ZydisDisasm" PROPERTIES COMPILE_FLAGS "/GL")
|
|
|
|
set_target_properties("ZydisDisasm" PROPERTIES LINK_FLAGS_RELEASE "/LTCG")
|
|
|
|
endif ()
|
2017-07-06 15:52:14 +08:00
|
|
|
|
2017-07-13 01:54:42 +08:00
|
|
|
add_executable("ZydisInfo" "tools/ZydisInfo.c")
|
|
|
|
target_link_libraries("ZydisInfo" "Zydis")
|
|
|
|
set_target_properties ("ZydisInfo" PROPERTIES FOLDER "Tools")
|
|
|
|
target_compile_definitions("ZydisInfo" PRIVATE "_CRT_SECURE_NO_WARNINGS")
|
2018-03-01 03:06:43 +08:00
|
|
|
if (ZYDIS_WHOLE_PROGRAM_OPTIMIZATION AND MSVC)
|
2018-02-28 06:56:43 +08:00
|
|
|
set_target_properties("ZydisInfo" PROPERTIES COMPILE_FLAGS "/GL")
|
|
|
|
set_target_properties("ZydisInfo" PROPERTIES LINK_FLAGS_RELEASE "/LTCG")
|
|
|
|
endif ()
|
2017-09-15 06:42:05 +08:00
|
|
|
endif ()
|
2016-05-26 03:25:48 +08:00
|
|
|
endif ()
|