Is it possible for CMake to generate unescaped quotes on the (bash) command line as a result of add_custom_command?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Is it possible for CMake to generate unescaped quotes on the (bash) command line as a result of add_custom_command?

Alan W. Irwin
Hi Nils:

I am asking this question directly of you because in the past (at
<https://cmake.org/Bug/view.php?id=15898>) you stated

"To pass quotes directly to the command either [["foo"]] or \"foo\"
should work."

But that doesn't work for me (using make and the bash command-line on
Linux), and instead with either of those two methods I get escaped
quotes on the command-line.

My use case (for add_custom_command with
VERBATIM and cmake 3.6.2 or higher) is as follows:

COMMAND test-drv-info
${LIBRARY_TARGET_PREFIX} ${SOURCE_ROOT_NAME}
> ${CMAKE_CURRENT_BINARY_DIR}/test_dyndrivers_dir/${SOURCE_ROOT_NAME}.driver_info

that translates to

./test-drv-info temporary_target_ ps > /home/software/plplot/HEAD/build_dir/drivers/test_dyndrivers_dir/ps.driver_info

on the command line which is correct for the case when
LIBRARY_TARGET_PREFIX has been set to "temporary_target_".  But when
LIBRARY_TARGET_PREFIX is set to the empty string the result is

./test-drv-info  ps > /home/software/plplot/HEAD/build_dir/drivers/test_dyndrivers_dir/ps.driver_info

However, that is wrong since that command currently needs two arguments even if
one of them is empty.  So instead I need the generated command to be

./test-drv-info "temporary_target_" ps > /home/software/plplot/HEAD/build_dir/drivers/test_dyndrivers_dir/ps.driver_info

or

./test-drv-info "" ps > /home/software/plplot/HEAD/build_dir/drivers/test_dyndrivers_dir/ps.driver_info

depending on how LIBRARY_TARGET_PREFIX is set.

Is it possible to implement that?  If I try your (historical)
suggestion above, I get instead

./test-drv-info \"temporary_target_\" ps > /home/software/plplot/HEAD/build_dir/drivers/test_dyndrivers_dir/ps.driver_info

or

./test-drv-info \"\" ps > /home/software/plplot/HEAD/build_dir/drivers/test_dyndrivers_dir/ps.driver_info


which isn't correct since unescaped quotes are needed on the generated command
line rather than escaped ones.

If the answer is unescaped quotes are not possible on the generated
command line, that is fine since there are multiple ways to work
around that CMake limitation (e.g., by changing the test-drv-info
executable to check the number of arguments and act differently if one
of them is missing). But in light of your quote above, I just want to
make sure I am not missing some obvious way that CMake can generate
unescaped quotes on the command-line.

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state
implementation for stellar interiors (freeeos.sf.net); the Time
Ephemerides project (timeephem.sf.net); PLplot scientific plotting
software package (plplot.sf.net); the libLASi project
(unifont.org/lasi); the Loads of Linux Links project (loll.sf.net);
and the Linux Brochure Project (lbproject.sf.net).
__________________________

Linux-powered Science
__________________________
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible for CMake to generate unescaped quotes on the (bash) command line as a result of add_custom_command?

Nils Gladitz-2
On 13.04.2018 21:48, Alan W. Irwin wrote:

> [...]
> However, that is wrong since that command currently needs two
> arguments even if
> one of them is empty.  So instead I need the generated command to be
>
> ./test-drv-info "temporary_target_" ps >
> /home/software/plplot/HEAD/build_dir/drivers/test_dyndrivers_dir/ps.driver_info
>
> or
>
> ./test-drv-info "" ps >
> /home/software/plplot/HEAD/build_dir/drivers/test_dyndrivers_dir/ps.driver_info
>
> depending on how LIBRARY_TARGET_PREFIX is set.
>
> Is it possible to implement that?

Hi Alan,

with VERBATIM just using regular unescaped quotes (which are cmake
syntax and not part of the value) around the argument should work e.g.

     COMMAND test-drv-info "${LIBRARY_TARGET_PREFIX}"
${SOURCE_ROOT_NAME}
${CMAKE_CURRENT_BINARY_DIR}/test_dyndrivers_dir/${SOURCE_ROOT_NAME}.driver_info


That way even when ${LIBRARY_TARGET_PREFIX} expands empty
add_custom_command() will receive an argument which it will escape /
quote as required by the build system.

Nils
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible for CMake to generate unescaped quotes on the (bash) command line as a result of add_custom_command?

Alan W. Irwin
On 2018-04-13 23:02+0200 Nils Gladitz wrote:

> On 13.04.2018 21:48, Alan W. Irwin wrote:
>> [...]
>> However, that is wrong since that command currently needs two arguments
>> even if
>> one of them is empty.  So instead I need the generated command to be
>>
>> ./test-drv-info "temporary_target_" ps >
>> /home/software/plplot/HEAD/build_dir/drivers/test_dyndrivers_dir/ps.driver_info
>>
>> or
>>
>> ./test-drv-info "" ps >
>> /home/software/plplot/HEAD/build_dir/drivers/test_dyndrivers_dir/ps.driver_info
>>
>> depending on how LIBRARY_TARGET_PREFIX is set.
>>
>> Is it possible to implement that?
>
> Hi Alan,
>
> with VERBATIM just using regular unescaped quotes (which are cmake syntax and
> not part of the value) around the argument should work e.g.
>
>     COMMAND test-drv-info "${LIBRARY_TARGET_PREFIX}" ${SOURCE_ROOT_NAME}
> ${CMAKE_CURRENT_BINARY_DIR}/test_dyndrivers_dir/${SOURCE_ROOT_NAME}.driver_info
>
>
> That way even when ${LIBRARY_TARGET_PREFIX} expands empty
> add_custom_command() will receive an argument which it will escape / quote as
> required by the build system.

Hi Nils:

When starting fresh with a clean cache using
"${LIBRARY_TARGET_PREFIX}" in the COMMAND worked perfectly, i.e.,
propagated as "" to the command line when ${LIBRARY_TARGET_PREFIX}
expands empty. Thanks for that suggestion!

The strange thing is I am virtually positive I tried that exact idea
earlier today, and it did not work, but maybe that was due to another
issue such as a dirty cache.

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state
implementation for stellar interiors (freeeos.sf.net); the Time
Ephemerides project (timeephem.sf.net); PLplot scientific plotting
software package (plplot.sf.net); the libLASi project
(unifont.org/lasi); the Loads of Linux Links project (loll.sf.net);
and the Linux Brochure Project (lbproject.sf.net).
__________________________

Linux-powered Science
__________________________
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake