summaryrefslogtreecommitdiffstats
path: root/Source/cmake.cxx
diff options
context:
space:
mode:
authorBill Hoffman <bill.hoffman@kitware.com>2008-10-15 17:56:07 (GMT)
committerBill Hoffman <bill.hoffman@kitware.com>2008-10-15 17:56:07 (GMT)
commit1777bb502a3c8dbcead54b11fe403e13fe9c225c (patch)
treee85da2c575bc1e88254287b220e4e236065f3285 /Source/cmake.cxx
parente099dccf4b3772c10c076ec1044dae01da510d28 (diff)
downloadCMake-1777bb502a3c8dbcead54b11fe403e13fe9c225c.zip
CMake-1777bb502a3c8dbcead54b11fe403e13fe9c225c.tar.gz
CMake-1777bb502a3c8dbcead54b11fe403e13fe9c225c.tar.bz2
BUG: 4244, add a --build option to cmake that can build projects configured by CMake
Diffstat (limited to 'Source/cmake.cxx')
-rw-r--r--Source/cmake.cxx90
1 files changed, 88 insertions, 2 deletions
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index 9a5a5d0..fcce00d 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -36,6 +36,7 @@
# include <cmsys/Terminal.h>
#endif
+#include <cmsys/CommandLineArguments.hxx>
#include <cmsys/Directory.hxx>
#include <cmsys/Process.h>
#include <cmsys/Glob.hxx>
@@ -947,7 +948,8 @@ void CMakeCommandUsage(const char* program)
errorStream
<< "cmake bootstrap\n";
#endif
-
+ // If you add new commands, change here,
+ // and in cmakemain.cxx in the options table
errorStream
<< "Usage: " << program << " -E [command] [arguments ...]\n"
<< "Available commands: \n"
@@ -973,6 +975,7 @@ void CMakeCommandUsage(const char* program)
<< " time command [args] ... - run command and return elapsed time\n"
<< " touch file - touch a file.\n"
<< " touch_nocreate file - touch a file but do not create it.\n"
+ << " build build_dir - build the project in build_dir.\n"
#if defined(_WIN32) && !defined(__CYGWIN__)
<< " write_regv key value - write registry value\n"
<< " delete_regv key - delete registry value\n"
@@ -987,6 +990,7 @@ void CMakeCommandUsage(const char* program)
int cmake::ExecuteCMakeCommand(std::vector<std::string>& args)
{
+ // IF YOU ADD A NEW COMMAND, DOCUMENT IT ABOVE and in cmakemain.cxx
if (args.size() > 1)
{
// Copy file
@@ -1188,7 +1192,6 @@ int cmake::ExecuteCMakeCommand(std::vector<std::string>& args)
<< "\n";
return ret;
}
-
// Command to calculate the md5sum of a file
else if (args[1] == "md5sum" && args.size() >= 3)
{
@@ -4329,3 +4332,86 @@ std::vector<std::string> const& cmake::GetDebugConfigs()
}
return this->DebugConfigs;
}
+
+
+int cmake::Build(const std::string& dir,
+ const std::string& target,
+ const std::string& config,
+ const std::string& extraBuildOptions,
+ bool clean)
+{
+ if(!cmSystemTools::FileIsDirectory(dir.c_str()))
+ {
+ std::cerr << "Error: " << dir << " is not a directory\n";
+ return 1;
+ }
+ std::string cachePath = dir;
+ cmSystemTools::ConvertToUnixSlashes(cachePath);
+ cmCacheManager* cachem = this->GetCacheManager();
+ cmCacheManager::CacheIterator it = cachem->NewIterator();
+ if(!cachem->LoadCache(cachePath.c_str()))
+ {
+ std::cerr << "Error: could not load cache\n";
+ return 1;
+ }
+ if(!it.Find("CMAKE_GENERATOR"))
+ {
+ std::cerr << "Error: could find generator in Cache\n";
+ return 1;
+ }
+ cmGlobalGenerator* gen =
+ this->CreateGlobalGenerator(it.GetValue());
+ std::string output;
+ std::string projName;
+ std::string makeProgram;
+ if(!it.Find("CMAKE_PROJECT_NAME"))
+ {
+ std::cerr << "Error: could not find CMAKE_PROJECT_NAME in Cache\n";
+ return 1;
+ }
+ projName = it.GetValue();
+ if(!it.Find("CMAKE_MAKE_PROGRAM"))
+ {
+ std::cerr << "Error: could not find CMAKE_MAKE_PROGRAM in Cache\n";
+ return 1;
+ }
+ makeProgram = it.GetValue();
+ return gen->Build(0, dir.c_str(),
+ projName.c_str(), target.c_str(),
+ &output,
+ makeProgram.c_str(),
+ config.c_str(), clean, false, 0, true);
+}
+
+int cmake::DoBuild(int ac, char* av[])
+{
+ std::string target;
+ std::string config = "Debug";
+ std::string extraBuildOptions;
+ std::string dir;
+ bool clean = false;
+ cmsys::CommandLineArguments arg;
+ arg.Initialize(ac, av);
+ typedef cmsys::CommandLineArguments argT;
+ arg.AddArgument("--build", argT::SPACE_ARGUMENT, &dir,
+ "Build a configured cmake project --build dir.");
+ arg.AddArgument("--target", argT::SPACE_ARGUMENT, &target,
+ "Specifiy the target to build,"
+ " if missing, all targets are built.");
+ arg.AddArgument("--config", argT::SPACE_ARGUMENT, &config,
+ "Specify configuration to build"
+ " if missing Debug is built.");
+ arg.AddArgument("--extra-options", argT::SPACE_ARGUMENT, &extraBuildOptions,
+ "Specify extra options to pass to build program,"
+ " for example with gmake -jN.");
+ arg.AddArgument("--clean", argT::NO_ARGUMENT, &clean,
+ "Clean before building.");
+ if ( !arg.Parse() )
+ {
+ std::cerr << "Problem parsing --build arguments:\n";
+ std::cerr << arg.GetHelp() << "\n";
+ return 1;
+ }
+ cmake cm;
+ return cm.Build(dir, target, config, extraBuildOptions, clean);
+}