set(MSVC_DEFAULT_FLAGS
  /D_CRT_SECURE_NO_WARNINGS 
  /Wall 
  /WX 
  /MP 
  /GS 
  /GF 
  /GR 
  /EHsc 
  /fp:fast 
  /fp:except- 
  /utf-8 
  /bigobj 
  /nologo
)
if(GENERATE_ASM_LISTING)
set(MSVC_DEFAULT_FLAGS ${MSVC_DEFAULT_FLAGS} /FAs /Fa$(IntDir))
endif()
string(REPLACE ";" " " MSVC_DEFAULT_FLAGS "${MSVC_DEFAULT_FLAGS}")

set(MSVC_OPTIMIZED_FLAGS
  /D_SECURE_SCL=0 
  /D_SCL_SECURE_NO_WARNINGS 
  /D_ITERATOR_DEBUG_LEVEL=0 
  /D_HAS_ITERATOR_DEBUGGING=0 
  /Ox 
  /Ob2 
  /Ot 
  /Oi 
  /Oy- 
  /GT 
  /GL
)
if(BUILD_SHARED)
set(MSVC_OPTIMIZED_FLAGS ${MSVC_OPTIMIZED_FLAGS} /MD)
else()
set(MSVC_OPTIMIZED_FLAGS ${MSVC_OPTIMIZED_FLAGS} /MT)
endif()
string(REPLACE ";" " " MSVC_OPTIMIZED_FLAGS "${MSVC_OPTIMIZED_FLAGS}")

set(MSVC_DEBUG_FLAGS
  /Od
  /Ob0 
  /ZI 
  /RTC1
)
if(BUILD_SHARED)
set(MSVC_OPTIMIZED_FLAGS ${MSVC_OPTIMIZED_FLAGS} /MDd)
else()
set(MSVC_OPTIMIZED_FLAGS ${MSVC_OPTIMIZED_FLAGS} /MTd)
endif()
string(REPLACE ";" " " MSVC_DEBUG_FLAGS "${MSVC_DEBUG_FLAGS}")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MSVC_DEFAULT_FLAGS}" CACHE INTERNAL "" FORCE)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${MSVC_DEBUG_FLAGS}" CACHE INTERNAL "" FORCE)
set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${MSVC_OPTIMIZED_FLAGS}" CACHE INTERNAL "" FORCE)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${MSVC_OPTIMIZED_FLAGS} /Oy" CACHE INTERNAL "" FORCE)

set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /DEBUG:FULL" CACHE INTERNAL "" FORCE)
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /DEBUG:FULL" CACHE INTERNAL "" FORCE)
set(CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG} /DEBUG:FULL" CACHE INTERNAL "" FORCE)
set(CMAKE_STATIC_LINKER_FLAGS_DEBUG "${CMAKE_STATIC_LINKER_FLAGS_DEBUG}" CACHE INTERNAL "" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /DEBUG /LTCG /OPT:REF /OPT:ICF=2" CACHE INTERNAL "" FORCE)
set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO} /DEBUG /LTCG /OPT:REF /OPT:ICF=2" CACHE INTERNAL "" FORCE)
set(CMAKE_MODULE_LINKER_FLAGS_PROFILE "${CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO} /DEBUG /LTCG /OPT:REF /OPT:ICF=2" CACHE INTERNAL "" FORCE)
set(CMAKE_STATIC_LINKER_FLAGS_PROFILE "${CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO} /LTCG" CACHE INTERNAL "" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG /OPT:REF /OPT:ICF=2" CACHE INTERNAL "" FORCE)
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /LTCG /OPT:REF /OPT:ICF=2" CACHE INTERNAL "" FORCE)
set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} /LTCG /OPT:REF /OPT:ICF=2" CACHE INTERNAL "" FORCE)
set(CMAKE_STATIC_LINKER_FLAGS_RELEASE "${CMAKE_STATIC_LINKER_FLAGS_RELEASE} /LTCG" CACHE INTERNAL "" FORCE)
