CMake generate Visual Studio 2008 solution for Win32 and x64

社会主义新天地 提交于 2019-12-18 09:04:13

问题


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?


回答1:


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.




回答2:


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.




回答3:


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


来源:https://stackoverflow.com/questions/3785976/cmake-generate-visual-studio-2008-solution-for-win32-and-x64

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!