private CMakeCommandEntry FindBestCMakeEntry(List <CMakeCommandEntry> commands, string documentName)
        {
            if (commands == null || documentName == null)
            {
                return(null);
            }

            string            documentFolder       = Path.GetDirectoryName(documentName) + '/';
            int               documentFolderLength = (documentFolder.Length - 1);
            string            documentFileName     = Path.GetFileNameWithoutExtension(documentName);
            string            lowerInput           = documentFolder.Replace('\\', '/').ToLower();
            int               bestScoreMatch       = 0;
            int               bestUpperFolder      = Int32.MaxValue;
            CMakeCommandEntry bestEntry            = null;

            foreach (CMakeCommandEntry entry in commands)
            {
                //This assumes no ../../ in those file and documentName paths
                string entryLower = entry.file.Replace('\\', '/').ToLower();
                int    scoreMatch = PathCompareScore(lowerInput, entryLower);
                if (scoreMatch >= bestScoreMatch)
                {
                    string entryDir        = Path.GetDirectoryName(entry.file);
                    int    thisUpperFolder = entryDir.Length - documentFolderLength;

                    if (thisUpperFolder == 0 && documentFileName == Path.GetFileNameWithoutExtension(entry.file))
                    {
                        //Same file with different extension match
                        //Early exit
                        return(entry);
                    }

                    if (scoreMatch > bestScoreMatch || (thisUpperFolder >= 0 && thisUpperFolder < bestUpperFolder))
                    {
                        bestScoreMatch  = scoreMatch;
                        bestUpperFolder = thisUpperFolder;
                        bestEntry       = entry;
                    }
                }
            }

            return(bestEntry);
        }
        private void ExtractCMakeProjectProperties(ProjectProperties inout, CMakeCommandEntry command)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (command == null)
            {
                return;
            }

            OutputLog.Log("Extracting commands from Translation Unit: " + command.file);

            inout.WorkingDirectory = command.directory;

            List <string> commands = ParseCommands(command.command);

            for (int i = 0; i < commands.Count; ++i)
            {
                string com = commands[i];

                if (com.Length > 2 && com[0] == '-' || com[0] == '/')
                {
                    if (com[1] == 'D')
                    {
                        inout.PrepocessorDefinitions.Add(com.Substring(2, com.Length - 2));
                    }
                    else if (com[1] == 'I')
                    {
                        inout.IncludeDirectories.Add(com.Substring(2, com.Length - 2));
                    }
                    else if (com == "-m32")
                    {
                        inout.Target = ProjectProperties.TargetType.x86;
                    }
                    else if (com == "-m64")
                    {
                        inout.Target = ProjectProperties.TargetType.x64;
                    }
                    else if (com.StartsWith("-std"))
                    {
                        string standard = com.Substring(5, com.Length - 5);
                        if (standard == "c++98")
                        {
                            inout.Standard = ProjectProperties.StandardVersion.Cpp98;
                        }
                        else if (standard == "c++03")
                        {
                            inout.Standard = ProjectProperties.StandardVersion.Cpp03;
                        }
                        else if (standard == "c++14")
                        {
                            inout.Standard = ProjectProperties.StandardVersion.Cpp14;
                        }
                        else if (standard == "c++17")
                        {
                            inout.Standard = ProjectProperties.StandardVersion.Cpp17;
                        }
                        else if (standard == "c++20")
                        {
                            inout.Standard = ProjectProperties.StandardVersion.Cpp20;
                        }
                        else if (standard == "gnu++98")
                        {
                            inout.Standard = ProjectProperties.StandardVersion.Gnu98;
                        }
                        else if (standard == "gnu++03")
                        {
                            inout.Standard = ProjectProperties.StandardVersion.Gnu03;
                        }
                        else if (standard == "gnu++14")
                        {
                            inout.Standard = ProjectProperties.StandardVersion.Gnu14;
                        }
                        else if (standard == "gnu++17")
                        {
                            inout.Standard = ProjectProperties.StandardVersion.Gnu17;
                        }
                        else if (standard == "gnu++20")
                        {
                            inout.Standard = ProjectProperties.StandardVersion.Gnu20;
                        }
                        else
                        {
                            inout.Standard = ProjectProperties.StandardVersion.Latest;
                        }
                    }
                    else if (com.StartsWith("-include"))
                    {
                        inout.IncludeDirectories.Add(com.Substring(8, com.Length - 8));
                    }
                }
            }
        }