As part of a larger cmake build I have an external project. A custom build command is created to build this part of the software.
I want to pass flags in quotes. However, cmake keeps wrapping my code with quotes where I do not want them. Take the following example case:
include(ExternalProject)
set(bar "echo;cxxflags=\"flag1 flag2\"")
ExternalProject_Add(test
PREFIX ""
DOWNLOAD_COMMAND ""
COMMAND "${bar}"
TEST ""
)
When I run
export VERBOSE=1
cmake ..
make
I the cxxflags argument is wrapped in quotes which is not usable for my purpose.
...
cd /some/path && echo "cxxflags=\"flag1 flag2\""
...
If I use the following CMakeLists.txt, the entire command is wrapped in quotes and won't execute.
include(ExternalProject)
set(bar "echo;cxxflags=\"flag1 flag2\"")
string(REPLACE ";" " " barcmd "${bar}")
ExternalProject_Add(test
PREFIX ""
DOWNLOAD_COMMAND ""
COMMAND ${barcmd}
TEST ""
)
The entire command is wrapped quotes:
...
cd /some/path && "echo cxxflags=\"flag1 flag2\""
...
What I need is something like
cd /some/path && echo cxxflags=\"flag1 flag2\"
When my arguments do not contain any quotation marks, the first approach works fine, i.e.
include(ExternalProject)
set(bar "echo;cxxflags=flag1)
ExternalProject_Add(test
PREFIX ""
DOWNLOAD_COMMAND ""
COMMAND "${bar}"
TEST ""
)
works as expected and outputs
cd /some/path && echo cxxflags=flag1
The question occurred building the boost library with cmake. There is no proper solution. Kitware devs suggest wrapping the entire argument with quotes and have no quotes within the argument itself. The call is written to a script file, which is invoked by cmake.
This solved my problem.