From dbdb880af976b82f6530de5753b84cfa53c985c8 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 23 Mar 2017 10:14:50 -0400 Subject: InstallRequiredSystemLibraries: Split VS IDE and DLL versions Refactor MSVC logic to split the IDE and DLL version variables. --- Modules/InstallRequiredSystemLibraries.cmake | 152 +++++++++++++++------------ 1 file changed, 86 insertions(+), 66 deletions(-) diff --git a/Modules/InstallRequiredSystemLibraries.cmake b/Modules/InstallRequiredSystemLibraries.cmake index 67dfe8f..d19d030 100644 --- a/Modules/InstallRequiredSystemLibraries.cmake +++ b/Modules/InstallRequiredSystemLibraries.cmake @@ -167,48 +167,54 @@ if(MSVC) endif() if(MSVC_VERSION EQUAL 1900 OR MSVC_VERSION EQUAL 1910) - set(_MSVCRT_VERSION 14) + set(_MSVCRT_DLL_VERSION 140) + set(_MSVCRT_IDE_VERSION 14) elseif(MSVC_VERSION EQUAL 1800) - set(_MSVCRT_VERSION 12) + set(_MSVCRT_DLL_VERSION 120) + set(_MSVCRT_IDE_VERSION 12) elseif(MSVC_VERSION EQUAL 1700) - set(_MSVCRT_VERSION 11) + set(_MSVCRT_DLL_VERSION 110) + set(_MSVCRT_IDE_VERSION 11) elseif(MSVC_VERSION EQUAL 1600) - set(_MSVCRT_VERSION 10) + set(_MSVCRT_DLL_VERSION 100) + set(_MSVCRT_IDE_VERSION 10) else() - set(_MSVCRT_VERSION "") + set(_MSVCRT_DLL_VERSION "") + set(_MSVCRT_IDE_VERSION "") endif() - if(_MSVCRT_VERSION) - set(v "${_MSVCRT_VERSION}") + if(_MSVCRT_DLL_VERSION) + set(v "${_MSVCRT_DLL_VERSION}") + set(vs "${_MSVCRT_IDE_VERSION}") # Find the runtime library redistribution directory. get_filename_component(msvc_install_dir - "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\${v}.0;InstallDir]" ABSOLUTE) + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\${vs}.0;InstallDir]" ABSOLUTE) set(programfilesx86 "ProgramFiles(x86)") - if(DEFINED MSVC${v}_REDIST_DIR AND EXISTS "${MSVC${v}_REDIST_DIR}") - set(MSVC_REDIST_DIR "${MSVC${v}_REDIST_DIR}") # use old cache entry + if(DEFINED MSVC${vs}_REDIST_DIR AND EXISTS "${MSVC${vs}_REDIST_DIR}") + set(MSVC_REDIST_DIR "${MSVC${vs}_REDIST_DIR}") # use old cache entry endif() - find_path(MSVC_REDIST_DIR NAMES ${CMAKE_MSVC_ARCH}/Microsoft.VC${v}0.CRT + find_path(MSVC_REDIST_DIR NAMES ${CMAKE_MSVC_ARCH}/Microsoft.VC${vs}0.CRT PATHS "${msvc_install_dir}/../../VC/redist" "${base_dir}/VC/redist" - "$ENV{ProgramFiles}/Microsoft Visual Studio ${v}.0/VC/redist" - "$ENV{${programfilesx86}}/Microsoft Visual Studio ${v}.0/VC/redist" + "$ENV{ProgramFiles}/Microsoft Visual Studio ${vs}.0/VC/redist" + "$ENV{${programfilesx86}}/Microsoft Visual Studio ${vs}.0/VC/redist" ) mark_as_advanced(MSVC_REDIST_DIR) - set(MSVC_CRT_DIR "${MSVC_REDIST_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.VC${v}0.CRT") + set(MSVC_CRT_DIR "${MSVC_REDIST_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.VC${vs}0.CRT") if(NOT CMAKE_INSTALL_DEBUG_LIBRARIES_ONLY) set(__install__libs - "${MSVC_CRT_DIR}/msvcp${v}0.dll" + "${MSVC_CRT_DIR}/msvcp${v}.dll" ) - if(NOT v VERSION_LESS 14) + if(NOT vs VERSION_LESS 14) list(APPEND __install__libs - "${MSVC_CRT_DIR}/vcruntime${v}0.dll" - "${MSVC_CRT_DIR}/concrt${v}0.dll" + "${MSVC_CRT_DIR}/vcruntime${v}.dll" + "${MSVC_CRT_DIR}/concrt${v}.dll" ) else() - list(APPEND __install__libs "${MSVC_CRT_DIR}/msvcr${v}0.dll") + list(APPEND __install__libs "${MSVC_CRT_DIR}/msvcr${v}.dll") endif() else() set(__install__libs) @@ -216,21 +222,21 @@ if(MSVC) if(CMAKE_INSTALL_DEBUG_LIBRARIES) set(MSVC_CRT_DIR - "${MSVC_REDIST_DIR}/Debug_NonRedist/${CMAKE_MSVC_ARCH}/Microsoft.VC${v}0.DebugCRT") + "${MSVC_REDIST_DIR}/Debug_NonRedist/${CMAKE_MSVC_ARCH}/Microsoft.VC${vs}0.DebugCRT") set(__install__libs ${__install__libs} - "${MSVC_CRT_DIR}/msvcp${v}0d.dll" + "${MSVC_CRT_DIR}/msvcp${v}d.dll" ) - if(NOT v VERSION_LESS 14) + if(NOT vs VERSION_LESS 14) list(APPEND __install__libs - "${MSVC_CRT_DIR}/vcruntime${v}0d.dll" - "${MSVC_CRT_DIR}/concrt${v}0d.dll" + "${MSVC_CRT_DIR}/vcruntime${v}d.dll" + "${MSVC_CRT_DIR}/concrt${v}d.dll" ) else() - list(APPEND __install__libs "${MSVC_CRT_DIR}/msvcr${v}0d.dll") + list(APPEND __install__libs "${MSVC_CRT_DIR}/msvcr${v}d.dll") endif() endif() - if(CMAKE_INSTALL_UCRT_LIBRARIES AND NOT v VERSION_LESS 14) + if(CMAKE_INSTALL_UCRT_LIBRARIES AND NOT vs VERSION_LESS 14) # Find the Windows Kits directory. get_filename_component(windows_kits_dir "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;KitsRoot10]" ABSOLUTE) @@ -357,19 +363,25 @@ if(MSVC) endif() if(MSVC_VERSION EQUAL 1900 OR MSVC_VERSION EQUAL 1910) - set(_MFC_VERSION 14) + set(_MFC_DLL_VERSION 140) + set(_MFC_IDE_VERSION 14) elseif(MSVC_VERSION EQUAL 1800) - set(_MFC_VERSION 12) + set(_MFC_DLL_VERSION 120) + set(_MFC_IDE_VERSION 12) elseif(MSVC_VERSION EQUAL 1700) - set(_MFC_VERSION 11) + set(_MFC_DLL_VERSION 110) + set(_MFC_IDE_VERSION 11) elseif(MSVC_VERSION EQUAL 1600) - set(_MFC_VERSION 10) + set(_MFC_DLL_VERSION 100) + set(_MFC_IDE_VERSION 10) else() - set(_MFC_VERSION "") + set(_MFC_DLL_VERSION "") + set(_MFC_IDE_VERSION "") endif() - if(_MFC_VERSION) - set(v "${_MFC_VERSION}") + if(_MFC_DLL_VERSION) + set(v "${_MFC_DLL_VERSION}") + set(vs "${_MFC_IDE_VERSION}") # Multi-Byte Character Set versions of MFC are available as optional # addon since Visual Studio 12. So for version 12 or higher, check @@ -377,46 +389,46 @@ if(MSVC) if(CMAKE_INSTALL_DEBUG_LIBRARIES) set(MSVC_MFC_DIR - "${MSVC_REDIST_DIR}/Debug_NonRedist/${CMAKE_MSVC_ARCH}/Microsoft.VC${v}0.DebugMFC") + "${MSVC_REDIST_DIR}/Debug_NonRedist/${CMAKE_MSVC_ARCH}/Microsoft.VC${vs}0.DebugMFC") set(__install__libs ${__install__libs} - "${MSVC_MFC_DIR}/mfc${v}0ud.dll" - "${MSVC_MFC_DIR}/mfcm${v}0ud.dll" + "${MSVC_MFC_DIR}/mfc${v}ud.dll" + "${MSVC_MFC_DIR}/mfcm${v}ud.dll" ) - if("${v}" LESS 12 OR EXISTS "${MSVC_MFC_DIR}/mfc${v}0d.dll") + if("${v}" LESS 12 OR EXISTS "${MSVC_MFC_DIR}/mfc${v}d.dll") set(__install__libs ${__install__libs} - "${MSVC_MFC_DIR}/mfc${v}0d.dll" - "${MSVC_MFC_DIR}/mfcm${v}0d.dll" + "${MSVC_MFC_DIR}/mfc${v}d.dll" + "${MSVC_MFC_DIR}/mfcm${v}d.dll" ) endif() endif() - set(MSVC_MFC_DIR "${MSVC_REDIST_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.VC${v}0.MFC") + set(MSVC_MFC_DIR "${MSVC_REDIST_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.VC${vs}0.MFC") if(NOT CMAKE_INSTALL_DEBUG_LIBRARIES_ONLY) set(__install__libs ${__install__libs} - "${MSVC_MFC_DIR}/mfc${v}0u.dll" - "${MSVC_MFC_DIR}/mfcm${v}0u.dll" + "${MSVC_MFC_DIR}/mfc${v}u.dll" + "${MSVC_MFC_DIR}/mfcm${v}u.dll" ) - if("${v}" LESS 12 OR EXISTS "${MSVC_MFC_DIR}/mfc${v}0.dll") + if("${v}" LESS 12 OR EXISTS "${MSVC_MFC_DIR}/mfc${v}.dll") set(__install__libs ${__install__libs} - "${MSVC_MFC_DIR}/mfc${v}0.dll" - "${MSVC_MFC_DIR}/mfcm${v}0.dll" + "${MSVC_MFC_DIR}/mfc${v}.dll" + "${MSVC_MFC_DIR}/mfcm${v}.dll" ) endif() endif() # include the language dll's as well as the actuall dll's - set(MSVC_MFCLOC_DIR "${MSVC_REDIST_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.VC${v}0.MFCLOC") + set(MSVC_MFCLOC_DIR "${MSVC_REDIST_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.VC${vs}0.MFCLOC") set(__install__libs ${__install__libs} - "${MSVC_MFCLOC_DIR}/mfc${v}0chs.dll" - "${MSVC_MFCLOC_DIR}/mfc${v}0cht.dll" - "${MSVC_MFCLOC_DIR}/mfc${v}0deu.dll" - "${MSVC_MFCLOC_DIR}/mfc${v}0enu.dll" - "${MSVC_MFCLOC_DIR}/mfc${v}0esn.dll" - "${MSVC_MFCLOC_DIR}/mfc${v}0fra.dll" - "${MSVC_MFCLOC_DIR}/mfc${v}0ita.dll" - "${MSVC_MFCLOC_DIR}/mfc${v}0jpn.dll" - "${MSVC_MFCLOC_DIR}/mfc${v}0kor.dll" - "${MSVC_MFCLOC_DIR}/mfc${v}0rus.dll" + "${MSVC_MFCLOC_DIR}/mfc${v}chs.dll" + "${MSVC_MFCLOC_DIR}/mfc${v}cht.dll" + "${MSVC_MFCLOC_DIR}/mfc${v}deu.dll" + "${MSVC_MFCLOC_DIR}/mfc${v}enu.dll" + "${MSVC_MFCLOC_DIR}/mfc${v}esn.dll" + "${MSVC_MFCLOC_DIR}/mfc${v}fra.dll" + "${MSVC_MFCLOC_DIR}/mfc${v}ita.dll" + "${MSVC_MFCLOC_DIR}/mfc${v}jpn.dll" + "${MSVC_MFCLOC_DIR}/mfc${v}kor.dll" + "${MSVC_MFCLOC_DIR}/mfc${v}rus.dll" ) endif() endif() @@ -425,24 +437,32 @@ if(MSVC) # Furthermore, there is no debug version of this if(CMAKE_INSTALL_OPENMP_LIBRARIES) if(MSVC_VERSION EQUAL 1900 OR MSVC_VERSION EQUAL 1910) - set(_MSOMP_VERSION 140) + set(_MSOMP_DLL_VERSION 140) + set(_MSOMP_IDE_VERSION 14) elseif(MSVC_VERSION EQUAL 1800) - set(_MSOMP_VERSION 120) + set(_MSOMP_DLL_VERSION 120) + set(_MSOMP_IDE_VERSION 12) elseif(MSVC_VERSION EQUAL 1700) - set(_MSOMP_VERSION 110) + set(_MSOMP_DLL_VERSION 110) + set(_MSOMP_IDE_VERSION 11) elseif(MSVC_VERSION EQUAL 1600) - set(_MSOMP_VERSION 100) + set(_MSOMP_DLL_VERSION 100) + set(_MSOMP_IDE_VERSION 10) elseif(MSVC_VERSION EQUAL 1500) - set(_MSOMP_VERSION 90) + set(_MSOMP_DLL_VERSION 90) + set(_MSOMP_IDE_VERSION 9) elseif(MSVC_VERSION EQUAL 1400) - set(_MSOMP_VERSION 80) + set(_MSOMP_DLL_VERSION 80) + set(_MSOMP_IDE_VERSION 8) else() - set(_MSOMP_VERSION "") + set(_MSOMP_DLL_VERSION "") + set(_MSOMP_IDE_VERSION "") endif() - if(_MSOMP_VERSION) - set(v "${_MSOMP_VERSION}") - set(MSVC_OPENMP_DIR "${MSVC_REDIST_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.VC${v}.OPENMP") + if(_MSOMP_DLL_VERSION) + set(v "${_MSOMP_DLL_VERSION}") + set(vs "${_MSOMP_IDE_VERSION}") + set(MSVC_OPENMP_DIR "${MSVC_REDIST_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.VC${vs}0.OPENMP") if(NOT CMAKE_INSTALL_DEBUG_LIBRARIES_ONLY) set(__install__libs ${__install__libs} -- cgit v0.12 From 5ed4e48128837df0539cb1570c954e2872256930 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 23 Mar 2017 10:26:52 -0400 Subject: InstallRequiredSystemLibraries: Split MFC redist dir variable --- Modules/InstallRequiredSystemLibraries.cmake | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Modules/InstallRequiredSystemLibraries.cmake b/Modules/InstallRequiredSystemLibraries.cmake index d19d030..2ff2f06 100644 --- a/Modules/InstallRequiredSystemLibraries.cmake +++ b/Modules/InstallRequiredSystemLibraries.cmake @@ -383,13 +383,15 @@ if(MSVC) set(v "${_MFC_DLL_VERSION}") set(vs "${_MFC_IDE_VERSION}") + set(MSVC_REDIST_MFC_DIR "${MSVC_REDIST_DIR}") + # Multi-Byte Character Set versions of MFC are available as optional # addon since Visual Studio 12. So for version 12 or higher, check # whether they are available and exclude them if they are not. if(CMAKE_INSTALL_DEBUG_LIBRARIES) set(MSVC_MFC_DIR - "${MSVC_REDIST_DIR}/Debug_NonRedist/${CMAKE_MSVC_ARCH}/Microsoft.VC${vs}0.DebugMFC") + "${MSVC_REDIST_MFC_DIR}/Debug_NonRedist/${CMAKE_MSVC_ARCH}/Microsoft.VC${vs}0.DebugMFC") set(__install__libs ${__install__libs} "${MSVC_MFC_DIR}/mfc${v}ud.dll" "${MSVC_MFC_DIR}/mfcm${v}ud.dll" @@ -402,7 +404,7 @@ if(MSVC) endif() endif() - set(MSVC_MFC_DIR "${MSVC_REDIST_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.VC${vs}0.MFC") + set(MSVC_MFC_DIR "${MSVC_REDIST_MFC_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.VC${vs}0.MFC") if(NOT CMAKE_INSTALL_DEBUG_LIBRARIES_ONLY) set(__install__libs ${__install__libs} "${MSVC_MFC_DIR}/mfc${v}u.dll" @@ -417,7 +419,7 @@ if(MSVC) endif() # include the language dll's as well as the actuall dll's - set(MSVC_MFCLOC_DIR "${MSVC_REDIST_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.VC${vs}0.MFCLOC") + set(MSVC_MFCLOC_DIR "${MSVC_REDIST_MFC_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.VC${vs}0.MFCLOC") set(__install__libs ${__install__libs} "${MSVC_MFCLOC_DIR}/mfc${v}chs.dll" "${MSVC_MFCLOC_DIR}/mfc${v}cht.dll" -- cgit v0.12 From d4a693a08385024175240a5543cc2a7bb7311966 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 23 Mar 2017 10:30:14 -0400 Subject: InstallRequiredSystemLibraries: Add support for VS 2017 VS 2017 (VS 15) places its redist DLLs in `Microsoft.VC150.*` directories but still uses version number `140` in the DLL names. The redist directories now have version numbers in their name, and the MSVC and MFC runtime DLLs may be in directories with different versions. Fill out our logic to handle this. For now assume we are given the `MSVC_REDIST_DIR` value as a cache entry. Unfortunately we cannot yet find the VS 2017 MSVC redist directory automatically since there is no registry entry for the VS installation. Later we will have to use `cmVSSetupHelper` for this. Issue: #16735 --- Modules/InstallRequiredSystemLibraries.cmake | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/Modules/InstallRequiredSystemLibraries.cmake b/Modules/InstallRequiredSystemLibraries.cmake index 2ff2f06..1061da0 100644 --- a/Modules/InstallRequiredSystemLibraries.cmake +++ b/Modules/InstallRequiredSystemLibraries.cmake @@ -166,7 +166,10 @@ if(MSVC) endif() endif() - if(MSVC_VERSION EQUAL 1900 OR MSVC_VERSION EQUAL 1910) + if(MSVC_VERSION EQUAL 1910) + set(_MSVCRT_DLL_VERSION 140) + set(_MSVCRT_IDE_VERSION 15) + elseif(MSVC_VERSION EQUAL 1900) set(_MSVCRT_DLL_VERSION 140) set(_MSVCRT_IDE_VERSION 14) elseif(MSVC_VERSION EQUAL 1800) @@ -191,7 +194,7 @@ if(MSVC) get_filename_component(msvc_install_dir "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\${vs}.0;InstallDir]" ABSOLUTE) set(programfilesx86 "ProgramFiles(x86)") - if(DEFINED MSVC${vs}_REDIST_DIR AND EXISTS "${MSVC${vs}_REDIST_DIR}") + if(vs VERSION_LESS 15 AND DEFINED MSVC${vs}_REDIST_DIR AND EXISTS "${MSVC${vs}_REDIST_DIR}") set(MSVC_REDIST_DIR "${MSVC${vs}_REDIST_DIR}") # use old cache entry endif() find_path(MSVC_REDIST_DIR NAMES ${CMAKE_MSVC_ARCH}/Microsoft.VC${vs}0.CRT @@ -362,7 +365,10 @@ if(MSVC) ) endif() - if(MSVC_VERSION EQUAL 1900 OR MSVC_VERSION EQUAL 1910) + if(MSVC_VERSION EQUAL 1910) + set(_MFC_DLL_VERSION 140) + set(_MFC_IDE_VERSION 15) + elseif(MSVC_VERSION EQUAL 1900) set(_MFC_DLL_VERSION 140) set(_MFC_IDE_VERSION 14) elseif(MSVC_VERSION EQUAL 1800) @@ -383,7 +389,16 @@ if(MSVC) set(v "${_MFC_DLL_VERSION}") set(vs "${_MFC_IDE_VERSION}") - set(MSVC_REDIST_MFC_DIR "${MSVC_REDIST_DIR}") + # Starting with VS 15 the MFC DLLs may be in a different directory. + if (NOT vs VERSION_LESS 15) + file(GLOB _MSVC_REDIST_DIRS "${MSVC_REDIST_DIR}/../*") + find_path(MSVC_REDIST_MFC_DIR NAMES ${CMAKE_MSVC_ARCH}/Microsoft.VC${vs}0.MFC + PATHS ${_MSVC_REDIST_DIRS} NO_DEFAULT_PATH) + mark_as_advanced(MSVC_REDIST_MFC_DIR) + unset(_MSVC_REDIST_DIRS) + else() + set(MSVC_REDIST_MFC_DIR "${MSVC_REDIST_DIR}") + endif() # Multi-Byte Character Set versions of MFC are available as optional # addon since Visual Studio 12. So for version 12 or higher, check @@ -438,7 +453,10 @@ if(MSVC) # MSVC 8 was the first version with OpenMP # Furthermore, there is no debug version of this if(CMAKE_INSTALL_OPENMP_LIBRARIES) - if(MSVC_VERSION EQUAL 1900 OR MSVC_VERSION EQUAL 1910) + if(MSVC_VERSION EQUAL 1910) + set(_MSOMP_DLL_VERSION 140) + set(_MSOMP_IDE_VERSION 15) + elseif(MSVC_VERSION EQUAL 1900) set(_MSOMP_DLL_VERSION 140) set(_MSOMP_IDE_VERSION 14) elseif(MSVC_VERSION EQUAL 1800) -- cgit v0.12