diff options
author | Brad King <brad.king@kitware.com> | 2019-05-14 14:54:08 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2019-05-14 14:58:43 (GMT) |
commit | 1f0a695561f12b8e3929066d7dc61535a20af66c (patch) | |
tree | a690574b97f3a7844f969a4e43ca130354a2617b /Source | |
parent | bae7a2e25074145a8b57baa96624f0b87428840d (diff) | |
parent | cdff7f4e2a255e083e5a19ac541b4de2874785af (diff) | |
download | CMake-1f0a695561f12b8e3929066d7dc61535a20af66c.zip CMake-1f0a695561f12b8e3929066d7dc61535a20af66c.tar.gz CMake-1f0a695561f12b8e3929066d7dc61535a20af66c.tar.bz2 |
Merge topic 'cmSytemTools_ExpandedList'
cdff7f4e2a cmSystemTools: Add ExpandedListArgument and ExpandedLists methods
Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Ben Boeckel <ben.boeckel@kitware.com>
Merge-request: !3313
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmGlobalXCodeGenerator.cxx | 10 | ||||
-rw-r--r-- | Source/cmRemoveCommand.cxx | 10 | ||||
-rw-r--r-- | Source/cmSystemTools.cxx | 24 | ||||
-rw-r--r-- | Source/cmSystemTools.h | 43 |
4 files changed, 58 insertions, 29 deletions
diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index db673bb..6cbdefa 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -2485,12 +2485,10 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateUtilityTarget( std::string cmGlobalXCodeGenerator::AddConfigurations(cmXCodeObject* target, cmGeneratorTarget* gtgt) { - std::string configTypes = - this->CurrentMakefile->GetRequiredDefinition("CMAKE_CONFIGURATION_TYPES"); - std::vector<std::string> configVectorIn; - std::vector<std::string> configVector; - configVectorIn.push_back(configTypes); - cmSystemTools::ExpandList(configVectorIn, configVector); + std::vector<std::string> const configVector = + cmSystemTools::ExpandedListArgument( + this->CurrentMakefile->GetRequiredDefinition( + "CMAKE_CONFIGURATION_TYPES")); cmXCodeObject* configlist = this->CreateObject(cmXCodeObject::XCConfigurationList); cmXCodeObject* buildConfigurations = diff --git a/Source/cmRemoveCommand.cxx b/Source/cmRemoveCommand.cxx index bb14e68..a64ad8c 100644 --- a/Source/cmRemoveCommand.cxx +++ b/Source/cmRemoveCommand.cxx @@ -25,15 +25,13 @@ bool cmRemoveCommand::InitialPass(std::vector<std::string> const& args, } // expand the variable - std::vector<std::string> varArgsExpanded; - cmSystemTools::ExpandListArgument(cacheValue, varArgsExpanded); + std::vector<std::string> const varArgsExpanded = + cmSystemTools::ExpandedListArgument(cacheValue); // expand the args // check for REMOVE(VAR v1 v2 ... vn) - std::vector<std::string> argsExpanded; - std::vector<std::string> temp; - temp.insert(temp.end(), args.begin() + 1, args.end()); - cmSystemTools::ExpandList(temp, argsExpanded); + std::vector<std::string> const argsExpanded = + cmSystemTools::ExpandedLists(args.begin() + 1, args.end()); // now create the new value std::string value; diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 17ed3f6..545e6c5 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -1208,16 +1208,8 @@ void cmSystemTools::GlobDirs(const std::string& path, } } -void cmSystemTools::ExpandList(std::vector<std::string> const& arguments, - std::vector<std::string>& newargs) -{ - for (std::string const& arg : arguments) { - cmSystemTools::ExpandListArgument(arg, newargs); - } -} - void cmSystemTools::ExpandListArgument(const std::string& arg, - std::vector<std::string>& newargs, + std::vector<std::string>& argsOut, bool emptyArgs) { // If argument is empty, it is an empty list. @@ -1226,7 +1218,7 @@ void cmSystemTools::ExpandListArgument(const std::string& arg, } // if there are no ; in the name then just copy the current string if (arg.find(';') == std::string::npos) { - newargs.push_back(arg); + argsOut.push_back(arg); return; } std::string newArg; @@ -1260,7 +1252,7 @@ void cmSystemTools::ExpandListArgument(const std::string& arg, last = c + 1; if (!newArg.empty() || emptyArgs) { // Add the last argument if the string is not empty. - newargs.push_back(newArg); + argsOut.push_back(newArg); newArg.clear(); } } @@ -1273,10 +1265,18 @@ void cmSystemTools::ExpandListArgument(const std::string& arg, newArg.append(last); if (!newArg.empty() || emptyArgs) { // Add the last argument if the string is not empty. - newargs.push_back(newArg); + argsOut.push_back(newArg); } } +std::vector<std::string> cmSystemTools::ExpandedListArgument( + const std::string& arg, bool emptyArgs) +{ + std::vector<std::string> argsOut; + ExpandListArgument(arg, argsOut, emptyArgs); + return argsOut; +} + bool cmSystemTools::SimpleGlob(const std::string& glob, std::vector<std::string>& files, int type /* = 0 */) diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index 8a87a37..d145d47 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -29,17 +29,50 @@ public: typedef cmsys::SystemTools Superclass; typedef cmProcessOutput::Encoding Encoding; - /** Expand out any arguments in the vector that have ; separated - * strings into multiple arguments. A new vector is created - * containing the expanded versions of all arguments in argsIn. + /** + * Expand the ; separated string @a arg into multiple arguments. + * All found arguments are appended to @a argsOut. */ - static void ExpandList(std::vector<std::string> const& argsIn, - std::vector<std::string>& argsOut); static void ExpandListArgument(const std::string& arg, std::vector<std::string>& argsOut, bool emptyArgs = false); /** + * Expand out any arguments in the string range [@a first, @a last) that have + * ; separated strings into multiple arguments. All found arguments are + * appended to @a argsOut. + */ + template <class InputIt> + static void ExpandLists(InputIt first, InputIt last, + std::vector<std::string>& argsOut) + { + for (; first != last; ++first) { + cmSystemTools::ExpandListArgument(*first, argsOut); + } + } + + /** + * Same as ExpandListArgument but a new vector is created containing + * the expanded arguments from the string @a arg. + */ + static std::vector<std::string> ExpandedListArgument(const std::string& arg, + bool emptyArgs = false); + + /** + * Same as ExpandList but a new vector is created containing the expanded + * versions of all arguments in the string range [@a first, @a last). + */ + template <class InputIt> + static std::vector<std::string> ExpandedLists(InputIt first, InputIt last) + { + std::vector<std::string> argsOut; + for (; first != last; ++first) { + cmSystemTools::ExpandListArgument(*first, argsOut); + } + return argsOut; + } + + /** * Look for and replace registry values in a string */ static void ExpandRegistryValues(std::string& source, |