Пример #1
0
        public void NewVariable(string name, string value)
        {
            CMakeCommand command = new CMakeCommand("set", null, this);

            command.AddArgument(name);
            command.AddArgument(value);

            setCommands.Add(string.Format("{0}:{1}{2}", "set", "new", setCommands.Count), command);
            allCommands.Add(string.Format("{0}:{1}{2}", "set", "new", allCommands.Count), command);
        }
Пример #2
0
        public void NewTarget(string name, CMakeTarget.Types type)
        {
            string commandName = "";
            string libraryType = "";

            switch (type)
            {
            case CMakeTarget.Types.Binary:
                commandName = "add_executable";
                break;

            case CMakeTarget.Types.SharedLibrary:
                commandName = "add_library";
                libraryType = "SHARED";
                break;

            case CMakeTarget.Types.StaticLibrary:
                commandName = "add_library";
                libraryType = "STATIC";
                break;

            case CMakeTarget.Types.Module:
                commandName = "add_library";
                libraryType = "MODULE";
                break;

            case CMakeTarget.Types.ObjectLibrary:
                commandName = "add_library";
                libraryType = "OBJECT";
                break;

            case CMakeTarget.Types.Unknown:
                commandName = "add_library";
                libraryType = "UNKNOWN";
                break;

            default:
                commandName = "add_executable";
                LoggingService.LogDebug("Unknown target type: {0}", type);
                break;
            }

            CMakeCommand command = new CMakeCommand(commandName, null, this);

            command.AddArgument(name);
            if (!string.IsNullOrEmpty(libraryType))
            {
                command.AddArgument(libraryType);
            }

            allCommands.Add(string.Format("{0}:{1}{2}", commandName, "new", allCommands.Count), command);

            SaveAll();
            Parse();
        }
Пример #3
0
        public CMakeTarget(CMakeCommand command, CMakeFileFormat parent)
        {
            Initialize(this);
            this.command = command;
            this.parent  = parent;
            if (command.Name.ToLower() == "add_executable")
            {
                type = Types.Binary;
            }

            PopulateFiles();
        }
        public void Set(string variableName, string value, bool isEditable = true, CMakeCommand command = null)
        {
            variableName = ResolveString(variableName);
            value        = ResolveString(value);

            if (Contains(variableName))
            {
                CMakeVariable v = variables [variableName];
                v.Value      = value;
                v.IsEditable = false;
                v.Commands.Add(command);
                return;
            }

            AddVariable(variableName, value, isEditable, command);
        }
Пример #5
0
        public void Parse()
        {
            Targets.Clear();
            SetCommands.Clear();
            allCommands.Clear();
            blocks.Clear();
            Children.Clear();
            projectName = "";

            contentFile = new TextFile(file);
            foreach (Match m in ReadNextCommand())
            {
                try {
                    ParseCommand(m);
                } catch (Exception ex) {
                    throw new Exception(string.Format("Exception: {0}\nFile: {1}", ex.Message, file));
                }
            }

            VariableManager = new CMakeVariableManager(this);

            foreach (CMakeCommand command in targetCommands)
            {
                CMakeTarget target = new CMakeTarget(command, this);

                if (!target.IsAliasOrImported)
                {
                    Targets.Add(string.Format("{0}:{1}", target.Name, command.Offset), target);
                    target.PrintTarget();
                }
            }

            targetCommands.Clear();

            foreach (CMakeFileFormat f in Children.Values)
            {
                targets = targets.Concat(f.Targets).ToDictionary(x => x.Key, x => x.Value);
            }

            if (blocks.Count > 0)
            {
                CMakeCommand c = blocks.Pop();
                throw new Exception(string.Format("Unmatched block command '{0}' in file '{1}' offset '{2}'.", c.Name, file, c.Offset));
            }

            LoggingService.LogDebug("CMake file '{0}' is Loaded.", file);
        }
Пример #6
0
        public bool Rename(string oldName, string newName)
        {
            CMakeCommand c = allCommands.FirstOrDefault((arg) => {
                return(arg.Key.ToLower().StartsWith("project", StringComparison.Ordinal));
            }).Value;

            if (c == null)
            {
                return(false);
            }

            if (c.EditArgument(oldName, newName))
            {
                Save();
                return(true);
            }
            return(false);
        }
Пример #7
0
        void TraverseArguments(CMakeCommand command, Action <string, CMakeCommand> callback, HashSet <CMakeCommand> commands = null)
        {
            CMakeVariableManager vm = parent.VariableManager;

            if (commands == null)
            {
                commands = new HashSet <CMakeCommand> ();
            }

            if (commands.Contains(command))
            {
                return;
            }

            commands.Add(command);

            foreach (var arg in command.Arguments)
            {
                foreach (var val in arg.GetValues())
                {
                    if (vm.IsVariable(val))
                    {
                        CMakeVariable v = vm.GetVariable(val.Substring(2, val.Length - 3));
                        if (v == null)
                        {
                            continue;
                        }

                        foreach (var c in v.Commands)
                        {
                            TraverseArguments(c, callback, commands);
                        }
                    }
                    else
                    {
                        callback(val, command);
                    }
                }
            }
        }
Пример #8
0
        void ParseCommand(Match commandMatch)
        {
            string       commandName = id.Match(commandMatch.Value).Value;
            CMakeCommand command     = new CMakeCommand(commandName, commandMatch, this);

            switch (command.Name.ToLower())
            {
            case "if":
                blocks.Push(command);
                break;

            case "elseif":
                blocks.Pop();
                blocks.Push(command);
                break;

            case "else":
                blocks.Pop();
                blocks.Push(command);
                break;

            case "endif":
                blocks.Pop();
                break;

            case "while":
                blocks.Push(command);
                break;

            case "endwhile":
                blocks.Pop();
                break;

            case "foreach":
                blocks.Push(command);
                break;

            case "endforeach":
                blocks.Pop();
                break;

            case "project":
                projectName = command.Arguments [0].ToString();
                break;

            case "set":
                SetCommands.Add(string.Format("{0}:{1}", command.Arguments [0].GetValues() [0], commandMatch.Index),
                                command);
                break;

            case "add_library":
            case "add_executable":
                targetCommands.Add(command);
                break;

            case "add_subdirectory":
                var temp     = new FilePath(command.Arguments [0].ToString());
                var fullPath = file.ParentDirectory.Combine(temp).Combine("CMakeLists.txt");

                if (!System.IO.File.Exists(fullPath))
                {
                    break;
                }

                if (Parent == null)
                {
                    if (!Children.ContainsKey(temp))
                    {
                        Children.Add(temp, new CMakeFileFormat(fullPath, Project, this));
                    }
                }
                else
                {
                    if (!Parent.Children.ContainsKey(temp))
                    {
                        Children.Add(temp, new CMakeFileFormat(fullPath, Project, Parent));
                    }
                }
                break;
            }

            command.IsNested = blocks.Count == 0;

            allCommands.Add(string.Format("{0}:{1}", commandName, commandMatch.Index), command);
        }
 void AddVariable(string variableName, string value, bool isEditable = true, CMakeCommand command = null)
 {
     variables.Add(variableName, new CMakeVariable(variableName, value, isEditable, command));
 }
Пример #10
0
 public CMakeVariable(string variableName, string value, bool isEditable = true, CMakeCommand command = null)
 {
     key             = variableName;
     this.value      = value;
     this.isEditable = isEditable;
     commands.Add(command);
 }