MacOS sysroot path is to specific, highly dependent on Xcode version
When compiling sac2c on MacOS, we append to
-isysroot flag to the CMake variable
CMAKE_OSX_SYSROOT. This is needed so that when using sac2c we are able to find C-libraries and other system libraries. We store
CCFLAGS in the sac2crc files.
It is not clear to me, but for whatever reason the
CMAKE_OSX_SYSROOT variable resolves to a path which is Xcode version specific, e.g.
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk. This can cause problems whenever a newer version of Xcode is installed. MacOS PKG files have no notion of inter-dependency --- it is not a package manager as such.
Furthermore, if there are multiple versions of Xcode on the system, then we are totally doomed. This was experienced in Stdlib PR 44.
It is not clear to me how best to resolve this, here are a few idea:
- there seems to be a generic sysroot path, of the form
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk, but its not clear to me if this is dependable enough to rely on it.
- another is to poll for it when calling sac2c, using
xcode-select --print-pathor similar.
- as this path is encoded in the sac2crc files, we just need to update this. This could be possible as part of the CPack productbuild process using the
CPACK_POSTFLIGHT_<COMP>_SCRIPTvariable to set a script which looks for the correct path, and updates the sac2crc files during install.