summaryrefslogtreecommitdiff
path: root/Source/cmakemain.cxx
diff options
context:
space:
mode:
authorSebastian Schuberth <sschuberth@gmail.com>2016-02-04 12:36:44 +0100
committerBrad King <brad.king@kitware.com>2016-02-05 11:48:16 -0500
commit497cad7c883dc401b4d78109c3a057fb38745d9e (patch)
tree8e8a1523e78ed5b586a6c3d3d1dec4e606dd8666 /Source/cmakemain.cxx
parent886acd80f09c807fccbfcde713c53a7686386968 (diff)
downloadcmake-497cad7c883dc401b4d78109c3a057fb38745d9e.tar.gz
cmake: Teach --build to reject multiple --target options
Previously we did not clearly document that `--target` is only supported to be specified once. Even worse, specifying it multiple times would silently ignore any previously specified targets and only build the last target. Update the documentation to specify this. Update the implementation to reject multiple `--target` options to prevent user errors.
Diffstat (limited to 'Source/cmakemain.cxx')
-rw-r--r--Source/cmakemain.cxx14
1 files changed, 13 insertions, 1 deletions
diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx
index a06b26fc69..c60b962ce3 100644
--- a/Source/cmakemain.cxx
+++ b/Source/cmakemain.cxx
@@ -60,6 +60,7 @@ static const char * cmDocumentationUsageNote[][2] =
#define CMAKE_BUILD_OPTIONS \
" <dir> = Project binary directory to be built.\n" \
" --target <tgt> = Build <tgt> instead of default targets.\n" \
+ " May only be specified once.\n" \
" --config <cfg> = For multi-configuration tools, choose <cfg>.\n" \
" --clean-first = Build target 'clean' first, then build.\n" \
" (To clean only, use --target 'clean'.)\n" \
@@ -386,6 +387,7 @@ static int do_build(int ac, char const* const* av)
std::string dir;
std::vector<std::string> nativeOptions;
bool clean = false;
+ bool hasTarget = false;
enum Doing { DoingNone, DoingDir, DoingTarget, DoingConfig, DoingNative};
Doing doing = DoingDir;
@@ -397,7 +399,17 @@ static int do_build(int ac, char const* const* av)
}
else if(strcmp(av[i], "--target") == 0)
{
- doing = DoingTarget;
+ if (!hasTarget)
+ {
+ doing = DoingTarget;
+ hasTarget = true;
+ }
+ else
+ {
+ std::cerr << "'--target' may not be specified more than once.\n\n";
+ dir = "";
+ break;
+ }
}
else if(strcmp(av[i], "--config") == 0)
{