Reputation: 1849
I am building my project using CMake. This project uses several external libraries, one of which does not specify its dependencies correctly. This causes my build to fail while running a parallel make job. I am wondering if there is a feature in cmake and/or make to run a certain piece of code serially and everything else in parallel.
More specifically I am using the FindCUDA.cmake module and within that using cuda_add_executable & cuda_add_library. I am fairly convinced, that while build the CUDA libraries, the FindCUDA module is not listing out its dependencies, causing race conditions while reading and writing intermediate object files to disk. Is there a way I can simply run the cuda_add_library macro serially while running the rest of my build in parallel?
Upvotes: 1
Views: 386
Reputation: 406
All CMake code is run single-threaded. CMake developers have been approached several times via bug tracker etc. if they could implement some parallel features but this has been rejected every time.
As of now (current CMake v3.24.3) I am not aware of any parallel built-in feature. CMake does not execute in parallel at all. CMake provides a unified way to instruct the build system (MSBuild, Make, Ninja, ...) to build in parallel (see doc CMake -j
switch) but after that the responsibility is handed over to the build system.
It is hard to synchronize any outputs of other software via CMake if it is not supported by CMake.
If your project structure in CMake supports it you could circumvent this limitation by using the approach described usr1234567
's answer (here).
Upvotes: 1
Reputation: 23294
As far as I know, you cannot influence build parallelism per target. But you can work around this.
You can build your target (or multiple targets with repeated calls) first that needs to be sequentially build
cmake --build . --target seq_target -j 1
Then you can build the whole project, so everything left can be build in parallel. The already built is not built again, so no error will occur:
cmake --build . -j 8
Upvotes: 0