summaryrefslogtreecommitdiffstats
path: root/Source/cmakemain.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2009-03-04 20:39:27 (GMT)
committerBrad King <brad.king@kitware.com>2009-03-04 20:39:27 (GMT)
commit170febac528b8f18a6f1b6d8fcb5895d67a8c10b (patch)
tree40bc6b332a79f9022544214babee411ce6ab3041 /Source/cmakemain.cxx
parentd35651fb6c59904b3b004474a5501280e694d37c (diff)
downloadCMake-170febac528b8f18a6f1b6d8fcb5895d67a8c10b.zip
CMake-170febac528b8f18a6f1b6d8fcb5895d67a8c10b.tar.gz
CMake-170febac528b8f18a6f1b6d8fcb5895d67a8c10b.tar.bz2
ENH: Cleanup cmake --build interface.
This cleans up the 'cmake --build' command-line interface: - Rename --clean to --clean-first to better describe it. - Replace --extra-options with a -- separator to simplify passing of multiple native build tool options. - Document the options in the main CMake man page description of the --build option, and shares this with the usage message. - Require --build to be the first argument when present. - Move implementation into cmakemain where it belongs.
Diffstat (limited to 'Source/cmakemain.cxx')
-rw-r--r--Source/cmakemain.cxx115
1 files changed, 100 insertions, 15 deletions
diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx
index 46a17ef..61e7cce 100644
--- a/Source/cmakemain.cxx
+++ b/Source/cmakemain.cxx
@@ -61,6 +61,14 @@ static const char * cmDocumentationDescription[][3] =
{0,0,0}
};
+#define CMAKE_BUILD_OPTIONS \
+ " <dir> = Project binary directory to be built.\n" \
+ " --target <tgt> = Build <tgt> instead of default targets.\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" \
+ " -- = Pass remaining options to the native tool.\n"
+
//----------------------------------------------------------------------------
static const char * cmDocumentationOptions[][3] =
{
@@ -85,11 +93,11 @@ static const char * cmDocumentationOptions[][3] =
"variables being created. If A is specified, then it will display also "
"advanced variables. If H is specified, it will also display help for "
"each variable."},
- {"--build dir", "Build a configured cmake tree found in dir.",
- "This option will use the native build tool from the command line to"
- " build the project. Other options that can be specified with this one"
- " are --target, --config, --extra-options, and --clean. For complete "
- "help run --build with no options."},
+ {"--build <dir>", "Build a CMake-generated project binary tree.",
+ "This abstracts a native build tool's command-line interface with the "
+ "following options:\n"
+ CMAKE_BUILD_OPTIONS
+ "Run cmake --build with no options for quick help."},
{"-N", "View mode only.",
"Only load the cache. Do not actually run configure and generate steps."},
{"-P <file>", "Process script mode.",
@@ -236,6 +244,7 @@ static const char * cmDocumentationNOTE[][3] =
#endif
int do_cmake(int ac, char** av);
+static int do_build(int ac, char** av);
static cmMakefile* cmakemainGetMakefile(void *clientdata)
{
@@ -307,6 +316,10 @@ int main(int ac, char** av)
{
cmSystemTools::EnableMSVCDebugHook();
cmSystemTools::FindExecutableDirectory(av[0]);
+ if(ac > 1 && strcmp(av[1], "--build") == 0)
+ {
+ return do_build(ac, av);
+ }
int ret = do_cmake(ac, av);
#ifdef CMAKE_BUILD_WITH_CMAKE
cmDynamicLoader::FlushCache();
@@ -412,7 +425,6 @@ int do_cmake(int ac, char** av)
bool list_help = false;
bool view_only = false;
bool script_mode = false;
- bool build = false;
std::vector<std::string> args;
for(int i =0; i < ac; ++i)
{
@@ -420,10 +432,6 @@ int do_cmake(int ac, char** av)
{
wiz = true;
}
- else if(!command && strcmp(av[i], "--build") == 0)
- {
- return cmake::DoBuild(ac, av);
- }
else if(!command && strcmp(av[i], "--system-information") == 0)
{
sysinfo = true;
@@ -475,11 +483,6 @@ int do_cmake(int ac, char** av)
args.push_back(av[i]);
}
}
- if(build)
- {
- int ret = cmake::DoBuild(ac, av);
- return ret;
- }
if(command)
{
int ret = cmake::ExecuteCMakeCommand(args);
@@ -544,3 +547,85 @@ int do_cmake(int ac, char** av)
}
}
+//----------------------------------------------------------------------------
+static int do_build(int ac, char** av)
+{
+#ifndef CMAKE_BUILD_WITH_CMAKE
+ std::cerr << "This cmake does not support --build\n";
+ return -1;
+#else
+ std::string target;
+ std::string config = "Debug";
+ std::string dir;
+ std::vector<std::string> nativeOptions;
+ bool clean = false;
+
+ enum Doing { DoingNone, DoingDir, DoingTarget, DoingConfig, DoingNative};
+ Doing doing = DoingDir;
+ for(int i=2; i < ac; ++i)
+ {
+ if(doing == DoingNative)
+ {
+ nativeOptions.push_back(av[i]);
+ }
+ else if(strcmp(av[i], "--target") == 0)
+ {
+ doing = DoingTarget;
+ }
+ else if(strcmp(av[i], "--config") == 0)
+ {
+ doing = DoingConfig;
+ }
+ else if(strcmp(av[i], "--clean-first") == 0)
+ {
+ clean = true;
+ doing = DoingNone;
+ }
+ else if(strcmp(av[i], "--") == 0)
+ {
+ doing = DoingNative;
+ }
+ else
+ {
+ switch (doing)
+ {
+ case DoingDir:
+ dir = av[i];
+ doing = DoingNone;
+ break;
+ case DoingTarget:
+ target = av[i];
+ doing = DoingNone;
+ break;
+ case DoingConfig:
+ config = av[i];
+ doing = DoingNone;
+ break;
+ default:
+ std::cerr << "Unknown argument " << av[i] << std::endl;
+ dir = "";
+ break;
+ }
+ }
+ }
+ if(dir.empty())
+ {
+ std::cerr <<
+ "Usage: cmake --build <dir> [options] [-- [native-options]]\n"
+ "Options:\n"
+ CMAKE_BUILD_OPTIONS
+ ;
+ return 1;
+ }
+
+ // Hack for vs6 that passes ".\Debug" as "$(IntDir)" value:
+ //
+ if (cmSystemTools::StringStartsWith(config.c_str(), ".\\"))
+ {
+ config = config.substr(2);
+ }
+
+ cmake cm;
+ return cm.Build(dir, target, config, nativeOptions, clean);
+#endif
+}