代码之家  ›  专栏  ›  技术社区  ›  sakra

cmake为Win32和x64生成Visual Studio 2008解决方案

  •  3
  • sakra  · 技术社区  · 14 年前

    我正在Windows XP下使用cmake 2.8,并希望生成一个包含Win32和x64版本和调试配置的Visual Studio 2008解决方案文件。

    可以通过在 CMakeLists.txt 文件?

    3 回复  |  直到 10 年前
        1
  •  3
  •   RobertJMaynard    14 年前

    CMakeList不是为项目指定生成器(makefile、xcode、Visual Studio)的位置。当用户在源上运行cmake时,将指定生成器。

        2
  •  2
  •   Fraser    12 年前

    您应该使用cmake.exe在控制台下生成解决方案文件。

    cmake-g“Visual Studio 9 2008”(包含cmakeLists.txt文件的目录)//这是用于x86的。

    cmake-g“Visual Studio 9 2008 Win64”(包含cmakeLists.txt文件的目录)//这是用于x64的。

        3
  •  2
  •   Validus Oculus    10 年前

    您肯定应该使用批处理脚本来自动化这些过程。我与您共享我自己的构建器脚本的简化版本。我自己的环境要复杂得多,因此我为您编写了这个脚本,以便于使用。

    它的用法非常基本。

    builder . -64bit -Debug
    

    表示源代码在当前目录中,编译配置为64位调试版本。

    您只需要在脚本中更改全局配置变量 Visual Studio目录和cmake目录。

    设置Visual Studio主页=

    设置cmake_主页=

    @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