# Not understanding why an if statement isn't working

**URL:** https://discourse.cmake.org/t/not-understanding-why-an-if-statement-isnt-working/13983
**Category:** Usage
**Created:** [April 25, 2025, 11:05am UTC](https://discourse.cmake.org/t/not-understanding-why-an-if-statement-isnt-working/13983 "2025-04-25T11:05:18Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![perdrix](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/a8b319/32.png) [@perdrix](https://discourse.cmake.org/u/perdrix)
#### Post date: [April 25, 2025, 11:05am UTC](https://discourse.cmake.org/t/not-understanding-why-an-if-statement-isnt-working/13983/1 "2025-04-25T11:05:18Z")

</div>

```auto
message("LINUX: " ${LINUX}) 
message("APPLE: " ${APPLE})
message("CMAKE_SYSTEM_NAME: " ${CMAKE_SYSTEM_NAME})
if (LINUX OR (APPLE AND ${CMAKE_OSX_ARCHITECTURES} EQUAL "x86_64"))
message("Setting AVX compile options")
  :
endif()

```

On macOS and building with CMAKE\_OSX\_ARCHITECTURES set to x86\_64 I get:

```auto
1> [CMake] CMAKE_OSX_ARCHITECTURES: x86_64
1> [CMake] LINUX: 
1> [CMake] APPLE: 1
1> [CMake] CMAKE_SYSTEM_NAME: Darwin

```

Note that the message “Setting AVX compile options” wasn’t issued???

I can’t see why not though. Am I being stupid?  
D.

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [April 25, 2025, 11:17am UTC](https://discourse.cmake.org/t/not-understanding-why-an-if-statement-isnt-working/13983/2 "2025-04-25T11:17:38Z")

</div>

To compare strings, use operator `STREQUAL`.

---

<div class="post-metadata">

### Author: ![perdrix](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/a8b319/32.png) [@perdrix](https://discourse.cmake.org/u/perdrix)
#### Post date: [April 25, 2025, 5:13pm UTC](https://discourse.cmake.org/t/not-understanding-why-an-if-statement-isnt-working/13983/3 "2025-04-25T17:13:08Z")

</div>

I tried

```auto
message("CMAKE_OSX_ARCHITECTURES: " ${CMAKE_OSX_ARCHITECTURES})
message("LINUX: " ${LINUX}) 
message("APPLE: " ${APPLE})
message("CMAKE_SYSTEM_NAME: " ${CMAKE_SYSTEM_NAME})
if (LINUX OR (APPLE AND (${CMAKE_OSX_ARCHITECTURES} STREQUAL "x86_64"))
message("Setting AVX compile options")

```

on LINUX and got:

```auto
1> [CMake] CMAKE_OSX_ARCHITECTURES: 
1> [CMake] LINUX: 1
1> [CMake] APPLE: 
1> [CMake] CMAKE_SYSTEM_NAME: Linux
1> [CMake] CMake Error at DeepSkyStackerKernel/CMakeLists.txt:227 (if):
1> [CMake] if given arguments:
1> [CMake] 
1> [CMake] "LINUX" "OR" "(" "APPLE" "AND" "(" "STREQUAL" "x86_64" ")" ")"
1> [CMake] 
1> [CMake] Unknown arguments specified

```

clearly my conditional CMake isn’t quite there yet …

D.

---

<div class="post-metadata">

### Author: ![LegalizeAdulthood](https://discourse.cmake.org/user_avatar/discourse.cmake.org/legalizeadulthood/32/5282_2.png) [@LegalizeAdulthood](https://discourse.cmake.org/u/LegalizeAdulthood)
#### Post date: [April 25, 2025, 7:14pm UTC](https://discourse.cmake.org/t/not-understanding-why-an-if-statement-isnt-working/13983/4 "2025-04-25T19:14:55Z")

</div>

As shown in the output `CMAKE_OSX_ARCHITECTURES` was empty, so when `${CMAKE_OSX_ARCHITECTURES}` is expanded, it expands to empty text, not an empty string. Try `"${CMAKE_OSX_ARCHITECTURES}"` to get the variable expanded into a string literal and then `STREQUAL` is comparing two string literals.

---

<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: [April 26, 2025, 4:28am UTC](https://discourse.cmake.org/t/not-understanding-why-an-if-statement-isnt-working/13983/5 "2025-04-26T04:28:26Z")

</div>

`CMAKE_OSX_ARCHITECTURES` by default is empty:  
[https://cmake.org/cmake/help/latest/variable/CMAKE\_OSX\_ARCHITECTURES.html](https://cmake.org/cmake/help/latest/variable/CMAKE_OSX_ARCHITECTURES.html)

It’s typically set by users. Either on the command line or a toolchain file. That way it’s registered before the first `project` call.

It’s a variable intended for when you want to build a binary with multiple architectures. Apple calls this a universal binary.

---

<div class="post-metadata">

### Author: ![perdrix](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/a8b319/32.png) [@perdrix](https://discourse.cmake.org/u/perdrix)
#### Post date: [April 26, 2025, 8:04am UTC](https://discourse.cmake.org/t/not-understanding-why-an-if-statement-isnt-working/13983/6 "2025-04-26T08:04:33Z")

</div>

Thank you that works 🙂  
David
