Browse Source

Merge topic 'CodeBlocksParallelFlag'

84ccd4f7 CodeBlocks: generate parallel project files (make -j)
Brad King 9 years ago
parent
commit
2039bf40e4

+ 15 - 0
Modules/CMakeFindCodeBlocks.cmake

@@ -23,3 +23,18 @@ endif()
 
 
 # Determine builtin macros and include dirs:
 # Determine builtin macros and include dirs:
 include(${CMAKE_CURRENT_LIST_DIR}/CMakeExtraGeneratorDetermineCompilerMacrosAndIncludeDirs.cmake)
 include(${CMAKE_CURRENT_LIST_DIR}/CMakeExtraGeneratorDetermineCompilerMacrosAndIncludeDirs.cmake)
+
+# Try to find out how many CPUs we have and set the -j argument for make accordingly
+set(_CMAKE_CODEBLOCKS_INITIAL_MAKE_ARGS "")
+
+include(ProcessorCount)
+processorcount(_CMAKE_CODEBLOCKS_PROCESSOR_COUNT)
+
+# Only set -j if we are under UNIX and if the make-tool used actually has "make" in the name
+# (we may also get here in the future e.g. for ninja)
+if("${_CMAKE_CODEBLOCKS_PROCESSOR_COUNT}" GREATER 1  AND  CMAKE_HOST_UNIX  AND  "${CMAKE_MAKE_PROGRAM}" MATCHES make)
+  set(_CMAKE_CODEBLOCKS_INITIAL_MAKE_ARGS "-j${_CMAKE_CODEBLOCKS_PROCESSOR_COUNT}")
+endif()
+
+# This variable is used by the CodeBlocks generator and appended to the make invocation commands.
+set(CMAKE_CODEBLOCKS_MAKE_ARGUMENTS "${_CMAKE_CODEBLOCKS_INITIAL_MAKE_ARGS}" CACHE STRING "Additional command line arguments when CodeBlocks invokes make. Enter e.g. -j<some_number> to get parallel builds")

+ 24 - 11
Source/cmExtraCodeBlocksGenerator.cxx

@@ -300,6 +300,8 @@ void cmExtraCodeBlocksGenerator
   // figure out the compiler
   // figure out the compiler
   std::string compiler = this->GetCBCompilerId(mf);
   std::string compiler = this->GetCBCompilerId(mf);
   std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
   std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
+  const std::string makeArgs = mf->GetSafeDefinition(
+                                            "CMAKE_CODEBLOCKS_MAKE_ARGUMENTS");
 
 
   fout<<"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\n"
   fout<<"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\n"
         "<CodeBlocks_project_file>\n"
         "<CodeBlocks_project_file>\n"
@@ -311,7 +313,8 @@ void cmExtraCodeBlocksGenerator
         "      "<<virtualFolders<<"\n"
         "      "<<virtualFolders<<"\n"
         "      <Build>\n";
         "      <Build>\n";
 
 
-  this->AppendTarget(fout, "all", 0, make.c_str(), lgs[0], compiler.c_str());
+  this->AppendTarget(fout, "all", 0, make.c_str(), lgs[0], compiler.c_str(),
+                     makeArgs);
 
 
   // add all executable and library targets and some of the GLOBAL
   // add all executable and library targets and some of the GLOBAL
   // and UTILITY targets
   // and UTILITY targets
@@ -333,7 +336,8 @@ void cmExtraCodeBlocksGenerator
                      (*lg)->GetBinaryDirectory())==0)
                      (*lg)->GetBinaryDirectory())==0)
             {
             {
             this->AppendTarget(fout, targetName, 0,
             this->AppendTarget(fout, targetName, 0,
-                               make.c_str(), *lg, compiler.c_str());
+                               make.c_str(), *lg, compiler.c_str(),
+                               makeArgs);
             }
             }
           }
           }
           break;
           break;
@@ -350,7 +354,7 @@ void cmExtraCodeBlocksGenerator
             }
             }
 
 
           this->AppendTarget(fout, targetName, 0,
           this->AppendTarget(fout, targetName, 0,
-                                 make.c_str(), *lg, compiler.c_str());
+                                 make.c_str(), *lg, compiler.c_str(),makeArgs);
           break;
           break;
         case cmState::EXECUTABLE:
         case cmState::EXECUTABLE:
         case cmState::STATIC_LIBRARY:
         case cmState::STATIC_LIBRARY:
