Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
luadebug committed Jan 10, 2025
1 parent de84458 commit 58c0eb3
Showing 1 changed file with 117 additions and 119 deletions.
236 changes: 117 additions & 119 deletions ports/libmem/0001-CMakeLists.patch
Original file line number Diff line number Diff line change
@@ -1,119 +1,117 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 534057a..e695861 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 3.22.1)

-include(ExternalProject)
+set(CMAKE_CXX_STANDARD 17)
+file(GLOB_RECURSE LLVM_DEM_SRC "${LIBMEM_DIR}/external/llvm/lib/*.cpp")

project(libmem
LANGUAGES
@@ -49,6 +50,7 @@ message(STATUS
message(STATUS "CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}")
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")

+if(0)
# External dependencies
set(EXTERNAL_DEPENDENCIES_DIR "${PROJECT_SOURCE_DIR}/external")
set(CAPSTONE_DIR "${EXTERNAL_DEPENDENCIES_DIR}/capstone")
@@ -67,6 +69,7 @@ add_library(keystone STATIC IMPORTED)
set_target_properties(keystone PROPERTIES IMPORTED_LOCATION ${KEYSTONE_IMPORT_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}keystone${CMAKE_STATIC_LIBRARY_SUFFIX})
# End of external dependencies

+endif()
set(LIBMEM_DIR "${PROJECT_SOURCE_DIR}")
set(LIBMEM_INC "${LIBMEM_DIR}/include")
set(INTERNAL_DIR "${LIBMEM_DIR}/internal")
@@ -89,24 +92,21 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL FreeBSD)
endif()
file(GLOB LIBMEM_SRC ${LIBMEM_ARCH_SRC} "${LIBMEM_DIR}/src/freebsd/*.c" "${LIBMEM_DIR}/src/freebsd/ptrace/*.c" "${LIBMEM_DIR}/src/common/*.c" "${LIBMEM_DIR}/src/common/*.cpp" "${INTERNAL_DIR}/posixutils/*.c" "${INTERNAL_DIR}/elfutils/*.c" "${INTERNAL_DIR}/demangler/*.cpp")
endif()
+find_package(PkgConfig)
+pkg_check_modules(keystone REQUIRED keystone)
+find_package(capstone CONFIG REQUIRED)
set(LIBMEM_DEPS
- capstone
- keystone
- llvm
+ capstone::capstone
+ "${keystone_LINK_LIBRARIES}"
)

-if (LIBMEM_BUILD_STATIC)
- add_library(libmem STATIC ${LIBMEM_SRC})
-else()
- add_library(libmem SHARED ${LIBMEM_SRC})
-endif()
+add_library(libmem ${LIBMEM_SRC} ${LLVM_DEM_SRC})
target_include_directories(libmem PRIVATE "${LIBMEM_DIR}/src" "${INTERNAL_DIR}" "${COMMON_DIR}")

include_directories(${PROJECT_SOURCE_DIR}
- ${LIBMEM_INC}
- ${CAPSTONE_INC}
- ${KEYSTONE_INC}
- ${LLVM_INC}
+ "${LIBMEM_INC}"
+ "${keystone_INCLUDE_DIRS}"
+ "${LIBMEM_DIR}/external/llvm/include"
)

if (LIBMEM_BUILD_TESTS)
@@ -116,10 +116,6 @@ endif()

set_target_properties(libmem PROPERTIES POSITION_INDEPENDENT_CODE True INCLUDES ${LIBMEM_INC})
target_compile_definitions(libmem PUBLIC LM_EXPORT)
-add_dependencies(libmem
- capstone-engine
- keystone-engine
-)

if(${CMAKE_SYSTEM_NAME} STREQUAL Windows OR ${CMAKE_SYSTEM_NAME} STREQUAL CYGWIN)
set(LIBMEM_DEPS
@@ -152,7 +148,7 @@ else()
endif()

target_link_libraries(libmem ${LIBMEM_DEPS})
-if(LIBMEM_BUILD_STATIC)
+if(0)
# Create a bundled static library containing all dependencies (to mimic the shared library behavior)
set_target_properties(libmem PROPERTIES OUTPUT_NAME "libmem_partial")
set(libmem_bundle_files "$<TARGET_FILE:libmem>")
@@ -193,7 +189,7 @@ if(LIBMEM_BUILD_STATIC)
endif()
endif()

-if(${CMAKE_SYSTEM_NAME} STREQUAL Windows OR ${CMAKE_SYSTEM_NAME} STREQUAL CYGWIN)
+if(0)
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL CYGWIN)
cmake_path(SET CMAKE_INSTALL_PREFIX "$ENV{ProgramFiles}")
else()
@@ -202,14 +198,18 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL Windows OR ${CMAKE_SYSTEM_NAME} STREQUAL CYGWIN
endif()
set(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/libmem")
execute_process(COMMAND mkdir "${CMAKE_INSTALL_PREFIX}")
-else()
set(CMAKE_INSTALL_PREFIX "/usr")
endif()

-install(TARGETS libmem
- LIBRARY DESTINATION lib)
-
-install(TARGETS libmem
- RUNTIME DESTINATION lib)
-
-install(DIRECTORY ${LIBMEM_INC}/libmem DESTINATION include)
+install(TARGETS libmem EXPORT libmem-target
+ LIBRARY DESTINATION lib
+ ARCHIVE DESTINATION lib
+ RUNTIME DESTINATION bin
+ PUBLIC_HEADER DESTINATION "include/libmem"
+)
+install(DIRECTORY "${LIBMEM_INC}/libmem" DESTINATION "include")
+install(EXPORT libmem-target NAMESPACE libmem:: DESTINATION "share/libmem")
+include(CMakePackageConfigHelpers)
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/libmem-config.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/libmem-config.cmake" @ONLY)
+write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/libmem-config-version.cmake" VERSION 5.0.4 COMPATIBILITY SameMajorVersion)
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libmem-config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/libmem-config-version.cmake" DESTINATION "share/libmem")
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 534057a..a4afa93 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 3.22.1)

-include(ExternalProject)
+set(CMAKE_CXX_STANDARD 17)
+file(GLOB_RECURSE LLVM_DEM_SRC "${LIBMEM_DIR}/external/llvm/lib/*.cpp")

project(libmem
LANGUAGES
@@ -49,6 +50,7 @@ message(STATUS
message(STATUS "CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}")
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")

+if(0)
# External dependencies
set(EXTERNAL_DEPENDENCIES_DIR "${PROJECT_SOURCE_DIR}/external")
set(CAPSTONE_DIR "${EXTERNAL_DEPENDENCIES_DIR}/capstone")
@@ -67,6 +69,7 @@ add_library(keystone STATIC IMPORTED)
set_target_properties(keystone PROPERTIES IMPORTED_LOCATION ${KEYSTONE_IMPORT_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}keystone${CMAKE_STATIC_LIBRARY_SUFFIX})
# End of external dependencies

+endif()
set(LIBMEM_DIR "${PROJECT_SOURCE_DIR}")
set(LIBMEM_INC "${LIBMEM_DIR}/include")
set(INTERNAL_DIR "${LIBMEM_DIR}/internal")
@@ -89,24 +92,21 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL FreeBSD)
endif()
file(GLOB LIBMEM_SRC ${LIBMEM_ARCH_SRC} "${LIBMEM_DIR}/src/freebsd/*.c" "${LIBMEM_DIR}/src/freebsd/ptrace/*.c" "${LIBMEM_DIR}/src/common/*.c" "${LIBMEM_DIR}/src/common/*.cpp" "${INTERNAL_DIR}/posixutils/*.c" "${INTERNAL_DIR}/elfutils/*.c" "${INTERNAL_DIR}/demangler/*.cpp")
endif()
+find_package(PkgConfig)
+pkg_check_modules(keystone REQUIRED keystone)
+find_package(capstone CONFIG REQUIRED)
set(LIBMEM_DEPS
- capstone
- keystone
- llvm
+ capstone::capstone
+ "${keystone_LINK_LIBRARIES}"
)

-if (LIBMEM_BUILD_STATIC)
- add_library(libmem STATIC ${LIBMEM_SRC})
-else()
- add_library(libmem SHARED ${LIBMEM_SRC})
-endif()
+add_library(libmem ${LIBMEM_SRC} ${LLVM_DEM_SRC})
target_include_directories(libmem PRIVATE "${LIBMEM_DIR}/src" "${INTERNAL_DIR}" "${COMMON_DIR}")

include_directories(${PROJECT_SOURCE_DIR}
${LIBMEM_INC}
- ${CAPSTONE_INC}
- ${KEYSTONE_INC}
- ${LLVM_INC}
+ "${keystone_INCLUDE_DIRS}"
+ "${LIBMEM_DIR}/external/llvm/include"
)

if (LIBMEM_BUILD_TESTS)
@@ -116,10 +116,6 @@ endif()

set_target_properties(libmem PROPERTIES POSITION_INDEPENDENT_CODE True INCLUDES ${LIBMEM_INC})
target_compile_definitions(libmem PUBLIC LM_EXPORT)
-add_dependencies(libmem
- capstone-engine
- keystone-engine
-)

if(${CMAKE_SYSTEM_NAME} STREQUAL Windows OR ${CMAKE_SYSTEM_NAME} STREQUAL CYGWIN)
set(LIBMEM_DEPS
@@ -152,7 +148,7 @@ else()
endif()

target_link_libraries(libmem ${LIBMEM_DEPS})
-if(LIBMEM_BUILD_STATIC)
+if(0)
# Create a bundled static library containing all dependencies (to mimic the shared library behavior)
set_target_properties(libmem PROPERTIES OUTPUT_NAME "libmem_partial")
set(libmem_bundle_files "$<TARGET_FILE:libmem>")
@@ -193,7 +189,7 @@ if(LIBMEM_BUILD_STATIC)
endif()
endif()

-if(${CMAKE_SYSTEM_NAME} STREQUAL Windows OR ${CMAKE_SYSTEM_NAME} STREQUAL CYGWIN)
+if(0)
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL CYGWIN)
cmake_path(SET CMAKE_INSTALL_PREFIX "$ENV{ProgramFiles}")
else()
@@ -202,14 +198,18 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL Windows OR ${CMAKE_SYSTEM_NAME} STREQUAL CYGWIN
endif()
set(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/libmem")
execute_process(COMMAND mkdir "${CMAKE_INSTALL_PREFIX}")
-else()
set(CMAKE_INSTALL_PREFIX "/usr")
endif()

-install(TARGETS libmem
- LIBRARY DESTINATION lib)
-
-install(TARGETS libmem
- RUNTIME DESTINATION lib)
-
install(DIRECTORY ${LIBMEM_INC}/libmem DESTINATION include)
+install(TARGETS libmem
+ EXPORT libmem-target
+ LIBRARY DESTINATION lib
+ ARCHIVE DESTINATION lib
+ RUNTIME DESTINATION bin
+)
+install(EXPORT libmem-target NAMESPACE libmem:: DESTINATION "share/libmem")
+include(CMakePackageConfigHelpers)
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/libmem-config.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/libmem-config.cmake" @ONLY)
+write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/libmem-config-version.cmake" VERSION 5.0.4 COMPATIBILITY SameMajorVersion)
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libmem-config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/libmem-config-version.cmake" DESTINATION "share/libmem")

0 comments on commit 58c0eb3

Please sign in to comment.