# Can Ninja replace Unix makefiles ?

**URL:** https://discourse.cmake.org/t/can-ninja-replace-unix-makefiles/13388
**Category:** Usage
**Tags:** gen:ninja
**Created:** [January 13, 2025, 1:24pm UTC](https://discourse.cmake.org/t/can-ninja-replace-unix-makefiles/13388 "2025-01-13T13:24:42Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Laur59](https://discourse.cmake.org/user_avatar/discourse.cmake.org/laur59/32/4200_2.png) [@Laur59](https://discourse.cmake.org/u/Laur59)
#### Post date: [January 13, 2025, 1:24pm UTC](https://discourse.cmake.org/t/can-ninja-replace-unix-makefiles/13388/1 "2025-01-13T13:24:42Z")

</div>

Hello

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

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

```

I wished to experiment with ninja thus I tried

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

```

But the build was issuing an error from ninja:

```auto
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

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [January 13, 2025, 8:21pm UTC](https://discourse.cmake.org/t/can-ninja-replace-unix-makefiles/13388/2 "2025-01-13T20:21:23Z")

</div>

Which cmake Version are you using?  
And which project?

---

<div class="post-metadata">

### Author: ![Laur59](https://discourse.cmake.org/user_avatar/discourse.cmake.org/laur59/32/4200_2.png) [@Laur59](https://discourse.cmake.org/u/Laur59)
#### Post date: [January 13, 2025, 8:39pm UTC](https://discourse.cmake.org/t/can-ninja-replace-unix-makefiles/13388/3 "2025-01-13T20:39:20Z")

</div>

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](https://discourse.cmake.org/uploads/short-url/ywApkReTuo221iR7XjWvizJQdNm.cmake) (11.3 KB)  
This is the file that is included by CMakeLists.txt

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [January 13, 2025, 8:44pm UTC](https://discourse.cmake.org/t/can-ninja-replace-unix-makefiles/13388/4 "2025-01-13T20:44:45Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Laur59](https://discourse.cmake.org/user_avatar/discourse.cmake.org/laur59/32/4200_2.png) [@Laur59](https://discourse.cmake.org/u/Laur59)
#### Post date: [January 13, 2025, 8:48pm UTC](https://discourse.cmake.org/t/can-ninja-replace-unix-makefiles/13388/5 "2025-01-13T20:48:07Z")

</div>

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

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [January 13, 2025, 8:53pm UTC](https://discourse.cmake.org/t/can-ninja-replace-unix-makefiles/13388/6 "2025-01-13T20:53:08Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Laur59](https://discourse.cmake.org/user_avatar/discourse.cmake.org/laur59/32/4200_2.png) [@Laur59](https://discourse.cmake.org/u/Laur59)
#### Post date: [January 13, 2025, 8:55pm UTC](https://discourse.cmake.org/t/can-ninja-replace-unix-makefiles/13388/7 "2025-01-13T20:55:12Z")

</div>

Here is an exemple of a CMakeLists.txt  
[CMakeLists.txt](https://discourse.cmake.org/uploads/short-url/vDIMel1yBMTuo1cgK0zwfmRgyHz.txt) (7.8 KB)

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [January 14, 2025, 3:12am UTC](https://discourse.cmake.org/t/can-ninja-replace-unix-makefiles/13388/8 "2025-01-14T03:12:39Z")

</div>

The problem is the [add\_custom\_command](https://cmake.org/cmake/help/latest/command/add_custom_command.html#add-custom-command)() in your `system.cmake` module:

```cmake
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!

---

<div class="post-metadata">

### Author: ![Laur59](https://discourse.cmake.org/user_avatar/discourse.cmake.org/laur59/32/4200_2.png) [@Laur59](https://discourse.cmake.org/u/Laur59)
#### Post date: [January 14, 2025, 3:39am UTC](https://discourse.cmake.org/t/can-ninja-replace-unix-makefiles/13388/9 "2025-01-14T03:39:15Z")

</div>

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

> The [Makefile Generators](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html#makefile-generators) will remove `BYPRODUCTS` and other [`GENERATED`](https://cmake.org/cmake/help/latest/prop_sf/GENERATED.html#prop_sf: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.

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [January 14, 2025, 3:42am UTC](https://discourse.cmake.org/t/can-ninja-replace-unix-makefiles/13388/10 "2025-01-14T03:42:38Z")

</div>

@craig.scott Is this right?

---

<div class="post-metadata">

### Author: ![Laur59](https://discourse.cmake.org/user_avatar/discourse.cmake.org/laur59/32/4200_2.png) [@Laur59](https://discourse.cmake.org/u/Laur59)
#### Post date: [January 14, 2025, 3:44am UTC](https://discourse.cmake.org/t/can-ninja-replace-unix-makefiles/13388/11 "2025-01-14T03:44:04Z")

</div>

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