CMake seems to ignore CMAKE_OSX_DEPLOYMENT_TARGET CMake seems to ignore CMAKE_OSX_DEPLOYMENT_TARGET xcode xcode

CMake seems to ignore CMAKE_OSX_DEPLOYMENT_TARGET


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.


(I tried to add this as a comment, but it's too long for the comment box, so I've posted it as an answer, though of course it's really a further question.)

Under Big Sur I've been trying to build the SDL2 version of DOSBox-X, with this string added to all cmakelists.txt files in the project, with the added line always above the project() line:

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

The FORCE at the end of the string was recommended in this thread (and I tried with and without FORCE.)

Why the CMAKE_OSX_DEPLOYMENT_TARGET not work when using cmake generate xcode project?

When I try to run the resulting executable under Mojave, I get this error:

Dyld Error Message:  Symbol not found: _objc_opt_class  Referenced from: /Users/USER/Desktop/dosbox-x (which was built for Mac OS X 11.0)  Expected in: /usr/lib/libobjc.A.dylib

DOSBox-X uses bash scripts to build under macOS and Linux. I can't find any solution here, and I wonder if anyone has any further thoughts.