0

When I call cmake like this, everything works:

cmake -G'Android Gradle - Ninja' ..

However, I'm setting up a bash script that lets me specify the target platform, changing the -G argument dynamically.

#!/usr/bin/env bash

CMAKE_GENERATOR="Ninja"
if [[ $TARGET_PLATFORM == "android" ]] ; then
    CMAKE_GENERATOR="'Android Gradle - Ninja'"
fi

cmake -G$CMAKE_GENERATOR ..

This gives me the following error:

CMake Error: Could not create named generator 'Android

Apparently cmake splits the generator name at the whitespace and interprets it as multiple arguments. I've tried multiple combinations of escaping the single/double quotes as well as the whitespaces but can't get it to work. I'm not even sure if this is a cmake or bash issue. Any ideas?

2
  • It looks like a question I asked a little while ago: stackoverflow.com/questions/5730881/… Commented Apr 7, 2017 at 13:02
  • And apologies if I broke any rule by referring to my own previous question... Commented Apr 7, 2017 at 13:02

1 Answer 1

4

Quotes are missing in following command:

cmake -G$CMAKE_GENERATOR ..

should be

cmake -G"$CMAKE_GENERATOR" ..

because word splitting occurs after parameter expansion more information in bash documentation

Sign up to request clarification or add additional context in comments.

1 Comment

That did it. Thanks for also linking to an explanation!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.