# check\_c\_source\_compiles order CMAKE\_REQUIRED\_FLAGS

**URL:** https://discourse.cmake.org/t/check-c-source-compiles-order-cmake-required-flags/15667
**Category:** Development
**Created:** [May 26, 2026, 7:15pm UTC](https://discourse.cmake.org/t/check-c-source-compiles-order-cmake-required-flags/15667 "2026-05-26T19:15:34Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Niram](https://discourse.cmake.org/user_avatar/discourse.cmake.org/niram/32/6140_2.png) [@Niram](https://discourse.cmake.org/u/Niram)
#### Post date: [May 26, 2026, 7:15pm UTC](https://discourse.cmake.org/t/check-c-source-compiles-order-cmake-required-flags/15667/1 "2026-05-26T19:15:34Z")

</div>

Hello,

Why not add CMAKE\_REQUIRED\_FLAGS before CMAKE\_\_FLAGS instead?

[https://cmake.org/cmake/help/latest/module/CheckCSourceCompiles.html](https://cmake.org/cmake/help/latest/module/CheckCSourceCompiles.html)

> CMAKE\_REQUIRED\_FLAGS
> 
> A space-separated string of additional flags to pass to the compiler. A semicolon-separated list will not work. The contents of CMAKE\__FLAGS and its associated configuration-specific CMAKEFLAGS_ variables are automatically prepended to the compiler command before the contents of this variable.

It would avoid flags like -mno-avx2 provided by root project to be ignored by -mavx2 in subproject for example : causing runtime issues on release with incompatible CPU

> **[Compiler Explorer - C++ (x86-64 clang (trunk))](https://godbolt.org/z/3j8zdG8xG)**
>
> cmake\_minimum\_required(VERSION 4.0)
> 
> project(shapes)
> 
> include(CheckCSourceCompiles)
> 
> add\_compile\_options(-march=x86-64-v2 -mno-avx2)
> 
> set(CMAKE\_REQUIRED\_FLAGS "-mavx2")
> check\_c\_source\_compiles(
> "#ifndef \_\_AVX2\_\_\\n#error \\"should be...
