From bd2ace7619821ff63ec7e8c659f802e2616a40ec Mon Sep 17 00:00:00 2001 From: Yuan Yu Date: Wed, 2 Jan 2019 14:50:34 -0800 Subject: [PATCH] Tweak linker flags to minimize the binary size. (#270) --- cmake/CMakeLists.txt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 95c031394f..3cc4d53a40 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -322,7 +322,7 @@ if (WIN32) string(APPEND CMAKE_CXX_FLAGS " /W4") endif() - #only treat warning as error on x64 platform. For x86, right no there are too many warnings to fix + # treat warning as error only on x64 platform. For x86, there are too many warnings to fix. if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND onnxruntime_DEV_MODE) # treat warnings as errors string(APPEND CMAKE_CXX_FLAGS " /WX") @@ -330,6 +330,14 @@ if (WIN32) set(CMAKE_${type}_LINKER_FLAGS "${CMAKE_${type}_LINKER_FLAGS} /WX") endforeach() endif() + + # set linker flags to minimize the binary size. + if (MSVC) + foreach(type EXE SHARED) + set(CMAKE_${type}_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_${type}_LINKER_FLAGS_RELWITHDEBINFO} /OPT:REF") + set(CMAKE_${type}_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_${type}_LINKER_FLAGS_RELWITHDEBINFO} /INCREMENTAL:NO") + endforeach() + endif() else() add_definitions(-DPLATFORM_POSIX) # Enable warning in Linux