[CMake] To quote (path) variables or not, and everywhere?

Oleksii Vilchanskyi alexvilchansky at yahoo.com
Mon Sep 25 06:57:48 EDT 2017


As usually with CMake, there are no recommendations/guidelines.

However, here's my logic:

1) if it's a path, always quote it
2) if it's not a pat, but inside an if() or any similar core language structure, quote it as well
3) don't quote only if you're sure the string can't have spaces - otherwise do quote
4) quoting is free and doesn't hurt

On Sep 25, 2017, 10:34, at 10:34, Mateusz Loskot <mateusz at loskot.net> wrote:
>Hi,
>
>A user of one of projects I maintain pointed out that according to
>CMake guidelines [1] all variables with strings (also paths) should be
>quoted, ie.
>
>include_directories(${SOCI_SOURCE_DIR}/core)
>
>should read
>
>include_directories("${SOCI_SOURCE_DIR}/core")
>
>Is that so?
>What is the current CMake recommendation?
>
>Some other guidelines [2] suggest rule of thumb when using
>variables in COMMAND calls:
>   Use quotes for the arguments that contain file paths
>
>Does this apply to include_directories. set_target_properties, etc.?
>
>I found "Paths with spaces - Visual Studio" [3] post which reports a
>problem with not quoted paths but David Cole's recommendation [4]
>uses add_library with path not quoted.
>
>I sense, the answer to quote or not to quote might depend on
>which CMake command is used.
>
>Could anyone tell what is the current recommendation?
>
>[1]
>https://cmake.org/Wiki/CMake/Language_Syntax#CMake_splits_arguments_unless_you_use_quotation_marks_or_escapes.
>[2] https://stackoverflow.com/a/35853080/151641
>[3] https://public.kitware.com/pipermail/cmake/2012-July/051138.html
>[4] https://public.kitware.com/pipermail/cmake/2012-July/051139.html
>
>Best regards,
>-- 
>Mateusz Loskot, http://mateusz.loskot.net
>-- 
>
>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:
>http://public.kitware.com/mailman/listinfo/cmake
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20170925/6b3b2890/attachment.html>


More information about the CMake mailing list