[CMake] add_custom_target: COMMAND embedded bash code
David Lind
davidklind at gmail.com
Fri Feb 24 19:00:51 EST 2017
I would like to create a custom target to run UnitTest++ based unit tests that has builtin default parameters.
For example:
make unit_test verbose=1 xml-output=1 run=test_name suite=suite_name
The actual parameters passed to the unit_test are:
unit_test --verbose --xml-output --run=test_name --suite=suite_name
I would prefer NOT to call a shell script but rather have the intelligence in the COMMAND itself.
Here’s what I’ve done:
add_custom_target(${PROJECT_NAME}_run
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${target} "$(if $(verbose), --verbose)" "$(if $(run), --run=$(run))" "$(if $(suite), --suite=$(suite))" "$(if $(xml-output), --xml-output)" \${PARAMS}
DEPENDS ${target}
)
What ends up in build.make is this:
…/unit_test $(if\ $(verbose),\ --verbose) $(if\ $(xml-output),\ --xml-output) $(if\ $(run),\ --run=$(run)) $(if\ $(suite),\ --suite=$(suite))
This would work great if CMake didn’t put ‘\’ characters in build.cmake. I can only assume it’s escaping the spaces within the quotes.
If I don’t use quotes in the COMMAND value I get this:
$ ( if $(verbose), --verbose )
Is there a way to format the COMMAND value so CMake doesn’t escape the spaces?
I’m using CMake version 3.7.2
—Dave
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20170224/1308c920/attachment.html>
More information about the CMake
mailing list