fileapi: codemodel-v2 link command fragment wrong relative path
The Ninja generator always runs commands with the current working directory set to the top-level build directory. However, the fileapi codemodel-v2 object can show link command fragments with relative paths computed with respect to the subdirectory in which the target is defined:
$ cat CMakeLists.txt
cmake_minimum_required(VERSION 3.16)
project(Issue22301 C)
add_library(foo STATIC foo.c)
add_subdirectory(sub)
$ cat sub/CMakeLists.txt
add_executable(bar bar.c)
target_link_libraries(bar PRIVATE foo)
$ mkdir -p build/.cmake/api/v1/query
$ >build/.cmake/api/v1/query/codemodel-v2
$ cd build
$ cmake .. -GNinja
$ ninja
... cc sub/CMakeFiles/bar.dir/bar.c.o -o sub/bar libfoo.a ...
$ grep -B 2 -A 2 libfoo.a .cmake/api/v1/reply/target-bar-*.json
{
"backtrace" : 2,
"fragment" : "../libfoo.a",
"role" : "libraries"
}
This was reported on discourse.
Edited by Brad King