GHS compiler + Ninja: Shell escapes for defines break response file usage
I attempt to use the Green Hills compiler with response files together with CMake's Ninja generator. Consider the following example:
CMakeLists.txt:
cmake_minimum_required(VERSION 3.12)
project(Test CXX)
add_executable(test
test.cpp
)
target_compile_definitions(test
PRIVATE CLASS_ATTRIBUTE=
)
test.cpp:
class CLASS_ATTRIBUTE myclass { };
int
main(int argc, char* argv[])
{
return 0;
}
Running cmake -G"Ninja" "-DCMAKE_CXX_RESPONSE_FILE_FLAG:STRING=@" "-DCMAKE_NINJA_FORCE_RESPONSE_FILE:BOOL=ON" -Hsrc -Bbin
and cmake --build bin
results in an compilation error.
The problem is that CMake escapes the defines for a consumption by a shell, i.e. it generates DEFINES = -DCLASS_ATTRIBUTE=""
for the corresponding Ninja build statement. Ninja writes this content verbatim to the rsp file and moreover the Green Hills compiler driver passes this verbatim to the compiler.
Hence, the source code is compiled with CLASS_ATTRIUTE=""
instead of CLASS_ATTRIBUTE=
which causes the problem.
Edited by Sebastian Lipponer