zydis/CMakeLists.txt

100 lines
3.2 KiB
CMake
Raw Normal View History

cmake_minimum_required(VERSION 2.8.12)
include(GenerateExportHeader)
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)
option(BUILD_SHARED_LIBS "Build shared libraries rather than static ones" FALSE)
option(FORCE_SHARED_CRT
"Forces shared linkage against the CRT even when building a static library"
FALSE)
option(BUILD_EXAMPLES "Build examples" TRUE)
2016-05-26 03:25:48 +08:00
option(BUILD_TOOLS "Build tools")
if (NOT CONFIGURED_ONCE)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
2016-05-26 03:25:48 +08:00
set(compiler_specific "-std=c99 -pedantic -Wextra -Werror")
elseif (MSVC)
2016-05-26 03:25:48 +08:00
set(compiler_specific "/WX /W4 /D_CRT_SECURE_NO_WARNINGS /TC")
endif ()
2015-02-06 10:16:39 +08:00
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${compiler_specific} ${compiler_specific_cxx}"
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 ()
# 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 FORCE_SHARED_CRT)
2016-05-26 03:25:48 +08:00
foreach(flag_var
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
if(${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif(${flag_var} MATCHES "/MD")
endforeach(flag_var)
endif ()
# Library
2015-05-16 11:25:11 +08:00
set(headers
2016-05-26 03:25:48 +08:00
"include/Zydis/Decoder.h"
"include/Zydis/Defines.h"
"include/Zydis/Formatter.h"
"include/Zydis/Input.h"
"include/Zydis/InstructionInfo.h"
"include/Zydis/Mnemonic.h"
"include/Zydis/Register.h"
"include/Zydis/Status.h"
"include/Zydis/SymbolResolver.h"
"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"
"src/Formatter.c"
"src/Input.c"
"src/InstructionTable.c"
"src/Mnemonic.c"
"src/Register.c"
"src/Utils.c"
"src/Zydis.c")
2015-05-22 03:42:06 +08:00
if (BUILD_SHARED_LIBS AND WIN32)
2016-05-26 03:25:48 +08:00
set(sources ${sources} "src/VersionInfo.rc")
endif ()
2015-05-16 11:25:11 +08:00
add_library("Zydis" ${headers} ${sources})
set_target_properties("Zydis" PROPERTIES COMPILE_DEFINITIONS "Zydis_EXPORTS")
generate_export_header(
2015-05-16 11:25:11 +08:00
"Zydis"
BASE_NAME "ZYDIS"
2015-05-16 11:25:11 +08:00
EXPORT_FILE_NAME "ZydisExportConfig.h")
include_directories(${PROJECT_BINARY_DIR})
2015-02-06 09:28:51 +08:00
# Examples
if (BUILD_EXAMPLES)
2016-05-26 03:25:48 +08:00
include_directories("include")
add_executable("ZydisTest" "examples/ZydisTest.c")
target_link_libraries("ZydisTest" "Zydis")
set_target_properties ("ZydisTest" PROPERTIES
FOLDER "Examples"
)
add_executable("ZydisPE" "examples/ZydisPE.c")
target_link_libraries("ZydisPE" "Zydis")
set_target_properties ("ZydisPE" PROPERTIES
FOLDER "Examples"
)
endif ()
2016-05-26 03:25:48 +08:00
# Tools
if (BUILD_TOOLS)
include_directories("include")
add_executable("ZydisDisasm" "tools/ZydisDisasm.c")
target_link_libraries("ZydisDisasm" "Zydis")
set_target_properties ("ZydisDisasm" PROPERTIES
FOLDER "Tools"
)
endif ()