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.
You need to split the -G
flag from its value in the command. Python appears to be effectively invoking
cmake "-G Visual Studio 11 Win64" <build_path>
What you want is more like:
cmakeCmd = ["cmake.exe", "-G", "Visual Studio 11 Win64", build_path]
Should be:
cmakeCmd = ['cmake', '-G', 'Visual Studio 11 Win64', build_path]
For the sake of cross-platformness, I recommend to do the following:
if sys.platform.startswith('win'):
shell = True
else:
shell = False
retCode = subprocess.check_call(cmakeCmd, stderr=subprocess.STDOUT, shell=shell)
if you plan to work with the project on several platforms (including Unix OS family). By the way, since you are using shell=True
on Windows, you can omit .exe
suffix in the cmakeCmd
(which is good if this script is used on Unix OS family too as there is no such thing as .exe
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With