2020-11-17 09:31:14 +00:00
|
|
|
cmake_minimum_required(VERSION 3.12)
|
2020-11-17 09:04:30 +00:00
|
|
|
|
2021-03-30 09:20:31 +00:00
|
|
|
set(BDD_VER_FILE ${CMAKE_CURRENT_LIST_DIR}/inc/version.h)
|
2020-11-17 10:44:10 +00:00
|
|
|
|
2021-03-30 09:20:31 +00:00
|
|
|
file(STRINGS ${BDD_VER_FILE} disasm_ver_major REGEX "DISASM_VERSION_MAJOR")
|
|
|
|
file(STRINGS ${BDD_VER_FILE} disasm_ver_minor REGEX "DISASM_VERSION_MINOR")
|
|
|
|
file(STRINGS ${BDD_VER_FILE} disasm_ver_patch REGEX "DISASM_VERSION_REVISION")
|
2020-11-17 10:44:10 +00:00
|
|
|
|
|
|
|
string(REGEX REPLACE "#define DISASM_VERSION_MAJOR[ \t\r\n]*" "" disasm_ver_major ${disasm_ver_major})
|
|
|
|
string(REGEX REPLACE "#define DISASM_VERSION_MINOR[ \t\r\n]*" "" disasm_ver_minor ${disasm_ver_minor})
|
|
|
|
string(REGEX REPLACE "#define DISASM_VERSION_REVISION[ \t\r\n]*" "" disasm_ver_patch ${disasm_ver_patch})
|
|
|
|
|
2021-03-30 09:20:31 +00:00
|
|
|
message(STATUS "Extracted version from ${BDD_VER_FILE}: ${disasm_ver_major}.${disasm_ver_minor}.${disasm_ver_patch}")
|
2020-11-17 10:44:10 +00:00
|
|
|
|
2021-03-30 09:20:47 +00:00
|
|
|
project(
|
|
|
|
bddisasm
|
2020-11-17 10:44:10 +00:00
|
|
|
VERSION ${disasm_ver_major}.${disasm_ver_minor}.${disasm_ver_patch}
|
2021-03-30 09:20:31 +00:00
|
|
|
DESCRIPTION "Bitdefender x86 instruction decoder and emulator"
|
2020-11-17 09:04:30 +00:00
|
|
|
LANGUAGES C
|
2021-03-30 09:20:47 +00:00
|
|
|
HOMEPAGE_URL https://github.com/bitdefender/bddisasm)
|
2020-11-17 09:04:30 +00:00
|
|
|
|
2021-03-30 09:20:31 +00:00
|
|
|
# Use Release as the build type if no build type was specified and we're not using a multi-config generator .
|
2021-03-30 09:36:35 +00:00
|
|
|
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
2020-11-17 09:41:19 +00:00
|
|
|
message(STATUS "No build type given. Will use 'Release'")
|
2021-03-30 09:20:47 +00:00
|
|
|
set(CMAKE_BUILD_TYPE
|
|
|
|
"Release"
|
|
|
|
CACHE STRING "Choose the type of build." FORCE)
|
2021-03-30 09:20:31 +00:00
|
|
|
# Set the possible values of build type for cmake-gui.
|
|
|
|
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release")
|
2021-03-30 09:36:35 +00:00
|
|
|
endif ()
|
2021-03-30 09:20:31 +00:00
|
|
|
|
|
|
|
# These are shared by bddisasm and bdshemu.
|
2021-03-30 09:36:35 +00:00
|
|
|
if (NOT MSVC)
|
2021-03-30 09:20:31 +00:00
|
|
|
set(BDDISASM_COMMON_COMPILE_OPTIONS
|
|
|
|
"$<$<CONFIG:Release>:-U_FORTIFY_SOURCE>"
|
|
|
|
"$<$<CONFIG:Release>:-D_FORTIFY_SOURCE=2>"
|
|
|
|
-Wall
|
|
|
|
-Wno-unknown-pragmas
|
|
|
|
-Wextra
|
|
|
|
-Wshadow
|
|
|
|
-Wformat-security
|
|
|
|
-Wstrict-overflow=2
|
|
|
|
-Wstrict-prototypes
|
|
|
|
-Wwrite-strings
|
|
|
|
-Wshadow
|
|
|
|
-Winit-self
|
|
|
|
-Wno-unused-function
|
|
|
|
-Wno-multichar
|
|
|
|
-Wno-incompatible-pointer-types
|
|
|
|
-Wno-discarded-qualifiers
|
|
|
|
-Wnull-dereference
|
|
|
|
-Wduplicated-cond
|
|
|
|
-Werror=format-security
|
|
|
|
-Werror=implicit-function-declaration
|
|
|
|
-pipe
|
|
|
|
-fwrapv
|
|
|
|
-fno-strict-aliasing
|
|
|
|
-fstack-protector-strong
|
|
|
|
-fno-omit-frame-pointer
|
|
|
|
-ffunction-sections
|
|
|
|
-fdata-sections
|
|
|
|
-g3
|
|
|
|
-gdwarf-4
|
|
|
|
-grecord-gcc-switches
|
2021-03-30 09:20:47 +00:00
|
|
|
-march=westmere)
|
2021-03-30 09:36:35 +00:00
|
|
|
else ()
|
2021-03-30 09:20:31 +00:00
|
|
|
set(BDDISASM_COMMON_COMPILE_OPTIONS /W4 /WX)
|
2021-03-30 09:36:35 +00:00
|
|
|
endif ()
|
2020-11-17 09:04:30 +00:00
|
|
|
|
2021-03-30 09:20:31 +00:00
|
|
|
set(BDDISASM_PUBLIC_HEADERS
|
|
|
|
"inc/bddisasm.h"
|
|
|
|
"inc/constants.h"
|
|
|
|
"inc/cpuidflags.h"
|
|
|
|
"inc/disasmstatus.h"
|
|
|
|
"inc/disasmtypes.h"
|
|
|
|
"inc/registers.h"
|
2021-03-30 09:20:47 +00:00
|
|
|
"inc/version.h")
|
2020-11-17 09:19:31 +00:00
|
|
|
|
2021-03-30 09:20:31 +00:00
|
|
|
include(GNUInstallDirs)
|
|
|
|
|
2021-03-30 09:20:47 +00:00
|
|
|
set(BDDISASM_INSTALL_INCLUDE_DIR
|
|
|
|
"${CMAKE_INSTALL_INCLUDEDIR}/bddisasm"
|
|
|
|
CACHE STRING "Path to bddisasm public include files.")
|
2021-03-30 09:20:31 +00:00
|
|
|
|
|
|
|
# -- bddisasm --
|
|
|
|
|
2021-03-30 09:20:47 +00:00
|
|
|
add_library(
|
|
|
|
bddisasm STATIC
|
2020-11-17 09:04:30 +00:00
|
|
|
bddisasm/crt.c
|
|
|
|
bddisasm/bddisasm.c
|
2021-03-30 09:20:31 +00:00
|
|
|
# Add the headers so they will show up in IDEs.
|
|
|
|
bddisasm/include/instructions.h
|
|
|
|
bddisasm/include/mnemonics.h
|
|
|
|
bddisasm/include/nd_crt.h
|
|
|
|
bddisasm/include/prefixes.h
|
|
|
|
bddisasm/include/table_evex.h
|
|
|
|
bddisasm/include/table_root.h
|
|
|
|
bddisasm/include/table_vex.h
|
|
|
|
bddisasm/include/table_xop.h
|
|
|
|
bddisasm/include/tabledefs.h
|
2021-03-30 09:20:47 +00:00
|
|
|
"${BDDISASM_PUBLIC_HEADERS}")
|
2021-03-30 09:20:31 +00:00
|
|
|
|
2021-03-30 09:20:47 +00:00
|
|
|
set_target_properties(
|
|
|
|
bddisasm
|
|
|
|
PROPERTIES POSITION_INDEPENDENT_CODE ON
|
|
|
|
C_STANDARD 11
|
|
|
|
VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
|
2021-03-30 09:20:31 +00:00
|
|
|
|
|
|
|
target_include_directories(bddisasm PRIVATE bddisasm/include)
|
2021-03-30 09:20:47 +00:00
|
|
|
target_include_directories(bddisasm PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/inc>
|
|
|
|
$<INSTALL_INTERFACE:${BDDISASM_INSTALL_INCLUDE_DIR}>)
|
2020-11-17 09:04:30 +00:00
|
|
|
|
2021-03-30 09:20:31 +00:00
|
|
|
target_compile_options(bddisasm PRIVATE ${BDDISASM_COMMON_COMPILE_OPTIONS})
|
|
|
|
|
2021-03-30 09:20:47 +00:00
|
|
|
set_target_properties(
|
|
|
|
bddisasm
|
|
|
|
PROPERTIES PUBLIC_HEADER "${BDDISASM_PUBLIC_HEADERS}"
|
|
|
|
VERSION ${CMAKE_PROJECT_VERSION}
|
|
|
|
SOVERSION ${CMAKE_PROJECT_VERSION_MAJOR})
|
2021-03-30 09:20:31 +00:00
|
|
|
|
|
|
|
add_library(bddisasm::bddisasm ALIAS bddisasm)
|
|
|
|
|
|
|
|
# -- bdshemu --
|
|
|
|
|
2021-03-30 09:20:47 +00:00
|
|
|
add_library(
|
|
|
|
bdshemu STATIC
|
2020-11-17 09:04:30 +00:00
|
|
|
bdshemu/bdshemu.c
|
2021-03-30 09:20:31 +00:00
|
|
|
# Add the headers so they will show up in IDEs.
|
2021-03-30 09:20:47 +00:00
|
|
|
inc/bdshemu.h)
|
2021-03-30 09:20:31 +00:00
|
|
|
|
2021-03-30 09:20:47 +00:00
|
|
|
set_target_properties(
|
|
|
|
bdshemu
|
|
|
|
PROPERTIES POSITION_INDEPENDENT_CODE ON
|
|
|
|
C_STANDARD 11
|
|
|
|
VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
|
2020-11-17 09:04:30 +00:00
|
|
|
|
2021-03-30 09:20:31 +00:00
|
|
|
target_include_directories(bdshemu PRIVATE bddisasm/include)
|
2021-03-30 09:20:47 +00:00
|
|
|
target_include_directories(bddisasm PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/inc>
|
|
|
|
$<INSTALL_INTERFACE:${BDDISASM_INSTALL_INCLUDE_DIR}>)
|
2020-11-20 12:43:12 +00:00
|
|
|
|
2021-03-30 09:20:31 +00:00
|
|
|
target_link_libraries(bdshemu PUBLIC bddisasm)
|
2020-11-17 09:04:30 +00:00
|
|
|
|
2021-03-30 09:20:31 +00:00
|
|
|
target_compile_options(bdshemu PRIVATE ${BDDISASM_COMMON_COMPILE_OPTIONS})
|
2021-03-30 09:36:35 +00:00
|
|
|
if (NOT MSVC)
|
2021-03-30 09:20:31 +00:00
|
|
|
target_compile_options(bdshemu PRIVATE -maes)
|
2021-03-30 09:36:35 +00:00
|
|
|
endif ()
|
2020-11-17 09:04:30 +00:00
|
|
|
|
2021-03-30 09:20:47 +00:00
|
|
|
set_target_properties(
|
|
|
|
bdshemu
|
|
|
|
PROPERTIES PUBLIC_HEADER "inc/bdshemu.h"
|
|
|
|
VERSION ${CMAKE_PROJECT_VERSION}
|
|
|
|
SOVERSION ${CMAKE_PROJECT_VERSION_MAJOR})
|
2021-03-30 09:20:31 +00:00
|
|
|
|
|
|
|
add_library(bddisasm::bdshemu ALIAS bdshemu)
|
|
|
|
|
|
|
|
# If this is the master project (or if the user requested it) add disasmtool.
|
2021-03-30 09:36:35 +00:00
|
|
|
if ((${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME}) OR BDD_INCLUDE_TOOL)
|
|
|
|
if (WIN32)
|
2021-03-30 09:20:31 +00:00
|
|
|
add_subdirectory(disasmtool)
|
2021-03-30 09:36:35 +00:00
|
|
|
else ()
|
2021-03-30 09:20:31 +00:00
|
|
|
add_subdirectory(disasmtool_lix)
|
2021-03-30 09:36:35 +00:00
|
|
|
endif ()
|
|
|
|
endif ()
|
2020-11-17 09:04:30 +00:00
|
|
|
|
2021-03-30 09:33:07 +00:00
|
|
|
# If this is the master project (or if the user requested it) add isagenerator.
|
2021-03-30 09:36:35 +00:00
|
|
|
if ((${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME}) OR BDD_INCLUDE_ISAGENERATOR)
|
2021-03-30 09:33:07 +00:00
|
|
|
add_subdirectory(isagenerator)
|
2021-03-30 09:36:35 +00:00
|
|
|
endif ()
|
2021-03-30 09:33:07 +00:00
|
|
|
|
2021-03-30 09:20:31 +00:00
|
|
|
# If this is the master project add install and package targets.
|
2021-03-30 09:36:35 +00:00
|
|
|
if (${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
|
2021-03-30 09:20:47 +00:00
|
|
|
set(BDDISASM_INSTALL_CMAKEDIR
|
|
|
|
"${CMAKE_INSTALL_LIBDIR}/cmake/bddisasm"
|
|
|
|
CACHE STRING "Path to bddisasm cmake files.")
|
2020-11-17 09:04:30 +00:00
|
|
|
|
2021-03-30 09:20:47 +00:00
|
|
|
set(BDDISASM_INSTALL_PCDIR
|
|
|
|
"${CMAKE_INSTALL_LIBDIR}/pkgconfig"
|
|
|
|
CACHE STRING "Path to bddisasm pkgconfig files.")
|
2020-11-17 09:04:30 +00:00
|
|
|
|
2021-03-30 09:20:31 +00:00
|
|
|
set(CMAKE_SKIP_BUILD_RPATH TRUE)
|
|
|
|
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
|
|
|
|
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
|
|
|
|
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
|
|
|
|
2021-03-30 09:20:47 +00:00
|
|
|
install(
|
|
|
|
TARGETS bddisasm bdshemu disasmtool
|
2021-03-30 09:20:31 +00:00
|
|
|
EXPORT bddisasmTargets
|
|
|
|
INCLUDES
|
2021-03-30 09:20:47 +00:00
|
|
|
DESTINATION ${BDDISASM_INSTALL_INCLUDE_DIR}
|
|
|
|
PUBLIC_HEADER DESTINATION ${BDDISASM_INSTALL_INCLUDE_DIR} COMPONENT bddisasm_Development
|
|
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT bddisasm_Runtime
|
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
COMPONENT bddisasm_Runtime
|
|
|
|
NAMELINK_COMPONENT bddisasm_Development
|
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT bddisasm_Development)
|
|
|
|
|
|
|
|
install(
|
|
|
|
EXPORT bddisasmTargets
|
2021-03-30 09:20:31 +00:00
|
|
|
DESTINATION ${BDDISASM_INSTALL_CMAKEDIR}
|
|
|
|
NAMESPACE bddisasm::
|
|
|
|
FILE bddisasmTargets.cmake
|
2021-03-30 09:20:47 +00:00
|
|
|
COMPONENT bddisasm_Development)
|
2020-11-18 12:21:08 +00:00
|
|
|
|
2021-03-30 09:20:31 +00:00
|
|
|
include(CMakePackageConfigHelpers)
|
2020-11-18 12:21:08 +00:00
|
|
|
|
2021-03-30 09:20:47 +00:00
|
|
|
write_basic_package_version_file(
|
|
|
|
"bddisasmConfigVersion.cmake"
|
2021-03-30 09:20:31 +00:00
|
|
|
VERSION ${CMAKE_PROJECT_VERSION}
|
2021-03-30 09:20:47 +00:00
|
|
|
COMPATIBILITY SameMajorVersion)
|
2020-11-18 12:21:08 +00:00
|
|
|
|
2021-03-30 09:20:47 +00:00
|
|
|
install(
|
|
|
|
FILES bddisasmConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/bddisasmConfigVersion.cmake
|
2021-03-30 09:20:31 +00:00
|
|
|
DESTINATION ${BDDISASM_INSTALL_CMAKEDIR}
|
2021-03-30 09:20:47 +00:00
|
|
|
COMPONENT bddisasm_Development)
|
2020-11-18 12:21:08 +00:00
|
|
|
|
2021-03-30 09:20:47 +00:00
|
|
|
configure_file("bddisasm.pc.in" "${CMAKE_STATIC_LIBRARY_PREFIX}bddisasm.pc" @ONLY)
|
2020-11-18 12:21:08 +00:00
|
|
|
|
2021-03-30 09:20:47 +00:00
|
|
|
install(
|
|
|
|
FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}bddisasm.pc"
|
2021-03-30 09:20:31 +00:00
|
|
|
DESTINATION "${BDDISASM_INSTALL_PCDIR}"
|
2021-03-30 09:20:47 +00:00
|
|
|
COMPONENT bddisasm_Development)
|
2020-11-18 11:55:31 +00:00
|
|
|
|
2021-03-30 09:20:31 +00:00
|
|
|
set(CPACK_PACKAGE_VENDOR "Bitdefender")
|
2020-11-18 11:55:31 +00:00
|
|
|
|
2021-03-30 09:36:35 +00:00
|
|
|
if (NOT CPACK_GENERATOR)
|
|
|
|
if (NOT WIN32)
|
2021-03-30 09:20:31 +00:00
|
|
|
set(CPACK_GENERATOR "DEB")
|
2021-03-30 09:36:35 +00:00
|
|
|
else ()
|
2021-03-30 09:20:31 +00:00
|
|
|
set(CPACK_GENERATOR "ZIP")
|
2021-03-30 09:36:35 +00:00
|
|
|
endif ()
|
|
|
|
endif ()
|
2020-11-18 11:55:31 +00:00
|
|
|
|
2021-03-30 09:20:31 +00:00
|
|
|
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Bitdefender HVI Team <hvmi-oss@bitdefender.com>")
|
|
|
|
set(CPACK_DEBIAN_PACKAGE_DEPENDS "")
|
|
|
|
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64")
|
|
|
|
set(CPACK_DEBIAN_PACKAGE_SECTION "devel")
|
2020-11-20 12:48:20 +00:00
|
|
|
|
2021-03-30 09:20:31 +00:00
|
|
|
include(CPack)
|
2021-03-30 09:36:35 +00:00
|
|
|
endif ()
|