From 749823e044e7b697f434648f9b58e600c220d3ce Mon Sep 17 00:00:00 2001 From: KOLANICH Date: Sat, 20 May 2023 11:37:57 +0000 Subject: [PATCH] build: Move `-s` additional compiler flags into linker flags, and enable it only when gcc/clang are used. (#1087) Compiler when compiling doesn't use them in those cases and emit a warning, which is turned into an error by `-Werror`. Unfortunately, CPack doesn't expose the logic it uses for stripping binaries. --- cmake/build_helpers.cmake | 6 +++--- lib/libimhex/CMakeLists.txt | 2 +- main/CMakeLists.txt | 2 +- plugins/windows/CMakeLists.txt | 2 +- tests/algorithms/CMakeLists.txt | 2 +- tests/common/CMakeLists.txt | 2 +- tests/helpers/CMakeLists.txt | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cmake/build_helpers.cmake b/cmake/build_helpers.cmake index ddffa2132..4acbeaab4 100644 --- a/cmake/build_helpers.cmake +++ b/cmake/build_helpers.cmake @@ -1,12 +1,12 @@ include(FetchContent) if(IMHEX_STRIP_RELEASE) - set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -s") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s") - if(CMAKE_BUILD_TYPE STREQUAL "Release") set(CPACK_STRIP_FILES TRUE) endif() + if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") + add_link_options($<$:-s>) + endif() endif() macro(addDefines) diff --git a/lib/libimhex/CMakeLists.txt b/lib/libimhex/CMakeLists.txt index 731555855..0e9445a1e 100644 --- a/lib/libimhex/CMakeLists.txt +++ b/lib/libimhex/CMakeLists.txt @@ -70,4 +70,4 @@ elseif (APPLE) endif () target_link_libraries(libimhex PRIVATE ${FMT_LIBRARIES}) -target_link_libraries(libimhex PUBLIC dl imgui ${NFD_LIBRARIES} magic ${CAPSTONE_LIBRARIES} LLVMDemangle microtar ${NLOHMANN_JSON_LIBRARIES} ${YARA_LIBRARIES} ${LIBCURL_LIBRARIES} ${MBEDTLS_LIBRARIES} ${LIBBACKTRACE_LIBRARIES} libpl ${MINIAUDIO_LIBRARIES} libwolv-utils libwolv-io libwolv-hash libwolv-net libwolv-containers) \ No newline at end of file +target_link_libraries(libimhex PUBLIC dl imgui ${NFD_LIBRARIES} magic ${CAPSTONE_LIBRARIES} LLVMDemangle microtar ${NLOHMANN_JSON_LIBRARIES} ${YARA_LIBRARIES} ${LIBCURL_LIBRARIES} ${MBEDTLS_LIBRARIES} ${LIBBACKTRACE_LIBRARIES} libpl ${MINIAUDIO_LIBRARIES} libwolv-utils libwolv-io libwolv-hash libwolv-net libwolv-containers) diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index d9d89d21c..164942e31 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -39,4 +39,4 @@ endif () if (APPLE) add_compile_definitions(GL_SILENCE_DEPRECATION) -endif () \ No newline at end of file +endif () diff --git a/plugins/windows/CMakeLists.txt b/plugins/windows/CMakeLists.txt index e71e514e2..37e06fff4 100644 --- a/plugins/windows/CMakeLists.txt +++ b/plugins/windows/CMakeLists.txt @@ -44,4 +44,4 @@ if (WIN32) set_target_properties(${LIBROMFS_LIBRARY} PROPERTIES POSITION_INDEPENDENT_CODE ON) target_link_libraries(${PROJECT_NAME} PRIVATE ${LIBROMFS_LIBRARY}) -endif () \ No newline at end of file +endif () diff --git a/tests/algorithms/CMakeLists.txt b/tests/algorithms/CMakeLists.txt index 76681489a..3aa618f48 100644 --- a/tests/algorithms/CMakeLists.txt +++ b/tests/algorithms/CMakeLists.txt @@ -44,4 +44,4 @@ set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAK foreach (test IN LISTS AVAILABLE_TESTS) add_test(NAME "${TEST_CATEGORY}/${test}" COMMAND ${PROJECT_NAME} "${test}" WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) endforeach () -add_dependencies(unit_tests ${PROJECT_NAME}) \ No newline at end of file +add_dependencies(unit_tests ${PROJECT_NAME}) diff --git a/tests/common/CMakeLists.txt b/tests/common/CMakeLists.txt index 7732e00b5..67d5b1435 100644 --- a/tests/common/CMakeLists.txt +++ b/tests/common/CMakeLists.txt @@ -6,4 +6,4 @@ add_library(tests_common STATIC source/main.cpp ) target_include_directories(tests_common PUBLIC include) -target_link_libraries(tests_common PUBLIC libimhex ${FMT_LIBRARIES}) \ No newline at end of file +target_link_libraries(tests_common PUBLIC libimhex ${FMT_LIBRARIES}) diff --git a/tests/helpers/CMakeLists.txt b/tests/helpers/CMakeLists.txt index 64826ad42..ab29ae664 100644 --- a/tests/helpers/CMakeLists.txt +++ b/tests/helpers/CMakeLists.txt @@ -44,4 +44,4 @@ set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAK foreach (test IN LISTS AVAILABLE_TESTS) add_test(NAME "${TEST_CATEGORY}/${test}" COMMAND ${PROJECT_NAME} "${test}" WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) endforeach () -add_dependencies(unit_tests ${PROJECT_NAME}) \ No newline at end of file +add_dependencies(unit_tests ${PROJECT_NAME})