On Fri, 2019-08-30 at 17:54 +0300, Eugene Karpov wrote: > I've tried this. But then it fails to compile due to `INTERFACE > API=${API_EXPORT_MACRO}` target compile definition.
Ah right, you want the file contents to be escaped while the compile flags are not. My next suggestion was going to be to use a generator expression that replaces `"` with `\"`, but there does not appear to be a "string replace" genex. In that case, I would suggest using add_custom_command()/add_custom_target() to call a cmake -P script which escapes the quotes and writes the file. For example: set(_compile_definitions "$<TARGET_PROPERTY:${_target},COMPILE_DEFINITIONS>") set(_compile_definitions "$<$<BOOL:${_compile_definitions}>:- D$<JOIN:${_compile_definitions},\n-D>\n>") add_custom_target(mkflags_${_target} COMMAND ${CMAKE_COMMAND} "- DDEFINITIONS=${_compile_definitions}" "-DFILENAME=${_filename}" -P path/to/script.cmake BYPRODUCTS "${_filename}") And then the script would look like: string(REPLACE "\"" "\\\"" DEFINITIONS "${DEFINITIONS}") file(WRITE "${FILENAME}" "${DEFINITIONS}") Kyle -- 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: https://cmake.org/mailman/listinfo/cmake-developers