cmake-build-extension icon indicating copy to clipboard operation
cmake-build-extension copied to clipboard

Add support for parallel build jobs on CMake

Open kdewald opened this issue 1 year ago • 4 comments

This should help speed up the builds of projects that have a large number of files that need to be compiled.

kdewald avatar Sep 16 '22 16:09 kdewald

This needs https://github.com/diegoferigo/cmake-build-extension/pull/38 landed before we can proceed.

kdewald avatar Sep 16 '22 17:09 kdewald

I'm not really sure about this PR @kdewald, the usage of Ninja was meant as a multiplatform solution that compiles jobs by default in parallel and automatically computes the right number of jobs depending on the hardware.

This PR enforces the default -j1, therefore all the automatic capability of Ninja is hindered.

I'm not very familiar with Windows builds, but on Linux the default generator is -G "Unix Makefiles" that can be selected as soon as #35 lands. In this case, specifying the number of jobs is a nice (optional) feature since by default it uses -j1.

I agree that making the feature optional is better. One weird thing I noticed at work is that for some reason building using Ninja seems to take much longer, so I'm not sure what could be happening there.

kdewald avatar Sep 19 '22 03:09 kdewald

One weird thing I noticed at work is that for some reason building using Ninja seems to take much longer, so I'm not sure what could be happening there.

Is your work setup based on Windows? Does your proejct use the gcc or the MSVC compiler? In my limited experience, setting up Ninja with MSVC is not straightforward. If I recall well, there were two alternatives:

  1. Prepare the terminal calling vcvars and then configure the project with -GNinja.
  2. Configure the project with -GNinja in a visual studio terminal (I remember there's a different terminal app in the windows menu just for VS, can't recall the precise name. It already opens with configured env vars).

Please note that the Windows jobs in CI select gcc, not the MSVC compiler:

[...]
  -- The C compiler identification is GNU 11.2.0
  -- The CXX compiler identification is GNU 11.2.0
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - done
  -- Check for working C compiler: C:/ProgramData/chocolatey/bin/gcc.exe - skipped
  -- Detecting C compile features
  -- Detecting C compile features - done
  -- Detecting CXX compiler ABI info
  -- Detecting CXX compiler ABI info - done
  -- Check for working CXX compiler: C:/ProgramData/chocolatey/bin/c++.exe - skipped
  -- Detecting CXX compile features
  -- Detecting CXX compile features - done
  -- Found Python3: C:/hostedtoolcache/windows/Python/3.8.10/x64/python3.exe (found version "3.8.10") found components: Interpreter Development.Module NumPy
  -- Found SWIG: C:/ProgramData/chocolatey/bin/swig.exe (found suitable version "4.0.2", minimum required is "4.0")
  -- Configuring done
  -- Generating done
[...]

diegoferigo avatar Sep 19 '22 07:09 diegoferigo

I just discovered that Ninja seems the default generator in VS2022:

Because Ninja is designed for fast build speeds instead of flexibility and function, it's set as the default. However, some CMake projects may be unable to correctly build using Ninja. If that occurs, you can instruct CMake to generate a Visual Studio project instead.

diegoferigo avatar Sep 19 '22 07:09 diegoferigo

Closing this stale PR. Feel free to comment or reopen in case of updates.

diegoferigo avatar May 14 '23 17:05 diegoferigo