Skip to content

Commit

Permalink
cmake: Add capstone macros and fix code style
Browse files Browse the repository at this point in the history
Signed-off-by: Rong Tao <[email protected]>
  • Loading branch information
Rtoax committed Aug 7, 2024
1 parent 8ea0997 commit f34c6da
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 34 deletions.
55 changes: 25 additions & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,59 +93,54 @@ message(STATUS "CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}")
message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
message(STATUS "Architecture: ${ARCHITECTURE}")

if(ELFUTILS_INCLUDE_DIRS)
message(STATUS "FOUND elfutils-devel")
else()
message(FATAL_ERROR "FOUND elfutils-devel")
endif()

if(BINUTILS_INCLUDE_DIRS)
message(STATUS "FOUND binutils-devel")
else()
message(FATAL_ERROR "Not FOUND binutils-devel")
endif()

if(CAPSTONE_INCLUDE_DIRS)
message(STATUS "FOUND capstone-devel")
endif()

if(LIBUNWIND_INCLUDE_DIRS)
message(STATUS "FOUND libunwind-devel")
endif()

if(KERNEL_HEADERS_INCLUDE_DIRS)
message(STATUS "FOUND kernel-headers")
endif()

if(LIBELF_FOUND)
message(STATUS "FOUND libelf")
endif()

# This variable store utils CFLAGS's macros(-D of compiler)
set(UTILS_CFLAGS_MACROS)
set(TESTS_CFLAGS_MACROS)

if(LIBELF_INCLUDE_DIRS)
message(STATUS "Found libelf headers")
set(UTILS_CFLAGS_MACROS "${UTILS_CFLAGS_MACROS}" HAVE_LIBELF_DEVEL)
endif()

if(ELFUTILS_INCLUDE_DIRS)
message(STATUS "Found elfutils headers")
set(UTILS_CFLAGS_MACROS "${UTILS_CFLAGS_MACROS}" HAVE_ELFUTILS_DEVEL)
else()
message(FATAL_ERROR "Not found elfutils header")
endif()

if(BINUTILS_INCLUDE_DIRS)
message(STATUS "Found binutils headers")
set(UTILS_CFLAGS_MACROS "${UTILS_CFLAGS_MACROS}" HAVE_BINUTILS_DEVEL)
else()
message(FATAL_ERROR "Not found binutils headers")
endif()

if(BINUTILS_BFD_H)
set(UTILS_CFLAGS_MACROS "${UTILS_CFLAGS_MACROS}" HAVE_BINUTILS_BFD_H)
endif()

if(LIBUNWIND_LIBUNWIND_H)
message(STATUS "Found libunwind headers")
set(UTILS_CFLAGS_MACROS "${UTILS_CFLAGS_MACROS}" HAVE_LIBUNWIND_H)
endif()

if(CAPSTONE_INCLUDE_DIRS)
message(STATUS "Found capstone headers")
set(UTILS_CFLAGS_MACROS "${UTILS_CFLAGS_MACROS}" HAVE_CAPSTONE_DEVEL)
endif()

if(CAPSTONE_CAPSTONE_H)
set(UTILS_CFLAGS_MACROS "${UTILS_CFLAGS_MACROS}" CAPSTONE_CAPSTONE_H)
set(UTILS_CFLAGS_MACROS "${UTILS_CFLAGS_MACROS}" HAVE_CAPSTONE_CAPSTONE_H)
endif()

if(KERNEL_HEADERS_INCLUDE_DIRS)
message(STATUS "Found kernel headers")
set(UTILS_CFLAGS_MACROS "${UTILS_CFLAGS_MACROS}" HAVE_KERNEL_HEADERS_DEVEL)
endif()

if(KERNEL_HEADERS_CONST_H)
set(UTILS_CFLAGS_MACROS "${UTILS_CFLAGS_MACROS}" KERNEL_HEADERS_CONST_H)
set(UTILS_CFLAGS_MACROS "${UTILS_CFLAGS_MACROS}" HAVE_KERNEL_HEADERS_CONST_H)
endif()

# macro ULPATCH_FTRACE_OBJ_PATH="/usr/share/ulpatch/ftrace-mcount.obj" for example
Expand Down
2 changes: 1 addition & 1 deletion cmake/find_binutils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ find_library(BINUTILS_BFD_LIBRARIES

include(FindPackageHandleStandardArgs)

FIND_PACKAGE_HANDLE_STANDARD_ARGS(binutils-devel "Please install the binutils-devel development package"
FIND_PACKAGE_HANDLE_STANDARD_ARGS(binutils-devel "Please install the binutils development package"
BINUTILS_BFD_LIBRARIES
BINUTILS_INCLUDE_DIRS)

Expand Down
15 changes: 13 additions & 2 deletions cmake/find_capstone.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Once done this will define
#
# CAPSTONE_FOUND - system has capstone
# CAPSTONE_LIBRARIES
# CAPSTONE_INCLUDE_DIRS - the capstone include directory
# CAPSTONE_CAPSTONE_H - the capstone has capstone.h header

Expand All @@ -13,9 +14,15 @@ find_path(CAPSTONE_INCLUDE_DIRS
PATH_SUFFIXES capstone
PATHS ENV CPATH)

find_library(CAPSTONE_LIBRARIES
NAMES capstone
PATHS
ENV LIBRARY_PATH
ENV LD_LIBRARY_PATH)

include(FindPackageHandleStandardArgs)

FIND_PACKAGE_HANDLE_STANDARD_ARGS(capstone-devel "Please install the capstone-devel development package"
FIND_PACKAGE_HANDLE_STANDARD_ARGS(capstone-devel "Please install the capstone development package"
CAPSTONE_INCLUDE_DIRS)

SET(CMAKE_REQUIRED_LIBRARIES capstone)
Expand All @@ -27,5 +34,9 @@ int main(void) {
}" CAPSTONE_CAPSTONE_H)
SET(CMAKE_REQUIRED_LIBRARIES)

mark_as_advanced(CAPSTONE_INCLUDE_DIRS CAPSTONE_CAPSTONE_H)
mark_as_advanced(
CAPSTONE_INCLUDE_DIRS
CAPSTONE_LIBRARIES
CAPSTONE_CAPSTONE_H
)

2 changes: 1 addition & 1 deletion src/utils/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
#endif

#if defined(KERNEL_HEADERS_CONST_H)
#if defined(HAVE_KERNEL_HEADERS_CONST_H)
#include <linux/const.h>
#endif

Expand Down

0 comments on commit f34c6da

Please sign in to comment.