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\")))") else() set(API_IMPORT_MACRO "__declspec(dllimport)") set(API_EXPORT_MACRO "__declspec(dllexport)") endif() function(export_all_flags _target _filename) set(_compile_definitions "$<TARGET_PROPERTY:${_target},COMPILE_DEFINITIONS>") set(_compile_definitions "$<$<BOOL:${_compile_definitions}>:-D$<JOIN:${_compile_definitions},\n-D>\n>") file(GENERATE OUTPUT "${_filename}" CONTENT "${_compile_definitions}") endfunction() add_library(${target} SHARED test.cpp) target_compile_definitions(${target} PRIVATE API=${API_EXPORT_MACRO} INTERFACE API=${API_IMPORT_MACRO}) export_all_flags(${target} ${CMAKE_BINARY_DIR}/flags.txt) ------------- CMakeLists.txt ------------------ ------------- test.cpp ------------------ void API test() {} ------------- test.cpp ------------------ The result file "flags.txt" is following: -DAPI=__attribute__((visibility("default"))) I would like any solution to make the result as: -DAPI=__attribute__((visibility(\"default\"))) Could you help me please? Eugene.
-- 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