@@ -360,11 +364,11 @@ void cmExtraCodeBlocksGenerator
           {
           {
           cmGeneratorTarget* gt = *ti;
           cmGeneratorTarget* gt = *ti;
           this->AppendTarget(fout, targetName, gt,
           this->AppendTarget(fout, targetName, gt,
-                             make.c_str(), *lg, compiler.c_str());
+                             make.c_str(), *lg, compiler.c_str(), makeArgs);
           std::string fastTarget = targetName;
           std::string fastTarget = targetName;
           fastTarget += "/fast";
           fastTarget += "/fast";
           this->AppendTarget(fout, fastTarget, gt,
           this->AppendTarget(fout, fastTarget, gt,
-                             make.c_str(), *lg, compiler.c_str());
+                             make.c_str(), *lg, compiler.c_str(), makeArgs);
           }
           }
           break;
           break;
         default:
         default:
@@ -555,7 +559,8 @@ void cmExtraCodeBlocksGenerator::AppendTarget(cmGeneratedFileStream& fout,
                                               cmGeneratorTarget* target,
                                               cmGeneratorTarget* target,
                                               const char* make,
                                               const char* make,
                                               const cmLocalGenerator* lg,
                                               const cmLocalGenerator* lg,
-                                              const char* compiler)
+                                              const char* compiler,
+                                              const std::string& makeFlags)
 {
 {
   cmMakefile const* makefile = lg->GetMakefile();
   cmMakefile const* makefile = lg->GetMakefile();
   std::string makefileName = lg->GetCurrentBinaryDirectory();
   std::string makefileName = lg->GetCurrentBinaryDirectory();
@@ -663,16 +668,18 @@ void cmExtraCodeBlocksGenerator::AppendTarget(cmGeneratedFileStream& fout,
 
 
   fout<<"         <MakeCommands>\n"
   fout<<"         <MakeCommands>\n"
         "            <Build command=\""
         "            <Build command=\""
-      << this->BuildMakeCommand(make, makefileName.c_str(), targetName)
+      << this->BuildMakeCommand(make, makefileName.c_str(), targetName,
+                                makeFlags)
       << "\" />\n"
       << "\" />\n"
         "            <CompileFile command=\""
         "            <CompileFile command=\""
-      << this->BuildMakeCommand(make, makefileName.c_str(),"&quot;$file&quot;")
+      << this->BuildMakeCommand(make, makefileName.c_str(),"&quot;$file&quot;",
+                                makeFlags)
       << "\" />\n"
       << "\" />\n"
         "            <Clean command=\""
         "            <Clean command=\""
-      << this->BuildMakeCommand(make, makefileName.c_str(), "clean")
+      << this->BuildMakeCommand(make, makefileName.c_str(), "clean", makeFlags)
       << "\" />\n"
       << "\" />\n"
         "            <DistClean command=\""
         "            <DistClean command=\""
-      << this->BuildMakeCommand(make, makefileName.c_str(), "clean")
+      << this->BuildMakeCommand(make, makefileName.c_str(), "clean", makeFlags)
       << "\" />\n"
       << "\" />\n"
         "         </MakeCommands>\n"
         "         </MakeCommands>\n"
         "      </Target>\n";
         "      </Target>\n";
@@ -802,9 +809,15 @@ int cmExtraCodeBlocksGenerator::GetCBTargetType(cmGeneratorTarget* target)
 // make
 // make
 std::string cmExtraCodeBlocksGenerator::BuildMakeCommand(
 std::string cmExtraCodeBlocksGenerator::BuildMakeCommand(
              const std::string& make, const char* makefile,
              const std::string& make, const char* makefile,
-             const std::string& target)
+             const std::string& target, const std::string& makeFlags)
 {
 {
   std::string command = make;
   std::string command = make;
+  if (makeFlags.size() > 0)
+    {
+    command += " ";
+    command += makeFlags;
+    }
+
   std::string generator = this->GlobalGenerator->GetName();
   std::string generator = this->GlobalGenerator->GetName();
   if (generator == "NMake Makefiles")
   if (generator == "NMake Makefiles")
     {
     {

+ 5 - 2
Source/cmExtraCodeBlocksGenerator.h

@@ -54,13 +54,16 @@ private:
   std::string GetCBCompilerId(const cmMakefile* mf);
   std::string GetCBCompilerId(const cmMakefile* mf);
   int GetCBTargetType(cmGeneratorTarget* target);
   int GetCBTargetType(cmGeneratorTarget* target);
   std::string BuildMakeCommand(const std::string& make, const char* makefile,
   std::string BuildMakeCommand(const std::string& make, const char* makefile,
-                               const std::string& target);
+                               const std::string& target,
+                               const std::string& makeFlags);
   void AppendTarget(cmGeneratedFileStream& fout,
   void AppendTarget(cmGeneratedFileStream& fout,
                     const std::string& targetName,
                     const std::string& targetName,
                     cmGeneratorTarget* target,
                     cmGeneratorTarget* target,
                     const char* make,
                     const char* make,
                     const cmLocalGenerator* lg,
                     const cmLocalGenerator* lg,
-                    const char* compiler);
+                    const char* compiler,
+                    const std::string& makeFlags
+                   );
 
 
 };
 };