fix-build-system-deps.patch 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. From 676063535d82077dc47de1e5ef163ec765b1f682 Mon Sep 17 00:00:00 2001
  2. From: Redbeanw44602 <[email protected]>
  3. Date: Mon, 31 Mar 2025 23:09:52 +0800
  4. Subject: [PATCH] fix build system deps
  5. ---
  6. CMakeLists.txt | 91 +++++++++++++-------------------------------------
  7. 1 file changed, 24 insertions(+), 67 deletions(-)
  8. diff --git a/CMakeLists.txt b/CMakeLists.txt
  9. index 1c3b2e9..0894f1d 100644
  10. --- a/CMakeLists.txt
  11. +++ b/CMakeLists.txt
  12. @@ -86,25 +86,8 @@ endfunction(add_subdirectory_pic)
  13. # capstone
  14. #
  15. if (DISASM_CAPSTONE)
  16. - configure_file(cmake/capstone.cmake.in capstone-download/CMakeLists.txt)
  17. - execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
  18. - WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/capstone-download"
  19. - )
  20. - execute_process(COMMAND "${CMAKE_COMMAND}" --build .
  21. - WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/capstone-download"
  22. - )
  23. -
  24. - string(TOUPPER ${FUNCHOOK_CPU} FUNCHOOK_CPU_UPPER)
  25. -
  26. - set(CAPSTONE_BUILD_SHARED OFF CACHE BOOL "")
  27. - set(CAPSTONE_BUILD_STATIC_RUNTIME OFF CACHE BOOL "")
  28. - set(CAPSTONE_BUILD_TESTS OFF CACHE BOOL "")
  29. - set(CAPSTONE_BUILD_CSTOOL OFF CACHE BOOL "")
  30. - set(CAPSTONE_ARCHITECTURE_DEFAULT OFF CACHE BOOL "")
  31. - set(CAPSTONE_${FUNCHOOK_CPU_UPPER}_SUPPORT ON CACHE BOOL "")
  32. - add_subdirectory_pic(${CMAKE_CURRENT_BINARY_DIR}/capstone-src ${CMAKE_CURRENT_BINARY_DIR}/capstone-build)
  33. -
  34. - list(APPEND FUNCHOOK_DEPS capstone-static)
  35. + find_package(capstone REQUIRED)
  36. + list(APPEND FUNCHOOK_DEPS capstone::capstone_static)
  37. set(DISASM capstone)
  38. endif ()
  39. @@ -112,55 +95,17 @@ endif ()
  40. # distorm
  41. #
  42. if (DISASM_DISTORM)
  43. - set(DISTORM_PATH distorm/)
  44. - set(DISTORM_SRC_DIR ${DISTORM_PATH}/src/)
  45. - set(DISTORM_SOURCES ${DISTORM_SRC_DIR}/decoder.c ${DISTORM_SRC_DIR}/distorm.c ${DISTORM_SRC_DIR}/instructions.c
  46. - ${DISTORM_SRC_DIR}/insts.c ${DISTORM_SRC_DIR}/mnemonics.c ${DISTORM_SRC_DIR}/operands.c
  47. - ${DISTORM_SRC_DIR}/prefix.c ${DISTORM_SRC_DIR}/textdefs.c)
  48. - if (MSVC)
  49. - # Suppress warning C4819:
  50. - # The file contains a character that cannot be represented in the current code
  51. - # page (number). Save the file in Unicode format to prevent data loss.
  52. - #
  53. - # prefix.c includes non-ascii chracters and C compiler warns C4819 on multibyte Windows
  54. - # environment.
  55. - set_source_files_properties(${DISTORM_SRC_DIR}/prefix.c PROPERTIES COMPILE_FLAGS /wd4819)
  56. - endif ()
  57. - add_library(distorm STATIC ${DISTORM_SOURCES})
  58. - set_target_properties(distorm PROPERTIES POSITION_INDEPENDENT_CODE ON)
  59. - target_include_directories(distorm PUBLIC ${DISTORM_PATH}/include)
  60. - if (HAVE_FVISIBILITY_HIDDEN)
  61. - target_compile_options(distorm PRIVATE -fvisibility=hidden)
  62. - endif ()
  63. set(DISASM distorm)
  64. - list(APPEND FUNCHOOK_DEPS distorm)
  65. endif ()
  66. #
  67. # zydis
  68. #
  69. if (DISASM_ZYDIS)
  70. - include(ExternalProject)
  71. - ExternalProject_Add(Zydis_src
  72. - GIT_REPOSITORY https://github.com/zyantific/zydis.git
  73. - GIT_TAG v3.1.0
  74. - GIT_SHALLOW TRUE
  75. - CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
  76. - -DCMAKE_TOOLCHAIN_FILE=${TOOLCHAIN_FILE}
  77. - -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
  78. - -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
  79. - -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}
  80. - -DCMAKE_POSITION_INDEPENDENT_CODE=ON
  81. - -DZYDIS_BUILD_SHARED_LIB=OFF
  82. - -DZYDIS_BUILD_EXAMPLES=OFF
  83. - -DZYDIS_BUILD_TOOLS=OFF
  84. - INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install && ${CMAKE_COMMAND} --build zycore --target install
  85. - )
  86. - file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/include)
  87. - add_library(Zydis STATIC IMPORTED)
  88. - set_property(TARGET Zydis PROPERTY IMPORTED_LOCATION ${CMAKE_BINARY_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}Zydis${CMAKE_STATIC_LIBRARY_SUFFIX})
  89. - set_property(TARGET Zydis PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_BINARY_DIR}/include)
  90. - list(APPEND FUNCHOOK_DEPS Zydis)
  91. + find_package(Zycore REQUIRED)
  92. + find_package(Zydis REQUIRED)
  93. + list(APPEND FUNCHOOK_DEPS Zydis::Zydis)
  94. + list(APPEND FUNCHOOK_DEPS Zycore::Zycore)
  95. set(DISASM Zydis)
  96. endif ()
  97. @@ -180,15 +125,9 @@ configure_file(src/cmake_config.h.in config.h)
  98. function (add_funchook_library target_name target_type)
  99. add_library(${target_name} ${target_type} ${FUNCHOOK_SOURCES})
  100. - if (DISASM_ZYDIS)
  101. - add_dependencies(${target_name} Zydis_src)
  102. - endif ()
  103. set_target_properties(${target_name} PROPERTIES ${FUNCHOOK_PROPERTIES})
  104. target_include_directories(${target_name} PUBLIC include)
  105. target_include_directories(${target_name} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) # to include config.h
  106. - if (DISASM_CAPSTONE)
  107. - target_include_directories(${target_name} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/capstone-src/include)
  108. - endif()
  109. target_link_libraries(${target_name} PRIVATE ${FUNCHOOK_DEPS})
  110. if (HAVE_FVISIBILITY_HIDDEN)
  111. target_compile_options(${target_name} PRIVATE -fvisibility=hidden)
  112. @@ -206,10 +145,28 @@ if (FUNCHOOK_BUILD_SHARED)
  113. if (MSVC)
  114. set_target_properties(funchook-shared PROPERTIES IMPORT_SUFFIX _dll.lib)
  115. endif ()
  116. + if (DISASM_DISTORM)
  117. + find_package(PkgConfig REQUIRED)
  118. + pkg_check_modules(DISTORM REQUIRED distorm)
  119. + target_include_directories(funchook-shared PRIVATE ${DISTORM_INCLUDE_DIRS}/distorm)
  120. + target_link_directories(funchook-shared PRIVATE ${DISTORM_LIBRARY_DIRS})
  121. + target_link_libraries(funchook-shared PRIVATE ${DISTORM_LIBRARIES})
  122. + target_compile_options(funchook-shared PRIVATE ${DISTORM_CFLAGS})
  123. + target_link_options(funchook-shared PRIVATE ${DISTORM_LDFLAGS})
  124. + endif ()
  125. endif ()
  126. if (FUNCHOOK_BUILD_STATIC)
  127. add_funchook_library(funchook-static STATIC)
  128. + if (DISASM_DISTORM)
  129. + find_package(PkgConfig REQUIRED)
  130. + pkg_check_modules(DISTORM REQUIRED distorm)
  131. + target_include_directories(funchook-static PRIVATE ${DISTORM_INCLUDE_DIRS}/distorm)
  132. + target_link_directories(funchook-static PRIVATE ${DISTORM_LIBRARY_DIRS})
  133. + target_link_libraries(funchook-static PRIVATE ${DISTORM_LIBRARIES})
  134. + target_compile_options(funchook-static PRIVATE ${DISTORM_CFLAGS})
  135. + target_link_options(funchook-static PRIVATE ${DISTORM_LDFLAGS})
  136. + endif ()
  137. endif ()
  138. #
  139. --
  140. 2.49.0