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

发布于 2024-09-25 05:26:45 字数 161 浏览 2 评论 0原文

我在 Windows XP 下使用 CMake 2.8,想要生成一个 Visual Studio 2008 解决方案文件,其中包含 Win32 和 x64 的发布和调试配置。

可以通过在 CMakeLists.txt 文件中设置 CMake 配置变量来完成此操作吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

撑一把青伞 2024-10-02 05:26:45

CMakeLists 不是您为项目指定生成器( makefile、XCode、Visual Studio )的位置。当用户在源上运行 CMake 时指定生成器。

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.

薄暮涼年 2024-10-02 05:26:45

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

CMake -G "Visual Studio 9 2008" (包含 CMakeLists.txt 文件的目录)// 这适用于 X86。

CMake -G "Visual Studio 9 2008 Win64" (包含 CMakeLists.txt 文件的目录)// 这适用于 X64。

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.

油焖大侠 2024-10-02 05:26:45

您绝对应该使用批处理脚本来自动化这些过程。我与您分享我自己的构建器脚本的简化版本。我自己的环境要复杂得多,因此我编写了这个脚本供您轻松使用。

它的用法非常基本。

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 on

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文