【问题标题】:Generate two Visual Studio Solutions at same folder using CMake使用 CMake 在同一文件夹中生成两个 Visual Studio 解决方案
【发布时间】:2014-02-21 15:38:07
【问题描述】:

使用 CMake,我正在尝试这样做:

在同一文件夹中创建两个 Visual Studio 解决方案。

例如:

root
|
|-- myproject.sln
|-- myproject_x64.sln

用命令行生成(.bat 文件):

cmake -G"Visual Studio 10"
del CMakeCache.txt // POG to generate win64 in the sequence "CMake ZERO_CHECK will cry"
cmake -G"Visual Studio 10 Win64"

cmake 文件内部:

PROJECT(myproject)

IF(NOT "${CMAKE_CL_64}" MATCHES "0")
    MESSAGE( STATUS "Generating x64 Solution...")
    PROJECT(myproject_x64)
ELSE()
    MESSAGE( STATUS "Generating x86 Solution...")
ENDIF()

(...)

有可能做这样的事情吗?

CMake 总是生成 ALL_BUILD 项目,结果如下:

root
|-- source/header files
|-- unittest.vcxproj
|
|-- ALL_BUILD.vcxproj (used for last generated project)
|-- myproject.sln
|-- myproject_x64.sln

有没有办法为 (ALL_BUILD.vcxproj,INSTALL.vcxproj,PACKAGE.vcxproj, ZERO_CHECK.vcxproj) 创建子目录?

例如:

root
|-- source/header files
|-- unittest.vcxproj
|
|-- myproject.sln
|-- myproject_x64.sln
|
|---- depDir
        |
        | (used for myproject)
        |-- ALL_BUILD.vcxproj 
        |-- INSTALL.vcxproj
        |-- PACKAGE.vcxproj
        |-- ZERO_CHECK.vcxproj
|---- depDir_x64
        |
        | (used for myproject_x64)
        |-- ALL_BUILD.vcxproj 
        |-- INSTALL.vcxproj
        |-- PACKAGE.vcxproj
        |-- ZERO_CHECK.vcxproj

或“首选”

root
|-- source/header files
|-- unittest.vcxproj
|
|-- myproject.sln
|-- myproject_x64.sln
|
|-- ALL_BUILD.vcxproj (used for myproject)
|-- INSTALL.vcxproj (used for myproject)
|-- PACKAGE.vcxproj (used for myproject)
|-- ZERO_CHECK.vcxproj
|
|---- depDir_x64
        |
        | (used for myproject_x64)
        |-- Additional CMakeLists.txt if needed.
        |-- ALL_BUILD.vcxproj 
        |-- INSTALL.vcxproj
        |-- PACKAGE.vcxproj
        |-- ZERO_CHECK.vcxproj

有可能做这样的事情吗?

【问题讨论】:

  • 我认为你会更多地与 CMake 抗争,而不是使用它。与单独的 x86 和 x64 构建文件夹相比有什么优势?
  • 由于 CMake 不允许在同一个“.sln”文件中使用单独的文件夹配置(Win32 和 x64)选项,因此可能不会与两个项目的文件 (ALL_BUILD.vcxproj) 冲突。

标签: visual-studio-2010 visual-studio cmake


【解决方案1】:

我找到了一个不错的选择!

我创建了一个 .bat 文件来生成 x86、x64 文件夹并使用单个 CMakeLists 文件。

@echo off
echo Generating x86 Solution...

mkdir x86
cd x86
cmake -G"Visual Studio 10" "../"
cd ..
mkshortcut "../" /target:"%~dp0\x86\myproject.sln" /shortcut:"myproject.sln"

echo Generating x64 Solution...

mkdir x64
cd x64
cmake -G"Visual Studio 10 Win64" "../"
cd ..
mkshortcut "../" /target:"%~dp0\x64\myproject.sln" /shortcut:"myproject_x64.sln"

pause

使用

cd x86 

cmake "../" 

我可以在 x86 文件夹中生成文件。

结果是:

root
|-- source/header files
|-- x86 <- folder
|-- x64 <- folder
|-- CMakeLists.txt
|-- myproject.sln <-shortcut to x86 .sln
|-- myproject_x64.sln <-shortcut to x64 .sln

创建快捷方式文件的代码

mkshortcut "../" /target:"%~dp0\x86\myproject.sln" /shortcut:"myproject.sln"

使用取自giannistsakiris.com的mkshortcut.vbs

rem This code is used to generate files shortcuts
rem eg.:
rem mkshortcut /target:"c:\myfile" /shortcut:"c:\myfileShortcut"

set WshShell = WScript.CreateObject("WScript.Shell" )
set oShellLink = WshShell.CreateShortcut(Wscript.Arguments.Named("shortcut") & ".lnk")
oShellLink.TargetPath = Wscript.Arguments.Named("target")
oShellLink.WindowStyle = 1
oShellLink.Save

查看是否使用了 cmake -G"Visual Studio 10 Win64":

IF(NOT "${CMAKE_CL_64}" MATCHES "0")
...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-24
    • 1970-01-01
    • 2013-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多