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

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

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

Mateusz Loskot
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
--
Mateusz Loskot
http://mateusz.loskot.net
Reply | Threaded
Open this post in threaded view
|

Re: To quote (path) variables or not, and everywhere?

CMake mailing list
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, at 10:34, Mateusz Loskot <[hidden email]> 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,

--

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
Reply | Threaded
Open this post in threaded view
|

Re: To quote (path) variables or not, and everywhere?

Mateusz Loskot
On 25 September 2017 at 12:57, Oleksii Vilchanskyi
<[hidden email]> wrote:
> As usually with CMake, there are no recommendations/guidelines.

So, cases with the ammo for CMake sceptics and opponents are not
empty, yet. Pity.

> 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

That sounds reasonable. Thank you.

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
--
Mateusz Loskot
http://mateusz.loskot.net
Reply | Threaded
Open this post in threaded view
|

Re: To quote (path) variables or not, and everywhere?

Miller Henry
To add fuel to this, I like to argue that paths should not be quoted if at all possible.  I find that in many cases where a path is quoted those quotes are being done to work around a bad project structure and you can reorganize your project to get rid of the need for quotes.

-----Original Message-----
From: CMake [mailto:[hidden email]] On Behalf Of Mateusz Loskot
Sent: Monday, September 25, 2017 6:41 AM
To: Oleksii Vilchanskyi <[hidden email]>
Cc: [hidden email]
Subject: Re: [CMake] To quote (path) variables or not, and everywhere?

On 25 September 2017 at 12:57, Oleksii Vilchanskyi <[hidden email]> wrote:
> As usually with CMake, there are no recommendations/guidelines.

So, cases with the ammo for CMake sceptics and opponents are not empty, yet. Pity.

> 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

That sounds reasonable. Thank you.

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
--

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
Reply | Threaded
Open this post in threaded view
|

Re: To quote (path) variables or not, and everywhere?

Mateusz Loskot
On 25 September 2017 at 16:58, Miller Henry <[hidden email]> wrote:
> To add fuel to this, I like to argue that paths should not be quoted if at all possible.

I agree.

> I find that in many cases where a path is quoted those quotes are being done to
> work around a bad project structure and you can reorganize your project to get rid of the need for quotes.

What if (Windows) user runs cmake inside

c:\my awesome projects\one-superb\build

and there is xxx_command(${CMAKE_SOURCE_DIR})

I find lack of CMake standarised conventions and idioms a mistake,
softly saying.

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
--
Mateusz Loskot
http://mateusz.loskot.net
Reply | Threaded
Open this post in threaded view
|

Re: To quote (path) variables or not, and everywhere?

Zan Lynx
On 09/25/2017 10:15 AM, Mateusz Loskot wrote:
> What if (Windows) user runs cmake inside
>
> c:\my awesome projects\one-superb\build
>
> and there is xxx_command(${CMAKE_SOURCE_DIR})

Indeed.

In my opinion, if software cannot handle arbitrary path names which
contain anything then that software is broken.

Spaces. Colons. Quotes. Even control characters should work.

--
                Knowledge is Power -- Power Corrupts
                        Study Hard -- Be Evil
--

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
Reply | Threaded
Open this post in threaded view
|

Re: To quote (path) variables or not, and everywhere?

Mateusz Loskot
On 25 September 2017 at 18:40, Zan Lynx <[hidden email]> wrote:

> On 09/25/2017 10:15 AM, Mateusz Loskot wrote:
>> What if (Windows) user runs cmake inside
>>
>> c:\my awesome projects\one-superb\build
>>
>> and there is xxx_command(${CMAKE_SOURCE_DIR})
>
> Indeed.
>
> In my opinion, if software cannot handle arbitrary path names which
> contain anything then that software is broken.

This is no good.
As CMake advocate, I've noticed traces of disappointment accumulated
over the years. In CMake 2 times, that was a small pill to swallow.
In CMake 3.9, it's very frustrating.
Idioms, conventions, PEP kind of papers, whatever is a must.

Niall Douglas crafted a quick CMake'ification demo for Boost [1] and
from the short README one can learn more about **how** to properly
develop a good build setup with CMake than from the CMake documentation.

[1] https://github.com/ned14/boost-bmv-cmake

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
--
Mateusz Loskot
http://mateusz.loskot.net