[CMake] Computation of CMAKE_OSX_SYSROOT

Craig Scott craig.scott at crascit.com
Mon Oct 1 09:25:08 EDT 2018


On Mon, Oct 1, 2018 at 10:53 PM James Turner via CMake <cmake at cmake.org>
wrote:

> Hi,
>
> The docs here:
>
>         https://cmake.org/cmake/help/v3.12/variable/CMAKE_OSX_SYSROOT.html
>
> state that CMAKE_OSX_SYSROOT is computed from CMAKE_OSX_DEPLOYMENT_TARGET
> if not explicitly set. Can anyone comment on how this works, because in my
> setup it seems to be failing. This showed up as -isysroot not being passed
> to the compiler, which then causes weird compile failures building on High
> Sierra with Xcode 10 and the 10.14 SDK.
>
> If explicitly set SDKROOT or CMAKE_OSX_SYSROOT to the 10.14 SDK,
> everything compiles fine. (Without passing -isysroot, some header is
> /usr/include are used, and apparently these don’t work for building the
> 10.14 frameworks)
>
> Deployment target is set to:
>
>         set(CMAKE_OSX_DEPLOYMENT_TARGET "10.7”)
>
> Note that I do this *after* calling project() because contrary to its
> docs, I find that when I call it before project(), it has no effect. (eg,
> passing -mmacosx-version-min=10.7 to the compiler).
>
> Full CMakeList.txt is here:
>
>
> https://sourceforge.net/p/flightgear/flightgear/ci/next/tree/CMakeLists.txt
>
> Any comments on what is going on, would be appreciated.
>


You need to set CMAKE_OSX_DEPLOYMENT_TARGET as a *cache* variable before
calling the project() command. If you set it as a normal (i.e. non-cache)
variable, the compiler detection logic triggered by the project() call
creates a cache variable if one doesn't exist, which would discard the
non-cache variable. It's a bit unfortunate, but that's what happens when
you set a cache variable for the first time. The relevant code related to
your observations is in Modules/Platform/Darwin-Initialize.cmake.


-- 
Craig Scott
Melbourne, Australia
https://crascit.com

New book released: Professional CMake: A Practical Guide
<https://crascit.com/professional-cmake/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20181001/2feffec0/attachment.html>


More information about the CMake mailing list