CMake generate Visual Studio 2008 solution for Win

2019-01-28 12:08发布

I am using CMake 2.8 under Windows XP and want to generate a Visual Studio 2008 solution file which contains Release and Debug configurations for both Win32 and x64.

Can this be done by setting a CMake configuration variable in the CMakeLists.txt file?

3条回答
三岁会撩人
2楼-- · 2019-01-28 12:19

The CMakeLists is not where you specify the generator ( makefile, XCode, Visual Studio ) for a project. The generator is specified when a user runs CMake on your source.

查看更多
来,给爷笑一个
3楼-- · 2019-01-28 12:27

You should produce a solution file under a console with CMake.exe.

CMake -G "Visual Studio 9 2008" (The directory which contains your CMakeLists.txt file)// This is for X86.

CMake -G "Visual Studio 9 2008 Win64" (The directory which contains your CMakeLists.txt file)// This is for X64.

查看更多
小情绪 Triste *
4楼-- · 2019-01-28 12:39

You should definitely use batch scripts to automate these kind of processes. I share simplified version of my own builder script with you. My own environment is much more complicated hence I wrote this script for you for using easily.

Its usage is pretty basic.

builder . -64bit -Debug

Means source code is in the current directory and compilation configuration is 64bit Debug version.

You only need to change global configuration variables in the script which point visual studio directory and cmake directory.

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 on
查看更多
登录 后发表回答