diff --git a/src/compile_commands.cpp b/src/compile_commands.cpp index ace761a..94a91e7 100644 --- a/src/compile_commands.cpp +++ b/src/compile_commands.cpp @@ -126,8 +126,16 @@ std::vector CompileCommands::get_arguments(const boost::filesystem: #ifdef __APPLE__ // Add -isysroot argument if it is missing on MacOS, which is needed by newer libclang if(std::none_of(arguments.begin(), arguments.end(), [](const std::string &argument) { return argument == "-isysroot"; })) { - arguments.emplace_back("-isysroot"); - arguments.emplace_back("/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"); + auto sysroots = {"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk", + "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"}; + boost::system::error_code ec; + for(auto &sysroot : sysroots) { + if(boost::filesystem::exists(sysroot, ec)) { + arguments.emplace_back("-isysroot"); + arguments.emplace_back(sysroot); + break; + } + } } #endif