Ninja: CMAKE_NINJA_OUTPUT_PATH_PREFIX not verified to be a suffix of CMAKE_BINARY_DIR
I think I have found a bug where include_directories(${CMAKE_CURRENT_BINARY_DIR})
is not rendering include paths properly when used alongside -DCMAKE_NINJA_OUTPUT_PATH_PREFIX=<prefix>
.
[1] is a minimal example that reproduces the issue, using cmake 3.20.4. Running [2] generates [3], which contains INCLUDES = -Isrc
. I would expect INCLUDES = -Isub1/src
or an absolute path.
Any ideas on either how to fix this (I am happy to work up a patch but need some general guidance), or how to workaround? Or am I misunderstanding how this feature is supposed to work? cmake + subninja is working quite well for us on several larger projects, but we have had to implement workarounds for this detail. Our workaround so far is basically to write include_directories(/${CMAKE_CURRENT_BINARY_DIR})
and then strip out the extra slash at the front via post-processing the generated file. That forces cmake to emit an absolute path and works well, but for integration of larger third party projects this isn't feasible (or very cumbersome at least).
Thank you!
[1]
cmake-subninja-bug# find
.
./build
./CMakeLists.txt
./src
./src/CMakeLists.txt
./src/prog.cc
cmake-subninja-bug# for f in `find -type f`; do echo "**** $f ***"; cat $f; echo; done
**** ./CMakeLists.txt ***
add_subdirectory(src)
**** ./src/CMakeLists.txt ***
include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_executable(prog prog.cc)
**** ./src/prog.cc ***
[2]
cmake-subninja-bug# cd build && cmake -GNinja -DCMAKE_NINJA_OUTPUT_PATH_PREFIX=sub1 ..
[3] generated build/build.ninja
.
.
.
build sub1/src/CMakeFiles/prog.dir/prog.o: CXX_COMPILER__prog sub1/../src/prog.cc || cmake_object_order_depends_target_prog
DEP_FILE = sub1/src/CMakeFiles/prog.dir/prog.o.d
INCLUDES = -Isrc
OBJECT_DIR = sub1/src/CMakeFiles/prog.dir
OBJECT_FILE_DIR = sub1/src/CMakeFiles/prog.dir
TARGET_COMPILE_PDB = sub1/src/CMakeFiles/prog.dir/
TARGET_PDB = sub1/src/prog.pdb
.
.
.