Skip to content

[bug] tools.build:jobs is ignored for MSBUILD with CMake & default is wrong #19384

@stevenwdv

Description

@stevenwdv

Describe the bug

tools.build:jobs is ignored on Windows with CMake toolchain and MSBUILD (Visual Studio ...) CMake generator.

It seems cmake.py only adds parallelism flags per build tool, and doesn't know how to add them for MSBUILD. However, there is tools.microsoft.msbuild:max_cpu_count which seems to accomplish the same thing but for MSBUILD.

# Arguments related to parallel
njobs = build_jobs(conanfile)
if njobs and ("Makefiles" in generator or "Ninja" in generator) and "NMake" not in generator:
args.append("-j{}".format(njobs))
maxcpucount = conanfile.conf.get("tools.microsoft.msbuild:max_cpu_count", check_type=int)
if maxcpucount is not None and "Visual Studio" in generator:
args.append(f"/m:{maxcpucount}" if maxcpucount > 0 else "/m")

  1. Why is this tools.microsoft.msbuild:max_cpu_count separate from tools.build:jobs?
  2. Also, the docs on tools.build:jobs say "default: max CPUs", but this apparently doesn't apply here, as MSBUILD by default uses no paralellism.

Since CMake 3.12 it's possible to just pass --parallel (-j) to cmake --build itself, instead of to the build tool (after --). You could consider adopting this approach instead, as it should be more portable.

How to reproduce it

For example:

On Windows with Visual Studio:

$ conan install --requires 'abseil/20250814.0' --build='abseil/*' -c:a 'tools.build:jobs=20'
[...]
abseil/20250814.0: Running CMake.build()
abseil/20250814.0: RUN: cmake --build "C:\Users\pep\.conan2\p\b\absei97ce99baaf616\b\build" --config Release
[...]

On Linux with Ninja: (expected behavior)

$ conan install --requires 'abseil/20250814.0' --build='abseil/*' -c:a 'tools.build:jobs=20'
[...]
abseil/20250814.0: Running CMake.build()
abseil/20250814.0: RUN: cmake --build "/home/swdv/.conan2/p/b/absei5aae6cef00263/b/build/Release" -- -j20
[...]

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions