[Cmake-commits] [cmake-commits] king committed cmake.cxx 1.407 1.408 cmake.h 1.118 1.119 cmakemain.cxx 1.87 1.88

cmake-commits at cmake.org cmake-commits at cmake.org
Wed Mar 4 15:39:29 EST 2009


Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv32371/Source

Modified Files:
	cmake.cxx cmake.h cmakemain.cxx 
Log Message:
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.


Index: cmake.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmake.h,v
retrieving revision 1.118
retrieving revision 1.119
diff -C 2 -d -r1.118 -r1.119
*** cmake.h	15 Oct 2008 17:56:06 -0000	1.118
--- cmake.h	4 Mar 2009 20:39:27 -0000	1.119
***************
*** 358,368 ****
                      cmListFileBacktrace const& backtrace);
    //  * run the --build option
-   static int DoBuild(int ac, char* av[]);
- protected:
    int Build(const std::string& dir,
              const std::string& target,
              const std::string& config,
!             const std::string& extraBuildOptions,
              bool clean);
    void InitializeProperties();
    int HandleDeleteCacheVariables(const char* var);
--- 358,367 ----
                      cmListFileBacktrace const& backtrace);
    //  * run the --build option
    int Build(const std::string& dir,
              const std::string& target,
              const std::string& config,
!             const std::vector<std::string>& nativeOptions,
              bool clean);
+ protected:
    void InitializeProperties();
    int HandleDeleteCacheVariables(const char* var);

Index: cmakemain.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmakemain.cxx,v
retrieving revision 1.87
retrieving revision 1.88
diff -C 2 -d -r1.87 -r1.88
*** cmakemain.cxx	15 Oct 2008 17:56:06 -0000	1.87
--- cmakemain.cxx	4 Mar 2009 20:39:27 -0000	1.88
***************
*** 62,65 ****
--- 62,73 ----
  };
  
+ #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] =
***************
*** 86,94 ****
     "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."},
    {"-N", "View mode only.",
     "Only load the cache. Do not actually run configure and generate steps."},
--- 94,102 ----
     "advanced variables. If H is specified, it will also display help for "
     "each variable."},
!   {"--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."},
***************
*** 237,240 ****
--- 245,249 ----
  
  int do_cmake(int ac, char** av);
+ static int do_build(int ac, char** av);
  
  static cmMakefile* cmakemainGetMakefile(void *clientdata)
***************
*** 308,311 ****
--- 317,324 ----
    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
***************
*** 413,417 ****
    bool view_only = false;
    bool script_mode = false;
-   bool build = false;
    std::vector<std::string> args;
    for(int i =0; i < ac; ++i)
--- 426,429 ----
***************
*** 421,428 ****
        wiz = true;
        }
-     else if(!command && strcmp(av[i], "--build") == 0)
-       {
-       return cmake::DoBuild(ac, av);
-       }
      else if(!command && strcmp(av[i], "--system-information") == 0)
        {
--- 433,436 ----
***************
*** 476,484 ****
        }
      }
-   if(build)
-     {
-     int ret = cmake::DoBuild(ac, av);
-     return ret;
-     }
    if(command)
      {
--- 484,487 ----
***************
*** 545,546 ****
--- 548,631 ----
  }
  
+ //----------------------------------------------------------------------------
+ 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
+ }

Index: cmake.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmake.cxx,v
retrieving revision 1.407
retrieving revision 1.408
diff -C 2 -d -r1.407 -r1.408
*** cmake.cxx	2 Mar 2009 21:02:19 -0000	1.407
--- cmake.cxx	4 Mar 2009 20:39:27 -0000	1.408
***************
*** 4395,4399 ****
                   const std::string& target,
                   const std::string& config,
!                  const std::string& extraBuildOptions,
                   bool clean)
  { 
--- 4395,4399 ----
                   const std::string& target,
                   const std::string& config,
!                  const std::vector<std::string>& nativeOptions,
                   bool clean)
  { 
***************
*** 4439,4488 ****
                      makeProgram.c_str(),
                      config.c_str(), clean, false, 0, true,
!                     extraBuildOptions.c_str());
! }
! 
! int cmake::DoBuild(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 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;
!     }
! 
!   // 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, extraBuildOptions, clean);
! #endif
  }
--- 4439,4442 ----
                      makeProgram.c_str(),
                      config.c_str(), clean, false, 0, true,
!                     0, nativeOptions);
  }



More information about the Cmake-commits mailing list