MenüHomeBlogMagic

CMake Visual Studio Redistributables

Wer mit Visual Studio und C++ Software schreibt wird wohl oder übel einmal den Pfad zu den passenden Redistributables brauchen.

Mit Cmake kann man sich die ganz einfach auslesen lassen:

set(CMAKE_INSTALL_DEBUG_LIBRARIES TRUE)
set(CMAKE_INSTALL_UCRT_LIBRARIES  TRUE)
include(InstallRequiredSystemLibraries)

if(MSVC_CRT_DIR)
  message("Visual Studio runtimes found at ${MSVC_CRT_DIR}")
  set(CURRENT_REDISTS ${MSVC_CRT_DIR}/../../..)
endif()

Im Anschluss kann man die redists z.B. in die notwendigen Verzeichnisse kopieren.

if(MSVC_CRT_DIR)
  message("Visual Studio runtimes found at ${MSVC_CRT_DIR}")
  file(COPY "${MSVC_CRT_DIR}/vcruntime140d.dll"                         ${TARGET_DIR})
  file(COPY "${MSVC_CRT_DIR}/vccorlib140d.dll"                          ${TARGET_DIR})
  file(COPY "${MSVC_CRT_DIR}/msvcp140d.dll"                             ${TARGET_DIR})
  file(COPY "${MSVC_CRT_DIR}/concrt140d.dll"                            ${TARGET_DIR})
  file(COPY "${MSVC_CRT_DIR}/../Microsoft.VC141.DebugMFC/mfc140ud.dll"  ${TARGET_DIR})
  if(WINDOWS_KITS_DIR)
    file(COPY "${WINDOWS_KITS_DIR}/bin/x64/ucrt/ucrtbased.dll"          ${TARGET_DIR})
  endif()
endif()

Wenn man den Pfad hat könnte man diese auch dem install Prozess hinzufügen.