summaryrefslogtreecommitdiffstats
path: root/Source/cmakemain.cxx
diff options
context:
space:
mode:
authorBartosz Kosiorek <bartosz.kosiorek@tomtom.com>2019-02-08 13:28:49 (GMT)
committerBrad King <brad.king@kitware.com>2019-03-05 13:55:28 (GMT)
commit324d18bb3418aee8dcb63e28106ac0dac6abea71 (patch)
tree390a0ccc8c8bb955c0330af9bd66621a71ea2041 /Source/cmakemain.cxx
parentebc94500c1726f393ac6119848d53deca47e1ccf (diff)
downloadCMake-324d18bb3418aee8dcb63e28106ac0dac6abea71.zip
CMake-324d18bb3418aee8dcb63e28106ac0dac6abea71.tar.gz
CMake-324d18bb3418aee8dcb63e28106ac0dac6abea71.tar.bz2
cmake: Teach --build mode to support multiple targets
Fixes: #16136
Diffstat (limited to 'Source/cmakemain.cxx')
-rw-r--r--Source/cmakemain.cxx44
1 files changed, 28 insertions, 16 deletions
diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx
index 3465721..1c56bcd 100644
--- a/Source/cmakemain.cxx
+++ b/Source/cmakemain.cxx
@@ -63,7 +63,7 @@ static const char* cmDocumentationUsageNote[][2] = {
"option\n" \
" is not given.\n" \
" --target <tgt> = Build <tgt> instead of default targets.\n" \
- " May only be specified once.\n" \
+ " May be specified multiple times.\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" \
@@ -394,13 +394,14 @@ static int do_build(int ac, char const* const* av)
return -1;
#else
int jobs = cmake::NO_BUILD_PARALLEL_LEVEL;
- std::string target;
+ std::vector<std::string> targets;
std::string config = "Debug";
std::string dir;
std::vector<std::string> nativeOptions;
- bool clean = false;
+ bool cleanFirst = false;
+ bool foundClean = false;
+ bool foundNonClean = false;
bool verbose = cmSystemTools::HasEnv("VERBOSE");
- bool hasTarget = false;
enum Doing
{
@@ -420,25 +421,20 @@ static int do_build(int ac, char const* const* av)
if (jobs < 0) {
dir.clear();
}
+ doing = DoingNone;
} else if (cmHasLiteralPrefix(av[i], "--parallel")) {
const char* nextArg = ((i + 1 < ac) ? av[i + 1] : nullptr);
jobs = extract_job_number(i, av[i], nextArg, sizeof("--parallel") - 1);
if (jobs < 0) {
dir.clear();
}
+ doing = DoingNone;
} else if (strcmp(av[i], "--target") == 0) {
- if (!hasTarget) {
- doing = DoingTarget;
- hasTarget = true;
- } else {
- std::cerr << "'--target' may not be specified more than once.\n\n";
- dir.clear();
- break;
- }
+ doing = DoingTarget;
} else if (strcmp(av[i], "--config") == 0) {
doing = DoingConfig;
} else if (strcmp(av[i], "--clean-first") == 0) {
- clean = true;
+ cleanFirst = true;
doing = DoingNone;
} else if ((strcmp(av[i], "--verbose") == 0) ||
(strcmp(av[i], "-v") == 0)) {
@@ -455,8 +451,23 @@ static int do_build(int ac, char const* const* av)
doing = DoingNone;
break;
case DoingTarget:
- target = av[i];
- doing = DoingNone;
+ if (strlen(av[i]) == 0) {
+ std::cerr << "Warning: Argument number " << i
+ << " after --target option is empty." << std::endl;
+ } else {
+ targets.emplace_back(av[i]);
+ if (strcmp(av[i], "clean") == 0) {
+ foundClean = true;
+ } else {
+ foundNonClean = true;
+ }
+ }
+ if (foundClean && foundNonClean) {
+ std::cerr << "Error: Building 'clean' and other targets together "
+ "is not supported."
+ << std::endl;
+ dir.clear();
+ }
break;
case DoingConfig:
config = av[i];
@@ -507,7 +518,8 @@ static int do_build(int ac, char const* const* av)
cm.SetProgressCallback([&cm](const std::string& msg, float prog) {
cmakemainProgressCallback(msg, prog, &cm);
});
- return cm.Build(jobs, dir, target, config, nativeOptions, clean, verbose);
+ return cm.Build(jobs, dir, targets, config, nativeOptions, cleanFirst,
+ verbose);
#endif
}