From ac76a3ffd31a29dd10ff07ebf73a998ee0b1fc9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lucas?= Date: Wed, 9 Apr 2025 11:00:04 -0300 Subject: [PATCH] chore: improve momo_strip_target and add unicord-emulator and windows-emulator-test --- cmake/utils.cmake | 47 +++++++++++++----------- src/unicorn-emulator/CMakeLists.txt | 2 + src/windows-emulator-test/CMakeLists.txt | 2 + 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/cmake/utils.cmake b/cmake/utils.cmake index 32aeaa52..9f203554 100644 --- a/cmake/utils.cmake +++ b/cmake/utils.cmake @@ -323,29 +323,34 @@ function(momo_strip_target target) return() endif() - if(NOT MSVC) - # TODO: detect LLVM IR bitcode and abort + if(MSVC) return() - if(NOT DEFINED STRIP_COMMAND) - set(STRIP_COMMAND strip) - endif() - - if(NOT DEFINED STRIP_FLAGS) - set(STRIP_FLAGS -g -s) - if(OSX) - set(STRIP_FLAGS -x) - endif() - endif() - - set(IN_FILE "$") - set(OUT_FILE "$/$$-unstripped$") - - add_custom_command(TARGET ${target} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy ${IN_FILE} ${OUT_FILE} - COMMAND "${STRIP_COMMAND}" ${STRIP_FLAGS} "${IN_FILE}" - COMMENT "Strippping ${target}" - ) endif() + + find_program(STRIP_COMMAND NAMES strip llvm-strip) + if(NOT STRIP_COMMAND) + message(WARNING "strip command not found, target ${target} will not be stripped.") + return() + endif() + + set(STRIP_FLAGS "-s") + + get_property(target_type TARGET ${target} PROPERTY TYPE) + + if(NOT (target_type STREQUAL "EXECUTABLE" OR target_type STREQUAL "SHARED_LIBRARY")) + return() + endif() + + set(TARGET_FILE "$") + + add_custom_command(TARGET ${target} POST_BUILD + COMMAND "${STRIP_COMMAND}" ${STRIP_FLAGS} "${TARGET_FILE}" + COMMAND_EXPAND_LISTS + COMMENT "Stripping ${target}" + VERBATIM + ) + + message(STATUS "Will strip ${target} using ${STRIP_COMMAND} ${STRIP_FLAGS}") endfunction() ########################################## diff --git a/src/unicorn-emulator/CMakeLists.txt b/src/unicorn-emulator/CMakeLists.txt index ad781b7e..8b44e286 100644 --- a/src/unicorn-emulator/CMakeLists.txt +++ b/src/unicorn-emulator/CMakeLists.txt @@ -16,3 +16,5 @@ target_include_directories(unicorn-emulator INTERFACE "${CMAKE_CURRENT_LIST_DIR} target_link_libraries(unicorn-emulator PUBLIC emulator) target_link_libraries(unicorn-emulator PRIVATE unicorn emulator-common) + +momo_strip_target(unicorn-emulator) diff --git a/src/windows-emulator-test/CMakeLists.txt b/src/windows-emulator-test/CMakeLists.txt index e1be9cb7..7bf36845 100644 --- a/src/windows-emulator-test/CMakeLists.txt +++ b/src/windows-emulator-test/CMakeLists.txt @@ -25,3 +25,5 @@ add_test(NAME windows-emulator-test WORKING_DIRECTORY "$") momo_targets_set_folder("tests" windows-emulator-test) + +momo_strip_target(windows-emulator-test)