# How to properly configure CMake script to run with osx\_deployment\_target 10.10?

**URL:** <https://discourse.cmake.org/t/how-to-properly-configure-cmake-script-to-run-with-osx-deployment-target-10-10/3395>\
**Category:** Code\
**Created:** [May 24, 2021, 8:47pm UTC](https://discourse.cmake.org/t/how-to-properly-configure-cmake-script-to-run-with-osx-deployment-target-10-10/3395 "2021-05-24T20:47:17Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![lolgear](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lolgear/32/1471_2.png) [@lolgear](https://discourse.cmake.org/u/lolgear)\
**Post date:** [May 24, 2021, 8:47pm UTC](https://discourse.cmake.org/t/how-to-properly-configure-cmake-script-to-run-with-osx-deployment-target-10-10/3395/1 "2021-05-24T20:47:17Z")

</div>

# History

I would like to build libgit2 project with the following script

```sh
#!/bin/sh

export MACOSX_DEPLOYMENT_TARGET=10.10

rm -rf "xcode"
mkdir "xcode"
cd "xcode"
cmake -G "Xcode" ..
open "libgit2.xcodeproj"

```

Open Xcode 12.5 and build git2 target.  
Xcode complains about `futimens` function.  
Warning is “‘futimens’ is only available on macOS 10.13 or newer”.

## Issue at libgit2

[Related issue](https://github.com/libgit2/libgit2/issues/5856) at libgit2.

## StackOverflow solution

I also tried this [solution](https://stackoverflow.com/questions/44318151/why-are-mac-os-x-version-min-required-and-mac-os-x-version-max-allowed-no-longer) at StackOverflow.

I changed CMakeLists.txt at root directory by adding these lines.

```auto
IF (APPLE)
	OPTION(USE_ICONV "Link with and use iconv library" ON)
	ADD_COMPILE_OPTIONS(-mmacosx-version-min=10.10) /// compile option
	set(CMAKE_OSX_DEPLOYMENT_TARGET "10.10" CACHE STRING "" FORCE) /// and cmake_osx_deployment target
ENDIF()

```

Nothing changed.

## Actual

Xcode still complains about `futimens` function.  
Could anybody help with proper configuration?

## Environment

macOS 11.3.1  
Xcode 12.5  
Cmake 3.20.2  
libgit2 ( latest main ).

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [May 26, 2021, 5:22pm UTC](https://discourse.cmake.org/t/how-to-properly-configure-cmake-script-to-run-with-osx-deployment-target-10-10/3395/2 "2021-05-26T17:22:04Z")

</div>

`CMAKE_OSX_DEPLOYMENT_TARGET` (as a CMake variable) should do it. I wonder if `check_function_exists` needs some help [here](https://github.com/libgit2/libgit2/blob/508361401fbb5d87118045eaeae3356a729131aa/src/CMakeLists.txt#L36)? Could you get the `try_compile` output from that bit with the `--debug-trycompile` flag?

---

<div class="post-metadata">

**Author:** ![lolgear](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lolgear/32/1471_2.png) [@lolgear](https://discourse.cmake.org/u/lolgear)\
**Post date:** [May 26, 2021, 8:25pm UTC](https://discourse.cmake.org/t/how-to-properly-configure-cmake-script-to-run-with-osx-deployment-target-10-10/3395/3 "2021-05-26T20:25:04Z")

</div>

Could you guide me about `try_compile` for my case?  
I only added `--debug-trycompile` flag in my script.

```auto
cmake --debug-trycompile -G "Xcode" ..

```

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [May 26, 2021, 8:36pm UTC](https://discourse.cmake.org/t/how-to-properly-configure-cmake-script-to-run-with-osx-deployment-target-10-10/3395/4 "2021-05-26T20:36:12Z")

</div>

The output is under `CMakeFiles` somewhere. You can put a `message(FATAL_ERROR)` after the `futimens` check to avoid extra work too.

---

<div class="post-metadata">

**Author:** ![lolgear](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lolgear/32/1471_2.png) [@lolgear](https://discourse.cmake.org/u/lolgear)\
**Post date:** [May 26, 2021, 8:54pm UTC](https://discourse.cmake.org/t/how-to-properly-configure-cmake-script-to-run-with-osx-deployment-target-10-10/3395/5 "2021-05-26T20:54:08Z")

</div>

`-target` is passed with value `x86_64-apple-macos10.10`.

```auto
Determining if the function futimens exists passed with the following output:
Change Dir: /Users/me/libgit2/xcode/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/xcodebuild -project CMAKE_TRY_COMPILE.xcodeproj build -target cmTC_50ec0 -parallelizeTargets -configuration Debug -hideShellScriptEnvironment && Command line invocation:
    /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -project CMAKE_TRY_COMPILE.xcodeproj build -target cmTC_50ec0 -parallelizeTargets -configuration Debug -hideShellScriptEnvironment

User defaults from command line:
    HideShellScriptEnvironment = YES
    IDEPackageSupportUseBuiltinSCM = YES

note: Using new build system
note: Building targets in parallel
note: Planning build
note: Analyzing workspace
note: Constructing build description
note: Build preparation complete

CompileC /Users/me/libgit2/xcode/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_50ec0.build/Objects-normal/x86_64/CheckFunctionExists.o /usr/local/Cellar/cmake/3.20.2/share/cmake/Modules/CheckFunctionExists.c normal x86_64 c com.apple.compilers.llvm.clang.1_0.compiler (in target 'cmTC_50ec0' from project 'CMAKE_TRY_COMPILE')
    cd /Users/me/libgit2/xcode/CMakeFiles/CMakeTmp
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x c 
    -target x86_64-apple-macos10.10 
    -fmessage-length\=0 
    -fdiagnostics-show-note-include-stack 
    -fmacro-backtrace-limit\=0 -Wno-trigraphs 
    -fpascal-strings 
    -O0 
    -Wno-missing-field-initializers 
    -Wno-missing-prototypes
    -Wno-return-type
    -Wno-missing-braces
    -Wparentheses
    -Wswitch
    -Wno-unused-function
    -Wno-unused-label
    -Wno-unused-parameter
    -Wno-unused-variable
    -Wunused-value
    -Wno-empty-body
    -Wno-uninitialized
    -Wno-unknown-pragmas
    -Wno-shadow
    -Wno-four-char-constants
    -Wno-conversion
    -Wno-constant-conversion
    -Wno-int-conversion
    -Wno-bool-conversion
    -Wno-enum-conversion
    -Wno-float-conversion
    -Wno-non-literal-null-conversion
    -Wno-objc-literal-conversion
    -Wno-shorten-64-to-32
    -Wpointer-sign
    -Wno-newline-eof
    -DCMAKE_INTDIR\=\"Debug\"
    -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk
    -fasm-blocks
    -fstrict-aliasing
    -Wdeprecated-declarations
    -g
    -Wno-sign-conversion
    -Wno-infinite-recursion
    -Wno-comma
    -Wno-block-capture-autoreleasing
    -Wno-strict-prototypes
    -Wno-semicolon-before-method-body
    -I/Users/me/libgit2/xcode/CMakeFiles/CMakeTmp/Debug/include
    -I/Users/me/libgit2/xcode/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_50ec0.build/DerivedSources-normal/x86_64
    -I/Users/me/libgit2/xcode/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_50ec0.build/DerivedSources/x86_64
    -I/Users/me/libgit2/xcode/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_50ec0.build/DerivedSources
    -F/Users/me/libgit2/xcode/CMakeFiles/CMakeTmp/Debug
    -D_GNU_SOURCE
    -Wall
    -Wextra
    -fvisibility\=hidden
    -fPIC
    -Wdocumentation
    -Wno-documentation-deprecated-sync
    -Wno-missing-field-initializers
    -Wstrict-aliasing
    -Wstrict-prototypes
    -Wdeclaration-after-statement
    -Wshift-count-overflow
    -Wunused-const-variable
    -Wunused-function
    -Wint-conversion
    -Wformat
    -Wformat-security
    -Wmissing-declarations
    -DCHECK_FUNCTION_EXISTS\=futimens
    -MMD
    -MT dependencies
    -MF /Users/me/libgit2/xcode/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_50ec0.build/Objects-normal/x86_64/CheckFunctionExists.d
    --serialize-diagnostics /Users/me/libgit2/xcode/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_50ec0.build/Objects-normal/x86_64/CheckFunctionExists.dia
    -c /usr/local/Cellar/cmake/3.20.2/share/cmake/Modules/CheckFunctionExists.c
    -o /Users/me/libgit2/xcode/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_50ec0.build/Objects-normal/x86_64/CheckFunctionExists.o

WriteAuxiliaryFile /Users/me/libgit2/xcode/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_50ec0.build/Objects-normal/x86_64/cmTC_50ec0.LinkFileList (in target 'cmTC_50ec0' from project 'CMAKE_TRY_COMPILE')
    cd /Users/me/libgit2/xcode/CMakeFiles/CMakeTmp
    write-file /Users/me/libgit2/xcode/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_50ec0.build/Objects-normal/x86_64/cmTC_50ec0.LinkFileList

Ld /Users/me/libgit2/xcode/CMakeFiles/CMakeTmp/Debug/cmTC_50ec0 normal (in target 'cmTC_50ec0' from project 'CMAKE_TRY_COMPILE')
    cd /Users/me/libgit2/xcode/CMakeFiles/CMakeTmp
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
    -target x86_64-apple-macos10.10
    -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk
    -L/Users/me/libgit2/xcode/CMakeFiles/CMakeTmp/Debug
    -F/Users/me/libgit2/xcode/CMakeFiles/CMakeTmp/Debug
    -filelist /Users/me/libgit2/xcode/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_50ec0.build/Objects-normal/x86_64/cmTC_50ec0.LinkFileList
    -Xlinker -object_path_lto 
    -Xlinker /Users/me/libgit2/xcode/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_50ec0.build/Objects-normal/x86_64/cmTC_50ec0_lto.o
    -Xlinker -no_deduplicate 
    -Wl,-search_paths_first 
    -Wl,-headerpad_max_install_names 
    -Xlinker -dependency_info 
    -Xlinker /Users/me/libgit2/xcode/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_50ec0.build/Objects-normal/x86_64/cmTC_50ec0_dependency_info.dat
    -o /Users/me/libgit2/xcode/CMakeFiles/CMakeTmp/Debug/cmTC_50ec0

RegisterExecutionPolicyException /Users/me/libgit2/xcode/CMakeFiles/CMakeTmp/Debug/cmTC_50ec0 (in target 'cmTC_50ec0' from project 'CMAKE_TRY_COMPILE')
    cd /Users/me/libgit2/xcode/CMakeFiles/CMakeTmp
    builtin-RegisterExecutionPolicyException /Users/me/libgit2/xcode/CMakeFiles/CMakeTmp/Debug/cmTC_50ec0

**BUILD SUCCEEDED**

```

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [May 26, 2021, 9:47pm UTC](https://discourse.cmake.org/t/how-to-properly-configure-cmake-script-to-run-with-osx-deployment-target-10-10/3395/6 "2021-05-26T21:47:57Z")

</div>

Hmm. So why did the build succeed? Maybe it should be tested for existence under `-Werror=deprecation` (err, not that one, but whatever flag makes sense)?

---

<div class="post-metadata">

**Author:** ![lolgear](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lolgear/32/1471_2.png) [@lolgear](https://discourse.cmake.org/u/lolgear)\
**Post date:** [May 27, 2021, 7:06am UTC](https://discourse.cmake.org/t/how-to-properly-configure-cmake-script-to-run-with-osx-deployment-target-10-10/3395/7 "2021-05-27T07:06:26Z")

</div>

I guess that I find a problem.  
It seems that the problem is out of scope. I tried to compile a representative file at related CMake [issue](https://gitlab.kitware.com/cmake/cmake/-/issues/17101) and it fails.

```auto
$ cat check.c
#include <fcntl.h>
#include <sys/stat.h>
int main()
{
  utimensat(0,0,0,0);
  return 0;
}
$ cc check.c -isysroot /Applications/Xcode-9-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -mmacosx-version-min=10.11
check.c:5:3: warning: 'utimensat' is only available on macOS 10.13 or newer [-Wunguarded-availability-new]
  utimensat(0,0,0,0);
  ^ ~~~~~~~~

```

In my case it compiles without a hassle with all warnings enabled. I open a xcodeproject file and I find that Xcode doesn’t include \<sys/stat.h\> header. So, my function is just defined as `futimens`. ( `char futimens(void)` - template ).

Could I somehow add or pass as parameters these headers to `check_function_exists`?

---

<div class="post-metadata">

**Author:** ![lolgear](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lolgear/32/1471_2.png) [@lolgear](https://discourse.cmake.org/u/lolgear)\
**Post date:** [May 27, 2021, 7:42am UTC](https://discourse.cmake.org/t/how-to-properly-configure-cmake-script-to-run-with-osx-deployment-target-10-10/3395/8 "2021-05-27T07:42:01Z")

</div>

## Current Version

If I use `check_function_exists`, it doesn’t include any related header to search for a function. Maybe it is a setting in these CMakeLIsts.txt

```cmake
enable_warnings(error)
# check_symbol_exists(futimens sys/stat.h HAVE_FUTIMENS)
check_function_exists(futimens HAVE_FUTIMENS)
IF (HAVE_FUTIMENS)
	SET(GIT_USE_FUTIMENS 1)
ENDIF()
message(FATAL_ERROR)

```

Source file is

```c
char futimens(void);
int main(int ac, char* av[])
{
  CHECK_FUNCTION_EXISTS();
  if (ac > 1000) {
    return *av[0];
  }
  return 0;
}

```

## Proposed solution

My solution is `check_symbol_exists`.

```cmake
enable_warnings(error)
check_symbol_exists(futimens sys/stat.h HAVE_FUTIMENS)
# check_function_exists(futimens HAVE_FUTIMENS)
IF (HAVE_FUTIMENS)
	SET(GIT_USE_FUTIMENS 1)
ENDIF()
message(FATAL_ERROR)

```

And related source file is

```c
/* */
#include <sys/stat.h>

int main(int argc, char** argv)
{
  (void)argv;
#ifndef futimens
  return ((int*)(&futimens))[argc]; // error
#else
  (void)argc;
  return 0;
#endif
}

```

I guess that it should be done in different way, no? `check_function_exists` should work, right?

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [May 27, 2021, 10:38am UTC](https://discourse.cmake.org/t/how-to-properly-configure-cmake-script-to-run-with-osx-deployment-target-10-10/3395/9 "2021-05-27T10:38:27Z")

</div>

> [@lolgear](#):
>
> I guess that it should be done in different way, no? `check_function_exists` should work, right?

There are differences between whether the symbol is a macro or an actual function I think. I would think that using `check_symbol_exists` is the way to fix this.

---

<div class="post-metadata">

**Author:** ![lolgear](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lolgear/32/1471_2.png) [@lolgear](https://discourse.cmake.org/u/lolgear)\
**Post date:** [May 27, 2021, 12:29pm UTC](https://discourse.cmake.org/t/how-to-properly-configure-cmake-script-to-run-with-osx-deployment-target-10-10/3395/10 "2021-05-27T12:29:43Z")

</div>

But CMake issue is closed.  
It should work, am I right?

I guess that I do something wrong or this script is broken.

Besides, if I understand it correctly, CMake do a pretty easy test for errors by compiling a program with given function invocation. In `check_function_exists` this macros will be substituted by provided value `futimens`.

But, what I really don’t understand, why example program doesn’t contain headers with “possible” symbol of a function. They should include it, no? How will compiler find a header with this function?

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [May 27, 2021, 1:33pm UTC](https://discourse.cmake.org/t/how-to-properly-configure-cmake-script-to-run-with-osx-deployment-target-10-10/3395/11 "2021-05-27T13:33:26Z")

</div>

> [@lolgear](#):
>
> But CMake issue is closed.

Which issue?

> [@lolgear](#):
>
> But, what I really don’t understand, why example program doesn’t contain headers with “possible” symbol of a function. They should include it, no? How will compiler find a header with this function?

Yes, if the function being tested is in `sys/stat.h`, the example program will need to include that. This really looks like an issue in the `libgit2` CMake code to me.

---

<div class="post-metadata">

**Author:** ![lolgear](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lolgear/32/1471_2.png) [@lolgear](https://discourse.cmake.org/u/lolgear)\
**Post date:** [May 29, 2021, 3:45pm UTC](https://discourse.cmake.org/t/how-to-properly-configure-cmake-script-to-run-with-osx-deployment-target-10-10/3395/12 "2021-05-29T15:45:30Z")

</div>

[CMake Issue](https://gitlab.kitware.com/cmake/cmake/-/issues/17101).

CMake has a note at [check\_function\_exists](https://cmake.org/cmake/help/latest/module/CheckFunctionExists.html) help page.

–  
Prefer using `CheckSymbolExists` instead of this module, for the following reasons:

- `check_function_exists()` can’t detect functions that are inlined in headers or specified as a macro.
- `check_function_exists()` can’t detect anything in the 32-bit versions of the Win32 API, because of a mismatch in calling conventions.
- `check_function_exists()` only verifies linking, it does not verify that the function is declared in system headers.

–

`futimens` neither inlined nor a macros nor a part of Win32 API.  
What I’m worried about is a last point.  
What if a function isn’t declared but it exists in previous versions of macOS?  
It makes sense why `check_function_exists` confirms existence of `futimens`.
