From cceadad5c6fa7771f89cdf7f9ab2c945ea5e71b8 Mon Sep 17 00:00:00 2001
From: Martyn Gigg <martyn.gigg@stfc.ac.uk>
Date: Sat, 7 Nov 2015 22:46:34 +0000
Subject: [PATCH] Reactivate tcmalloc for release builds.

---
 buildconfig/CMake/MSVCSetup.cmake | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/buildconfig/CMake/MSVCSetup.cmake b/buildconfig/CMake/MSVCSetup.cmake
index fb1df32dff1..0fca37c9697 100644
--- a/buildconfig/CMake/MSVCSetup.cmake
+++ b/buildconfig/CMake/MSVCSetup.cmake
@@ -61,13 +61,20 @@ set ( PYTHONW_EXECUTABLE "${PYTHON_DIR}/pythonw.exe" CACHE FILEPATH
 ###########################################################################
 # If required, find tcmalloc
 ###########################################################################
-set ( USE_TCMALLOC OFF CACHE BOOL "If true, link with tcmalloc" )
+option ( USE_TCMALLOC "If true, link with tcmalloc" ON )
 # If not wanted, just carry on without it
 if ( USE_TCMALLOC )
-  set ( TCMALLOC_LIBRARIES optimized "${CMAKE_LIBRARY_PATH}/libtcmalloc_minimal.lib" debug "${CMAKE_LIBRARY_PATH}/libtcmalloc_minimal-debug.lib" )
+  # Only link in release configurations. There seems to be problem linking in debug mode
+  set ( TCMALLOC_LIBRARIES optimized "${CMAKE_LIBRARY_PATH}/libtcmalloc_minimal.lib" )
   # Use an alternate variable name so that it is only set on Windows
   set ( TCMALLOC_LIBRARIES_LINKTIME ${TCMALLOC_LIBRARIES})
-  set ( CMAKE_SHARED_LINKER_FLAGS /INCLUDE:"__tcmalloc" )
+  set ( _configs RELEASE RELWITHDEBINFO MINSIZEREL )
+  set ( _targets EXE SHARED )
+  foreach ( _tgt ${_targets})
+    foreach ( _cfg ${_configs})
+      set ( CMAKE_${_tgt}_LINKER_FLAGS_${_cfg} "${CMAKE_${_tgt}_LINKER_FLAGS_${_cfg}} /INCLUDE:__tcmalloc" )
+    endforeach ()
+  endforeach ()
 else ( USE_TCMALLOC )
   message ( STATUS "TCMalloc will not be included." )
 endif ()
-- 
GitLab