Runs cmake to build binaries.
(self, my_env: Dict[str, str])
| 345 | self.run(args, env=my_env) |
| 346 | |
| 347 | def build(self, my_env: Dict[str, str]) -> None: |
| 348 | "Runs cmake to build binaries." |
| 349 | |
| 350 | from .env import build_type |
| 351 | |
| 352 | build_args = [ |
| 353 | "--build", |
| 354 | ".", |
| 355 | "--target", |
| 356 | "install", |
| 357 | "--config", |
| 358 | build_type.build_type_string, |
| 359 | ] |
| 360 | |
| 361 | # Determine the parallelism according to the following |
| 362 | # priorities: |
| 363 | # 1) MAX_JOBS environment variable |
| 364 | # 2) If using the Ninja build system, delegate decision to it. |
| 365 | # 3) Otherwise, fall back to the number of processors. |
| 366 | |
| 367 | # Allow the user to set parallelism explicitly. If unset, |
| 368 | # we'll try to figure it out. |
| 369 | max_jobs = os.getenv("MAX_JOBS") |
| 370 | |
| 371 | if max_jobs is not None or not USE_NINJA: |
| 372 | # Ninja is capable of figuring out the parallelism on its |
| 373 | # own: only specify it explicitly if we are not using |
| 374 | # Ninja. |
| 375 | |
| 376 | # This lists the number of processors available on the |
| 377 | # machine. This may be an overestimate of the usable |
| 378 | # processors if CPU scheduling affinity limits it |
| 379 | # further. In the future, we should check for that with |
| 380 | # os.sched_getaffinity(0) on platforms that support it. |
| 381 | max_jobs = max_jobs or str(multiprocessing.cpu_count()) |
| 382 | |
| 383 | # This ``if-else'' clause would be unnecessary when cmake |
| 384 | # 3.12 becomes minimum, which provides a '-j' option: |
| 385 | # build_args += ['-j', max_jobs] would be sufficient by |
| 386 | # then. Until then, we use "--" to pass parameters to the |
| 387 | # underlying build system. |
| 388 | build_args += ["--"] |
| 389 | if IS_WINDOWS and not USE_NINJA: |
| 390 | # We are likely using msbuild here |
| 391 | build_args += [f"/p:CL_MPCount={max_jobs}"] |
| 392 | else: |
| 393 | build_args += ["-j", max_jobs] |
| 394 | self.run(build_args, my_env) |