[cmake-developers] escape double quote in generated file

Eugene Karpov karpov.en at gmail.com
Fri Aug 30 10:54:35 EDT 2019


I've tried this. But then it fails to compile due to `INTERFACE
API=${API_EXPORT_MACRO}` target compile definition.

пт, 30 авг. 2019 г. в 17:49, Kyle Edwards <kyle.edwards at kitware.com>:

> On Fri, 2019-08-30 at 17:36 +0300, Eugene Karpov wrote:
> > Hello all,
> >
> > I'm working on a cross platform project. On Ubuntu I would like to
> > save all the compiler options, definitions and other complier related
> > stuff to a generated file to use it later for precompiled header
> > generation.
> > My issue is that I have to specify a macro that contain double quotes
> > for g++ compiler visibility attribute. When I generate a file with
> > double quotes they are not escaped. I also tried to use
> > `string(replace "\"" "\\\""...)` without effect.
> > I've made simple two files project of a shared library to show the
> > issue. It has only target compile definitions for simplicity.
> >
> > ------------- CMakeLists.txt ------------------
> > cmake_minimum_required(VERSION 3.14)
> > set(target test)
> > project(${target})
> > if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
> >     set(API_IMPORT_MACRO "__attribute__((visibility(\"default\")))")
> >     set(API_EXPORT_MACRO "__attribute__((visibility(\"default\")))")
>
> The quotes here need to be double-escaped, like so:
>
> set(API_IMPORT_MACRO "__attribute__((visibility(\\\"default\\\")))")
> set(API_EXPORT_MACRO "__attribute__((visibility(\\\"default\\\")))")
>
> Kyle
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake-developers/attachments/20190830/7b96dc62/attachment.html>


More information about the cmake-developers mailing list