我在CMake上有自定义包装器,它为各种平台(win32,SunOS等)和不同的编译器执行配置,编译和创建分发。我需要将所有需要的运行时库(libgcc_s.so,libstdc ++。所以用于* nix,如OS .msvcr90.dll,msvcp100.dll for win32)放入。例如,gcc具有机制,允许获取这些库的全名:
# 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
所以我需要msvc(2008,2010)的类似机制,这可能吗? (它可以是给定编译器的环境变量,也可以是注册表值,或者是smth else)。或者可能有一些获取此类信息的CMake机制。
答案 0 :(得分:4)
您可以将InstallRequiredSystemLibraries cmake-module.用于CMake,它会将msvc dll(和清单)添加到您的cmake-install目标。
作为替代方案,您可以编写自己的小cmake代码,检查注册表中已安装的Visual Studio版本并找到vcredist。然后,您可以将vcredist软件包添加到您自己的发行版中,并将其安装“安装”到您自己的安装程序中。
E.g。类似下面的内容将搜索vcredist_2010并将其添加到NSIS安装程序:
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 )