问题
I have custom wrapper over CMake, which perform configuring, compilation, and creating distrib for various platforms (win32, SunOS and so on) and different compilers. I need to put into distrib all needed runtime libraries (libgcc_s.so, libstdc++.so for *nix like OS. msvcr90.dll, msvcp100.dll for win32). For example, gcc has mechanism, which allows to get full names of these libraries:
# get location of libgcc_s of default compiler
bash-3.2$ g++ -print-file-name=libgcc_s.so
/usr/local/lib/gcc/sparc-sun-solaris2.10/3.4.6/../../../libgcc_s.so
# get location of libstdc++ of custom compiler
bash-3.2$ g++-4.5.3 -print-file-name=libstdc++.so
/u/gccbuild/installed/gcc-4.5.3/lib/gcc/sparc-sun-solaris2.10/4.5.3/../../../libstdc++.so
So i need similar mechanism for msvc (2008, 2010), is this possible? (It can be environment variable for given compiler, or registry value, or smth else). Or maybe there is some CMake mechanism for obtaining such information.
回答1:
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 )
来源:https://stackoverflow.com/questions/13577979/how-to-get-location-of-needed-runtime-libraries-for-msvc