# Processing assembly files with C Preprocessor statements

**URL:** https://discourse.cmake.org/t/processing-assembly-files-with-c-preprocessor-statements/3599
**Category:** Usage
**Tags:** os:windows, gen:makefiles
**Created:** [June 21, 2021, 9:58am UTC](https://discourse.cmake.org/t/processing-assembly-files-with-c-preprocessor-statements/3599 "2021-06-21T09:58:09Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Bilal](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/3ab097/32.png) [@Bilal](https://discourse.cmake.org/u/Bilal)
#### Post date: [June 21, 2021, 9:58am UTC](https://discourse.cmake.org/t/processing-assembly-files-with-c-preprocessor-statements/3599/1 "2021-06-21T09:58:09Z")

</div>

Hi,

I have assembly files(\*.asm extension) with C preprocessor statements. These files are recognized by CMAKE as ASM files. On compilers where the control program/compiler itself supports pre-processing and assembling I do not run into any problems. On the compilers where the compiler only supported preprocessing and assembling has to be done by the seperate assembler, I run into problems(as I can either send the files to the compiler to preprocess or to the assembler to assembler but not both).

I read up on [https://gitlab.kitware.com/cmake/cmake/-/issues/21376](https://gitlab.kitware.com/cmake/cmake/-/issues/21376) which is a similar problem. But, I did not find a recommended way to solve the problem.

Can someone point me to the right direction on what would be the best way to preprocess the .asm using the CMAKE\_C\_COMPILER and then piping the output over to the CMAKE\_ASM\_COMPILER for assembling.

Best,  
–Bilal

---

<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: [June 21, 2021, 5:30pm UTC](https://discourse.cmake.org/t/processing-assembly-files-with-c-preprocessor-statements/3599/2 "2021-06-21T17:30:54Z")

</div>

I don’t think CMake has a preprocessing step for ASM files for use in general. @brad.king?

---

<div class="post-metadata">

### Author: ![Bilal](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/3ab097/32.png) [@Bilal](https://discourse.cmake.org/u/Bilal)
#### Post date: [June 22, 2021, 9:58am UTC](https://discourse.cmake.org/t/processing-assembly-files-with-c-preprocessor-statements/3599/3 "2021-06-22T09:58:20Z")

</div>

If that really is the case,what is the recommended way to workaround it ?

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [June 22, 2021, 1:11pm UTC](https://discourse.cmake.org/t/processing-assembly-files-with-c-preprocessor-statements/3599/4 "2021-06-22T13:11:28Z")

</div>

CMake does not model explicit preprocessing in general. ASM sources may be preprocessed if the assembler itself supports doing so. Many assemblers support preprocessing upper-case extensions, particularly when the C compiler itself is used as the assembler.

Otherwise, one could look at using `add_custom_command` to run the C preprocessor first and generate an already-preprocessed source that is then given to `add_library` or `add_executable` as an ASM source.

---

<div class="post-metadata">

### Author: ![elmot](https://discourse.cmake.org/user_avatar/discourse.cmake.org/elmot/32/1947_2.png) [@elmot](https://discourse.cmake.org/u/elmot)
#### Post date: [November 8, 2021, 11:09pm UTC](https://discourse.cmake.org/t/processing-assembly-files-with-c-preprocessor-statements/3599/5 "2021-11-08T23:09:36Z")

</div>

Our customer faced the same problem.  
Assembler preprocessing is done by gcc and, most probably, armclang if `-x assembler-with-cpp` CLI options are provided. So for me `add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-x$<SEMICOLON>assembler-with-cpp>)` clause does the trick.
