'How can I pass variables with space to cmake through CLI?

There is an option defined in a third party CMake file.

SET(PHYSX_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-rtti -fno-exceptions -ffunction-sections -fdata-sections -fno-strict-aliasing ${GCC_WARNINGS}" CACHE INTERNAL "PhysX CXX")

I am trying to pass custom flags to CMAKE_CXX_FLAGS:

cmake physx/sources/compiler/cmake -B build -DCMAKE_CXX_FLAGS="-Wno-restrict -Wno-class-memaccess"

Because I have space between the two GCC warning flags, the final result ends up breaking the string:

CXX_FLAGS = "-Wno-restrict ... # Quote is not closed

and I get an error about unterminated string

WHen I use no quotes around the flag CMake variable value:

cmake physx/sources/compiler/cmake -B build -DCMAKE_CXX_FLAGS=-Wno-restrict -Wno-class-memaccess

The final result ignores the value after space, which makes sense since space will be treated as a separate variable.

Is there something that I can do to set values with space into CMake variable?

Thanks @KamilCuk,

My problem was with the Python script that was triggering the commands. I had the following line in Python:

subprocess.run(parsedCmdLine.split(' '), shell=platform.system() == 'Windows', cwd=x['sourceDir'])

Luckily, Python has a lexical utility module that resembles shell:

import shlex

subprocess.run(shlex.split(parsedCmdLine.split), shell=platform.system() == 'Windows', cwd=x['sourceDir'])


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source