mirror of
https://github.com/bitdefender/bddisasm.git
synced 2024-12-21 21:48:07 +00:00
cmake: Various improvements, especially to the way the bddisasm package is consumed
This should make integrating the project easier. CMake also works on Windows now.
This commit is contained in:
parent
fccf11915d
commit
3495a7cc84
2
.gitignore
vendored
2
.gitignore
vendored
@ -64,6 +64,6 @@ bdshemu_fuzz/out-32
|
|||||||
bdshemu_fuzz/out-64
|
bdshemu_fuzz/out-64
|
||||||
docs/build
|
docs/build
|
||||||
libbddisasm.pc
|
libbddisasm.pc
|
||||||
build
|
build*
|
||||||
.vscode
|
.vscode
|
||||||
disasmtool_lix/_build
|
disasmtool_lix/_build
|
||||||
|
340
CMakeLists.txt
340
CMakeLists.txt
@ -1,172 +1,250 @@
|
|||||||
cmake_minimum_required(VERSION 3.12)
|
cmake_minimum_required(VERSION 3.12)
|
||||||
|
|
||||||
include("${CMAKE_CURRENT_LIST_DIR}/project-meta-info.in")
|
include(CMakePrintHelpers)
|
||||||
|
|
||||||
set(disasm_version_file ${CMAKE_CURRENT_LIST_DIR}/inc/version.h)
|
set(BDD_VER_FILE ${CMAKE_CURRENT_LIST_DIR}/inc/version.h)
|
||||||
|
|
||||||
file(STRINGS ${disasm_version_file} disasm_ver_major REGEX "DISASM_VERSION_MAJOR")
|
file(STRINGS ${BDD_VER_FILE} disasm_ver_major REGEX "DISASM_VERSION_MAJOR")
|
||||||
file(STRINGS ${disasm_version_file} disasm_ver_minor REGEX "DISASM_VERSION_MINOR")
|
file(STRINGS ${BDD_VER_FILE} disasm_ver_minor REGEX "DISASM_VERSION_MINOR")
|
||||||
file(STRINGS ${disasm_version_file} disasm_ver_patch REGEX "DISASM_VERSION_REVISION")
|
file(STRINGS ${BDD_VER_FILE} disasm_ver_patch REGEX "DISASM_VERSION_REVISION")
|
||||||
|
|
||||||
string(REGEX REPLACE "#define DISASM_VERSION_MAJOR[ \t\r\n]*" "" disasm_ver_major ${disasm_ver_major})
|
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_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})
|
string(REGEX REPLACE "#define DISASM_VERSION_REVISION[ \t\r\n]*" "" disasm_ver_patch ${disasm_ver_patch})
|
||||||
|
|
||||||
message(STATUS "Extracted version from ${disasm_version_file}: ${disasm_ver_major}.${disasm_ver_minor}.${disasm_ver_patch}")
|
message(STATUS "Extracted version from ${BDD_VER_FILE}: ${disasm_ver_major}.${disasm_ver_minor}.${disasm_ver_patch}")
|
||||||
|
|
||||||
project(bddisasm
|
project(bddisasm
|
||||||
VERSION ${disasm_ver_major}.${disasm_ver_minor}.${disasm_ver_patch}
|
VERSION ${disasm_ver_major}.${disasm_ver_minor}.${disasm_ver_patch}
|
||||||
DESCRIPTION ${project_description}
|
DESCRIPTION "Bitdefender x86 instruction decoder and emulator"
|
||||||
LANGUAGES C
|
LANGUAGES C
|
||||||
)
|
HOMEPAGE_URL https://github.com/bitdefender/bddisasm
|
||||||
|
)
|
||||||
|
|
||||||
if (NOT CMAKE_BUILD_TYPE)
|
# Use Release as the build type if no build type was specified and we're not using a multi-config generator .
|
||||||
|
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
||||||
message(STATUS "No build type given. Will use 'Release'")
|
message(STATUS "No build type given. Will use 'Release'")
|
||||||
set(CMAKE_BUILD_TYPE Release)
|
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE)
|
||||||
|
# Set the possible values of build type for cmake-gui.
|
||||||
|
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# These are shared by bddisasm and bdshemu.
|
||||||
|
if (NOT MSVC)
|
||||||
|
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
|
||||||
|
-march=westmere
|
||||||
|
)
|
||||||
|
else ()
|
||||||
|
set(BDDISASM_COMMON_COMPILE_OPTIONS /W4 /WX)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/x64/${CMAKE_BUILD_TYPE})
|
set(BDDISASM_PUBLIC_HEADERS
|
||||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/x64/${CMAKE_BUILD_TYPE})
|
"inc/bddisasm.h"
|
||||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/x64/${CMAKE_BUILD_TYPE})
|
"inc/constants.h"
|
||||||
|
"inc/cpuidflags.h"
|
||||||
|
"inc/disasmstatus.h"
|
||||||
|
"inc/disasmtypes.h"
|
||||||
|
"inc/registers.h"
|
||||||
|
"inc/version.h"
|
||||||
|
)
|
||||||
|
|
||||||
message(STATUS "Output directory set to: ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
|
cmake_print_variables(BDDISASM_PUBLIC_HEADERS)
|
||||||
|
cmake_print_variables(CMAKE_INSTALL_PREFIX)
|
||||||
|
|
||||||
set(bddisasm_src
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
|
set(BDDISASM_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/bddisasm"
|
||||||
|
CACHE STRING "Path to bddisasm public include files."
|
||||||
|
)
|
||||||
|
|
||||||
|
# -- bddisasm --
|
||||||
|
|
||||||
|
add_library(bddisasm STATIC
|
||||||
bddisasm/crt.c
|
bddisasm/crt.c
|
||||||
bddisasm/bddisasm.c
|
bddisasm/bddisasm.c
|
||||||
)
|
# Add the headers so they will show up in IDEs.
|
||||||
add_library(bddisasm STATIC ${bddisasm_src})
|
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
|
||||||
|
"${BDDISASM_PUBLIC_HEADERS}"
|
||||||
|
)
|
||||||
|
|
||||||
set_target_properties(bddisasm PROPERTIES
|
set_target_properties(bddisasm PROPERTIES
|
||||||
POSITION_INDEPENDENT_CODE ON
|
POSITION_INDEPENDENT_CODE ON
|
||||||
C_STANDARD 11
|
C_STANDARD 11
|
||||||
VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}
|
VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}
|
||||||
)
|
)
|
||||||
|
|
||||||
set(bdshemu_src
|
target_include_directories(bddisasm PRIVATE bddisasm/include)
|
||||||
|
target_include_directories(bddisasm PUBLIC
|
||||||
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/inc>
|
||||||
|
$<INSTALL_INTERFACE:${BDDISASM_INSTALL_INCLUDE_DIR}>
|
||||||
|
)
|
||||||
|
|
||||||
|
target_compile_options(bddisasm PRIVATE ${BDDISASM_COMMON_COMPILE_OPTIONS})
|
||||||
|
|
||||||
|
set_target_properties(bddisasm PROPERTIES
|
||||||
|
PUBLIC_HEADER "${BDDISASM_PUBLIC_HEADERS}"
|
||||||
|
VERSION ${CMAKE_PROJECT_VERSION}
|
||||||
|
SOVERSION ${CMAKE_PROJECT_VERSION_MAJOR}
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(bddisasm::bddisasm ALIAS bddisasm)
|
||||||
|
|
||||||
|
# -- bdshemu --
|
||||||
|
|
||||||
|
add_library(bdshemu STATIC
|
||||||
bdshemu/bdshemu.c
|
bdshemu/bdshemu.c
|
||||||
)
|
# Add the headers so they will show up in IDEs.
|
||||||
add_library(bdshemu STATIC ${bdshemu_src})
|
inc/bdshemu.h
|
||||||
|
)
|
||||||
|
|
||||||
set_target_properties(bdshemu PROPERTIES
|
set_target_properties(bdshemu PROPERTIES
|
||||||
POSITION_INDEPENDENT_CODE ON
|
POSITION_INDEPENDENT_CODE ON
|
||||||
C_STANDARD 11
|
C_STANDARD 11
|
||||||
VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}
|
VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}
|
||||||
)
|
)
|
||||||
add_dependencies(bdshemu bddisasm)
|
|
||||||
|
|
||||||
include_directories(
|
target_include_directories(bdshemu PRIVATE bddisasm/include)
|
||||||
inc
|
target_include_directories(bddisasm PUBLIC
|
||||||
bddisasm/include
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/inc>
|
||||||
)
|
$<INSTALL_INTERFACE:${BDDISASM_INSTALL_INCLUDE_DIR}>
|
||||||
|
)
|
||||||
|
|
||||||
if (CMAKE_BUILD_TYPE EQUAL "Release")
|
target_link_libraries(bdshemu PUBLIC bddisasm)
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Ofast -DNDEBUG")
|
|
||||||
else ()
|
target_compile_options(bdshemu PRIVATE ${BDDISASM_COMMON_COMPILE_OPTIONS})
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -D_DEBUG -DDEBUG")
|
if (NOT MSVC)
|
||||||
|
target_compile_options(bdshemu PRIVATE -maes)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
set(BDDISASM_COMPILE_OPTIONS
|
set_target_properties(bdshemu PROPERTIES
|
||||||
"$<$<CONFIG:Release>:-U_FORTIFY_SOURCE>"
|
PUBLIC_HEADER "inc/bdshemu.h"
|
||||||
"$<$<CONFIG:Release>:-D_FORTIFY_SOURCE=2>"
|
VERSION ${CMAKE_PROJECT_VERSION}
|
||||||
-Wall
|
SOVERSION ${CMAKE_PROJECT_VERSION_MAJOR}
|
||||||
-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
|
|
||||||
-march=westmere
|
|
||||||
)
|
|
||||||
|
|
||||||
target_compile_options(bddisasm PRIVATE ${BDDISASM_COMPILE_OPTIONS})
|
add_library(bddisasm::bdshemu ALIAS bdshemu)
|
||||||
target_compile_options(bdshemu PRIVATE ${BDDISASM_COMPILE_OPTIONS} -maes)
|
|
||||||
|
|
||||||
include(GNUInstallDirs)
|
# If this is the master project (or if the user requested it) add disasmtool.
|
||||||
|
if ((${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME}) OR BDD_INCLUDE_TOOL)
|
||||||
set(CMAKE_SKIP_BUILD_RPATH TRUE)
|
if (WIN32)
|
||||||
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
|
add_subdirectory(disasmtool)
|
||||||
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
|
else ()
|
||||||
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
add_subdirectory(disasmtool_lix)
|
||||||
|
endif ()
|
||||||
get_filename_component(public_header_path "${PROJECT_SOURCE_DIR}/inc" REALPATH)
|
|
||||||
file(GLOB_RECURSE public_headers "${public_header_path}/*.h")
|
|
||||||
set_target_properties(bddisasm PROPERTIES PUBLIC_HEADER "${public_headers}")
|
|
||||||
|
|
||||||
set(DEST_DIR "${CMAKE_INSTALL_PREFIX}")
|
|
||||||
set(LIB_DIR "${CMAKE_INSTALL_LIBDIR}")
|
|
||||||
set(INC_DIR "${CMAKE_INSTALL_INCLUDEDIR}")
|
|
||||||
set(PRIVATE_LIBS "-lbdshemu -lbddisasm")
|
|
||||||
set(DATA_DIR "${CMAKE_INSTALL_DATADIR}")
|
|
||||||
|
|
||||||
CONFIGURE_FILE("${CMAKE_STATIC_LIBRARY_PREFIX}bddisasm.pc.in"
|
|
||||||
"${PROJECT_SOURCE_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}bddisasm.pc"
|
|
||||||
@ONLY
|
|
||||||
)
|
|
||||||
|
|
||||||
INSTALL(TARGETS bddisasm bdshemu
|
|
||||||
EXPORT bddisasmTargets
|
|
||||||
LIBRARY DESTINATION "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}"
|
|
||||||
ARCHIVE DESTINATION "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}"
|
|
||||||
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/bddisasm"
|
|
||||||
)
|
|
||||||
|
|
||||||
set(CMAKE_INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/bddisasm)
|
|
||||||
install(EXPORT bddisasmTargets
|
|
||||||
DESTINATION ${CMAKE_INSTALL_CONFIGDIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
include(CMakePackageConfigHelpers)
|
|
||||||
|
|
||||||
configure_package_config_file(${PROJECT_SOURCE_DIR}/bddisasmConfig.cmake.in ${PROJECT_BINARY_DIR}/bddisasmConfig.cmake
|
|
||||||
INSTALL_DESTINATION ${CMAKE_INSTALL_CONFIGDIR}
|
|
||||||
PATH_VARS CMAKE_INSTALL_FULL_INCLUDEDIR CMAKE_INSTALL_FULL_LIBDIR
|
|
||||||
)
|
|
||||||
|
|
||||||
write_basic_package_version_file(${PROJECT_BINARY_DIR}/bddisasmConfigVersion.cmake
|
|
||||||
VERSION ${PROJECT_VERSION}
|
|
||||||
COMPATIBILITY SameMajorVersion
|
|
||||||
)
|
|
||||||
|
|
||||||
install(FILES ${PROJECT_BINARY_DIR}/bddisasmConfig.cmake ${PROJECT_BINARY_DIR}/bddisasmConfigVersion.cmake
|
|
||||||
DESTINATION ${CMAKE_INSTALL_CONFIGDIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
INSTALL(FILES "${PROJECT_SOURCE_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}bddisasm.pc"
|
|
||||||
DESTINATION "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/pkgconfig"
|
|
||||||
)
|
|
||||||
|
|
||||||
if (NOT CPACK_GENERATOR)
|
|
||||||
set(CPACK_GENERATOR "DEB")
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Bitdefender HVI Team <hvmi-oss@bitdefender.com>")
|
# If this is the master project add install and package targets.
|
||||||
set(CPACK_DEBIAN_PACKAGE_DEPENDS "")
|
if (${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
|
||||||
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64")
|
set(BDDISASM_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/bddisasm"
|
||||||
set(CPACK_DEBIAN_PACKAGE_SECTION "devel")
|
CACHE STRING "Path to bddisasm cmake files."
|
||||||
|
)
|
||||||
|
|
||||||
if (INCLUDE_TOOL)
|
set(BDDISASM_INSTALL_PCDIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
|
||||||
add_subdirectory("disasmtool_lix")
|
CACHE STRING "Path to bddisasm pkgconfig files."
|
||||||
add_dependencies(disasmtool bdshemu)
|
)
|
||||||
endif()
|
|
||||||
|
|
||||||
include(CPack)
|
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)
|
||||||
|
|
||||||
|
install(TARGETS bddisasm bdshemu disasmtool
|
||||||
|
EXPORT bddisasmTargets
|
||||||
|
INCLUDES
|
||||||
|
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
|
||||||
|
DESTINATION ${BDDISASM_INSTALL_CMAKEDIR}
|
||||||
|
NAMESPACE bddisasm::
|
||||||
|
FILE bddisasmTargets.cmake
|
||||||
|
COMPONENT bddisasm_Development
|
||||||
|
)
|
||||||
|
|
||||||
|
include(CMakePackageConfigHelpers)
|
||||||
|
|
||||||
|
write_basic_package_version_file("bddisasmConfigVersion.cmake"
|
||||||
|
VERSION ${CMAKE_PROJECT_VERSION}
|
||||||
|
COMPATIBILITY SameMajorVersion
|
||||||
|
)
|
||||||
|
|
||||||
|
install(FILES bddisasmConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/bddisasmConfigVersion.cmake
|
||||||
|
DESTINATION ${BDDISASM_INSTALL_CMAKEDIR}
|
||||||
|
COMPONENT bddisasm_Development
|
||||||
|
)
|
||||||
|
|
||||||
|
CONFIGURE_FILE("bddisasm.pc.in" "${CMAKE_STATIC_LIBRARY_PREFIX}bddisasm.pc" @ONLY)
|
||||||
|
|
||||||
|
INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}bddisasm.pc"
|
||||||
|
DESTINATION "${BDDISASM_INSTALL_PCDIR}"
|
||||||
|
COMPONENT bddisasm_Development
|
||||||
|
)
|
||||||
|
|
||||||
|
set(CPACK_PACKAGE_VENDOR "Bitdefender")
|
||||||
|
|
||||||
|
if (NOT CPACK_GENERATOR)
|
||||||
|
if (NOT WIN32)
|
||||||
|
set(CPACK_GENERATOR "DEB")
|
||||||
|
else ()
|
||||||
|
set(CPACK_GENERATOR "ZIP")
|
||||||
|
endif ()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
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")
|
||||||
|
|
||||||
|
include(CPack)
|
||||||
|
endif ()
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
dir_prefix=@DEST_DIR@
|
dir_prefix=@CMAKE_INSTALL_PREFIX@
|
||||||
lib=@LIB_DIR@
|
lib=@CMAKE_INSTALL_LIBDIR@
|
||||||
include=@INC_DIR@
|
include=@BDDISASM_INSTALL_INCLUDE_DIR@
|
||||||
data_dir=@DATA_DIR@
|
data_dir=@CMAKE_INSTALL_DATADIR@
|
||||||
|
|
||||||
prefix=${dir_prefix}
|
prefix=${dir_prefix}
|
||||||
lib_dir=${dir_prefix}/${lib}
|
lib_dir=${dir_prefix}/${lib}
|
||||||
@ -15,5 +15,5 @@ Description: "Bitdefender x86 instruction decoder and shellcode emulator"
|
|||||||
URL: https://github.com/bitdefender/bddisasm
|
URL: https://github.com/bitdefender/bddisasm
|
||||||
Version: @PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@
|
Version: @PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@
|
||||||
|
|
||||||
Libs: -L${lib_dir} @PRIVATE_LIBS@
|
Libs: -L${lib_dir} -lbdshemu -lbddisasm
|
||||||
Cflags: -I${include_dir}
|
Cflags: -I${include_dir}
|
1
bddisasmConfig.cmake
Normal file
1
bddisasmConfig.cmake
Normal file
@ -0,0 +1 @@
|
|||||||
|
include(${CMAKE_CURRENT_LIST_DIR}/bddisasmTargets.cmake)
|
59
disasmtool/CMakeLists.txt
Normal file
59
disasmtool/CMakeLists.txt
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.16)
|
||||||
|
|
||||||
|
project(disasmtool LANGUAGES C)
|
||||||
|
|
||||||
|
# Use Release as the build type if no build type was specified and we're not using a multi-config generator .
|
||||||
|
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
||||||
|
message(STATUS "No build type given. Will use 'Release'")
|
||||||
|
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE)
|
||||||
|
# Set the possible values of build type for cmake-gui.
|
||||||
|
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_executable(disasmtool disasmtool.c)
|
||||||
|
target_link_libraries(disasmtool PRIVATE bddisasm::bddisasm bddisasm::bdshemu)
|
||||||
|
|
||||||
|
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
|
||||||
|
include(CheckIPOSupported)
|
||||||
|
check_ipo_supported(RESULT USE_IPO)
|
||||||
|
if (USE_IPO)
|
||||||
|
set_target_properties(bddisasm PROPERTIES INTERPROCEDURAL_OPTIMIZATION True)
|
||||||
|
endif ()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (NOT MSVC)
|
||||||
|
target_compile_options(disasmtool PRIVATE
|
||||||
|
-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
|
||||||
|
-march=westmere
|
||||||
|
)
|
||||||
|
else ()
|
||||||
|
target_compile_options(disasmtool PRIVATE
|
||||||
|
/W4 /WX)
|
||||||
|
endif ()
|
@ -7,6 +7,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <Intrin.h>
|
||||||
|
|
||||||
typedef uint64_t QWORD, *PQWORD;
|
typedef uint64_t QWORD, *PQWORD;
|
||||||
|
|
||||||
|
@ -2,281 +2,64 @@ cmake_minimum_required (VERSION 3.12)
|
|||||||
|
|
||||||
project(disasmtool LANGUAGES CXX)
|
project(disasmtool LANGUAGES CXX)
|
||||||
|
|
||||||
if (NOT CMAKE_BUILD_TYPE)
|
# Use Release as the build type if no build type was specified and we're not using a multi-config generator .
|
||||||
message(STATUS "No build type given. Will use 'Release'!")
|
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
||||||
set(CMAKE_BUILD_TYPE Release)
|
message(STATUS "No build type given. Will use 'Release'")
|
||||||
|
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE)
|
||||||
|
# Set the possible values of build type for cmake-gui.
|
||||||
|
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (CMAKE_CXX_FLAGS)
|
add_executable(disasmtool disasmtool.cpp dumpers.cpp)
|
||||||
message(STATUS "Passed CXXFLAGS: ${CMAKE_CXX_FLAGS}")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") AND (CMAKE_CXX_FLAGS_DEBUG))
|
target_compile_options(disasmtool PRIVATE
|
||||||
message(STATUS "Passed CXXFLAGS_DEBUG: ${CMAKE_CXX_FLAGS_DEBUG}")
|
"$<$<CONFIG:Release>:-U_FORTIFY_SOURCE>"
|
||||||
endif()
|
"$<$<CONFIG:Release>:-D_FORTIFY_SOURCE=2>"
|
||||||
|
-Wall
|
||||||
|
-Wextra
|
||||||
|
-Wshadow
|
||||||
|
-Wformat-security
|
||||||
|
-Wstrict-overflow=2
|
||||||
|
-Wno-unused-function
|
||||||
|
-Wno-multichar
|
||||||
|
-Werror=format-security
|
||||||
|
-pipe
|
||||||
|
-fpie
|
||||||
|
-fwrapv
|
||||||
|
-fno-strict-aliasing
|
||||||
|
-fstack-protector-strong
|
||||||
|
-ffunction-sections
|
||||||
|
-fdata-sections
|
||||||
|
-g3
|
||||||
|
-gdwarf-4
|
||||||
|
-grecord-gcc-switches
|
||||||
|
-march=nehalem
|
||||||
|
-fno-omit-frame-pointer
|
||||||
|
)
|
||||||
|
|
||||||
if (("${CMAKE_BUILD_TYPE}" STREQUAL "Release") AND (CMAKE_CXX_FLAGS_RELEASE))
|
# find_package(bddisasm REQUIRED)
|
||||||
message(STATUS "Passed CXXFLAGS_RELEASE: ${CMAKE_CXX_FLAGS_RELEASE}")
|
find_package(RapidJSON QUIET)
|
||||||
endif()
|
|
||||||
|
|
||||||
get_filename_component(DISASM_DIRECTORY "${PROJECT_SOURCE_DIR}/.." REALPATH)
|
|
||||||
set(DISASM_BUILD_PREFIX "bin/x64")
|
|
||||||
|
|
||||||
set(disasmtool_src_files
|
|
||||||
disasmtool.cpp
|
|
||||||
dumpers.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
find_package(RapidJSON)
|
|
||||||
|
|
||||||
|
target_link_libraries(disasmtool PRIVATE bddisasm::bddisasm bddisasm::bdshemu)
|
||||||
if (RapidJSON_FOUND)
|
if (RapidJSON_FOUND)
|
||||||
message(STATUS "Dependency: rapidjson found")
|
# :( https://github.com/satishbabariya/modern-cmake#good-boys-export-their-targets
|
||||||
include_directories(${RapidJSON_INCLUDE_DIRS})
|
target_include_directories(disasmtool PRIVATE ${RapidJSON_INCLUDE_DIRS})
|
||||||
add_compile_definitions(HAS_RAPIDJSON)
|
target_sources(disasmtool PRIVATE rapidjson.cpp)
|
||||||
list(APPEND disasmtool_src_files rapidjson.cpp)
|
target_compile_definitions(disasmtool PRIVATE HAS_RAPIDJSON)
|
||||||
else()
|
endif ()
|
||||||
message(FATAL_ERROR "Dependency: rapidjson not found")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME} ${disasmtool_src_files})
|
|
||||||
|
|
||||||
|
|
||||||
target_compile_options(${PROJECT_NAME} PRIVATE
|
|
||||||
"$<$<CONFIG:Release>:-U_FORTIFY_SOURCE>"
|
|
||||||
"$<$<CONFIG:Release>:-D_FORTIFY_SOURCE=2>"
|
|
||||||
-Wall
|
|
||||||
-Wextra
|
|
||||||
-Wshadow
|
|
||||||
-Wformat-security
|
|
||||||
-Wstrict-overflow=2
|
|
||||||
-Wno-unused-function
|
|
||||||
-Wno-multichar
|
|
||||||
-Werror=format-security
|
|
||||||
-pipe
|
|
||||||
-fpie
|
|
||||||
-fwrapv
|
|
||||||
-fno-strict-aliasing
|
|
||||||
-fstack-protector-strong
|
|
||||||
-ffunction-sections
|
|
||||||
-fdata-sections
|
|
||||||
-g3
|
|
||||||
-gdwarf-4
|
|
||||||
-grecord-gcc-switches
|
|
||||||
-march=nehalem
|
|
||||||
-fno-omit-frame-pointer
|
|
||||||
# -fsanitize=leak
|
|
||||||
# -fsanitize=address
|
|
||||||
)
|
|
||||||
|
|
||||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} \
|
|
||||||
-Wl,--fatal-warnings \
|
|
||||||
-Wl,--warn-common \
|
|
||||||
-Wl,--no-undefined \
|
|
||||||
-Wl,-z,noexecstack \
|
|
||||||
-Wl,-z,relro \
|
|
||||||
-Wl,-z,now \
|
|
||||||
-Wl,--build-id")
|
|
||||||
|
|
||||||
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} -Wl,-O1")
|
|
||||||
|
|
||||||
if (CMAKE_COMPILER_IS_GNUCXX)
|
|
||||||
if (NOT (CMAKE_CXX_COMPILER_VERSION LESS 6.0))
|
|
||||||
target_compile_options(${PROJECT_NAME} PRIVATE
|
|
||||||
-Wshift-overflow=2
|
|
||||||
-Wnull-dereference
|
|
||||||
-Wduplicated-cond
|
|
||||||
-Wlogical-op
|
|
||||||
-Wvla
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (NOT (CMAKE_CXX_COMPILER_VERSION LESS 7.0))
|
|
||||||
target_compile_options(${PROJECT_NAME} PRIVATE
|
|
||||||
-Wdangling-else
|
|
||||||
-Wshadow=global
|
|
||||||
-Walloc-zero
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (NOT (CMAKE_CXX_COMPILER_VERSION LESS 8.0))
|
|
||||||
target_compile_options(${PROJECT_NAME} PRIVATE
|
|
||||||
-Wmultistatement-macros
|
|
||||||
-Warray-bounds=2
|
|
||||||
-Wformat-overflow=2
|
|
||||||
-Wformat-truncation=1
|
|
||||||
-Wstringop-truncation
|
|
||||||
-Wpointer-arith
|
|
||||||
-Wdouble-promotion
|
|
||||||
-Wmissing-include-dirs
|
|
||||||
-Wuninitialized
|
|
||||||
-Wmissing-noreturn
|
|
||||||
-Wsuggest-attribute=noreturn
|
|
||||||
-Walloca
|
|
||||||
-Wtrampolines
|
|
||||||
-Wcast-qual
|
|
||||||
-Wcast-align
|
|
||||||
-Wparentheses
|
|
||||||
-Wfloat-conversion
|
|
||||||
-Wredundant-decls
|
|
||||||
-Wdisabled-optimization
|
|
||||||
-Woverlength-strings
|
|
||||||
-Wswitch-enum
|
|
||||||
-fstack-clash-protection
|
|
||||||
-static
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (NOT (CMAKE_CXX_COMPILER_VERSION LESS 9.0))
|
|
||||||
target_compile_options(${PROJECT_NAME} PRIVATE
|
|
||||||
-Wcatch-value=2
|
|
||||||
-Wduplicated-branches
|
|
||||||
-Wextra-semi
|
|
||||||
-Wif-not-aligned
|
|
||||||
-Wplacement-new=2
|
|
||||||
-Wsuggest-override
|
|
||||||
-Wunused-but-set-parameter
|
|
||||||
-Wswitch-enum
|
|
||||||
-Wuseless-cast
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
|
||||||
target_compile_options(${PROJECT_NAME} PRIVATE
|
|
||||||
-Wno-missing-braces
|
|
||||||
)
|
|
||||||
|
|
||||||
if (NOT (CMAKE_CXX_COMPILER_VERSION LESS 6.0))
|
|
||||||
target_compile_options(${PROJECT_NAME} PRIVATE
|
|
||||||
-Wshift-overflow
|
|
||||||
-Wnull-dereference
|
|
||||||
-Wvla
|
|
||||||
-Wdangling-else
|
|
||||||
-Wpragmas
|
|
||||||
-Wtautological-compare
|
|
||||||
-Wzero-as-null-pointer-constant
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (NOT (CMAKE_CXX_COMPILER_VERSION LESS 10.0))
|
|
||||||
target_compile_options(${PROJECT_NAME} PRIVATE
|
|
||||||
-Warray-bounds-pointer-arithmetic
|
|
||||||
-Wassign-enum
|
|
||||||
-Watomic-implicit-seq-cst
|
|
||||||
-Watomic-properties
|
|
||||||
-Wauto-import
|
|
||||||
-Wbad-function-cast
|
|
||||||
-Wbind-to-temporary-copy
|
|
||||||
-Wbitfield-enum-conversion
|
|
||||||
-Wbitwise-op-parentheses
|
|
||||||
-Wcomma
|
|
||||||
-Wconditional-uninitialized
|
|
||||||
-Wconsumed
|
|
||||||
-Wcstring-format-directive
|
|
||||||
-Wctad-maybe-unsupported
|
|
||||||
-Wcustom-atomic-properties
|
|
||||||
-Wdelete-non-abstract-non-virtual-dtor
|
|
||||||
-Wdeprecated-copy
|
|
||||||
-Wdeprecated-copy-dtor
|
|
||||||
-Wdeprecated-dynamic-exception-spec
|
|
||||||
-Wdeprecated-implementations
|
|
||||||
-Wdouble-promotion
|
|
||||||
-Wduplicate-enum
|
|
||||||
-Wduplicate-method-arg
|
|
||||||
-Wduplicate-method-match
|
|
||||||
-Wembedded-directive
|
|
||||||
-Wempty-init-stmt
|
|
||||||
-Wexit-time-destructors
|
|
||||||
-Wexplicit-ownership-type
|
|
||||||
-Wextra-semi
|
|
||||||
-Wfloat-conversion
|
|
||||||
-Wfor-loop-analysis
|
|
||||||
-Wformat-non-iso
|
|
||||||
-Wformat-type-confusion
|
|
||||||
-Wheader-hygiene
|
|
||||||
-Widiomatic-parentheses
|
|
||||||
-Winfinite-recursion
|
|
||||||
-Wlogical-op-parentheses
|
|
||||||
-Wmethod-signatures
|
|
||||||
-Wmissing-noreturn
|
|
||||||
-Wmissing-variable-declarations
|
|
||||||
-Wmove
|
|
||||||
-Wnon-gcc
|
|
||||||
-Wnon-virtual-dtor
|
|
||||||
-Wnull-pointer-arithmetic
|
|
||||||
-Wnullable-to-nonnull-conversion
|
|
||||||
-Wover-aligned
|
|
||||||
-Woverlength-strings
|
|
||||||
-Woverloaded-virtual
|
|
||||||
-Woverriding-method-mismatch
|
|
||||||
-Wpragma-pack
|
|
||||||
-Wpragma-pack-suspicious-include
|
|
||||||
-Wquoted-include-in-framework-header
|
|
||||||
-Wrange-loop-analysis
|
|
||||||
-Wredundant-move
|
|
||||||
-Wredundant-parens
|
|
||||||
-Wreserved-id-macro
|
|
||||||
-Wreturn-std-move
|
|
||||||
-Wself-assign
|
|
||||||
-Wself-move
|
|
||||||
-Wsemicolon-before-method-body
|
|
||||||
-Wshadow-all
|
|
||||||
-Wshift-sign-overflow
|
|
||||||
-Wsometimes-uninitialized
|
|
||||||
-Wstatic-in-inline
|
|
||||||
-Wstrict-prototypes
|
|
||||||
-Wstrict-selector-match
|
|
||||||
-Wstring-conversion
|
|
||||||
-Wsuper-class-method-mismatch
|
|
||||||
-Wswitch-enum
|
|
||||||
-Wtautological-bitwise-compare
|
|
||||||
-Wtautological-constant-in-range-compare
|
|
||||||
-Wtautological-overlap-compare
|
|
||||||
-Wtautological-type-limit-compare
|
|
||||||
-Wtautological-unsigned-enum-zero-compare
|
|
||||||
-Wtautological-unsigned-zero-compare
|
|
||||||
-Wunneeded-internal-declaration
|
|
||||||
-Wunneeded-member-function
|
|
||||||
-Wunreachable-code-aggressive
|
|
||||||
-Wunused-label
|
|
||||||
-Wunused-lambda-capture
|
|
||||||
-Wunused-local-typedef
|
|
||||||
-Wunused-variable
|
|
||||||
-Wvla-extension
|
|
||||||
-Wzero-length-array
|
|
||||||
|
|
||||||
-Wno-sign-conversion
|
|
||||||
-Wno-shorten-64-to-32
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
else()
|
|
||||||
message(FATAL_ERROR "Unsupported compiler!")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
target_include_directories(${PROJECT_NAME} PRIVATE
|
|
||||||
${DISASM_DIRECTORY}/inc
|
|
||||||
${DISASM_DIRECTORY}/bddisasm/include
|
|
||||||
)
|
|
||||||
|
|
||||||
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
|
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
|
||||||
include(CheckIPOSupported)
|
include(CheckIPOSupported)
|
||||||
check_ipo_supported(RESULT USE_IPO)
|
check_ipo_supported(RESULT USE_IPO)
|
||||||
set_target_properties(${PROJECT_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION True)
|
if (USE_IPO)
|
||||||
|
set_target_properties(bddisasm PROPERTIES INTERPROCEDURAL_OPTIMIZATION True)
|
||||||
|
endif ()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set_target_properties(${PROJECT_NAME}
|
set_target_properties(disasmtool
|
||||||
PROPERTIES
|
PROPERTIES
|
||||||
POSITION_INDEPENDENT_CODE ON
|
POSITION_INDEPENDENT_CODE ON
|
||||||
CXX_STANDARD 17
|
CXX_STANDARD 17
|
||||||
CXX_STANDARD_REQUIRED ON
|
CXX_STANDARD_REQUIRED ON
|
||||||
CXX_EXTENSIONS ON
|
CXX_EXTENSIONS ON
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_directories(${PROJECT_NAME} PRIVATE "${DISASM_DIRECTORY}/bin/x64/${CMAKE_BUILD_TYPE}")
|
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE bddisasm bdshemu)
|
|
||||||
|
|
||||||
INSTALL(TARGETS disasmtool
|
|
||||||
RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}"
|
|
||||||
)
|
|
||||||
|
|
||||||
unset(DISASM_LIB CACHE)
|
|
||||||
unset(SHEMU_LIB CACHE)
|
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
# project-meta-info.in
|
|
||||||
|
|
||||||
set(project_description "Bitdefender x86 instruction decoder and emulator")
|
|
Loading…
Reference in New Issue
Block a user