# Fail to compile ARM assembly files by CMake

**URL:** https://discourse.cmake.org/t/fail-to-compile-arm-assembly-files-by-cmake/4300
**Category:** Code
**Tags:** os:linux
**Created:** [October 18, 2021, 2:50pm UTC](https://discourse.cmake.org/t/fail-to-compile-arm-assembly-files-by-cmake/4300 "2021-10-18T14:50:29Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Takao](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/t/ce7236/32.png) [@Takao](https://discourse.cmake.org/u/Takao)
#### Post date: [October 18, 2021, 2:50pm UTC](https://discourse.cmake.org/t/fail-to-compile-arm-assembly-files-by-cmake/4300/1 "2021-10-18T14:50:29Z")

</div>

Hi,  
I have cross compile environment with arm embedded toolchain(gcc-arm-none-eabi-5\_4-2016q3) on Ubuntu20.04. If I try to compile ARM assembly file by cli, it works fine:

```auto
> arm-none-eabi-gcc -x assembler-with-cpp -mcpu=cortex-m7 -mthumb -I include/ src/sys/startup_file.s --specs=nosys.specs -c -o startup_file.o

```

However if I try to do the same by CMake, it complains:

```auto
Assembler messages:
Error: selected processor does not support `dmb' in ARM mode
Error: selected processor does not support `dsb' in ARM mode
Error: attempt to use an ARM instruction on a Thumb-only processor -- `strd R0,R1,[R2]'
Error: attempt to use an ARM instruction on a Thumb-only processor -- `bx R14'

```

For especially ASM, I’ve set following parameters in CMakeLists.txt and toolchain.cmake file respectively:  
**[CMakeLists.txt]**

```auto
enable_language(C ASM)

```

**[toolchain.cmake]**

```auto
set(CMAKE_C_COMPILER arm-none-eabi-gcc)
set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER})
unset(CMAKE_ASM_FLAGS CACHE)
set(CMAKE_ASM_FLAGS "-x assembler-with-cpp -mcpu=cortex-m7 -mthumb \
                    --specs=nosys.specs -c" CACHE STRING "" FORCE)

```

Do you see anything missing or wrong?

---

<div class="post-metadata">

### Author: ![buildSystemPerson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/buildsystemperson/32/2851_2.png) [@buildSystemPerson](https://discourse.cmake.org/u/buildSystemPerson)
#### Post date: [October 18, 2021, 4:08pm UTC](https://discourse.cmake.org/t/fail-to-compile-arm-assembly-files-by-cmake/4300/2 "2021-10-18T16:08:21Z")

</div>

> [@Takao](#):
>
> ```auto
> unset(CMAKE_ASM_FLAGS CACHE)
> set(CMAKE_ASM_FLAGS "-x assembler-with-cpp -mcpu=cortex-m7 -mthumb \
> --specs=nosys.specs -c" CACHE STRING "" FORCE)
> 
> ```

You need to use this variable instead I believe:  
[https://cmake.org/cmake/help/latest/variable/CMAKE\_LANG\_FLAGS\_INIT.html](https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_FLAGS_INIT.html)

Toolchain files shouldn’t set CMAKE\_LANG\_FLAGS variable you need to set the \_INIT equivalent.
