2014-11-18 03:54:30 +08:00
|
|
|
cmake_minimum_required(VERSION 2.8.12)
|
2015-03-17 00:58:07 +08:00
|
|
|
include(GenerateExportHeader)
|
2014-11-18 03:54:30 +08:00
|
|
|
|
2015-05-16 11:25:11 +08:00
|
|
|
project(Zydis)
|
2016-05-26 03:25:48 +08:00
|
|
|
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
2014-11-18 03:54:30 +08:00
|
|
|
|
2017-01-10 13:01:04 +08:00
|
|
|
option(ZYDIS_BUILD_SHARED_LIBS
|
2016-08-23 21:57:38 +08:00
|
|
|
"Build shared libraries rather than static ones"
|
2017-04-09 01:36:16 +08:00
|
|
|
OFF)
|
2017-01-10 13:01:04 +08:00
|
|
|
option(ZYDIS_FORCE_SHARED_CRT
|
2017-04-09 01:36:16 +08:00
|
|
|
"Forces shared linkage against the CRT even when building a static library. MSVC only."
|
|
|
|
OFF)
|
2017-01-10 13:01:04 +08:00
|
|
|
option(ZYDIS_FEATURE_IMPLICITLY_USED_REGISTERS
|
2016-08-23 21:57:38 +08:00
|
|
|
"Include information about implicitly used registers"
|
2017-04-09 01:36:16 +08:00
|
|
|
OFF)
|
2017-01-10 13:01:04 +08:00
|
|
|
option(ZYDIS_FEATURE_AFFECTED_FLAGS
|
2016-08-23 21:57:38 +08:00
|
|
|
"Include information about affected flags"
|
2017-04-09 01:36:16 +08:00
|
|
|
OFF)
|
2017-01-10 13:01:04 +08:00
|
|
|
option(ZYDIS_FEATURE_CPUID
|
2016-08-23 21:57:38 +08:00
|
|
|
"Include information about CPUID feature-flags"
|
2017-04-09 01:36:16 +08:00
|
|
|
OFF)
|
|
|
|
option(ZYDIS_BUILD_EXAMPLES "Build examples" ON)
|
|
|
|
option(ZYDIS_BUILD_TOOLS "Build tools" ON)
|
2014-11-18 03:54:30 +08:00
|
|
|
|
|
|
|
if (NOT CONFIGURED_ONCE)
|
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")
|
2016-05-26 03:25:48 +08:00
|
|
|
set(compiler_specific "-std=c99 -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 ()
|
|
|
|
|
2015-03-17 01:30:14 +08:00
|
|
|
# CMake always orders MSVC to build with a shared CRT. Hack CMake variables in order
|
2017-01-06 09:06:08 +08:00
|
|
|
# to generate with a statically linked CRT when we build a static library.
|
2017-01-10 13:01:04 +08:00
|
|
|
if (("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC") AND NOT ZYDIS_FORCE_SHARED_CRT)
|
2016-05-26 03:25:48 +08:00
|
|
|
foreach(flag_var
|
2016-06-20 07:33:29 +08:00
|
|
|
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
|
|
|
|
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
|
2016-05-26 03:25:48 +08:00
|
|
|
if(${flag_var} MATCHES "/MD")
|
|
|
|
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
|
2016-06-20 07:33:29 +08:00
|
|
|
endif ()
|
2016-08-23 21:57:38 +08:00
|
|
|
endforeach ()
|
2015-03-17 01:30:14 +08:00
|
|
|
endif ()
|
|
|
|
|
2014-11-18 03:54:30 +08:00
|
|
|
# Library
|
2015-05-16 11:25:11 +08:00
|
|
|
set(headers
|
2016-05-26 03:25:48 +08:00
|
|
|
"include/Zydis/Decoder.h"
|
2017-04-09 01:36:16 +08:00
|
|
|
#"include/Zydis/Encoder.h"
|
2016-05-26 03:25:48 +08:00
|
|
|
"include/Zydis/Defines.h"
|
|
|
|
"include/Zydis/Formatter.h"
|
|
|
|
"include/Zydis/InstructionInfo.h"
|
|
|
|
"include/Zydis/Mnemonic.h"
|
|
|
|
"include/Zydis/Register.h"
|
|
|
|
"include/Zydis/Status.h"
|
2016-12-05 09:24:01 +08:00
|
|
|
"include/Zydis/Types.h"
|
2016-05-26 03:25:48 +08:00
|
|
|
"include/Zydis/Utils.h"
|
|
|
|
"include/Zydis/Zydis.h"
|
|
|
|
"include/Zydis/Internal/InstructionTable.h")
|
2015-05-16 11:25:11 +08:00
|
|
|
set(sources
|
2016-05-26 03:25:48 +08:00
|
|
|
"src/Decoder.c"
|
2017-04-09 01:36:16 +08:00
|
|
|
#"src/Encoder.c"
|
2016-05-26 03:25:48 +08:00
|
|
|
"src/Formatter.c"
|
|
|
|
"src/InstructionTable.c"
|
|
|
|
"src/Mnemonic.c"
|
|
|
|
"src/Register.c"
|
|
|
|
"src/Utils.c"
|
|
|
|
"src/Zydis.c")
|
2015-05-20 03:45:53 +08:00
|
|
|
|
2017-01-10 13:01:04 +08:00
|
|
|
if (ZYDIS_BUILD_SHARED_LIBS AND WIN32)
|
2016-05-26 03:25:48 +08:00
|
|
|
set(sources ${sources} "src/VersionInfo.rc")
|
2015-05-18 08:26:18 +08:00
|
|
|
endif ()
|
2014-11-18 03:54:30 +08:00
|
|
|
|
2015-05-16 11:25:11 +08:00
|
|
|
add_library("Zydis" ${headers} ${sources})
|
2017-01-06 09:06:08 +08:00
|
|
|
target_include_directories("Zydis" PUBLIC "include/" ${PROJECT_BINARY_DIR})
|
2017-01-10 13:01:04 +08:00
|
|
|
target_compile_definitions("Zydis" PRIVATE "_CRT_SECURE_NO_WARNINGS" "ZYDIS_EXPORTS")
|
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-01-10 13:01:04 +08:00
|
|
|
if (ZYDIS_FEATURE_IMPLICITLY_USED_REGISTERS)
|
|
|
|
target_compile_definitions("Zydis" PRIVATE "ZYDIS_ENABLE_FEATURE_IMPLICITLY_USED_REGISTERS")
|
2016-11-12 05:03:26 +08:00
|
|
|
endif ()
|
2017-01-10 13:01:04 +08:00
|
|
|
if (ZYDIS_FEATURE_AFFECTED_FLAGS)
|
|
|
|
target_compile_definitions("Zydis" PRIVATE "ZYDIS_ENABLE_FEATURE_AFFECTED_FLAGS")
|
2016-11-12 05:03:26 +08:00
|
|
|
endif ()
|
2017-01-10 13:01:04 +08:00
|
|
|
if (ZYDIS_FEATURE_CPUID)
|
2017-01-11 18:51:18 +08:00
|
|
|
target_compile_definitions("Zydis" PRIVATE "ZYDIS_ENABLE_FEATURE_CPUID")
|
2016-11-12 05:03:26 +08:00
|
|
|
endif ()
|
|
|
|
|
2014-11-18 03:54:30 +08:00
|
|
|
# Examples
|
2017-01-10 13:01:04 +08:00
|
|
|
if (ZYDIS_BUILD_EXAMPLES)
|
2016-11-26 20:08:37 +08:00
|
|
|
add_executable("FormatterHooks"
|
|
|
|
"examples/FormatterHooks.c"
|
|
|
|
"examples/FormatHelper.h")
|
|
|
|
target_link_libraries("FormatterHooks" "Zydis")
|
|
|
|
set_target_properties ("FormatterHooks" PROPERTIES FOLDER "Examples/Formatter")
|
2017-01-11 19:18:26 +08:00
|
|
|
target_compile_definitions("FormatterHooks" PRIVATE "_CRT_SECURE_NO_WARNINGS")
|
2014-11-18 03:54:30 +08:00
|
|
|
endif ()
|
|
|
|
|
2016-05-26 03:25:48 +08:00
|
|
|
# Tools
|
2017-01-10 13:01:04 +08:00
|
|
|
if (ZYDIS_BUILD_TOOLS)
|
2016-05-26 03:25:48 +08:00
|
|
|
add_executable("ZydisDisasm" "tools/ZydisDisasm.c")
|
|
|
|
target_link_libraries("ZydisDisasm" "Zydis")
|
2016-08-29 05:12:40 +08:00
|
|
|
set_target_properties ("ZydisDisasm" PROPERTIES FOLDER "Tools")
|
2017-01-11 19:18:26 +08:00
|
|
|
target_compile_definitions("ZydisDisasm" PRIVATE "_CRT_SECURE_NO_WARNINGS")
|
2016-08-29 05:12:40 +08:00
|
|
|
|
|
|
|
add_executable("ZydisFuzzIn" "tools/ZydisFuzzIn.c")
|
|
|
|
target_link_libraries("ZydisFuzzIn" "Zydis")
|
|
|
|
set_target_properties("ZydisFuzzIn" PROPERTIES FOLDER "Tools")
|
2017-01-11 19:18:26 +08:00
|
|
|
target_compile_definitions("ZydisFuzzIn" PRIVATE "_CRT_SECURE_NO_WARNINGS")
|
2016-05-26 03:25:48 +08:00
|
|
|
endif ()
|