GraphViz output does not escape quotes properly
What?
The GraphViz generator does not handle dependencies with quotation marks ("
) in their name properly.
How to reproduce
The following CMake project will demonstrate the bug.
cmake_minimum_required(VERSION 3.15.2)
project(graphviz-bug C)
file(WRITE
${CMAKE_BINARY_DIR}/foo.c
"void foo(void) {}")
add_library(foo STATIC
${CMAKE_BINARY_DIR}/foo.c)
target_link_libraries(foo PUBLIC "\"-lm\"")
Use the (current) CMake from master:
$ cmake --version
cmake version 3.15.20190921-g47a12c6
CMake suite maintained and supported by Kitware (kitware.com/cmake).
Generate the GraphViz dot file(s):
graphviz-bug$ cmake -S. -Bbuild --graphviz=build/graph.dot
And then run dot:
graphviz-bug$ dot -Tpng -o graph.png build/graph.dot
Error: build/graph.dot: syntax error in line 6 near '-'
It fails because graph.dot:6
contains label=""-lm""
.
How to fix the issue
I made a quick fix for the issue in this commit: thomsten/cmake@1624358d Someone better at CMake/C++ might point to the correct way of fixing this.
There is a separate issue which originally drew my attention to the problem.
The target_link_libraries()
supports specifying linker flags, and these appear
as dependencies for the target. Is that the intended behavior?