<div dir="ltr">Hello all,<div><br></div><div>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.</div><div>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.</div><div>I've made simple two files project of a shared library to show the issue. It has only target compile definitions for simplicity.</div><div><br></div><div>------------- CMakeLists.txt ------------------</div><div>cmake_minimum_required(VERSION 3.14)<br>set(target test)<br>project(${target})<br>if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")<br>    set(API_IMPORT_MACRO "__attribute__((visibility(\"default\")))")<br>    set(API_EXPORT_MACRO "__attribute__((visibility(\"default\")))")<br>else()<br>    set(API_IMPORT_MACRO "__declspec(dllimport)")<br>    set(API_EXPORT_MACRO "__declspec(dllexport)")<br>endif()<br>function(export_all_flags _target _filename)<br>  set(_compile_definitions "$<TARGET_PROPERTY:${_target},COMPILE_DEFINITIONS>")<br>  set(_compile_definitions "$<$<BOOL:${_compile_definitions}>:-D$<JOIN:${_compile_definitions},\n-D>\n>")<br>  file(GENERATE OUTPUT "${_filename}" CONTENT "${_compile_definitions}")<br>endfunction()<br>add_library(${target} SHARED test.cpp)<br>target_compile_definitions(${target}<br>    PRIVATE API=${API_EXPORT_MACRO}<br>    INTERFACE API=${API_IMPORT_MACRO})<br>export_all_flags(${target} ${CMAKE_BINARY_DIR}/flags.txt)<br></div><div>------------- CMakeLists.txt ------------------<br></div><div>------------- test.cpp ------------------<br></div><div>void API test() {}<br></div><div>------------- test.cpp ------------------<br></div><div><br></div><div>The result file "flags.txt" is following:</div><div>-DAPI=__attribute__((visibility("default")))<br></div><div><br></div><div>I would like any solution to make the result as:</div><div>-DAPI=__attribute__((visibility(\"default\")))<br></div><div><br></div><div>Could you help me please?</div><div><br></div><div>Eugene.</div></div>