# How to prevent CMake from adding host system flags (-arch arm64) when cross-compiling with ExternalProject\_Add?

**URL:** https://discourse.cmake.org/t/how-to-prevent-cmake-from-adding-host-system-flags-arch-arm64-when-cross-compiling-with-externalproject-add/13374
**Category:** Usage
**Created:** [January 11, 2025, 1:09pm UTC](https://discourse.cmake.org/t/how-to-prevent-cmake-from-adding-host-system-flags-arch-arm64-when-cross-compiling-with-externalproject-add/13374 "2025-01-11T13:09:33Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![diegoll](https://discourse.cmake.org/user_avatar/discourse.cmake.org/diegoll/32/5263_2.png) [@diegoll](https://discourse.cmake.org/u/diegoll)
#### Post date: [January 11, 2025, 1:09pm UTC](https://discourse.cmake.org/t/how-to-prevent-cmake-from-adding-host-system-flags-arch-arm64-when-cross-compiling-with-externalproject-add/13374/1 "2025-01-11T13:09:33Z")

</div>

I’m working on cross-compiling a library for RISC-V using CMake’s ExternalProject\_Add. When CMake tries to test the compiler, it’s adding macOS-specific flags (-arch arm64 -isysroot) even though I’m using a RISC-V toolchain. Here’s the error:

> `[1/2] /path/to/riscv32-esp-elf-gcc -march=rv32imc_zicsr_zifencei -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX15.1.sdk ... riscv32-esp-elf-gcc: error: unrecognized command-line option '-arch'`

I’ve tried:

- Setting CMAKE\_OSX\_\* variables to empty strings
- Using a custom toolchain file
- Setting CMAKE\_SYSTEM\_NAME and CMAKE\_SYSTEM\_PROCESSOR

But CMake still adds these macOS-specific flags when testing the compiler. How can I prevent CMake from adding host system flags when using ExternalProject\_Add?"

---

<div class="post-metadata">

### Author: ![diegoll](https://discourse.cmake.org/user_avatar/discourse.cmake.org/diegoll/32/5263_2.png) [@diegoll](https://discourse.cmake.org/u/diegoll)
#### Post date: [January 12, 2025, 10:55pm UTC](https://discourse.cmake.org/t/how-to-prevent-cmake-from-adding-host-system-flags-arch-arm64-when-cross-compiling-with-externalproject-add/13374/2 "2025-01-12T22:55:34Z")

</div>

I solved it by properly passing the toolchain that I was using to build my main project. For future reference this is just by passing

```auto
CMAKE_ARGS
    "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}"
    # ... rest of the args`

```
