1

I'm trying to write a CMakeLists.txt file for a project with some Makefile-based dependencies. To build the dependencies I use ExternalProject CMake plugin. In simple cases all is OK. But now I want to redefine CFLAGS variable for Makefile-based subproject and cannot do it.

I want to set the following:

CFLAGS='-fPIC -mfloat-abi=softfp -mfpu=neon'

If I use this string literally in BUILD_COMMAND tag, the generated Makefile contains the following:

"CFLAGS='-fPIC" -mfloat-abi=softfp "-mfpu=neon'"

So I get this error during compilation:

/bin/sh: 1: CFLAGS='-fPIC: not found

If I use "CFLAGS='-fPIC -mfloat-abi=softfp -mfpu=neon'", I get

"CFLAGS='-fPIC -mfloat-abi=softfp -mfpu=neon'"

in generated Makefile and get this:

/bin/sh: 1: CFLAGS='-fPIC -mfloat-abi=softfp -mfpu=neon': not found

Is there a right way to quote string with whitespaces in CMake?

J. Chomel
  • 8,193
  • 15
  • 41
  • 69
  • Use " but escape them inside the string with \". But you sould never change the CFLAGS this way, that removes user input and is not how to use CMake. – usr1234567 Oct 07 '16 at 11:27
  • @usr1234567 It works, thank you! Can you post you advise as an answer to let me accept it? Redefining `CFLAGS` is surely a very bad idea, but for _external_ project with plain `Makefile` it seems the only way to manage compiler options. – Yuriy Al. Shirokov Oct 07 '16 at 12:44

0 Answers0