Can Ninja replace Unix makefiles ?

Hello

I use so far Unix makefiles as generator in projects. The typical building process is to go project directory and

rm -r build
cmake -S . -B build
cmake --build build

I wished to experiment with ninja thus I tried

rm -r build
cmake -G Ninja -S . -B build
cmake --build build

But the build was issuing an error from ninja:

ninja: error: build.ninja:1135: FLASH.sig.c is defined as an output multiple times

Looks like then CMake does always replace one generator by another to manage projects.
Is there some special care to take in writing CMakeLists.txt when one wish to use ninja?
Thanks for any hint

Which cmake Version are you using?
And which project?

I am using the latest version of CMake 3.31.4.
Projects are building am RTOS for embedded Arm platform (no public access).
system.cmake (11.3 KB)
This is the file that is included by CMakeLists.txt

I guess your project generates this file more than ones in different subdirectories

No there is only one instance of the file. The file is not generated in the project. It is a common file that has been manually generated and is included by projetcts

One file, but more than one rule to generate it. Share or check your cmake project files!

Here is an exemple of a CMakeLists.txt
CMakeLists.txt (7.8 KB)

The problem is the add_custom_command() in your system.cmake module:

add_custom_command(
    OUTPUT ${LOCAL_TARGET}.sig.c
    COMMAND
        sh -c
        "thesha=\$(shasum --algorithm 256 NOSIG.bin | cut -c 1-64); echo const char aFLASH_signature[] __attribute__\\\(\\\(section\\\(\\\".signature\\\"\\\)\\\)\\\) = \\\"\${thesha}\\\"\;"
        > ${LOCAL_TARGET}.sig.c
    VERBATIM
    COMMAND
        sh -c
        "thesha=\$(shasum --algorithm 256 NOSIG.bin | cut -c 1-64); echo STRG_LOC_CONST\\\(aSignature[]\\\) = \\\"\${thesha}\\\"\;"
        > ${LOCAL_TARGET}.ck
    VERBATIM
    DEPENDS ${TARGET_NOSIG_ELF} NOSIG.bin
    # FIXME: BYPRODUCTS ${LOCAL_TARGET}.sig.c
    COMMENT "Generating signature C source file"
)
target_sources(${TARGET_ELF} PUBLIC ${LOCAL_TARGET}.sig.c)

It should not set BYPRODUCTS and OUTPUT both to the same file!

Thank you!
I was using this because i misinterpreted the documentation

The Makefile Generators will remove BYPRODUCTS and other GENERATED files during make clean .

to have this file removed by make clean. But I understand this is not necessaary because files listed in OUTPUT are tagged GENERATED and will be removed also.

@craig.scott Is this right?

Yes, it is. I have add the check box to “Solution” to your message