diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e3d601d..6c983c66 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -891,13 +891,6 @@ if(MSVC) string(REGEX REPLACE "/Z.[^:]" "/Z7 " CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") string(REGEX REPLACE "/Z.[^:]" "/Z7 " CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") - # Optimization flags. http://msdn.microsoft.com/en-us/magazine/cc301698.aspx - if(NOT ${CMAKE_BUILD_TYPE} MATCHES "Debug") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GL") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LTCG") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /LTCG") - set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /LTCG") - endif() endif() # ----------------------------------------------------------------------------- @@ -1319,6 +1312,27 @@ if(MSVC) VS_GLOBAL_RunCodeAnalysis true) endfunction() if(BUILD_SHARED) + # Whole Program Optimization flags. http://msdn.microsoft.com/en-us/magazine/cc301698.aspx + # + # "Finally, there's the subject of libraries. It's possible to create .LIB + # files with code in its IL form. The linker will happily work with these + # .LIB files. Be aware that these libraries will be tied to a specific + # version of the compiler and linker. If you distribute these libraries, + # you'll need to update them if Microsoft changes the format of IL in a + # future release." + # + # /GL and /LTCG can cause problems when libraries built with different + # versions of compiler are later linked into an executable while /LTCG is active. + # https://social.msdn.microsoft.com/Forums/vstudio/en-US/5c102025-c254-4f02-9a51-c775c6cc9f4b/problem-with-ltcg-when-building-a-static-library-in-vs2005?forum=vcgeneral + # + # For this reason, enable only when building a "Release" (e.g. non-DEBUG) DLL. + if(NOT ${CMAKE_BUILD_TYPE} MATCHES "Debug") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GL") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LTCG") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /LTCG") + set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /LTCG") + endif() + add_library(libzmq SHARED ${sources} ${public_headers} ${html-docs} ${readme-docs} ${CMAKE_CURRENT_BINARY_DIR}/NSIS.template.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc) if(ENABLE_ANALYSIS)