Multi-line strings with indentation ignored

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Multi-line strings with indentation ignored

Robert Dailey-2
At the moment, with CMake 3.0 and on, I can use this syntax for
multi-line strings:


option( ZIOSK_ENABLE_ZPAY_DIAGNOSTICS "\
Enable additional diagnostic logs for zPay related code. \
Should not be enabled for production due to the sensitivity \
and volume of logs that will be printed." )

The problem with this approach is that it's ugly; I can't indent the
code because the indentations are made to be a literal part of the
string itself. I prefer the C++ approach to multi-line strings because
it allows strings to be hard-wrapped AND indent them for style, all
without affecting the actual string data:

option( ZIOSK_ENABLE_ZPAY_DIAGNOSTICS
    "Enable additional diagnostic logs for zPay related code. "
    "Should not be enabled for production due to the sensitivity "
    "and volume of logs that will be printed" )

This is much nicer, but CMake fails this code because it sees each
string as a separate parameter. Is there a mechanism I can use to
style my strings this way? If not, are there any plans to add better
multi-line string support?
--

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
|  
Report Content as Inappropriate

Re: [cmake-developers] Multi-line strings with indentation ignored

Brad King
On 01/18/2017 10:52 AM, Robert Dailey wrote:
> At the moment, with CMake 3.0 and on, I can use this syntax for
> multi-line strings:
>
> option( ZIOSK_ENABLE_ZPAY_DIAGNOSTICS "\
> Enable additional diagnostic logs for zPay related code. \
> Should not be enabled for production due to the sensitivity \
> and volume of logs that will be printed." )

One can also use bracket arguments:

https://cmake.org/cmake/help/v3.7/manual/cmake-language.7.html#bracket-argument

but they (intentionally) don't process any variable references.
Also they don't ignore indentation.

>     "Enable additional diagnostic logs for zPay related code. "
>     "Should not be enabled for production due to the sensitivity "
>     "and volume of logs that will be printed" )
>
> it sees each string as a separate parameter.

Correct.

> Is there a mechanism I can use to style my strings this way?

One can do it with an intermediate variable:

```
string(CONCAT mystringvar
  "Enable additional diagnostic logs for zPay related code. "
  "Should not be enabled for production due to the sensitivity "
  "and volume of logs that will be printed"
  )
option(ZIOSK_ENABLE_ZPAY_DIAGNOSTICS "${mystringvar}")
```

> are there any plans to add better multi-line string support?

Not currently.

-Brad

--

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