# Create a dissasembly from a single c file

**URL:** https://discourse.cmake.org/t/create-a-dissasembly-from-a-single-c-file/6868
**Category:** Code
**Tags:** tool:cmake
**Created:** [November 14, 2022, 6:36pm UTC](https://discourse.cmake.org/t/create-a-dissasembly-from-a-single-c-file/6868 "2022-11-14T18:36:31Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![patsv](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/90db22/32.png) [@patsv](https://discourse.cmake.org/u/patsv)
#### Post date: [November 14, 2022, 6:36pm UTC](https://discourse.cmake.org/t/create-a-dissasembly-from-a-single-c-file/6868/1 "2022-11-14T18:36:31Z")

</div>

Hi, I want to compile and produce an assembly file from a c file.  
Am translating some makefiles where one produces a single dissasembly file from a c file to determine some info about how this compiler aligns data and so on.  
They just do: $(CC) -o disassem.s -c -S dissassem.c  
Have tried with add\_executable and change the options but it wants to link which fails.  
Like :  
add\_executable(create\_offset asm-offsets.c)

set\_target\_properties(create\_offset  
PROPERTIES  
RUNTIME\_OUTPUT\_DIRECTORY ${GEN\_DIR\_NEW}   
OUTPUT\_NAME asm-offsets.s  
COMPILE\_OPTIONS -S  
)  
Is there a better way?

---

<div class="post-metadata">

### Author: ![fdk17](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/f/ea666f/32.png) [@fdk17](https://discourse.cmake.org/u/fdk17)
#### Post date: [November 15, 2022, 4:16pm UTC](https://discourse.cmake.org/t/create-a-dissasembly-from-a-single-c-file/6868/2 "2022-11-15T16:16:46Z")

</div>

You’d probably have to use `execute_process()` or `custom_target()` to run the compiler to generate the `asm-offsets.s` file. You hint that after creating the disassembly file then something parses `asm-offsets.s` file and then generates a header file or something. Then that all needs to be done a project generation time or before compiling files that need the data.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 15, 2022, 7:54pm UTC](https://discourse.cmake.org/t/create-a-dissasembly-from-a-single-c-file/6868/3 "2022-11-15T19:54:18Z")

</div>

I think the Makefiles generators support this? I don’t quite see how to do it from the main entry points, but this works:

```nohighlight
$ make -f Utilities/KWIML/test/CMakeFiles/kwiml_test.dir/build.make Utilities/KWIML/test/CMakeFiles/kwiml_test.dir/test.c.s
Compiling C source to assembly CMakeFiles/kwiml_test.dir/test.c.s
$ cat Utilities/KWIML/test/CMakeFiles/kwiml_test.dir/test.c.s
…

```

---

<div class="post-metadata">

### Author: ![patsv](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/90db22/32.png) [@patsv](https://discourse.cmake.org/u/patsv)
#### Post date: [November 16, 2022, 6:45am UTC](https://discourse.cmake.org/t/create-a-dissasembly-from-a-single-c-file/6868/4 "2022-11-16T06:45:17Z")

</div>

Yes, maybe but that is not my immediate problem.  
For the moment it tries to link and fails which halts the compilation.

---

<div class="post-metadata">

### Author: ![patsv](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/90db22/32.png) [@patsv](https://discourse.cmake.org/u/patsv)
#### Post date: [November 17, 2022, 7:54am UTC](https://discourse.cmake.org/t/create-a-dissasembly-from-a-single-c-file/6868/5 "2022-11-17T07:54:42Z")

</div>

Interesting, I did not understand what to enter in my CMakeList though.  
I found the generator code and a CMAKE\_CREATE\_ASSEMBLER variable but I could not find that in LLVM compiler which I want to support as an alternative compiler.  
For now I solved it with a add\_custom\_command that calls the CMAKE\_C\_COMPILER .  
Thanks anyway

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 17, 2022, 2:30pm UTC](https://discourse.cmake.org/t/create-a-dissasembly-from-a-single-c-file/6868/6 "2022-11-17T14:30:20Z")

</div>

For the Makefiles generator, there’s nothing to add. You just need to “know” what file to ask for the relevant `.s` file to create.

---

<div class="post-metadata">

### Author: ![patsv](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/90db22/32.png) [@patsv](https://discourse.cmake.org/u/patsv)
#### Post date: [November 18, 2022, 7:17am UTC](https://discourse.cmake.org/t/create-a-dissasembly-from-a-single-c-file/6868/7 "2022-11-18T07:17:01Z")

</div>

Well I just tried to understand what the generator did. I do not know what to enter in my CMakeLists.txt for getting just a .s file and not trigger any linking.  
I am using a cross-compiler and am building a new OS so I do not have anything to link to (yet).  
But the old add\_custom\_target is good enough I think.
