Ninja generator doesn't properly handle POST_BUILD commands with `||`
To reproduce
- Create an empty
main.cpp
- Create a
CMakeLists.txt
with the following content:cmake_minimum_required(VERSION 3.10...3.26) project(cmaketest LANGUAGES CXX) add_executable(cmaketest main.cpp) add_custom_command(TARGET cmaketest POST_BUILD COMMAND false || true )
- Compile with
cmake -B build && make -C build
- Compile with
cmake -B build-ninja -G Ninja && ninja -v -C build-ninja
Expected result
The build fails with a linking error, due to not having a main function, in both make and ninja
Actual result
The make build fails with a linking error.
The ninja build prints the linker error's message, but returns with a 0 (success) exit code, making CIs think that the build succeeded. It looks like the ninja generator handles POST_BUILD commands by appending them to the main build command with &&
. This ends up running as (<build> && <postbuild0>) || <postbuild1>
instead of <build> && (<postbuild0> || <postbuild1>)
.
Edited by TellowKrinkle