check_pie_supported not always working if the toolchain needs a sysroot
The check_pie_supported() function when testing for the support of the various PIE flags, does not seem to use the CMAKE_SYSROOT
, CMAKE_OSX_SYSROOT
contents, or (for macOS), in general it won't use the same logic as the normal compilation does to discover required flags, so that the test compilation works.
On Linux this is an issue because the test fails linking, since it cannot always find the proper libc library to link if there's a custom toolchain which uses a sysroot.
On macOS Big Sur, the issue is that (some?) standard libraries have moved around in the system.
CMake when compiling normally, automatically passes -isysroot "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"
and this seems enough.
I've also noticed that the sysroot needs to be passed only when using the compiler under "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++|cc", which is what CMake automatically detects without setting the CMAKE_<LANG>_COMPILER
variables.
If passing clang
and clang++
to them instead, the sysroot is not needed.