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)
|
2014-11-18 03:54:30 +08:00
|
|
|
|
2015-03-17 00:58:07 +08:00
|
|
|
option(BUILD_SHARED_LIBS "Build shared libraries rather than static ones" FALSE)
|
2015-03-17 01:30:14 +08:00
|
|
|
option(FORCE_SHARED_CRT
|
|
|
|
"Forces shared linkage against the CRT even when building a static library"
|
|
|
|
FALSE)
|
2014-11-18 03:54:30 +08:00
|
|
|
option(BUILD_EXAMPLES "Build examples" TRUE)
|
2015-05-16 11:25:11 +08:00
|
|
|
option(BUILD_C_BINDINGS "Build C bindings" TRUE)
|
2014-11-18 03:54:30 +08:00
|
|
|
|
|
|
|
if (NOT CONFIGURED_ONCE)
|
|
|
|
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR
|
|
|
|
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
2015-02-06 10:16:39 +08:00
|
|
|
set(compiler_specific "-Werror")
|
2015-05-20 06:44:28 +08:00
|
|
|
set(compiler_specific_cxx "-std=c++14")
|
2015-03-17 01:30:14 +08:00
|
|
|
elseif (MSVC)
|
2015-03-20 00:13:37 +08:00
|
|
|
set(compiler_specific "/WX /W4 /D_CRT_SECURE_NO_WARNINGS")
|
2014-11-18 03:54:30 +08:00
|
|
|
endif ()
|
|
|
|
|
2015-02-06 10:16:39 +08:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${compiler_specific} ${compiler_specific_cxx}"
|
2014-11-18 03:54:30 +08:00
|
|
|
CACHE STRING "Flags used by the compiler during all build types." FORCE)
|
|
|
|
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
|
|
|
|
# to generate with a statically linked CRT when we build as a static library.
|
|
|
|
if (MSVC AND NOT BUILD_SHARED_LIBS AND NOT FORCE_SHARED_CRT)
|
|
|
|
set(manipulated_vars
|
|
|
|
CMAKE_CXX_FLAGS_DEBUG
|
|
|
|
CMAKE_CXX_FLAGS_MINSIZEREL
|
|
|
|
CMAKE_CXX_FLAGS_RELEASE
|
|
|
|
CMAKE_CXX_FLAGS_RELWITHDEBINFO
|
|
|
|
CMAKE_C_FLAGS_DEBUG
|
|
|
|
CMAKE_C_FLAGS_MINSIZEREL
|
|
|
|
CMAKE_C_FLAGS_RELEASE
|
|
|
|
CMAKE_C_FLAGS_RELWITHDEBINFO)
|
|
|
|
foreach (cur_var ${manipulated_vars})
|
|
|
|
string(REPLACE "/MD" "/MT" ${cur_var} "${${cur_var}}")
|
|
|
|
endforeach ()
|
|
|
|
endif ()
|
|
|
|
|
2014-11-18 03:54:30 +08:00
|
|
|
# Library
|
2015-05-16 11:25:11 +08:00
|
|
|
set(headers
|
2015-05-20 03:45:53 +08:00
|
|
|
"Zydis/Zydis.hpp"
|
|
|
|
"Zydis/ZydisInstructionDecoder.hpp"
|
2015-05-18 08:26:18 +08:00
|
|
|
"Zydis/ZydisInstructionFormatter.hpp"
|
2015-05-20 03:45:53 +08:00
|
|
|
"Zydis/ZydisOpcodeTable.hpp"
|
2015-05-18 08:26:18 +08:00
|
|
|
"Zydis/ZydisSymbolResolver.hpp"
|
|
|
|
"Zydis/ZydisTypes.hpp"
|
|
|
|
"Zydis/ZydisUtils.hpp")
|
2015-05-16 11:25:11 +08:00
|
|
|
set(sources
|
2015-05-18 08:26:18 +08:00
|
|
|
"Zydis/ZydisInstructionDecoder.cpp"
|
|
|
|
"Zydis/ZydisInstructionFormatter.cpp"
|
|
|
|
"Zydis/ZydisOpcodeTable.cpp"
|
|
|
|
"Zydis/ZydisSymbolResolver.cpp"
|
|
|
|
"Zydis/ZydisUtils.cpp")
|
2015-05-20 03:45:53 +08:00
|
|
|
|
2015-05-18 08:26:18 +08:00
|
|
|
if (BUILD_C_BINDINGS)
|
2015-05-20 03:45:53 +08:00
|
|
|
set(headers ${headers}
|
|
|
|
"Zydis/ZydisAPI.h")
|
|
|
|
set(sources ${sources}
|
|
|
|
"Zydis/ZydisAPI.cpp")
|
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})
|
2015-03-17 00:58:07 +08:00
|
|
|
generate_export_header(
|
2015-05-16 11:25:11 +08:00
|
|
|
"Zydis"
|
2015-05-18 08:26:18 +08:00
|
|
|
BASE_NAME "ZYDIS"
|
2015-05-16 11:25:11 +08:00
|
|
|
EXPORT_FILE_NAME "ZydisExportConfig.h")
|
2015-03-17 00:58:07 +08:00
|
|
|
include_directories(${PROJECT_BINARY_DIR})
|
2015-02-06 09:28:51 +08:00
|
|
|
|
2014-11-18 03:54:30 +08:00
|
|
|
# Examples
|
|
|
|
if (BUILD_EXAMPLES)
|
2015-05-18 08:26:18 +08:00
|
|
|
include_directories("Zydis")
|
2014-11-18 03:54:30 +08:00
|
|
|
|
2015-05-20 03:45:53 +08:00
|
|
|
add_executable("SimpleDemo_CPP" "Examples/CPP/SimpleDemo/SimpleDemo.cpp")
|
|
|
|
target_link_libraries("SimpleDemo_CPP" "Zydis")
|
|
|
|
|
|
|
|
if (BUILD_C_BINDINGS)
|
|
|
|
add_executable("SimpleDemo_C" "Examples/C/SimpleDemo/SimpleDemo.c")
|
|
|
|
target_link_libraries("SimpleDemo_C" "Zydis")
|
|
|
|
endif ()
|
2014-11-18 03:54:30 +08:00
|
|
|
endif ()
|
|
|
|
|
2015-02-06 10:16:39 +08:00
|
|
|
set(CONFIGURED_ONCE TRUE CACHE INTERNAL "CMake has configured at least once.")
|