6

I'm building a project that should be able to move freely between machines. In order to not have hundreds of MB of libs I'm writing a series of python scripts that download and build the dependencies as well as my own project. I'm using CMake to generate VS projects.

To call CMake I build a command line and I use python subprocess.check_call as below

cmakeCmd = ["cmake.exe", '-G "Visual Studio 11 Win64"', build_path]
retCode = subprocess.check_call(cmakeCmd, stderr=subprocess.STDOUT, shell=True)

The problem is that if I use -G option from CMake I get the following error regardless of the generator I choose:

CMake Error: Could not create named generator  "Visual Studio 11 Win64"

I was thinking that should be some enviroment variable missing but the python path is complete with all my systems' variables.

What is odd is that if I don't set the generator and let CMake choose the default one the script runs fine. I have no ideia why.

4

2 回答 2

13

您需要将-G标志与其在命令中的值分开。Python 似乎在有效地调用

cmake "-G Visual Studio 11 Win64" <build_path>

你想要的更像是:

cmakeCmd = ["cmake.exe", "-G", "Visual Studio 11 Win64", build_path]
于 2013-04-18T02:50:59.007 回答
1

应该:

cmakeCmd = ['cmake', '-G', 'Visual Studio 11 Win64', build_path]

为了跨平台,我建议执行以下操作:

if sys.platform.startswith('win'):
    shell = True
else:
    shell = False

retCode = subprocess.check_call(cmakeCmd, stderr=subprocess.STDOUT, shell=shell)

如果您计划在多个平台(包括 Unix OS 系列)上使用该项目。顺便说一句,由于您shell=True在 Windows 上使用,您可以省略.exe中的后缀cmakeCmd(如果此脚本也用于 Unix OS 系列,这很好,因为没有类似的东西.exe)。

于 2013-04-18T02:51:40.803 回答