Formula fails to build, but only if XCode is installed

I’ve got a personal formula for a command line tool that fails to build…but only if XCode is installed. If Xcode isn’t there, it builds just fine using the XCode command line tools. I can reproduce this by dragging XCode back and forth from the trash. When I look at the logs, there’s one obvious difference: the command line tools are using MacOSX10.15.sdk, while XCode is using MacOSX10.14.sdk:

~~ with Xcode command-line tools ~~
superenv added:    -pipe -Os -march=nehalem /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk --sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk -isystem/usr/local/include -isystem/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/libxml2 -isystem/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/OpenGL.framework/Versions/Current/Headers -I/usr/local/opt/libarchive/include -I/usr/local/opt/openssl/include

~~ with Xcode app installed ~~
superenv added:    -pipe -Os -march=nehalem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -isystem/usr/local/include -isystem/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/libxml2 -isystem/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/OpenGL.framework/Versions/Current/Headers -I/usr/local/opt/libarchive/include -I/usr/local/opt/openssl/include

I’m not sure exactly why it’s failing to build with the 10.14 SDK…but is it possible to just add something to the recipe to force usage of the command line tools, or of a particular SDK version?

I have had this problem most often with high sierra (10.13) using the 10.14 SDK when I don’t want it to. Unsetting the SDKROOT in the def install method of your formula is one thing to try, since that variable gets set automatically by homebrew somewhere:

ENV.delete("SDKROOT")

I have also tinkered with the MACOSX_DEPLOYMENT_TARGET environment variable.

Thank you for the tips! After playing with it for a while, though, I just decided to add a bottle for Mojave (built with no xcode installed), and not worry about building it at all.