I changed CMakeLists.txt at root directory by adding these lines.
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?
CMAKE_OSX_DEPLOYMENT_TARGET (as a CMake variable) should do it. I wonder if check_function_exists needs some help here? Could you get the try_compile output from that bit with the --debug-trycompile flag?
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)?
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 and it fails.
$ 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?
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.
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?
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.
–
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.