我在Windows XP下使用的是CMake 2.8,我想生成一个Visual Studio2008解决方案文件,其中包含Win32和x64的发布和调试配置。
这可以通过在CMakeLists.txt文件中设置CMake配置变量来实现吗?
发布于 2010-09-24 23:12:56
CMakeLists不是为项目指定生成器( makefile、XCode、Visual Studio )的地方。生成器是在用户在源代码上运行CMake时指定的。
发布于 2013-02-04 09:28:50
您应该使用CMake.exe在控制台下生成一个解决方案文件。
CMake -G "Visual Studio9 2008“(包含CMakeLists.txt文件的目录)//这是针对X86的。
CMake -G "Visual Studio9 2008 Win64“(包含CMakeLists.txt文件的目录)//这是针对X64的。
发布于 2014-10-24 13:49:46
您绝对应该使用批处理脚本来自动化这些类型的过程。我与你分享我自己的构建器脚本的简化版本。我自己的环境要复杂得多,所以我为你写了这个脚本,以便于使用。
它的用法非常简单。
builder . -64bit -Debug表示源代码在当前目录下,编译配置为64位Debug版本。
您只需更改脚本中指向visual studio目录和cmake目录的全局配置变量。
SET VISUAL_STUDIO_9_HOME=
SET CMAKE_HOME=
@echo off
rem ===== Usage
rem builder c:\workspace\project1 -32bit -Release
rem builder . -64bit -Debug
rem Global configuration variables. Should be update based on your system
SET VISUAL_STUDIO_9_HOME=c:\Program Files\Microsoft Visual Studio 9.0
SET CMAKE_HOME=c:\Documents and Settings\stumk\My Documents\toolkit\cmake
rem First parameter is project folder path
SET PROJECT_DIR=%1
rem Add executables into path
rem Only add them once
if NOT DEFINED SETENV  SET SETENV=0
if %SETENV% EQU 0 SET PATH=%CMAKE_HOME%\bin;%VISUAL_STUDIO_9_HOME%\Common7\Tools;%PATH%
SET SETENV=1
rem Go to project director
cd %PROJECT_DIR%
rem Create build folder, don't mess the source code with visual studio project files
md build
rem Go to build folder
cd build\
   rem Set visual studio environment variables
   call vsvars32.bat 
   rem Second parameter defines 32 bit or 64 bit compilation
   if "%2"=="-32bit" (
       cmake.exe .. -G "Visual Studio 9 2008"
   )
   if "%2"=="-64bit" (
       cmake.exe .. -G "Visual Studio 9 2008 Win64"
   )
   rem Third parameter defines debug or release compilation
   if "%3"=="-Debug" (
           cmake.exe --build . --target ALL_BUILD --config Debug
   )
   if "%3"=="-Release" (
           cmake.exe --build . --target ALL_BUILD --config Release
   )
   rem Go to source code directory and finalize script
   cd ..
@echo onhttps://stackoverflow.com/questions/3785976
复制相似问题