1

For building applications I use CMake. I parse my CMake command in a script with several variables:

CMAKE_COMMAND=" \
$CMAKE \
-G "$Build_TOOL_CMAKE" \
[...]"

After parsing that command I print it with printf for control:

printf "\n${CMAKE_COMMAND}\n"

And then I eventually execute the command with:

$CMAKE_COMMAND

This script worked as long as I had "Ninja" as Generator (the -G option --> BUILD_TOOL_CMAKE="Ninja") as it does have no space characters in it.

Now I want to use "Eclipse CDT4 - Unix Makefiles" as Generator. I tried several ways of escaping the space characters, e.g.:

CMAKE_COMMAND=" \
$CMAKE \
-G \"$Build_TOOL_CMAKE\" \
[...]"

or

CMAKE_COMMAND=" \
$CMAKE \
-G '$Build_TOOL_CMAKE' \
[...]"

The printed command became correct in some cases, but the execution of it resulted in errors like:

CMake Error: Could not create named generator Eclipse

or

CMake Error: Could not create named generator "Eclipse

This leads to the assumption that something is wrong with escaping the spaces, but the printf works:

cmake.exe -G"Eclipse CDT4 - Unix Makefiles" -S sourcefolder -B buildfolder # printf $CMAKE_COMMAND

Did I miss something? Maybe the executing merely by the variable ($CMAKE_COMMAND) is also the wrong approach.

h0ch5tr4355
  • 2,092
  • 4
  • 28
  • 51

1 Answers1

1

You can use the CMake's configure_file command: documentation

Place all the variables in command.in and write it to command.

configure_file(command.in, command)

The file command.in can looks like this:

${CMAKE_COMMAND} -G ${Build_TOOL_CMAKE}
Kevin
  • 16,549
  • 8
  • 60
  • 74
Th. Thielemann
  • 2,592
  • 1
  • 23
  • 38