From c692ff0f16574f73dce6fa142690a5adea990ec5 Mon Sep 17 00:00:00 2001 From: "5684185+vsariola@users.noreply.github.com" <5684185+vsariola@users.noreply.github.com> Date: Sat, 2 Sep 2023 22:33:48 +0300 Subject: [PATCH] build: allow optional use of Crinkler when linking examples --- examples/code/CMakeLists.txt | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/examples/code/CMakeLists.txt b/examples/code/CMakeLists.txt index 3176713..a5eb0f8 100644 --- a/examples/code/CMakeLists.txt +++ b/examples/code/CMakeLists.txt @@ -1,3 +1,32 @@ +if(("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4") AND MSVC) + # in 32-bit mode with MSVC toolset, we can use Crinkler to compress the executable + set(CRINKLER_LEVEL "off" CACHE STRING "Crinkler compression level: off, light, medium, heavy") + + if(NOT CRINKLER_LEVEL STREQUAL OFF) + find_program(CRINKLER NAMES Crinkler) + if (NOT CRINKLER) + message(WARNING "Crinkler not found. Cannot compress executable; using default linker. Get Crinkler from https://github.com/runestubbe/Crinkler & put it in path (as Crinkler.exe)") + set(CRINKLER_LEVEL OFF) + endif() + endif() + + if (NOT CRINKLER_LEVEL STREQUAL OFF) + message(STATUS "Crinkler found at: ${CRINKLER}") + set(CRINKLER_FLAGS "/PROGRESSGUI /UNSAFEIMPORT /UNALIGNCODE /HASHSIZE:1000 /REPORT:.report.html") + # TBD: do we add /SATURATE + if (CRINKLER_LEVEL STREQUAL LIGHT) + set(CRINKLER_FLAGS "${CRINKLER_FLAGS} /HASHTRIES:100 /COMPMODE:INSTANT /ORDERTRIES:2000") + elseif (CRINKLER_LEVEL STREQUAL HEAVY) + set(CRINKLER_FLAGS "${CRINKLER_FLAGS} /HASHTRIES:1000 /COMPMODE:VERYSLOW /ORDERTRIES:30000") + else() + set(CRINKLER_FLAGS "${CRINKLER_FLAGS} /HASHTRIES:300 /COMPMODE:SLOW /ORDERTRIES:9000") + endif() + + # we drop the whole manifest creation from the front; did not find a way to disable it from CMake otherwise + set (CMAKE_C_LINK_EXECUTABLE "${CRINKLER} /out: ${CRINKLER_FLAGS} ") + endif() +endif() + set_directory_properties(PROPERTIES EXCLUDE_FROM_ALL ON) add_custom_target(examples)