From 962d0dda78ffddc51cbd476ea65a06aade92dfc2 Mon Sep 17 00:00:00 2001 From: Ben Niu <niuben003@gmail.com> Date: Thu, 4 Jul 2019 08:08:32 -0700 Subject: [PATCH] Pass /RELEASE to MSVC linker Without /RELEASE passed to MSVC linker, the checksum field in exe/dll is not calculated. When you load the exe/dll in windbg (e.g., windbg -z libz3.dll), a warning "Unable to verify checksum" will show. With /RELEASE passed to linker, the warning will be gone. --- CMakeLists.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ea5098d7..b1c77910a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -425,6 +425,14 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") include(${PROJECT_SOURCE_DIR}/cmake/msvc_legacy_quirks.cmake) endif() +################################################################################ +# Pass /RELEASE to the linker so that checksums in PE files are calculated. +################################################################################ +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + string(APPEND CMAKE_EXE_LINKER_FLAGS " /RELEASE") + string(APPEND CMAKE_SHARED_LINKER_FLAGS " /RELEASE") +endif() + ################################################################################ # Report default CMake flags ################################################################################