1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License for more information.
11 ============================================================================*/
12 #ifndef cmListCommand_h
13 #define cmListCommand_h
15 #include "cmCommand.h"
17 /** \class cmListCommand
18 * \brief Common list operations
21 class cmListCommand : public cmCommand
25 * This is a virtual constructor for the command.
27 virtual cmCommand* Clone()
29 return new cmListCommand;
33 * This is called when the command is first encountered in
34 * the CMakeLists.txt file.
36 virtual bool InitialPass(std::vector<std::string> const& args,
37 cmExecutionStatus &status);
40 * This determines if the command is invoked when in script mode.
42 virtual bool IsScriptable() const { return true; }
45 * The name of the command as specified in CMakeList.txt.
47 virtual const char* GetName() const { return "list";}
50 * Succinct documentation.
52 virtual const char* GetTerseDocumentation() const
54 return "List operations.";
60 virtual const char* GetFullDocumentation() const
63 " list(LENGTH <list> <output variable>)\n"
64 " list(GET <list> <element index> [<element index> ...]\n"
65 " <output variable>)\n"
66 " list(APPEND <list> <element> [<element> ...])\n"
67 " list(FIND <list> <value> <output variable>)\n"
68 " list(INSERT <list> <element_index> <element> [<element> ...])\n"
69 " list(REMOVE_ITEM <list> <value> [<value> ...])\n"
70 " list(REMOVE_AT <list> <index> [<index> ...])\n"
71 " list(REMOVE_DUPLICATES <list>)\n"
72 " list(REVERSE <list>)\n"
73 " list(SORT <list>)\n"
74 "LENGTH will return a given list's length.\n"
75 "GET will return list of elements specified by indices from the list.\n"
76 "APPEND will append elements to the list.\n"
77 "FIND will return the index of the element specified in the list or -1 "
78 "if it wasn't found.\n"
79 "INSERT will insert elements to the list to the specified location.\n"
80 "REMOVE_AT and REMOVE_ITEM will remove items from the list. The "
81 "difference is that REMOVE_ITEM will remove the given items, while "
82 "REMOVE_AT will remove the items at the given indices.\n"
83 "REMOVE_DUPLICATES will remove duplicated items in the list.\n"
84 "REVERSE reverses the contents of the list in-place.\n"
85 "SORT sorts the list in-place alphabetically.\n"
86 "The list subcommands APPEND, INSERT, REMOVE_AT, REMOVE_ITEM, "
87 "REMOVE_DUPLICATES, REVERSE and SORT may create new values for "
88 "the list within the current CMake variable scope. Similar to "
89 "the SET command, the LIST command creates new variable values "
90 "in the current scope, even if the list itself is actually "
91 "defined in a parent scope. To propagate the results of these "
92 "operations upwards, use SET with PARENT_SCOPE, SET with CACHE "
93 "INTERNAL, or some other means of value propagation.\n"
94 "NOTES: A list in cmake is a ; separated group of strings. "
95 "To create a list the set command can be used. For example, "
96 "set(var a b c d e) creates a list with a;b;c;d;e, and "
97 "set(var \"a b c d e\") creates a string or a list with one "
99 "When specifying index values, if <element index> is 0 or"
100 " greater, it is indexed from the "
101 "beginning of the list, with 0 representing the first list element. "
102 "If <element index> is -1 or lesser, it is indexed from the end of "
103 "the list, with -1 representing the last list element. Be careful "
104 "when counting with negative indices: they do not start from 0. "
105 "-0 is equivalent to 0, the first list element.\n"
109 cmTypeMacro(cmListCommand, cmCommand);
111 bool HandleLengthCommand(std::vector<std::string> const& args);
112 bool HandleGetCommand(std::vector<std::string> const& args);
113 bool HandleAppendCommand(std::vector<std::string> const& args);
114 bool HandleFindCommand(std::vector<std::string> const& args);
115 bool HandleInsertCommand(std::vector<std::string> const& args);
116 bool HandleRemoveAtCommand(std::vector<std::string> const& args);
117 bool HandleRemoveItemCommand(std::vector<std::string> const& args);
118 bool HandleRemoveDuplicatesCommand(std::vector<std::string> const& args);
119 bool HandleSortCommand(std::vector<std::string> const& args);
120 bool HandleReverseCommand(std::vector<std::string> const& args);
123 bool GetList(std::vector<std::string>& list, const char* var);
124 bool GetListString(std::string& listString, const char* var);