How to get location of needed runtime libraries for msvc

别说谁变了你拦得住时间么 提交于 2019-12-02 08:58:24

You could use the InstallRequiredSystemLibraries cmake-module. for CMake which will add the msvc dlls (and manifests) to your cmake-install target.

As an alternative, you could write your own little cmake code which checks the registry for installed visual studio versions and finds the vcredist. You could then add the vcredist package to your own distribution and "slipstream" its installation in your own installer.

E.g. something like the following will search for vcredist_2010 and add it to the NSIS installer:

if(CMAKE_CL_64)
     set(CMAKE_MSVC_ARCH amd64)
   else(CMAKE_CL_64)
     set(CMAKE_MSVC_ARCH x86)
endif(CMAKE_CL_64)

# Try and find the vcredist_XX.exe, normally this is in the WindowsSDK folder.
if( MSVC10 )
    find_program(MSVC_REDIST NAMES VC/vcredist_${CMAKE_MSVC_ARCH}.exe
        PATHS
        "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v7.1;InstallationFolder]/Redist/"               
        )
        get_filename_component(vcredist_name "${MSVC_REDIST}" NAME)
endif( MSVC10 )

# If we found a vcredist-package, we add it simply to the 
# installation-folder and run it with NSis.
if( vcredist_name )
    message( STATUS "    Adding " ${vcredist_name} " to Install" )
    install(PROGRAMS ${MSVC_REDIST} COMPONENT System DESTINATION bin)
    # Add /q to make the vcredist install silent
    set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "ExecWait '\\\"$INSTDIR\\\\bin\\\\${vcredist_name}\\\" /q'" )
endif( vcredist_name )
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!