# How to set CMAKE\_OSX\_DEPLOYMENT\_TARGET, conditionally?

**URL:** https://discourse.cmake.org/t/how-to-set-cmake-osx-deployment-target-conditionally/7772
**Category:** Usage
**Tags:** os:macos
**Created:** [March 27, 2023, 4:49am UTC](https://discourse.cmake.org/t/how-to-set-cmake-osx-deployment-target-conditionally/7772 "2023-03-27T04:49:20Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![bavulapati](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bavulapati/32/3270_2.png) [@bavulapati](https://discourse.cmake.org/u/bavulapati)
#### Post date: [March 27, 2023, 4:49am UTC](https://discourse.cmake.org/t/how-to-set-cmake-osx-deployment-target-conditionally/7772/1 "2023-03-27T04:49:20Z")

</div>

Our project uses a single CMakeLists.txt file for both iOS and MacOS apps. We would like to set `CMAKE_OSX_DEPLOYMENT_TARGET` from the CMakeLists.txt file depending on the target OS(iOS, MacOS).

CMAKE\_OSX\_DEPLOYMENT\_TARGET has to be set before `project()` call and `CMAKE_SYSTEM_NAME` would be undefined before `project()` call. Do we have any way to set `CMAKE_OSX_DEPLOYMENT_TARGET` conditionally?

---

<div class="post-metadata">

### Author: ![bavulapati](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bavulapati/32/3270_2.png) [@bavulapati](https://discourse.cmake.org/u/bavulapati)
#### Post date: [March 27, 2023, 6:55am UTC](https://discourse.cmake.org/t/how-to-set-cmake-osx-deployment-target-conditionally/7772/2 "2023-03-27T06:55:43Z")

</div>

cc: @RaisinTen @craig.scott for better reach

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [March 27, 2023, 8:24am UTC](https://discourse.cmake.org/t/how-to-set-cmake-osx-deployment-target-conditionally/7772/3 "2023-03-27T08:24:45Z")

</div>

You could take advantage of the fact that `CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET` will override `CMAKE_OSX_DEPLOYMENT_TARGET` for iOS. Set the former to your iOS deployment target the latter to your macOS deployment target. In theory, I think that should work.

The IPHONEOS\_DEPLOYMENT\_TARGET is just one of the build settings Xcode supports. It also has `MACOSX_DEPLOYMENT_TARGET`, `TVOS_DEPLOYMENT_TARGET`, and so on. You should be able to set all of these using `CMAKE_XCODE_ATTRIBUTE_...` variables if you need different values for different target architectures. I believe they should all override whatever `CMAKE_OSX_DEPLOYMENT_TARGET` is set to, which you might not even have to set at all then.
