Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake seems to ignore CMAKE_OSX_DEPLOYMENT_TARGET

Tags:

c++

xcode

cmake

I'm using CMake 3.3.2 and Xcode 7.1 on OS X 10.10.5.

I have a small C++ project that uses CMake. I want it to run on OS X 10.9 or later. So I modified my CMakeLists.txt to look start this:

cmake_minimum_required(VERSION 3.3)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9")

project(...

Then I create the Xcode project like this:

cmake -G Xcode <path>

However, the resulting xcodeproj bundle doesn't seem to have a deployment target set. When I open the contained project.pbxproj file in a text editor, there is no line mentioning MACOSX_DEPLOYMENT_TARGET.

Accordingly, when I open the project in Xcode, under Build Settings > Deployment > OS X Deployment Target, Xcode always displays the default value "OS X 10.11", no matter what I specify in CMakeLists.txt. When I manually change the setting in Xcode and then re-open the project file in a text editor, the line MACOSX_DEPLOYMENT_TARGET = 10.9; has correctly been added.

Am I doing something wrong? Googling the problem didn't give any recent results.

like image 849
Daniel Wolf Avatar asked Dec 10 '15 17:12

Daniel Wolf


1 Answers

The variable CMAKE_OSX_DEPLOYMENT_TARGET must initialized as a cache variable prior to the first project() command in order for the Xcode project generation to be picked up properly:

set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "Minimum OS X deployment version")

If not set explicitly as a cache variable the CMAKE_OSX_DEPLOYMENT_TARGET is initialized by the MACOSX_DEPLOYMENT_TARGET environment variable.

The initialization of a cache variable like in the assignment above will also override the value of non-cache variables of the same name in the same scope.

like image 105
sakra Avatar answered Oct 03 '22 06:10

sakra